Browse Source

MSHO.Collection.Service

hudou 5 years ago
parent
commit
3c97b2ae34
28 changed files with 3672 additions and 0 deletions
  1. 205 0
      MSHO.Collection.Service/MSHO.Collection.DataAccess/MSHO.Collection.DataAccess.csproj
  2. 36 0
      MSHO.Collection.Service/MSHO.Collection.DataAccess/Properties/AssemblyInfo.cs
  3. 37 0
      MSHO.Collection.Service/MSHO.Collection.Service.sln
  4. 41 0
      MSHO.Collection.Service/MSHO.Collection.Service/App.config
  5. 161 0
      MSHO.Collection.Service/MSHO.Collection.Service/ClearHistoryFileService.cs
  6. 73 0
      MSHO.Collection.Service/MSHO.Collection.Service/Configuration.cs
  7. 68 0
      MSHO.Collection.Service/MSHO.Collection.Service/Helper.cs
  8. 14 0
      MSHO.Collection.Service/MSHO.Collection.Service/IO/DataTypeConst.cs
  9. 318 0
      MSHO.Collection.Service/MSHO.Collection.Service/IO/IOServer.Partial.cs
  10. 1216 0
      MSHO.Collection.Service/MSHO.Collection.Service/IO/IOServer.Process.Partial.cs
  11. 177 0
      MSHO.Collection.Service/MSHO.Collection.Service/IO/IOServer.cs
  12. 49 0
      MSHO.Collection.Service/MSHO.Collection.Service/IO/JsonSerializable.cs
  13. 108 0
      MSHO.Collection.Service/MSHO.Collection.Service/IO/Message.cs
  14. 243 0
      MSHO.Collection.Service/MSHO.Collection.Service/IO/Msg.cs
  15. 108 0
      MSHO.Collection.Service/MSHO.Collection.Service/MSHO.Collection.Service.csproj
  16. 40 0
      MSHO.Collection.Service/MSHO.Collection.Service/MainService.Designer.cs
  17. 45 0
      MSHO.Collection.Service/MSHO.Collection.Service/MainService.cs
  18. 123 0
      MSHO.Collection.Service/MSHO.Collection.Service/MainService.resx
  19. 25 0
      MSHO.Collection.Service/MSHO.Collection.Service/Program.cs
  20. 60 0
      MSHO.Collection.Service/MSHO.Collection.Service/ProjectInstaller.Designer.cs
  21. 19 0
      MSHO.Collection.Service/MSHO.Collection.Service/ProjectInstaller.cs
  22. 129 0
      MSHO.Collection.Service/MSHO.Collection.Service/ProjectInstaller.resx
  23. 36 0
      MSHO.Collection.Service/MSHO.Collection.Service/Properties/AssemblyInfo.cs
  24. 16 0
      MSHO.Collection.Service/MSHO.Collection.Service/SystemLogSource.cs
  25. 40 0
      MSHO.Collection.Service/Test/App.config
  26. 169 0
      MSHO.Collection.Service/Test/Program.cs
  27. 36 0
      MSHO.Collection.Service/Test/Properties/AssemblyInfo.cs
  28. 80 0
      MSHO.Collection.Service/Test/Test.csproj

+ 205 - 0
MSHO.Collection.Service/MSHO.Collection.DataAccess/MSHO.Collection.DataAccess.csproj

