Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
df8543d8
IoTSharp
项目概览
IoTSharp
/
IoTSharp
8 个月 前同步成功
通知
15
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
df8543d8
编写于
5月 21, 2019
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add RunAsEnv Used to run the environment adaptively
上级
b6d308d9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
123 addition
and
18 deletion
+123
-18
IoTSharp/Extensions/MiscExtension.cs
IoTSharp/Extensions/MiscExtension.cs
+118
-0
IoTSharp/IoTSharp.csproj
IoTSharp/IoTSharp.csproj
+1
-0
IoTSharp/Program.cs
IoTSharp/Program.cs
+2
-2
README.md
README.md
+2
-16
未找到文件。
IoTSharp/Extensions/MiscExtension.cs
浏览文件 @
df8543d8
using
IoTSharp.Data
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Hosting.WindowsServices
;
using
Microsoft.AspNetCore.Mvc
;
using
System
;
using
System.Diagnostics
;
using
System.Reflection
;
using
System.Runtime.InteropServices
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Extensions
...
...
@@ -28,5 +32,119 @@ namespace IoTSharp.Extensions
}
});
}
public
static
IWebHostBuilder
UseContentRootAsEnv
(
this
IWebHostBuilder
hostBuilder
)
{
bool
IsWindowsService
=
false
;
Encoding
.
RegisterProvider
(
CodePagesEncodingProvider
.
Instance
);
if
(
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
))
{
using
(
var
process
=
GetParent
(
Process
.
GetCurrentProcess
()))
{
IsWindowsService
=
process
!=
null
&&
process
.
ProcessName
==
"services"
;
}
}
if
(
Environment
.
CommandLine
.
Contains
(
"--usebasedirectory"
)
||
(
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
)
&&
IsWindowsService
))
{
hostBuilder
.
UseContentRoot
(
AppContext
.
BaseDirectory
);
}
else
{
if
(!
Debugger
.
IsAttached
)
{
hostBuilder
.
UseContentRoot
(
System
.
IO
.
Directory
.
GetCurrentDirectory
());
}
}
return
hostBuilder
;
}
public
static
void
RunAsEnv
(
this
IWebHost
host
)
{
bool
IsWindowsService
=
false
;
Encoding
.
RegisterProvider
(
CodePagesEncodingProvider
.
Instance
);
if
(
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
))
{
using
(
var
process
=
GetParent
(
Process
.
GetCurrentProcess
()))
{
IsWindowsService
=
process
!=
null
&&
process
.
ProcessName
==
"services"
;
}
}
if
(
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
)
&&
IsWindowsService
)
{
System
.
IO
.
Directory
.
SetCurrentDirectory
(
AppContext
.
BaseDirectory
);
host
.
RunAsService
();
}
else
{
if
(
Environment
.
CommandLine
.
Contains
(
"--usebasedirectory"
))
{
System
.
IO
.
Directory
.
SetCurrentDirectory
(
AppContext
.
BaseDirectory
);
}
host
.
Run
();
}
}
private
static
Process
GetParent
(
Process
child
)
{
var
parentId
=
0
;
var
handle
=
CreateToolhelp32Snapshot
(
TH32CS_SNAPPROCESS
,
0
);
if
(
handle
==
IntPtr
.
Zero
)
{
return
null
;
}
var
processInfo
=
new
PROCESSENTRY32
{
dwSize
=
(
uint
)
Marshal
.
SizeOf
(
typeof
(
PROCESSENTRY32
))
};
if
(!
Process32First
(
handle
,
ref
processInfo
))
{
return
null
;
}
do
{
if
(
child
.
Id
==
processInfo
.
th32ProcessID
)
{
parentId
=
(
int
)
processInfo
.
th32ParentProcessID
;
}
}
while
(
parentId
==
0
&&
Process32Next
(
handle
,
ref
processInfo
));
if
(
parentId
>
0
)
{
return
Process
.
GetProcessById
(
parentId
);
}
return
null
;
}
private
static
uint
TH32CS_SNAPPROCESS
=
2
;
[
DllImport
(
"kernel32.dll"
)]
public
static
extern
bool
Process32Next
(
IntPtr
hSnapshot
,
ref
PROCESSENTRY32
lppe
);
[
DllImport
(
"kernel32.dll"
,
SetLastError
=
true
)]
public
static
extern
IntPtr
CreateToolhelp32Snapshot
(
uint
dwFlags
,
uint
th32ProcessID
);
[
DllImport
(
"kernel32.dll"
)]
public
static
extern
bool
Process32First
(
IntPtr
hSnapshot
,
ref
PROCESSENTRY32
lppe
);
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
PROCESSENTRY32
{
public
uint
dwSize
;
public
uint
cntUsage
;
public
uint
th32ProcessID
;
public
IntPtr
th32DefaultHeapID
;
public
uint
th32ModuleID
;
public
uint
cntThreads
;
public
uint
th32ParentProcessID
;
public
int
pcPriClassBase
;
public
uint
dwFlags
;
[
MarshalAs
(
UnmanagedType
.
ByValTStr
,
SizeConst
=
260
)]
public
string
szExeFile
;
}
}
}
\ No newline at end of file
IoTSharp/IoTSharp.csproj
浏览文件 @
df8543d8
...
...
@@ -45,6 +45,7 @@
<RpmDependency Include="libicu" Version="50.1.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="2.2.0" />
<PackageReference Include="Packaging.Targets" Version="0.1.78" />
</ItemGroup>
...
...
IoTSharp/Program.cs
浏览文件 @
df8543d8
...
...
@@ -4,6 +4,7 @@ using System.IO;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
IoTSharp.Extensions
;
using
Microsoft.AspNetCore
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.Extensions.Configuration
;
...
...
@@ -15,8 +16,7 @@ namespace IoTSharp
{
public
static
void
Main
(
string
[]
args
)
{
Encoding
.
RegisterProvider
(
CodePagesEncodingProvider
.
Instance
);
CreateWebHostBuilder
(
args
).
Build
().
Run
();
CreateWebHostBuilder
(
args
).
Build
().
RunAsEnv
();
}
public
static
IWebHostBuilder
CreateWebHostBuilder
(
string
[]
args
)
=>
...
...
README.md
浏览文件 @
df8543d8
...
...
@@ -17,21 +17,7 @@ IoTSharp is an open-source IoT platform for data collection, processing, visuali
-
[
Stackoverflow
](
http://stackoverflow.com/questions/tagged/iotsharp
)
## Documentation
## How to install
### Linux
-
mkdir /var/iotsharp
-
cp ./
*
/var/iotsharp/
-
chmod 777 IoTSharp
-
cp iotsharp.service /etc/systemd/system/iotsharp.service
-
sudo systemctl enable /etc/systemd/system/iotsharp.service
-
sudo systemctl start iotsharp.service
-
sudo journalctl -fu iotsharp.service
-
http://127.0.0.1:5000/
### Windows
-
sc create iotsharp binPath= "D:
\i
otsharp
\I
oTSharp.exe" displayname= "IoTSharp" start= auto
## [Document](https://docs.iotsharp.io)
![
IotSharp Logo
](
docs/images/iot_sharp_logo.png
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录