@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{91DC72E1-87FF-4C81-B9F5-E65861C3EBDF}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>MSHO.Collection.DataAccess</RootNamespace>
+    <AssemblyName>MSHO.Collection.DataAccess</AssemblyName>
+    <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>TRACE;DEBUG;NATIVE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE;NATIVE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="EntityFramework">
+      <HintPath>..\..\References\EntityFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer">
+      <HintPath>..\..\References\EntityFramework.SqlServer.dll</HintPath>
+    </Reference>
+    <Reference Include="HK.File.Client">
+      <HintPath>..\..\References\HK.File.Client.dll</HintPath>
+    </Reference>
+    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\References\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.ComponentModel.Composition" />
+    <Reference Include="System.ComponentModel.DataAnnotations" />
+    <Reference Include="System.Configuration" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\MSHOReportService.cs" />
+    <Compile Include="..\..\MSHO.Collection.DataAccess\SystemSettingService.cs" />
+    <Compile Include="..\..\MSHO.Collection.DataAccess\MSHOService.cs" />
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Enums\SystemLogTypeEnum.cs">
+      <Link>Enums\SystemLogTypeEnum.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Enums\WEIGHTING_FILE_TYPE.cs">
+      <Link>Enums\WEIGHTING_FILE_TYPE.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\User.cs">
+      <Link>Models\User.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\DictionaryType.cs">
+      <Link>Models\DictionaryType.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Role.cs">
+      <Link>Models\Role.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Station.cs">
+      <Link>Models\Station.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\SystemLog.cs">
+      <Link>Models\SystemLog.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\CollectConfig.cs">
+      <Link>Models\CollectConfig.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Device.cs">
+      <Link>Models\Device.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\OverloadRange.cs">
+      <Link>Models\OverloadRange.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\LimitStandard.cs">
+      <Link>Models\LimitStandard.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Weighting.cs">
+      <Link>Models\Weighting.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Helper\FileService.cs">
+      <Link>Helper\FileService.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Helper\JsonSerializable.cs">
+      <Link>Helper\JsonSerializable.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Helper\UtilsHelper.cs">
+      <Link>Helper\UtilsHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\UserRoles\RoleClaim.cs">
+      <Link>Models\UserRoles\RoleClaim.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\UserRoles\UserClaim.cs">
+      <Link>Models\UserRoles\UserClaim.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\UserRoles\UserLogin.cs">
+      <Link>Models\UserRoles\UserLogin.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\UserRoles\UserRole.cs">
+      <Link>Models\UserRoles\UserRole.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\UserRoles\UserToken.cs">
+      <Link>Models\UserRoles\UserToken.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\DbContexts\BaseService.cs">
+      <Link>DbContexts\BaseService.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\DbContexts\MSHO_DBContext.cs">
+      <Link>DbContexts\MSHO_DBContext.cs</Link>
+    </Compile>
+<Compile Include="..\..\MSHO.Collection.DataAccess\ViewModels\TodayOverload.cs">
+      <Link>ViewModels\TodayOverload.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\ClientModels\Bus_Weighting.cs">
+      <Link>ClientModels\Bus_Weighting.cs</Link>
+    </Compile>
+<Compile Include="..\..\MSHO.Collection.DataAccess\ClientModels\Kdtc_Weighting.cs">
+      <Link>ClientModels\Kdtc_Weighting.cs</Link>
+    </Compile>
+<Compile Include="..\..\MSHO.Collection.DataAccess\ClientModels\Weighting.cs">
+      <Link>ClientModels\Weighting.cs</Link>
+    </Compile>
+<Compile Include="..\..\MSHO.Collection.DataAccess\ClientModels\SQL2000_DiBangData_Weighting.cs">
+      <Link>ClientModels\SQL2000_DiBangData_Weighting.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\ClientModels\SQL2000_oreManageDBCli_Weighting.cs">
+      <Link>ClientModels\SQL2000_oreManageDBCli_Weighting.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\ClientModels\SQL2000_oreManageDBCli_2_Weighting.cs">
+      <Link>ClientModels\SQL2000_oreManageDBCli_2_Weighting.cs</Link>
+    </Compile>
+<Compile Include="..\..\MSHO.Collection.DataAccess\ClientModels\SQL2000_oreManageDBCli_3_Weighting.cs">
+      <Link>ClientModels\SQL2000_oreManageDBCli_3_Weighting.cs</Link>
+    </Compile>
+<Compile Include="..\..\MSHO.Collection.DataAccess\ClientModels\LowSpeedNew_Weighting.cs">
+      <Link>ClientModels\LowSpeedNew_Weighting.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\ClientModels\Access_Weighting.cs">
+      <Link>ClientModels\Access_Weighting.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\ClientModels\ClientDataType.cs">
+      <Link>ClientModels\ClientDataType.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Systems\MenuOperation.cs">
+      <Link>Models\Systems\MenuOperation.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Systems\RoleMenu.cs">
+      <Link>Models\Systems\RoleMenu.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Systems\RoleMenuOperation.cs">
+      <Link>Models\Systems\RoleMenuOperation.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Systems\SystemMenu.cs">
+      <Link>Models\Systems\SystemMenu.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Systems\SystemMenuOperation.cs">
+      <Link>Models\Systems\SystemMenuOperation.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Organizations\Organization.cs">
+      <Link>Models\Organizations\Organization.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Organizations\OrganizationDepartment.cs">
+      <Link>Models\Organizations\OrganizationDepartment.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\Models\Organizations\OrganizationJob.cs">
+      <Link>Models\Organizations\OrganizationJob.cs</Link>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\ViewModels\GetReportMonthSame_Resp.cs">
+      <Link>ViewModels\GetReportMonthSame_Resp.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\ViewModels\GetReportStationTotal_Resp.cs">
+      <Link>ViewModels\GetReportStationTotal_Resp.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\ViewModels\GetReportStation_Resp.cs">
+      <Link>ViewModels\GetReportStation_Resp.cs</Link>
+    </Compile>
+    <Compile Include="..\..\MSHO.Collection.DataAccess\ViewModels\GetReportTimeRangeOverload_Resp.cs">
+      <Link>ViewModels\GetReportTimeRangeOverload_Resp.cs</Link>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 36 - 0
MSHO.Collection.Service/MSHO.Collection.DataAccess/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("MSHO.Collection.DataAccess")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("MSHO.Collection.DataAccess")]
+[assembly: AssemblyCopyright("Copyright ©  2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("91dc72e1-87ff-4c81-b9f5-e65861c3ebdf")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 37 - 0
MSHO.Collection.Service/MSHO.Collection.Service.sln

@@ -0,0 +1,37 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.27004.2006
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSHO.Collection.Service", "MSHO.Collection.Service\MSHO.Collection.Service.csproj", "{86E705F3-58F6-4158-A572-7AAB2ADCA8DE}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{49780335-069D-4D82-BC84-CAE1D79F4CBD}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSHO.Collection.DataAccess", "MSHO.Collection.DataAccess\MSHO.Collection.DataAccess.csproj", "{91DC72E1-87FF-4C81-B9F5-E65861C3EBDF}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{86E705F3-58F6-4158-A572-7AAB2ADCA8DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{86E705F3-58F6-4158-A572-7AAB2ADCA8DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{86E705F3-58F6-4158-A572-7AAB2ADCA8DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{86E705F3-58F6-4158-A572-7AAB2ADCA8DE}.Release|Any CPU.Build.0 = Release|Any CPU
+		{49780335-069D-4D82-BC84-CAE1D79F4CBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{49780335-069D-4D82-BC84-CAE1D79F4CBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{49780335-069D-4D82-BC84-CAE1D79F4CBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{49780335-069D-4D82-BC84-CAE1D79F4CBD}.Release|Any CPU.Build.0 = Release|Any CPU
+		{91DC72E1-87FF-4C81-B9F5-E65861C3EBDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{91DC72E1-87FF-4C81-B9F5-E65861C3EBDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{91DC72E1-87FF-4C81-B9F5-E65861C3EBDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{91DC72E1-87FF-4C81-B9F5-E65861C3EBDF}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {EA15E10F-638F-41E2-9B1C-6981C8E1A0A4}
+	EndGlobalSection
+EndGlobal

+ 41 - 0
MSHO.Collection.Service/MSHO.Collection.Service/App.config

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+  <configSections>
+    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+  </configSections>
+  <entityFramework>
+    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
+      <parameters>
+        <parameter value="mssqllocaldb" />
+      </parameters>
+    </defaultConnectionFactory>
+    <providers>
+      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
+    </providers>
+  </entityFramework>
+  <system.data>
+    <DbProviderFactories>
+      <remove invariant="MySql.Data.MySqlClient" />
+      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
+    </DbProviderFactories>
+  </system.data>
+
+  <connectionStrings>
+    <add name="MSHO.DBConnection" connectionString="Data Source=101.0.0.30;Initial Catalog=MSHO;User ID=sa;Password=ycd123;" providerName="System.Data.SqlClient" />
+  </connectionStrings>
+
+  <appSettings>
+    <add key="IP" value=""/>
+    <add key="Port" value="9001"/>
+    <add key="MaxConnection" value="100"/>
+    <add key="BufferSize" value="4096"/>
+    <add key="PrivateKey" value=""/>
+    <add key="FileServerConnection" value="Data Source=localhost;Initial Catalog=MSHO;buffer size=524288;" />
+    <add key="HardDisk" value="C"/>
+    <add key="MSHO_DIR" value="D:\MSHO_FILES"/>
+  </appSettings>
+  
+  <startup> 
+    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
+  </startup>
+</configuration>

+ 161 - 0
MSHO.Collection.Service/MSHO.Collection.Service/ClearHistoryFileService.cs

@@ -0,0 +1,161 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service
+{
+    public class ClearHistoryFileService
+    {
+        private System.Threading.Timer m_Timer;
+        private bool m_Running = false;
+        private bool m_IsRunning = false;
+
+        public ClearHistoryFileService() { }
+
+        public void Start()
+        {
+            m_Running = true;
+            m_Timer = new System.Threading.Timer(delegate (object state)
+            {
+                try
+                {
+                    if (m_IsRunning == false)
+                    {
+                        m_IsRunning = true;
+
+                        if (m_Running)
+                        {
+                            try
+                            {
+                                var service = System.ServiceProcess.ServiceController.GetServices();
+                                foreach (var sc in service) {
+                                    if (string.Compare(sc.ServiceName, "HK.File.Service", true) == 0)
+                                    {
+                                        if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped)
+                                        {
+                                            try
+                                            {
+                                                sc.Start();
+                                            }
+                                            catch
+                                            {
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                            catch
+                            {
+                            }
+                        }
+
+
+                        if (m_Running)
+                        {
+                            var hardDisk = System.Configuration.ConfigurationManager.AppSettings["HardDisk"];
+                            if (!string.IsNullOrEmpty(hardDisk))
+                            {
+                                var freeSpace = GetHardDiskSpace(hardDisk);
+                                while (m_Running && freeSpace <= 10)
+                                {
+                                    var fileQuery = MSHO.Collection.DataAccess.MSHOService.Instance.GetWeightingFiles();
+                                    var files = fileQuery.Take(100).ToArray();
+                                    foreach (var file in files)
+                                    {
+                                        try
+                                        {
+                                            MSHO.Collection.DataAccess.MSHOService.Instance.DeleteWeightingFile(file.ID);
+                                        }
+                                        catch(Exception ex) {
+                                            Console.WriteLine(ex.Message);
+                                        }
+                                        if (m_Running == false)
+                                        {
+                                            break;
+                                        }
+                                    }
+
+                                    var dir = System.Configuration.ConfigurationManager.AppSettings["MSHO_DIR"];
+
+                                    if (m_Running)
+                                    {
+                                        var logDir = new System.IO.DirectoryInfo(System.IO.Path.Combine(dir, "__Log"));
+                                        foreach (var file in logDir.GetFiles())
+                                        {
+                                            try
+                                            {
+                                                file.Delete();
+                                            }
+                                            catch { }
+                                        }
+                                    }
+
+                                    //if (m_Running)
+                                    //{
+                                    //    var tempDir = new System.IO.DirectoryInfo(System.IO.Path.Combine(dir, "__Temp"));
+                                    //    foreach (var file in tempDir.GetFiles())
+                                    //    {
+                                    //        try
+                                    //        {
+                                    //            file.Delete();
+                                    //        }
+                                    //        catch { }
+                                    //    }
+                                    //}
+
+                                    freeSpace = GetHardDiskSpace(hardDisk);
+                                }
+                            }
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    MSHO.Collection.DataAccess.MSHOService.Instance.SaveSystemLog("MSHO.Collection.Service", "ClearHistoryFileService", ex);
+                }
+                finally {
+                    m_IsRunning = false;
+                }
+            }, this, new TimeSpan(0, 0, 0), new TimeSpan(0, 5, 0));
+        }
+
+        /// <summary>
+        /// GB
+        /// </summary>
+        /// <param name="str_HardDiskName"></param>
+        /// <returns></returns>
+        public long GetHardDiskSpace(string str_HardDiskName)
+        {
+            long totalSize = 0;
+            try
+            {
+                str_HardDiskName = str_HardDiskName + ":\\";
+                System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
+                foreach (System.IO.DriveInfo drive in drives)
+                {
+                    if (drive.Name == str_HardDiskName)
+                    {
+                        totalSize = drive.TotalFreeSpace / (1024 * 1024 * 1024);
+                        break;
+                    }
+                }
+            }
+            catch {
+
+            }
+            return totalSize;
+        }
+
+        public void Stop() {
+            m_Running = false;
+            if (m_Timer != null)
+            {
+                m_Timer.Dispose();
+                m_Timer = null;
+            }
+        }
+
+    }
+}

+ 73 - 0
MSHO.Collection.Service/MSHO.Collection.Service/Configuration.cs

@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service
+{
+    public class Configuration
+    {
+        private static Configuration m_Instance = new Configuration();
+        private Configuration() { }
+
+        public static Configuration Instance {
+            get {
+                return m_Instance;
+            }
+        }
+
+        private string AppSetting(string key) {
+            return System.Configuration.ConfigurationManager.AppSettings[key];
+        }
+
+        public string IP {
+            get {
+                return AppSetting("IP");
+            }
+        }
+
+        public string FileServerConnection {
+            get {
+                return AppSetting("FileServerConnection");
+            }
+        }
+
+        public int Port {
+            get {
+                int n = 0;
+                if (int.TryParse(AppSetting("Port"), out n)) {
+                    return n;
+                }
+
+                return 8888;
+            }
+        }
+
+        public int MaxConnection {
+            get {
+                int n = 0;
+                if (int.TryParse(AppSetting("MaxConnection"), out n))
+                {
+                    return n;
+                }
+
+                return 100;
+            }
+        }
+
+        public int BufferSize {
+            get {
+                int n = 0;
+                if (int.TryParse(AppSetting("BufferSize"), out n))
+                {
+                    return n;
+                }
+
+                return 4096;
+            }
+        }
+
+
+    }
+}

+ 68 - 0
MSHO.Collection.Service/MSHO.Collection.Service/Helper.cs

@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service
+{
+    public static class Helper {
+        
+        public static byte[] Int32ToBytes(this int n) {
+            var bytes = new byte[4];
+            bytes[0] = (byte)(n & 0xFF);
+            bytes[1] = (byte)(n >> 8 & 0xFF);
+            bytes[2] = (byte)(n >> 16 & 0xFF);
+            bytes[3] = (byte)(n >> 24 & 0xFF);
+
+            return bytes;
+        }
+
+        public static int BytesToInt32(this byte[] bytes, int index = 0) {
+            int n = 0;
+            if (bytes != null && bytes.Length >= 4) {
+                n = bytes[index + 3];
+                n = n << 8 | bytes[index + 2];
+                n = n << 8 | bytes[index + 1];
+                n = n << 8 | bytes[index + 0];
+            }
+
+            return n;
+        }
+
+        public static byte[] LongToBytes(this long n)
+        {
+            var bytes = new byte[sizeof(long)];
+            for (var i = 0; i < sizeof(long); i++) {
+                bytes[i] = (byte)((n >> (i*8)) & 0xFF);
+            }
+
+            return bytes;
+        }
+
+        public static long BytesToLong(this byte[] bytes, int index = 0)
+        {
+            long n = 0;
+            if (bytes != null && bytes.Length >= sizeof(long))
+            {
+                for (var i = sizeof(long) - 1; i >=0; i--) {
+                    n = n << 8 | bytes[index + i];
+                }
+            }
+
+            return n;
+        }
+
+        public static T GetEnum<T>(string val, T d) where T : struct
+        {
+            T result = default(T);
+            if (!Enum.TryParse<T>(val, out result))
+            {
+                result = d;
+            }
+
+            return result;
+
+        }
+    }
+}

+ 14 - 0
MSHO.Collection.Service/MSHO.Collection.Service/IO/DataTypeConst.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service.IO
+{
+    //public class DataTypeConst
+    //{
+    //    public const string Bus_Weighting = "Bus_Weighting";
+    //    public const string Access_Weighting = "Access_Weighting";
+    //}
+}

+ 318 - 0
MSHO.Collection.Service/MSHO.Collection.Service/IO/IOServer.Partial.cs

@@ -0,0 +1,318 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service.IO
+{
+    partial class IOServer
+    {
+        private object m_lock_client = new object();
+        private Dictionary<string, Task> m_ClientTask = new Dictionary<string, Task>();
+
+        public void StartClientTask(System.Net.Sockets.Socket client) {
+            var task = new System.Threading.Tasks.Task(ProcessClientMsg, client);
+            task.Start();
+        }
+
+        private void ProcessClientMsg(object state) {
+            var client = state as System.Net.Sockets.Socket;
+
+            try
+            {
+                do
+                {
+                    var msg = ReceiveMsg(client);
+                    if (msg == null)
+                    {
+#if DEBUG
+                        Console.WriteLine("msg == null");
+#endif
+                        break;
+                    }
+                    else if (msg.BadMsg)
+                    {
+                        SendMsg(client, new Message(new Msg()
+                        {
+                            Content = "错误的请求消息"
+                        }));
+                    } else if(msg.Length > (long)0) {
+                        var mm = Msg.ParseMsg(msg);
+                        if (mm != null)
+                        {
+                            switch (mm.MessageType)
+                            {
+                                case MessageTypeEnum.Connect:
+                                    ProcessConnectMsg(client, mm);
+                                    break;
+
+                                case MessageTypeEnum.Heart:
+                                    ProcessHeartMsg(client, mm);
+                                    break;
+
+                                case MessageTypeEnum.ReportData:
+                                    ProcessReportDataMsg(client, mm);
+                                    break;
+
+                                case MessageTypeEnum.ErrorData:
+                                    Process_Exception(client, mm);
+                                    break;
+
+                                case MessageTypeEnum.UploadFile:
+                                    Process_UploadFile(client, mm);
+                                    break;
+
+                                case MessageTypeEnum.GetUploadFile:
+                                    Process_GetUploadFile(client, mm);
+                                    break;
+                            }
+                        }
+                        else
+                        {
+                            SendMsg(client, new Message(new Msg()
+                            {
+                                Content = "错误的请求消息"
+                            }));
+                        }
+                    }
+                } while (m_Running);
+            }
+            catch (Exception ex)
+            {
+                MSHO.Collection.DataAccess.MSHOService.Instance.SaveSystemLog("MSHO.Collection.Service", "ProcessClientMsg", ex);
+            }
+            finally
+            {
+                if (client != null)
+                {
+                    try
+                    {
+#if DEBUG
+                        Console.WriteLine(".............................................断开客户端连接");
+#endif
+                        client.Close();
+                    }
+                    catch { }
+                }
+            }
+        }
+
+        private void ProcessReportDataMsg(System.Net.Sockets.Socket client, Msg data)
+        {
+#if DEBUG
+            Console.WriteLine("收到数据,开始处理");
+            var watch = new System.Diagnostics.Stopwatch();
+            watch.Start();
+#endif
+            var msg = new DataReportRespMsg();
+            msg.ClientCode = data.ClientCode;
+
+            var data_report = data as DataReportMsg;
+            if (data_report != null) {
+                switch (data_report.DataType) {
+                    case MSHO.Collection.DataAccess.ClientModels.ClientDataType.Bus_Weighting:
+                        Process_Bus_Weighting(msg, data_report);
+                        break;
+
+                    case MSHO.Collection.DataAccess.ClientModels.ClientDataType.Access_Weighting:
+                        Process_Access_Weighting(msg, data_report);
+                        break;
+
+                    case MSHO.Collection.DataAccess.ClientModels.ClientDataType.Kdtc_Weighting:
+                        Process_Kdtc_Weighting(msg, data_report);
+                        break;
+
+                    case MSHO.Collection.DataAccess.ClientModels.ClientDataType.SQL2000_DiBangData_Weighting:
+                        Process_SQL2000_DiBangData_Weighting(msg, data_report);
+                        break;
+
+                    case MSHO.Collection.DataAccess.ClientModels.ClientDataType.SQL2000_oreManageDBCli_Weighting:
+                        Process_SQL2000_oreManageDBCli_Weighting(msg, data_report);
+                        break;
+
+                    case MSHO.Collection.DataAccess.ClientModels.ClientDataType.SQL2000_oreManageDBCli_2_Weighting:
+                        Process_SQL2000_oreManageDBCli_2_Weighting(msg, data_report);
+                        break;
+
+                    case MSHO.Collection.DataAccess.ClientModels.ClientDataType.SQL2000_oreManageDBCli_3_Weighting:
+                        Process_SQL2000_oreManageDBCli_3_Weighting(msg, data_report);
+                        break;
+
+                    case MSHO.Collection.DataAccess.ClientModels.ClientDataType.LowSpeedNew_Weighting:
+                        Process_LowSpeedNew_Weighting(msg, data_report);
+                        break;
+                }
+            }
+            
+            SendMsg(client, new Message(msg));
+
+#if DEBUG
+            watch.Stop();
+            Console.WriteLine("处理完成SaveWeighting({0}): {1}", msg.ClientCode, watch.Elapsed);
+#endif
+        }
+
+
+        private void ProcessConnectMsg(System.Net.Sockets.Socket client, Msg connect) {
+#if DEBUG
+            Console.WriteLine("{0}获取配置", connect.ClientCode);
+#endif
+            var config = MSHO.Collection.DataAccess.MSHOService.Instance.GetCollectConfigByCode(connect.ClientCode);
+            if (config != null) {
+                var msg = new ConnectRespMsg();
+                msg.ClientCode = connect.ClientCode;
+                var serverConfig = config.ToServerConfig();
+                if (serverConfig != null) {
+                    serverConfig.LastSourceID = config.LastSourceID;
+                    serverConfig.LastSourceTime = config.LastSourceTime;
+                    msg.Content = serverConfig.ToJson();
+
+                    SendMsg(client, new Message(msg));
+                    return;
+                }
+            }
+
+
+            SendMsg(client, new Message(new Msg()
+            {
+                Content = "未知的采集编号"
+            }));
+        }
+
+        private void ProcessHeartMsg(System.Net.Sockets.Socket client, Msg heart)
+        {
+            var msg = new HeartRespMsg();
+            msg.ClientCode = heart.ClientCode;
+            msg.Time = DateTime.Now;
+            MSHO.Collection.DataAccess.MSHOService.Instance.UpdateDeviceStatus(heart.ClientCode);
+#if DEBUG
+            Console.WriteLine("心跳消息:{0}", heart.ClientCode);
+#endif
+            SendMsg(client, new Message(msg));
+        }
+
+        private void Process_UploadFile(System.Net.Sockets.Socket client, Msg data) {
+#if DEBUG
+            Console.WriteLine("开始处理文件...");
+#endif
+            var msg = new UploadFileMsgRespMsg();
+            msg.ClientCode = data.ClientCode;
+
+            var uploadFileMsg = data as UploadFileMsg;
+            if (uploadFileMsg != null) {
+                if (uploadFileMsg.WeightingID > 0)
+                {
+                    if (!string.IsNullOrEmpty(uploadFileMsg.FileStreamBase64))
+                    {
+                        msg.Result = MSHO.Collection.DataAccess.MSHOService.Instance.SaveWeightingFile(uploadFileMsg.ID, uploadFileMsg.WeightingID, uploadFileMsg.FileStreamBase64, uploadFileMsg.BufferLength);
+                    }
+                    else
+                    {
+                        msg.Result = true;
+                    }
+                }
+            }
+
+            SendMsg(client, new Message(msg));
+
+#if DEBUG
+            Console.WriteLine("...............处理文件完成");
+#endif
+        }
+
+        private void Process_GetUploadFile(System.Net.Sockets.Socket client, Msg data)
+        {
+            var msg = new GetUploadFileMsgRespMsg();
+            msg.ClientCode = data.ClientCode;
+
+            MSHO.Collection.DataAccess.Models.CollectConfig clientConfig = null;
+            if (m_CollectConfigs.ContainsKey(msg.ClientCode))
+            {
+                clientConfig = m_CollectConfigs[msg.ClientCode];
+            }
+            if (clientConfig == null)
+            {
+                clientConfig = MSHO.Collection.DataAccess.MSHOService.Instance.GetCollectConfigByCode(msg.ClientCode);
+            }
+
+            msg.WeightingFiles = MSHO.Collection.DataAccess.MSHOService.Instance.GetWeightingFileByDeviceID(clientConfig.DeviceID).Take(10).ToList();
+
+            SendMsg(client, new Message(msg));
+        }
+
+        private Message ReceiveMsg(System.Net.Sockets.Socket client)
+        {
+            try
+            {
+                var msg = new Message();
+                var buffer = new byte[sizeof(long)];
+                if (client.Connected)
+                {
+                    var len = client.Receive(buffer, 0, buffer.Length, System.Net.Sockets.SocketFlags.None);
+                    if (len > 0 && len == sizeof(long))
+                    {
+                        var length = Helper.BytesToLong(buffer);
+#if DEBUG
+                        if (length > 0)
+                        {
+                            Console.WriteLine("开始接收消息({0})", length);
+                        }
+#endif
+
+                        if (length > 0)
+                        {
+                            var stream = new System.IO.MemoryStream();
+                            while (stream.Length < length)
+                            {
+                                buffer = new byte[length];
+                                len = client.Receive(buffer, 0, buffer.Length, System.Net.Sockets.SocketFlags.None);
+                                if (len > 0)
+                                {
+                                    stream.Write(buffer, 0, len);
+                                }
+                                else
+                                {
+                                    msg.BadMsg = true;
+                                    break;
+                                }
+                            }
+
+                            msg.Write(stream.ToArray());
+                        }
+#if DEBUG
+                        if (msg.BadMsg == false && msg.Length > 0)
+                        {
+                            Console.WriteLine("................消息接收完成({0})", msg.Length);
+                        }
+#endif
+                    }
+                    else {
+                        msg.BadMsg = true;
+                    }
+                }
+
+                return msg;
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+            }
+            return null;
+        }
+
+        private void SendMsg(System.Net.Sockets.Socket client, Message msg)
+        {
+            if (m_Running && client != null)
+            {
+                if (client.Connected)
+                {
+                    var buffer = msg.ToBuffer();
+                    client.Send(buffer, 0, buffer.Length, System.Net.Sockets.SocketFlags.None);
+                }
+            }
+        }
+
+
+    }
+}

File diff suppressed because it is too large
+ 1216 - 0
MSHO.Collection.Service/MSHO.Collection.Service/IO/IOServer.Process.Partial.cs


+ 177 - 0
MSHO.Collection.Service/MSHO.Collection.Service/IO/IOServer.cs

@@ -0,0 +1,177 @@
+using System;
+using System.Linq;
+using System.Text;
+using System.Net;
+using System.Net.Sockets;
+using System.Threading;
+using System.Collections.Generic;
+
+namespace MSHO.Collection.Service.IO
+{
+    /// <summary>
+    /// IOCP服务主程序
+    /// </summary>
+    public partial class IOServer : IDisposable
+    {
+        private bool m_Running = false;
+        private bool m_Disposed = false;
+        private int m_MaxConnections;
+        private int m_BufferSize;
+        private string m_IPAddress;
+        private int m_Port;
+        private System.Net.Sockets.Socket m_ListenSocket;
+        private System.Threading.Tasks.Task m_ServerThread;
+
+        /// <summary>
+        /// IOCP服务主程序
+        /// </summary>
+        /// <param name="ip">IP地址</param>
+        /// <param name="port">端口</param>
+        /// <param name="maxConnections">最大连接数</param>
+        /// <param name="bufferSize">缓冲区大小</param>
+        public IOServer(string ip, int port, int maxConnections, int bufferSize)
+        {
+            #region check arguments
+            if (maxConnections <= 0)
+            {
+                throw new ArgumentException("invalid maxConnections");
+            }
+
+            if (bufferSize <= 0)
+            {
+                throw new ArgumentException("invalid bufferSize");
+            }
+
+            if (port <= 0)
+            {
+                throw new ArgumentException("invalid port");
+            }
+            #endregion
+
+            m_MaxConnections = maxConnections;
+            m_BufferSize = bufferSize;
+            m_IPAddress = ip;
+            m_Port = port;
+        }
+
+        /// <summary>
+        /// 启动服务
+        /// </summary>
+        public void Start()
+        {
+            m_ServerThread = new System.Threading.Tasks.Task(AcceptClient);
+            m_ServerThread.Start();
+        }
+
+        private void AcceptClient() {
+            m_Running = true;
+
+            var ipAddress = System.Net.IPAddress.Any;
+            if (!System.Net.IPAddress.TryParse(m_IPAddress, out ipAddress))
+            {
+                ipAddress = System.Net.IPAddress.Any;
+            }
+
+            m_ListenSocket = new System.Net.Sockets.Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+            m_ListenSocket.ReceiveBufferSize = m_BufferSize;
+            m_ListenSocket.SendBufferSize = m_BufferSize;
+            m_ListenSocket.ReceiveTimeout = 60 * 1000;
+            m_ListenSocket.SendTimeout = 30 * 1000;
+
+
+            if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6)
+            {
+                m_ListenSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
+                m_ListenSocket.Bind(new IPEndPoint(IPAddress.IPv6Any, m_Port));
+            }
+            else
+            {
+                m_ListenSocket.Bind(new IPEndPoint(IPAddress.Any, m_Port));
+            }
+
+            m_ListenSocket.Listen(m_MaxConnections);
+
+            try
+            {
+                while (m_Running)
+                {
+                    var client = m_ListenSocket.Accept();
+                    if (client == null)
+                    {
+                        break;
+                    }
+                    else
+                    {
+#if DEBUG
+                        Console.WriteLine("...........................................采集端连接");
+#endif
+                        client.ReceiveBufferSize = m_BufferSize;
+                        client.SendBufferSize = m_BufferSize;
+                        client.ReceiveTimeout = 60 * 1000;
+                        client.SendTimeout = 30 * 1000;
+                        StartClientTask(client);
+                    }
+                }
+            }
+            catch(Exception ex) {
+                MSHO.Collection.DataAccess.MSHOService.Instance.SaveSystemLog("MSHO.Collection.Service", "AcceptClient", ex);
+                Console.WriteLine(ex.Message);
+            }
+        }
+
+
+        #region Close
+        /// <summary>
+        /// 停止服务
+        /// </summary>
+        public void Stop()
+        {
+            if (!m_Disposed)
+            {
+                m_Running = false;
+                if (m_ListenSocket != null)
+                {
+                    try
+                    {
+                        m_ListenSocket.Shutdown(SocketShutdown.Both);
+                    }
+                    catch { }
+
+                    try
+                    {
+                        m_ListenSocket.Close();
+                    }
+                    catch { }
+                    m_ListenSocket = null;
+                }
+
+                if (m_ServerThread != null) {
+                    m_ServerThread = null;
+                }
+            }
+        }
+
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        private void Dispose(bool disposing)
+        {
+            if (!m_Disposed)
+            {
+                this.Stop();
+                m_Disposed = true;
+            }
+        }
+
+        ~IOServer()
+        {
+            Dispose(false);
+        }
+        #endregion
+
+    }
+
+}

+ 49 - 0
MSHO.Collection.Service/MSHO.Collection.Service/IO/JsonSerializable.cs

@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MSHO.Collection.Service.IO
+{
+    /// <summary>
+    /// 可序列化为JSON
+    /// </summary>
+    public class JsonSerializable
+    {
+        /// <summary>
+        /// 对象转json
+        /// </summary>
+        /// <returns></returns>
+        public static string ToJson(object obj) {
+            var ser = new Newtonsoft.Json.JsonSerializer();
+
+            var sb = new StringBuilder();
+            var writer = new System.IO.StringWriter(sb);
+            ser.Serialize(writer, obj);
+
+            return sb.ToString();
+        }
+
+        /// <summary>
+        /// json转对象
+        /// </summary>
+        /// <param name="json"></param>
+        public static T FromJson<T>(string json) where T: class {
+            var ser = new Newtonsoft.Json.JsonSerializer();
+
+            var reader = new System.IO.StringReader(json);
+
+            return ser.Deserialize(reader, typeof(T)) as T;
+        }
+
+        public static IList<T> FromListJson<T>(string json) where T : class
+        {
+            var ser = new Newtonsoft.Json.JsonSerializer();
+
+            var reader = new System.IO.StringReader(json);
+
+            return ser.Deserialize(reader, typeof(IList<T>)) as IList<T>;
+        }
+    }
+
+}

+ 108 - 0
MSHO.Collection.Service/MSHO.Collection.Service/IO/Message.cs

@@ -0,0 +1,108 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service.IO
+{
+
+    public class Message
+    {
+        public Message() { }
+
+        public Message(Msg msg) {
+            this.Content = JsonSerializable.ToJson(msg);
+        }
+
+        public Encoding Encoding {
+            get { return Encoding.UTF8; }
+        }
+
+        public long Length {
+            get {
+                if (this.Stream != null) {
+                    return this.Stream.Length;
+                }
+                return 0;
+            }
+        }
+
+        public System.IO.MemoryStream Stream { get; set; }
+
+        /// <summary>
+        /// 错误的消息
+        /// </summary>
+        public bool BadMsg { get; set; }
+
+        public string Content {
+            get {
+                if (this.Stream != null)
+                {
+                    return this.Encoding.GetString(this.Stream.ToArray());
+                }
+
+                return null;
+            }
+            set {
+                if (value != null)
+                {
+                    var buffer = this.Encoding.GetBytes(value);
+                    if (this.Stream == null) { this.Stream = new System.IO.MemoryStream(); }
+                    this.Stream.Write(buffer, 0, buffer.Length);
+                }
+                else {
+                    this.Stream = null;
+                }
+            }
+        }
+
+        public byte[] ToBuffer()
+        {
+            var mem = new System.IO.MemoryStream();
+            var buffer = Helper.LongToBytes(this.Length);
+            mem.Write(buffer, 0, buffer.Length);
+
+
+            if (!string.IsNullOrEmpty(this.Content))
+            {
+                buffer = Encoding.UTF8.GetBytes(this.Content);
+                mem.Write(buffer, 0, buffer.Length);
+            }
+
+            return mem.ToArray();
+        }
+
+        public void FromStream(System.IO.MemoryStream stream) {
+            if (stream != null) {
+                var buffer = new byte[sizeof(long)];
+                var len = stream.Read(buffer, 0, buffer.Length);
+                if (len == sizeof(long)) {
+                    var length = Helper.BytesToLong(buffer);
+                    buffer = new byte[length];
+                    len = stream.Read(buffer, 0, (int)length);
+                    this.Content = this.Encoding.GetString(buffer);
+                }
+            }
+        }
+
+        public void Write(byte[] buffer, int pos, int size) {
+            if (Stream == null) {
+                Stream = new System.IO.MemoryStream();
+            }
+            Stream.Write(buffer, pos, size);
+        }
+
+        public void Write(byte[] buffer)
+        {
+            if (Stream == null)
+            {
+                Stream = new System.IO.MemoryStream();
+            }
+            Stream.Write(buffer, 0, buffer.Length);
+        }
+
+    }
+
+    
+}

+ 243 - 0
MSHO.Collection.Service/MSHO.Collection.Service/IO/Msg.cs

@@ -0,0 +1,243 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service.IO
+{
+
+    public enum MessageTypeEnum
+    {
+        NONE = 0,
+
+        Connect = 1,
+
+        ConnectResp = 11,
+
+        Heart = 2,
+
+        HeartResp = 22,
+
+        ReportData = 3,
+
+        ReportDataResp = 33,
+
+        ErrorData = 4,
+
+        ErrorDataResp = 44,
+
+        UploadFile = 5,
+
+        UploadFileResp = 55,
+
+        GetUploadFile = 6,
+
+        GetUploadFileResp = 66,
+    }
+
+    public class Msg
+    {
+        public string ClientCode { get; set; }
+
+        public MessageTypeEnum MessageType { get; set; }
+
+        public string Content { get; set; }
+
+        public static Msg ParseMsg(Message net_msg)
+        {
+            var content = net_msg.Content;
+            if (!string.IsNullOrEmpty(content))
+            {
+                try
+                {
+                    var msg = JsonSerializable.FromJson<Msg>(content);
+                    if (msg != null)
+                    {
+                        switch (msg.MessageType)
+                        {
+                            case MessageTypeEnum.Connect:
+                                msg = JsonSerializable.FromJson<ConnectMsg>(content);
+                                break;
+
+                            case MessageTypeEnum.ConnectResp:
+                                msg = JsonSerializable.FromJson<ConnectRespMsg>(content);
+                                break;
+
+                            case MessageTypeEnum.Heart:
+                                msg = JsonSerializable.FromJson<HeartMsg>(content);
+                                break;
+
+                            case MessageTypeEnum.ReportData:
+                                msg = JsonSerializable.FromJson<DataReportMsg>(content);
+                                break;
+
+                            case MessageTypeEnum.ErrorData:
+                                msg = JsonSerializable.FromJson<ErrorMsg>(content);
+                                break;
+
+                            case MessageTypeEnum.UploadFile:
+                                msg = JsonSerializable.FromJson<UploadFileMsg>(content);
+                                break;
+
+                            case MessageTypeEnum.GetUploadFile:
+                                msg = JsonSerializable.FromJson<GetUploadFileMsg>(content);
+                                break;
+                        }
+
+                        if (msg != null)
+                        {
+                            msg.Content = content;
+                        }
+
+                        return msg;
+                    }
+                }
+                catch(Exception ex) {
+#if DEBUG
+                    Console.WriteLine(ex.Message);
+                    Console.WriteLine(content);
+#endif
+                }
+            }
+
+            return null;
+        }
+
+    }
+
+    public class ConnectMsg : Msg
+    {
+        public ConnectMsg()
+        {
+            this.MessageType = MessageTypeEnum.Connect;
+        }
+    }
+
+    public class ConnectRespMsg : Msg
+    {
+        public ConnectRespMsg()
+        {
+            this.MessageType = MessageTypeEnum.ConnectResp;
+        }
+    }
+
+    public class HeartMsg : Msg
+    {
+        public HeartMsg()
+        {
+            this.MessageType = MessageTypeEnum.Heart;
+        }
+        public DateTime Time { get; set; }
+    }
+
+    public class HeartRespMsg : Msg
+    {
+        public HeartRespMsg()
+        {
+            this.MessageType = MessageTypeEnum.HeartResp;
+        }
+        public DateTime Time { get; set; }
+    }
+
+    public class DataReportMsg : Msg
+    {
+        public DataReportMsg()
+        {
+            this.MessageType = MessageTypeEnum.ReportData;
+        }
+        public string Result { get; set; }
+        public string DataType { get; set; }
+
+    }
+
+    public class DataReportRespMsg : Msg
+    {
+        public DataReportRespMsg() {
+            this.MessageType = MessageTypeEnum.ReportDataResp;
+        }
+
+        /// <summary>
+        /// 客户端数据ID
+        /// </summary>
+        public string DataId { get; set; }
+        public bool Result { get; set; }
+
+        /// <summary>
+        /// 文件
+        /// </summary>
+        public List<MSHO.Collection.DataAccess.Models.WeightingFile> WeightingFiles { get; set; }
+    }
+
+    /// <summary>
+    /// 错误消息
+    /// </summary>
+    public class ErrorMsg : Msg
+    {
+        public ErrorMsg()
+        {
+            MessageType = MessageTypeEnum.ErrorData;
+        }
+
+        public string Model { get; set; }
+        public string LogMessage { get; set; }
+        public string LogDetails { get; set; }
+    }
+
+    public class ErrorMsgRespMsg : Msg
+    {
+        public ErrorMsgRespMsg()
+        {
+            MessageType = MessageTypeEnum.ErrorDataResp;
+        }
+        public bool Result { get; set; }
+    }
+
+
+    /// <summary>
+    /// 上传文件消息
+    /// </summary>
+    public class UploadFileMsg : Msg
+    {
+        public UploadFileMsg()
+        {
+            MessageType = MessageTypeEnum.UploadFile;
+        }
+
+        public long ID { get; set; }
+        public long WeightingID { get; set; }
+        public long BufferLength { get; set; }
+        public string FileStreamBase64 { get; set; }
+    }
+
+    public class UploadFileMsgRespMsg : Msg
+    {
+        public UploadFileMsgRespMsg()
+        {
+            MessageType = MessageTypeEnum.UploadFileResp;
+        }
+        public bool Result { get; set; }
+    }
+
+
+
+    /////////////////////////////////////
+    public class GetUploadFileMsg : Msg
+    {
+        public GetUploadFileMsg()
+        {
+            MessageType = MessageTypeEnum.GetUploadFile;
+        }
+
+    }
+
+    public class GetUploadFileMsgRespMsg : Msg
+    {
+        public GetUploadFileMsgRespMsg()
+        {
+            MessageType = MessageTypeEnum.GetUploadFileResp;
+        }
+        public List<MSHO.Collection.DataAccess.Models.WeightingFile> WeightingFiles { get; set; }
+    }
+
+}

+ 108 - 0
MSHO.Collection.Service/MSHO.Collection.Service/MSHO.Collection.Service.csproj

@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{86E705F3-58F6-4158-A572-7AAB2ADCA8DE}</ProjectGuid>
+    <OutputType>WinExe</OutputType>
+    <RootNamespace>MSHO.Collection.Service</RootNamespace>
+    <AssemblyName>MSHO.Collection.Service</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="EntityFramework">
+      <HintPath>..\..\References\EntityFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer">
+      <HintPath>..\..\References\EntityFramework.SqlServer.dll</HintPath>
+    </Reference>
+    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\References\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Configuration" />
+    <Reference Include="System.Configuration.Install" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Management" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.ServiceProcess" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="ClearHistoryFileService.cs" />
+    <Compile Include="Configuration.cs" />
+    <Compile Include="Helper.cs" />
+    <Compile Include="IO\IOServer.Process.Partial.cs" />
+    <Compile Include="IO\DataTypeConst.cs" />
+    <Compile Include="IO\IOServer.cs" />
+    <Compile Include="IO\IOServer.Partial.cs" />
+    <Compile Include="IO\JsonSerializable.cs" />
+    <Compile Include="IO\Message.cs" />
+    <Compile Include="IO\Msg.cs" />
+    <Compile Include="MainService.cs">
+      <SubType>Component</SubType>
+    </Compile>
+    <Compile Include="MainService.Designer.cs">
+      <DependentUpon>MainService.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Program.cs" />
+    <Compile Include="ProjectInstaller.cs">
+      <SubType>Component</SubType>
+    </Compile>
+    <Compile Include="ProjectInstaller.Designer.cs">
+      <DependentUpon>ProjectInstaller.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SystemLogSource.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config">
+      <SubType>Designer</SubType>
+    </None>
+  </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="MainService.resx">
+      <DependentUpon>MainService.cs</DependentUpon>
+    </EmbeddedResource>
+    <EmbeddedResource Include="ProjectInstaller.resx">
+      <DependentUpon>ProjectInstaller.cs</DependentUpon>
+    </EmbeddedResource>
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Exceptions\" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\MSHO.Collection.DataAccess\MSHO.Collection.DataAccess.csproj">
+      <Project>{91dc72e1-87ff-4c81-b9f5-e65861c3ebdf}</Project>
+      <Name>MSHO.Collection.DataAccess</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 40 - 0
MSHO.Collection.Service/MSHO.Collection.Service/MainService.Designer.cs

@@ -0,0 +1,40 @@
+namespace MSHO.Collection.Service
+{
+    partial class MainService
+    {
+        /// <summary> 
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region 组件设计器生成的代码
+
+        /// <summary> 
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            // 
+            // MainService
+            // 
+            this.ServiceName = "MSHO.Collection.Service";
+
+        }
+
+        #endregion
+    }
+}

+ 45 - 0
MSHO.Collection.Service/MSHO.Collection.Service/MainService.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Diagnostics;
+using System.Linq;
+using System.ServiceProcess;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service
+{
+    public partial class MainService : ServiceBase
+    {
+        private ClearHistoryFileService m_ClearHistoryFileService;
+        private MSHO.Collection.Service.IO.IOServer m_IOServer;
+        public MainService()
+        {
+            InitializeComponent();
+        }
+
+        protected override void OnStart(string[] args)
+        {
+            var config = MSHO.Collection.Service.Configuration.Instance;
+            m_IOServer = new MSHO.Collection.Service.IO.IOServer(config.IP, config.Port, config.MaxConnection, config.BufferSize);
+
+            m_IOServer.Start();
+
+            m_ClearHistoryFileService = new ClearHistoryFileService();
+            m_ClearHistoryFileService.Start();
+        }
+
+        protected override void OnStop()
+        {
+            if (m_IOServer != null) {
+                m_IOServer.Stop();
+            }
+
+            if (m_ClearHistoryFileService != null) {
+                m_ClearHistoryFileService.Stop();
+                m_ClearHistoryFileService = null;
+            }
+        }
+    }
+}

+ 123 - 0
MSHO.Collection.Service/MSHO.Collection.Service/MainService.resx

@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>False</value>
+  </metadata>
+</root>

+ 25 - 0
MSHO.Collection.Service/MSHO.Collection.Service/Program.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.ServiceProcess;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service
+{
+    static class Program
+    {
+        /// <summary>
+        /// 应用程序的主入口点。
+        /// </summary>
+        static void Main()
+        {
+            ServiceBase[] ServicesToRun;
+            ServicesToRun = new ServiceBase[]
+            {
+                new MainService()
+            };
+            ServiceBase.Run(ServicesToRun);
+        }
+    }
+}

+ 60 - 0
MSHO.Collection.Service/MSHO.Collection.Service/ProjectInstaller.Designer.cs

@@ -0,0 +1,60 @@
+namespace MSHO.Collection.Service
+{
+    partial class ProjectInstaller
+    {
+        /// <summary>
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary> 
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region 组件设计器生成的代码
+
+        /// <summary>
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
+            this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
+            // 
+            // serviceProcessInstaller1
+            // 
+            this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.NetworkService;
+            this.serviceProcessInstaller1.Password = null;
+            this.serviceProcessInstaller1.Username = null;
+            // 
+            // serviceInstaller1
+            // 
+            this.serviceInstaller1.Description = "MSHO.Collection.Service";
+            this.serviceInstaller1.DisplayName = "MSHO.Collection.Service";
+            this.serviceInstaller1.ServiceName = "MSHO.Collection.Service";
+            this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
+            // 
+            // ProjectInstaller
+            // 
+            this.Installers.AddRange(new System.Configuration.Install.Installer[] {
+            this.serviceProcessInstaller1,
+            this.serviceInstaller1});
+
+        }
+
+        #endregion
+
+        private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
+        private System.ServiceProcess.ServiceInstaller serviceInstaller1;
+    }
+}

+ 19 - 0
MSHO.Collection.Service/MSHO.Collection.Service/ProjectInstaller.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Configuration.Install;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service
+{
+    [RunInstaller(true)]
+    public partial class ProjectInstaller : System.Configuration.Install.Installer
+    {
+        public ProjectInstaller()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 129 - 0
MSHO.Collection.Service/MSHO.Collection.Service/ProjectInstaller.resx

@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="serviceProcessInstaller1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+  <metadata name="serviceInstaller1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>208, 17</value>
+  </metadata>
+  <metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>False</value>
+  </metadata>
+</root>

+ 36 - 0
MSHO.Collection.Service/MSHO.Collection.Service/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("MSHO.Collection.Service")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("MSHO.Collection.Service")]
+[assembly: AssemblyCopyright("Copyright ©  2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("86e705f3-58f6-4158-a572-7aab2adca8de")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 16 - 0
MSHO.Collection.Service/MSHO.Collection.Service/SystemLogSource.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace MSHO.Collection.Service
+{
+    public class SystemLogSource
+    {
+        public const string MSHO_Collection_Service = "MSHO.Collection.Service";
+
+        public int Status {
+            get;set;
+        }
+    }
+}

+ 40 - 0
MSHO.Collection.Service/Test/App.config

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+  <configSections>
+    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+  </configSections>
+  <entityFramework>
+    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
+      <parameters>
+        <parameter value="mssqllocaldb" />
+      </parameters>
+    </defaultConnectionFactory>
+    <providers>
+      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
+    </providers>
+  </entityFramework>
+  <system.data>
+    <DbProviderFactories>
+      <remove invariant="MySql.Data.MySqlClient" />
+      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
+    </DbProviderFactories>
+  </system.data>
+
+  <connectionStrings>
+    <add name="MSHO.DBConnection" connectionString="Data Source=101.0.0.30;Initial Catalog=MSHO;User ID=sa;Password=ycd123;" providerName="System.Data.SqlClient" />
+  </connectionStrings>
+
+  <appSettings>
+    <add key="IP" value=""/>
+    <add key="Port" value="9001"/>
+    <add key="MaxConnection" value="100"/>
+    <add key="BufferSize" value="8192"/>
+    <add key="PrivateKey" value=""/>
+    <add key="FileServerConnection" value="Data Source=localhost;Initial Catalog=MSHO;buffer size=524288;" />
+    <!--<add key="FileServerConnection" value="Data Source=101.0.0.30;Initial Catalog=MSHO;buffer size=524288;" />-->
+  </appSettings>
+
+  <startup>
+    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
+  </startup>
+</configuration>

+ 169 - 0
MSHO.Collection.Service/Test/Program.cs

@@ -0,0 +1,169 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Test
+{
+    class Program
+    {
+        private static string Process_Bus_Weighting_LoadFile(string path, ref long length)
+        {
+            try
+            {
+                if (!string.IsNullOrEmpty(path))
+                {
+                    path = path.Replace("/", "\\");
+                    if (System.IO.File.Exists(path))
+                    {
+                        var buffer = new byte[1024 * 4];
+                        using (var stream = new System.IO.MemoryStream())
+                        {
+                            using (var fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
+                            {
+                                int len = 0;
+                                while ((len = fs.Read(buffer, 0, buffer.Length)) != 0)
+                                {
+                                    stream.Write(buffer, 0, len);
+                                }
+                                fs.Close();
+                            }
+
+                            var temp = stream.ToArray();
+                            length = temp.Length;
+                            return Convert.ToBase64String(temp, 0, temp.Length);
+                        }
+                    }
+                }
+            }
+            catch
+            {
+            }
+            return null;
+        }
+
+        static void Main(string[] args)
+        {
+
+            var service = new MSHO.Collection.Service.ClearHistoryFileService();
+            service.Start();
+
+
+            Console.ReadLine();
+
+
+            return;
+
+
+            long file_length = 0;
+            var fileStreamBase64 = Process_Bus_Weighting_LoadFile(@"C:\temp\192.168.101.166_20181120160822502_Plate.mp4", ref file_length);
+
+            if (fileStreamBase64 != null)
+            {
+                //var buffer = Convert.FromBase64String(base64);
+                System.IO.MemoryStream fileStream = null;
+                //System.IO.File.WriteAllBytes(@"C:\temp\192.mp4", buffer);
+                using (var connection = new HK.File.Client.FileClientConnection("Data Source=localhost;Initial Catalog=MSHO;buffer size=524288;"))
+                {
+                    connection.Open();
+                    var trans = connection.BeginTransaction();
+
+                    try
+                    {
+                        var cmd = connection.CreateCommand(HK.File.Client.Command.CommandType.InsertFile) as HK.File.Client.Command.InsertFileCommand;
+                        cmd.FileName = "192.168.101.166_20181120160822502_Plate.mp4";
+                        cmd.FileDescription = ".mp4";
+                        cmd.FolderPath = "video";
+                        cmd.Transaction = trans;
+
+                        MSHO.Collection.DataAccess.Helper.FileService.CreateFolder(connection, "video");
+                        if (fileStream == null)
+                        {
+                            var fileInfo = new System.IO.FileInfo("192.168.101.166_20181120160822502_Plate.mp4");
+                            var buffer = Convert.FromBase64String(fileStreamBase64);
+                            if (file_length > 0)
+                            {
+                                if (file_length != buffer.LongLength)
+                                {
+                                    //return false;
+                                }
+                            }
+
+                            {
+                                fileStream = new System.IO.MemoryStream(buffer, 0, buffer.Length);
+                            }
+                        }
+                        if (fileStream != null)
+                        {
+                            fileStream.Seek(0, System.IO.SeekOrigin.Begin);
+                            cmd.Stream = fileStream;
+                        }
+
+                        if (cmd.Execute())
+                        {
+                            var fileServerID = cmd.UniqueID;
+                            fileStream.Seek(0, System.IO.SeekOrigin.Begin);
+
+                            trans.Commit();
+                            trans = null;
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        MSHO.Collection.DataAccess.MSHOService.Instance.SaveSystemLog("MSHO.Collection.Service", "MSHOService.SaveWeightingFile", ex);
+                        trans.Rollback();
+                        trans = null;
+                    }
+                    finally
+                    {
+                        if (trans != null)
+                        {
+                            trans.Rollback();
+                            trans = null;
+                        }
+                    }
+
+                    connection.Close();
+                }
+            }
+
+            //remove_repeat();
+            return;
+
+            var config = MSHO.Collection.Service.Configuration.Instance;
+            var server = new MSHO.Collection.Service.IO.IOServer(config.IP, config.Port, config.MaxConnection, config.BufferSize);
+
+            server.Start();
+
+
+            Console.WriteLine("Server Starting.........");
+            Console.ReadLine();
+            server.Stop();
+
+        }
+
+
+
+
+        static void remove_repeat()
+        {
+            decimal rate = (decimal)0.3;
+
+            var query = MSHO.Collection.DataAccess.MSHOService.Instance.GetAllWeightings();
+            var ids = (from o in query
+                       where (o.DeviceID == 5 || o.DeviceID == 12) && o.OverloadRate >= rate
+                       select o.ID).ToArray();
+
+            foreach (var id in ids) {
+                MSHO.Collection.DataAccess.MSHOService.Instance.DeleteWeighting(id);
+                Console.WriteLine("删除 {0}", id);
+            }
+
+            Console.WriteLine("删除完成");
+
+        }
+
+
+    }
+}

+ 36 - 0
MSHO.Collection.Service/Test/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("Test")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Test")]
+[assembly: AssemblyCopyright("Copyright ©  2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("49780335-069d-4d82-bc84-cae1d79f4cbd")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 80 - 0
MSHO.Collection.Service/Test/Test.csproj

@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{49780335-069D-4D82-BC84-CAE1D79F4CBD}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>Test</RootNamespace>
+    <AssemblyName>Test</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\References\EntityFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="EntityFramework.SqlServer">
+      <HintPath>..\..\References\EntityFramework.SqlServer.dll</HintPath>
+    </Reference>
+    <Reference Include="HK.File.Client, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\References\HK.File.Client.dll</HintPath>
+    </Reference>
+    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\References\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Configuration" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config">
+      <SubType>Designer</SubType>
+    </None>
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\MSHO.Collection.DataAccess\MSHO.Collection.DataAccess.csproj">
+      <Project>{91dc72e1-87ff-4c81-b9f5-e65861c3ebdf}</Project>
+      <Name>MSHO.Collection.DataAccess</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\MSHO.Collection.Service\MSHO.Collection.Service.csproj">
+      <Project>{86e705f3-58f6-4158-a572-7aab2adca8de}</Project>
+      <Name>MSHO.Collection.Service</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>