shshdxk 4 years ago
parent
commit
6923e9a223

+ 2 - 0
README.md

@@ -1,2 +1,4 @@
 # serverHelper
 
+## 注意事项
+运行时,将Libs/Microsoft.Win32.TaskScheduler.dll手动复制到运行目录

+ 41 - 0
ServiceHelper.sln

@@ -0,0 +1,41 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29920.165
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceHelper", "ServiceHelper\ServiceHelper.csproj", "{590549FA-E057-4032-8329-214103B0F5FF}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Debug|x64 = Debug|x64
+		Debug|x86 = Debug|x86
+		Release|Any CPU = Release|Any CPU
+		Release|x64 = Release|x64
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{590549FA-E057-4032-8329-214103B0F5FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{590549FA-E057-4032-8329-214103B0F5FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{590549FA-E057-4032-8329-214103B0F5FF}.Debug|x64.ActiveCfg = Debug|x86
+		{590549FA-E057-4032-8329-214103B0F5FF}.Debug|x64.Build.0 = Debug|x86
+		{590549FA-E057-4032-8329-214103B0F5FF}.Debug|x86.ActiveCfg = Debug|x86
+		{590549FA-E057-4032-8329-214103B0F5FF}.Debug|x86.Build.0 = Debug|x86
+		{590549FA-E057-4032-8329-214103B0F5FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{590549FA-E057-4032-8329-214103B0F5FF}.Release|Any CPU.Build.0 = Release|Any CPU
+		{590549FA-E057-4032-8329-214103B0F5FF}.Release|x64.ActiveCfg = Release|x64
+		{590549FA-E057-4032-8329-214103B0F5FF}.Release|x64.Build.0 = Release|x64
+		{590549FA-E057-4032-8329-214103B0F5FF}.Release|x86.ActiveCfg = Release|x86
+		{590549FA-E057-4032-8329-214103B0F5FF}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {A48A4EBD-5DC2-428E-A767-26CF9DB985E7}
+	EndGlobalSection
+	GlobalSection(SubversionScc) = preSolution
+		Svn-Managed = True
+		Manager = AnkhSVN - Subversion Support for Visual Studio
+	EndGlobalSection
+EndGlobal

BIN
ServiceHelper/Libs/Microsoft.Win32.TaskScheduler.dll


+ 85 - 0
ServiceHelper/ManagerXml.cs

@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Xml;
+
+namespace ServiceHelper
+{
+    public class ManagerXml
+    {
+        private XmlDocument _xmlDocument;
+        private string _fileName;
+        
+        private const string USETASK = "UseTask";
+        private const string TASKDAYSINTERVAL = "TaskDaysInterval";
+        private const string TASKSTARTBOUNDARY = "TaskStartBoundary";
+
+        public ManagerXml(string fileName)
+        {
+            _xmlDocument = new XmlDocument();
+            _xmlDocument.Load(fileName);
+            _fileName = fileName;
+
+            //检查配置文件中配置项是否齐全,补齐缺漏
+            List<string> nodeNames = new List<string>();
+            nodeNames.Add(USETASK);
+            nodeNames.Add(TASKDAYSINTERVAL);
+            nodeNames.Add(TASKSTARTBOUNDARY);
+
+            XmlNode appSettringNode = _xmlDocument.SelectSingleNode("//appSettings");
+
+            foreach (string nodeName in nodeNames)
+            {
+                XmlNode node = _xmlDocument.SelectSingleNode("//appSettings/add[@key='" + nodeName + "']");
+                if (node == null)
+                {
+                    XmlElement newElement = _xmlDocument.CreateElement("add");
+                    newElement.SetAttribute("key", nodeName);
+                    string defaultValue = "";
+                    switch (nodeName)
+                    {
+                        case USETASK:
+                            defaultValue = "false";
+                            break;
+                        case TASKDAYSINTERVAL:
+                            defaultValue = "1";
+                            break;
+                        case TASKSTARTBOUNDARY:
+                            defaultValue = "06:00:00";
+                            break;
+                    }
+                    newElement.SetAttribute("value", defaultValue);
+                    appSettringNode.AppendChild(newElement);
+                }
+            }
+            _xmlDocument.Save(_fileName);
+        }
+
+        public string Get(string name)
+        {
+            XmlNode node = _xmlDocument.SelectSingleNode("//appSettings/add[@key='" + name + "']");
+            return node.Attributes.GetNamedItem("value").Value;
+        }
+
+        public void Set(string name, string value)
+        {
+            XmlNode node = _xmlDocument.SelectSingleNode("//appSettings/add[@key='" + name + "']");
+            node.Attributes.GetNamedItem("value").Value = value;
+            _xmlDocument.Save(_fileName);
+        }
+
+        public string GetLogLevel()
+        {
+            XmlNode node = _xmlDocument.SelectSingleNode("//log4net/root/level");
+            return node.Attributes.GetNamedItem("value").Value;
+        }
+
+        public void SetLogLevel(string level)
+        {
+            XmlNode node = _xmlDocument.SelectSingleNode("//log4net/root/level");
+            node.Attributes.GetNamedItem("value").Value = level;
+            _xmlDocument.Save(_fileName);
+        }
+    }
+}

+ 21 - 0
ServiceHelper/Program.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+
+namespace ServiceHelper
+{
+    static class Program
+    {
+        /// <summary>
+        /// 应用程序的主入口点。
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            Application.Run(new ServiceHelper());
+        }
+    }
+}

+ 62 - 0
ServiceHelper/Progress.Designer.cs

@@ -0,0 +1,62 @@
+namespace ServiceHelper
+{
+    partial class Progress
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.progressBar = new System.Windows.Forms.ProgressBar();
+            this.SuspendLayout();
+            // 
+            // progressBar
+            // 
+            this.progressBar.Location = new System.Drawing.Point(12, 18);
+            this.progressBar.Name = "progressBar";
+            this.progressBar.Size = new System.Drawing.Size(260, 23);
+            this.progressBar.TabIndex = 0;
+            // 
+            // Progress
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(284, 62);
+            this.Controls.Add(this.progressBar);
+            this.MaximizeBox = false;
+            this.MinimizeBox = false;
+            this.Name = "Progress";
+            this.ShowIcon = false;
+            this.ShowInTaskbar = false;
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+            this.Text = "Progress";
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.ProgressBar progressBar;
+    }
+}

+ 38 - 0
ServiceHelper/Progress.cs

@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace ServiceHelper
+{
+    public partial class Progress : Form
+    {
+        public Progress()
+        {
+            InitializeComponent();
+        }
+
+        public void Reset()
+        {
+            progressBar.Value = 0;
+        }
+
+        public void Done() 
+        {
+            progressBar.Value = 100;
+            this.Hide();
+        }
+
+        public void UpdateProgress()
+        {
+            if (progressBar.Value < 80)
+            {
+                progressBar.Value += 20;
+            }
+        }
+    }
+}

+ 120 - 0
ServiceHelper/Progress.resx

@@ -0,0 +1,120 @@
+<?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>
+</root>

+ 36 - 0
ServiceHelper/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息通过以下
+// 特性集控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("ServiceHelper")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ServiceHelper")]
+[assembly: AssemblyCopyright("Copyright ©  2014")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 使此程序集中的类型
+// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
+// 则将该类型上的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("4fcc6e81-c979-4195-8ba4-58cca11d1075")]
+
+// 程序集的版本信息由下面四个值组成:
+//
+//      主版本
+//      次版本 
+//      内部版本号
+//      修订号
+//
+// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 63 - 0
ServiceHelper/Properties/Resources.Designer.cs

@@ -0,0 +1,63 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     此代码由工具生成。
+//     运行时版本:4.0.30319.42000
+//
+//     对此文件的更改可能会导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace ServiceHelper.Properties {
+    using System;
+    
+    
+    /// <summary>
+    ///   一个强类型的资源类,用于查找本地化的字符串等。
+    /// </summary>
+    // 此类是由 StronglyTypedResourceBuilder
+    // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
+    // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+    // (以 /str 作为命令选项),或重新生成 VS 项目。
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    internal class Resources {
+        
+        private static global::System.Resources.ResourceManager resourceMan;
+        
+        private static global::System.Globalization.CultureInfo resourceCulture;
+        
+        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+        internal Resources() {
+        }
+        
+        /// <summary>
+        ///   返回此类使用的缓存的 ResourceManager 实例。
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Resources.ResourceManager ResourceManager {
+            get {
+                if (object.ReferenceEquals(resourceMan, null)) {
+                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ServiceHelper.Properties.Resources", typeof(Resources).Assembly);
+                    resourceMan = temp;
+                }
+                return resourceMan;
+            }
+        }
+        
+        /// <summary>
+        ///   使用此强类型资源类,为所有资源查找
+        ///   重写当前线程的 CurrentUICulture 属性。
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Globalization.CultureInfo Culture {
+            get {
+                return resourceCulture;
+            }
+            set {
+                resourceCulture = value;
+            }
+        }
+    }
+}

+ 117 - 0
ServiceHelper/Properties/Resources.resx

@@ -0,0 +1,117 @@
+<?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.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: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" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+            </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" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+            </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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 26 - 0
ServiceHelper/Properties/Settings.Designer.cs

@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     此代码由工具生成。
+//     运行时版本:4.0.30319.42000
+//
+//     对此文件的更改可能会导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace ServiceHelper.Properties {
+    
+    
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+        
+        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+        
+        public static Settings Default {
+            get {
+                return defaultInstance;
+            }
+        }
+    }
+}

+ 7 - 0
ServiceHelper/Properties/Settings.settings

@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
+  <Profiles>
+    <Profile Name="(Default)" />
+  </Profiles>
+  <Settings />
+</SettingsFile>

+ 72 - 0
ServiceHelper/QueryPerformance.cs

@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Runtime.InteropServices;
+
+namespace ServiceHelper
+{
+    public class QueryPerformance
+    {
+        [DllImport("Kernel32.dll")]
+        private static extern bool QueryPerformanceCounter(out long performanceCount);
+
+        [DllImport("Kernel32.dll")]
+        private static extern bool QueryPerformanceFrequency(out long frequency);
+
+        private  long begintTime = 0;//开始时间  
+
+        private  long endTime = 0;//结束时间  
+
+        private  long frequency = 0;//处理器频率  
+
+        public long BegintTime
+        {
+            get { return begintTime; }
+        }
+
+        public long EndTime
+        {
+            get { return endTime; }
+        }
+
+        public long Frequency
+        {
+            get { return frequency; }
+        }
+
+
+        public QueryPerformance()  
+        {
+            QueryPerformanceFrequency(out frequency);//获取频率  
+        }
+
+        public void Start()
+        {
+            QueryPerformanceCounter(out begintTime);
+        }
+
+        public string Stop(bool showRecord)
+        {
+            QueryPerformanceCounter(out endTime);
+
+            if (showRecord)
+            {
+                return string.Format("用时:{0}ms", TastTime);
+            }
+            return null;
+        }
+
+        public double TastTime//花费时间:单位S  
+        {
+            get
+            {
+                if (frequency > 0)
+                    return (double)(endTime - begintTime)*1000 / frequency;
+                else
+                    return 0;
+            }
+        }  
+    }
+}

+ 175 - 0
ServiceHelper/ServiceControl.cs

@@ -0,0 +1,175 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.ServiceProcess;
+using System.Collections;
+using System.Configuration.Install;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace ServiceHelper
+{
+    public static class ServiceControl
+    {
+        public static void Install(string serviceName, string serviceInstallPath)
+        {
+            IDictionary mySavedState = new Hashtable();
+
+            try
+            {
+                ServiceController serviceController = new ServiceController(serviceName);
+
+                if (Exist(serviceName))
+                {
+                    throw new Exception(string.Format("服务{0}已存在", serviceName));
+                }
+
+                ServiceHelper.bgWorker.ReportProgress(0);
+                AssemblyInstaller assemblyInstaller = new AssemblyInstaller();
+                mySavedState.Clear();
+                assemblyInstaller.Path = serviceInstallPath;
+                assemblyInstaller.UseNewContext = true;
+                ServiceHelper.bgWorker.ReportProgress(0);
+                assemblyInstaller.Install(mySavedState);
+                ServiceHelper.bgWorker.ReportProgress(0);
+                assemblyInstaller.Commit(mySavedState);
+                ServiceHelper.bgWorker.ReportProgress(0);
+                assemblyInstaller.Dispose();
+                ServiceHelper.bgWorker.ReportProgress(0);
+            }
+            catch (Exception e)
+            {
+                throw new Exception("安装服务时出错:" + e.Message);
+            }
+        }
+
+        public static void Uninstall(string serviceName, string serviceInstallPath)
+        {
+            try
+            {
+                if (!Exist(serviceName))
+                {
+                    throw new Exception(string.Format("服务{0}不存在", serviceName));
+                }
+
+                ServiceHelper.bgWorker.ReportProgress(0);
+                AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
+                myAssemblyInstaller.UseNewContext = true;
+                myAssemblyInstaller.Path = serviceInstallPath;
+                ServiceHelper.bgWorker.ReportProgress(0);
+                myAssemblyInstaller.Uninstall(null);
+                ServiceHelper.bgWorker.ReportProgress(0);
+                myAssemblyInstaller.Dispose();
+                ServiceHelper.bgWorker.ReportProgress(0);
+            }
+            catch (Exception e)
+            {
+                throw new Exception("卸载服务时出错:" + e.Message);
+            }
+        }
+
+        public static bool Exist(string serviceName)
+        {
+            ServiceController[] services = ServiceController.GetServices();
+            foreach (ServiceController s in services)
+            {
+                if (s.ServiceName == serviceName)
+                {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        public static void Start(string serviceName)
+        {
+            try
+            {
+                if (!Exist(serviceName))
+                {
+                    throw new Exception(string.Format("服务{0}不存在", serviceName));
+                }
+                ServiceHelper.bgWorker.ReportProgress(0);
+                ServiceController service = new ServiceController(serviceName);
+                if (service.Status != ServiceControllerStatus.Running && service.Status != ServiceControllerStatus.StartPending)
+                {
+                    ServiceHelper.bgWorker.ReportProgress(0);
+                    service.Start();
+                    for (int i = 0; i < 30; i++)
+                    {
+                        service.Refresh();
+                        Thread.Sleep(1000);
+                        if (service.Status == ServiceControllerStatus.Running)
+                        {
+                            service.Dispose();
+                            break;
+                        }
+                        if (i == 29)
+                        {
+                            service.Dispose();
+                            throw new Exception("服务" + serviceName + "启动失败!");
+                        }
+                    }
+                }
+                ServiceHelper.bgWorker.ReportProgress(0);
+            }
+            catch (Exception e)
+            {
+                throw new Exception("启动服务时出错:" + e.Message);
+            }
+            
+        }
+
+        public static void Stop(string serviceName)
+        {
+            try
+            {
+                if (!Exist(serviceName))
+                {
+                    throw new Exception(string.Format("服务{0}不存在", serviceName));
+                }
+                ServiceHelper.bgWorker.ReportProgress(0);
+                ServiceController service = new ServiceController(serviceName);
+                if (service.Status == ServiceControllerStatus.Running)
+                {
+                    ServiceHelper.bgWorker.ReportProgress(0);
+                    service.Stop();
+                    for (int i = 0; i < 30; i++)
+                    {
+                        service.Refresh();
+                        System.Threading.Thread.Sleep(1000);
+                        if (service.Status == ServiceControllerStatus.Stopped)
+                        {
+                            service.Dispose();
+                            break;
+                        }
+                        if (i == 29)
+                        {
+                            service.Dispose();
+                            throw new Exception("服务" + serviceName + "停止失败!");
+                        }
+                    }
+                }
+                ServiceHelper.bgWorker.ReportProgress(0);
+            }
+            catch (Exception e)
+            {
+                throw new Exception("停止服务失败:" + e.Message);
+            }
+        }
+
+        public static void Restart(string serviceName)
+        {
+            try
+            {
+                Stop(serviceName);
+                Start(serviceName);
+            }
+            catch (Exception e)
+            {
+                throw e;
+            }
+        }
+    }
+}

+ 128 - 0
ServiceHelper/ServiceHelper.Designer.cs

@@ -0,0 +1,128 @@
+namespace ServiceHelper
+{
+    partial class ServiceHelper
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.InstallBtn = new System.Windows.Forms.Button();
+            this.UninstallBtn = new System.Windows.Forms.Button();
+            this.StartBtn = new System.Windows.Forms.Button();
+            this.StopBtn = new System.Windows.Forms.Button();
+            this.ConfigBtn = new System.Windows.Forms.Button();
+            this.RestartBtn = new System.Windows.Forms.Button();
+            this.SuspendLayout();
+            // 
+            // InstallBtn
+            // 
+            this.InstallBtn.Location = new System.Drawing.Point(22, 12);
+            this.InstallBtn.Name = "InstallBtn";
+            this.InstallBtn.Size = new System.Drawing.Size(150, 50);
+            this.InstallBtn.TabIndex = 0;
+            this.InstallBtn.Text = "安装Service服务";
+            this.InstallBtn.UseVisualStyleBackColor = true;
+            this.InstallBtn.Click += new System.EventHandler(this.InstallBtn_Click);
+            // 
+            // UninstallBtn
+            // 
+            this.UninstallBtn.Location = new System.Drawing.Point(22, 68);
+            this.UninstallBtn.Name = "UninstallBtn";
+            this.UninstallBtn.Size = new System.Drawing.Size(150, 50);
+            this.UninstallBtn.TabIndex = 1;
+            this.UninstallBtn.Text = "卸载Service服务";
+            this.UninstallBtn.UseVisualStyleBackColor = true;
+            this.UninstallBtn.Click += new System.EventHandler(this.UninstallBtn_Click);
+            // 
+            // StartBtn
+            // 
+            this.StartBtn.Location = new System.Drawing.Point(22, 124);
+            this.StartBtn.Name = "StartBtn";
+            this.StartBtn.Size = new System.Drawing.Size(150, 50);
+            this.StartBtn.TabIndex = 2;
+            this.StartBtn.Text = "开启Service服务";
+            this.StartBtn.UseVisualStyleBackColor = true;
+            this.StartBtn.Click += new System.EventHandler(this.StartBtn_Click);
+            // 
+            // StopBtn
+            // 
+            this.StopBtn.Location = new System.Drawing.Point(22, 180);
+            this.StopBtn.Name = "StopBtn";
+            this.StopBtn.Size = new System.Drawing.Size(150, 50);
+            this.StopBtn.TabIndex = 3;
+            this.StopBtn.Text = "停止Service服务";
+            this.StopBtn.UseVisualStyleBackColor = true;
+            this.StopBtn.Click += new System.EventHandler(this.StopBtn_Click);
+            // 
+            // ConfigBtn
+            // 
+            this.ConfigBtn.Location = new System.Drawing.Point(22, 292);
+            this.ConfigBtn.Name = "ConfigBtn";
+            this.ConfigBtn.Size = new System.Drawing.Size(150, 50);
+            this.ConfigBtn.TabIndex = 4;
+            this.ConfigBtn.Text = "配置Service服务";
+            this.ConfigBtn.UseVisualStyleBackColor = true;
+            this.ConfigBtn.Click += new System.EventHandler(this.ConfigBtn_Click);
+            // 
+            // RestartBtn
+            // 
+            this.RestartBtn.Location = new System.Drawing.Point(22, 236);
+            this.RestartBtn.Name = "RestartBtn";
+            this.RestartBtn.Size = new System.Drawing.Size(150, 50);
+            this.RestartBtn.TabIndex = 5;
+            this.RestartBtn.Text = "重启Service服务";
+            this.RestartBtn.UseVisualStyleBackColor = true;
+            this.RestartBtn.Click += new System.EventHandler(this.RestartBtn_Click);
+            // 
+            // ServiceHelper
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(194, 362);
+            this.Controls.Add(this.RestartBtn);
+            this.Controls.Add(this.ConfigBtn);
+            this.Controls.Add(this.StopBtn);
+            this.Controls.Add(this.StartBtn);
+            this.Controls.Add(this.UninstallBtn);
+            this.Controls.Add(this.InstallBtn);
+            this.MaximizeBox = false;
+            this.MinimizeBox = false;
+            this.Name = "ServiceHelper";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+            this.Text = "ServiceHelper";
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Button InstallBtn;
+        private System.Windows.Forms.Button UninstallBtn;
+        private System.Windows.Forms.Button StartBtn;
+        private System.Windows.Forms.Button StopBtn;
+        private System.Windows.Forms.Button ConfigBtn;
+        private System.Windows.Forms.Button RestartBtn;
+    }
+}

+ 181 - 0
ServiceHelper/ServiceHelper.cs

@@ -0,0 +1,181 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using System.Threading;
+
+namespace ServiceHelper
+{
+    public enum WorkType
+    { 
+        Install,
+        Uninstall,
+        Start,
+        Stop,
+        Restart,
+    }
+
+    public partial class ServiceHelper : Form
+    {
+        private const string serviceName = "Aca.Certain.MiddleService";
+        private const string serviceInstallPath = "Aca.Certain.MiddleService.exe";
+        private Progress progress = new Progress();
+        public static BackgroundWorker bgWorker = new BackgroundWorker();
+
+        public ServiceHelper()
+        {
+            InitializeComponent();
+            bgWorker.WorkerReportsProgress = true;
+            bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
+            bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_ProgressChanged);
+            bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);
+        }
+
+        void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
+        {
+            progress.Done();
+            if (!string.IsNullOrEmpty((string)e.Result))
+            {
+                MessageBox.Show((string)e.Result, "消息", MessageBoxButtons.OK);
+            }
+        }
+
+        void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
+        {
+            progress.UpdateProgress();
+        }
+
+        void bgWorker_DoWork(object sender, DoWorkEventArgs e)
+        {
+            try
+            {
+                progress.Reset();
+                switch ((WorkType)e.Argument)
+                {
+                    case WorkType.Install:
+                        {
+                            ServiceControl.Install(serviceName, serviceInstallPath);
+                            e.Result = "安装服务成功!";
+                        }
+                        break;
+                    case WorkType.Uninstall:
+                        {
+                            ServiceControl.Uninstall(serviceName, serviceInstallPath);
+                            e.Result = "卸载服务成功!";
+                        }
+                        break;
+                    case WorkType.Start:
+                        {
+                            ServiceControl.Start(serviceName);
+                            e.Result = "启动服务成功!";
+                        }
+                        break;
+                    case WorkType.Stop:
+                        {
+                            ServiceControl.Stop(serviceName);
+                            e.Result = "停止服务成功!";
+                        }
+                        break;
+                    case WorkType.Restart:
+                        {
+                            ServiceControl.Restart(serviceName);
+                            e.Result = "重启服务成功!";
+                        }
+                        break;
+                }
+            }
+            catch (Exception ex)
+            {
+                progress.Hide();
+                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK);
+            }            
+        }
+
+        private void InstallBtn_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                bgWorker.RunWorkerAsync(WorkType.Install);
+                progress.Text = "安装服务中……";
+                progress.ShowDialog(this);
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK);
+            }
+        }
+
+        private void UninstallBtn_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                bgWorker.RunWorkerAsync(WorkType.Uninstall);
+                progress.Text = "卸载服务中……";
+                progress.ShowDialog(this);
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK);
+            }
+        }
+
+        private void StartBtn_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                bgWorker.RunWorkerAsync(WorkType.Start);
+                progress.Text = "启动服务中……";
+                progress.ShowDialog(this);
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK);
+            }
+        }
+
+        private void StopBtn_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                bgWorker.RunWorkerAsync(WorkType.Stop);
+                progress.Text = "停止服务中……";
+                progress.ShowDialog(this);
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK);
+            }
+        }
+
+        private void RestartBtn_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                bgWorker.RunWorkerAsync(WorkType.Restart);
+                progress.Text = "重启服务中……";
+                progress.ShowDialog(this);
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK);
+            }
+        }
+
+        private void ConfigBtn_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                Settings settings = new Settings();
+                settings.ShowDialog(this);
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message, "获取配置失败", MessageBoxButtons.OK);
+            }
+        }
+    }
+}

+ 202 - 0
ServiceHelper/ServiceHelper.csproj

@@ -0,0 +1,202 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{590549FA-E057-4032-8329-214103B0F5FF}</ProjectGuid>
+    <OutputType>WinExe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>ServiceHelper</RootNamespace>
+    <AssemblyName>ServiceHelper</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+    <FileAlignment>512</FileAlignment>
+    <PublishUrl>publish\</PublishUrl>
+    <Install>true</Install>
+    <InstallFrom>Disk</InstallFrom>
+    <UpdateEnabled>false</UpdateEnabled>
+    <UpdateMode>Foreground</UpdateMode>
+    <UpdateInterval>7</UpdateInterval>
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+    <UpdatePeriodically>false</UpdatePeriodically>
+    <UpdateRequired>false</UpdateRequired>
+    <MapFileExtensions>true</MapFileExtensions>
+    <ApplicationRevision>0</ApplicationRevision>
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+    <IsWebBootstrapper>false</IsWebBootstrapper>
+    <UseApplicationTrust>false</UseApplicationTrust>
+    <BootstrapperEnabled>true</BootstrapperEnabled>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <PlatformTarget>x86</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|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <CodeAnalysisLogFile>bin\Debug\DicomServiceHelper.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+    <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+    <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <CodeAnalysisRuleSetDirectories>;D:\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
+    <CodeAnalysisRuleDirectories>;D:\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+    <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
+    <CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <CodeAnalysisLogFile>bin\Release\DicomServiceHelper.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+    <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+    <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <CodeAnalysisRuleSetDirectories>;D:\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+    <CodeAnalysisRuleDirectories>;D:\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x64\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <CodeAnalysisLogFile>bin\Debug\DicomServiceHelper.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+    <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+    <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <CodeAnalysisRuleSetDirectories>;D:\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
+    <CodeAnalysisRuleDirectories>;D:\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+    <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <CodeAnalysisLogFile>bin\Release\DicomServiceHelper.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+    <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+    <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <CodeAnalysisRuleSetDirectories>;D:\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+    <CodeAnalysisRuleDirectories>;D:\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Microsoft.Win32.TaskScheduler, Version=2.2.2.26204, Culture=neutral, PublicKeyToken=0d013ddd5178a2ae, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>Libs\Microsoft.Win32.TaskScheduler.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Configuration.Install" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.ServiceProcess" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Deployment" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="ServiceHelper.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="ServiceHelper.Designer.cs">
+      <DependentUpon>ServiceHelper.cs</DependentUpon>
+    </Compile>
+    <Compile Include="ManagerXml.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Progress.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Progress.Designer.cs">
+      <DependentUpon>Progress.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="QueryPerformance.cs" />
+    <Compile Include="ServiceControl.cs" />
+    <Compile Include="Settings.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Settings.Designer.cs">
+      <DependentUpon>Settings.cs</DependentUpon>
+    </Compile>
+    <Compile Include="TaskControl.cs" />
+    <EmbeddedResource Include="ServiceHelper.resx">
+      <DependentUpon>ServiceHelper.cs</DependentUpon>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Progress.resx">
+      <DependentUpon>Progress.cs</DependentUpon>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Properties\Resources.resx">
+      <Generator>ResXFileCodeGenerator</Generator>
+      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+      <SubType>Designer</SubType>
+    </EmbeddedResource>
+    <Compile Include="Properties\Resources.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Resources.resx</DependentUpon>
+      <DesignTime>True</DesignTime>
+    </Compile>
+    <EmbeddedResource Include="Settings.resx">
+      <DependentUpon>Settings.cs</DependentUpon>
+    </EmbeddedResource>
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Settings.settings</DependentUpon>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="Libs\Microsoft.Win32.TaskScheduler.dll" />
+  </ItemGroup>
+  <ItemGroup>
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+      <Visible>False</Visible>
+      <ProductName>.NET Framework 3.5 SP1</ProductName>
+      <Install>false</Install>
+    </BootstrapperPackage>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 120 - 0
ServiceHelper/ServiceHelper.resx

@@ -0,0 +1,120 @@
+<?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>
+</root>

+ 178 - 0
ServiceHelper/Settings.Designer.cs

@@ -0,0 +1,178 @@
+namespace ServiceHelper
+{
+    partial class Settings
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.OkBtn = new System.Windows.Forms.Button();
+            this.CancleBtn = new System.Windows.Forms.Button();
+            this.tabControl = new System.Windows.Forms.TabControl();
+            this.Task = new System.Windows.Forms.TabPage();
+            this.groupBox3 = new System.Windows.Forms.GroupBox();
+            this.maskedTextBoxStartBoundary = new System.Windows.Forms.MaskedTextBox();
+            this.labelStartBoundary = new System.Windows.Forms.Label();
+            this.textBoxDaysInterval = new System.Windows.Forms.TextBox();
+            this.labelDaysInterval = new System.Windows.Forms.Label();
+            this.checkBoxUseTask = new System.Windows.Forms.CheckBox();
+            this.tabControl.SuspendLayout();
+            this.Task.SuspendLayout();
+            this.groupBox3.SuspendLayout();
+            this.SuspendLayout();
+            // 
+            // OkBtn
+            // 
+            this.OkBtn.Location = new System.Drawing.Point(133, 377);
+            this.OkBtn.Name = "OkBtn";
+            this.OkBtn.Size = new System.Drawing.Size(75, 23);
+            this.OkBtn.TabIndex = 1;
+            this.OkBtn.Text = "确定";
+            this.OkBtn.UseVisualStyleBackColor = true;
+            this.OkBtn.Click += new System.EventHandler(this.OkBtn_Click);
+            // 
+            // CancleBtn
+            // 
+            this.CancleBtn.Location = new System.Drawing.Point(214, 377);
+            this.CancleBtn.Name = "CancleBtn";
+            this.CancleBtn.Size = new System.Drawing.Size(75, 23);
+            this.CancleBtn.TabIndex = 2;
+            this.CancleBtn.Text = "取消";
+            this.CancleBtn.UseVisualStyleBackColor = true;
+            this.CancleBtn.Click += new System.EventHandler(this.CancleBtn_Click);
+            // 
+            // tabControl
+            // 
+            this.tabControl.Controls.Add(this.Task);
+            this.tabControl.Location = new System.Drawing.Point(12, 12);
+            this.tabControl.Name = "tabControl";
+            this.tabControl.SelectedIndex = 0;
+            this.tabControl.Size = new System.Drawing.Size(277, 359);
+            this.tabControl.TabIndex = 0;
+            // 
+            // Task
+            // 
+            this.Task.Controls.Add(this.groupBox3);
+            this.Task.Controls.Add(this.checkBoxUseTask);
+            this.Task.Location = new System.Drawing.Point(4, 22);
+            this.Task.Name = "Task";
+            this.Task.Padding = new System.Windows.Forms.Padding(3);
+            this.Task.Size = new System.Drawing.Size(269, 333);
+            this.Task.TabIndex = 4;
+            this.Task.Text = "计划任务";
+            this.Task.UseVisualStyleBackColor = true;
+            // 
+            // groupBox3
+            // 
+            this.groupBox3.Controls.Add(this.maskedTextBoxStartBoundary);
+            this.groupBox3.Controls.Add(this.labelStartBoundary);
+            this.groupBox3.Controls.Add(this.textBoxDaysInterval);
+            this.groupBox3.Controls.Add(this.labelDaysInterval);
+            this.groupBox3.Location = new System.Drawing.Point(6, 22);
+            this.groupBox3.Name = "groupBox3";
+            this.groupBox3.Size = new System.Drawing.Size(257, 85);
+            this.groupBox3.TabIndex = 4;
+            this.groupBox3.TabStop = false;
+            this.groupBox3.Text = "Service服务重启计划";
+            // 
+            // maskedTextBoxStartBoundary
+            // 
+            this.maskedTextBoxStartBoundary.Location = new System.Drawing.Point(65, 50);
+            this.maskedTextBoxStartBoundary.Mask = "90:00:00";
+            this.maskedTextBoxStartBoundary.Name = "maskedTextBoxStartBoundary";
+            this.maskedTextBoxStartBoundary.Size = new System.Drawing.Size(82, 21);
+            this.maskedTextBoxStartBoundary.TabIndex = 7;
+            // 
+            // labelStartBoundary
+            // 
+            this.labelStartBoundary.AutoSize = true;
+            this.labelStartBoundary.Location = new System.Drawing.Point(6, 53);
+            this.labelStartBoundary.Name = "labelStartBoundary";
+            this.labelStartBoundary.Size = new System.Drawing.Size(53, 12);
+            this.labelStartBoundary.TabIndex = 4;
+            this.labelStartBoundary.Text = "触发时间";
+            // 
+            // textBoxDaysInterval
+            // 
+            this.textBoxDaysInterval.Location = new System.Drawing.Point(65, 23);
+            this.textBoxDaysInterval.Name = "textBoxDaysInterval";
+            this.textBoxDaysInterval.Size = new System.Drawing.Size(43, 21);
+            this.textBoxDaysInterval.TabIndex = 6;
+            // 
+            // labelDaysInterval
+            // 
+            this.labelDaysInterval.AutoSize = true;
+            this.labelDaysInterval.Location = new System.Drawing.Point(6, 26);
+            this.labelDaysInterval.Name = "labelDaysInterval";
+            this.labelDaysInterval.Size = new System.Drawing.Size(125, 12);
+            this.labelDaysInterval.TabIndex = 5;
+            this.labelDaysInterval.Text = "触发间隔          天";
+            // 
+            // checkBoxUseTask
+            // 
+            this.checkBoxUseTask.AutoSize = true;
+            this.checkBoxUseTask.Location = new System.Drawing.Point(167, 301);
+            this.checkBoxUseTask.Name = "checkBoxUseTask";
+            this.checkBoxUseTask.Size = new System.Drawing.Size(96, 16);
+            this.checkBoxUseTask.TabIndex = 0;
+            this.checkBoxUseTask.Text = "启用计划任务";
+            this.checkBoxUseTask.UseVisualStyleBackColor = true;
+            // 
+            // Settings
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(299, 412);
+            this.Controls.Add(this.CancleBtn);
+            this.Controls.Add(this.OkBtn);
+            this.Controls.Add(this.tabControl);
+            this.MaximizeBox = false;
+            this.MinimizeBox = false;
+            this.Name = "Settings";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+            this.Text = "Service配置";
+            this.tabControl.ResumeLayout(false);
+            this.Task.ResumeLayout(false);
+            this.Task.PerformLayout();
+            this.groupBox3.ResumeLayout(false);
+            this.groupBox3.PerformLayout();
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Button OkBtn;
+        private System.Windows.Forms.Button CancleBtn;
+        private System.Windows.Forms.TabControl tabControl;
+        private System.Windows.Forms.TabPage Task;
+        private System.Windows.Forms.CheckBox checkBoxUseTask;
+        private System.Windows.Forms.GroupBox groupBox3;
+        private System.Windows.Forms.Label labelDaysInterval;
+        private System.Windows.Forms.MaskedTextBox maskedTextBoxStartBoundary;
+        private System.Windows.Forms.Label labelStartBoundary;
+        private System.Windows.Forms.TextBox textBoxDaysInterval;
+    }
+}

+ 57 - 0
ServiceHelper/Settings.cs

@@ -0,0 +1,57 @@
+using System;
+using System.Windows.Forms;
+
+namespace ServiceHelper
+{
+    public partial class Settings : Form
+    {
+        private string _configFilePath = "service.config";
+        public ManagerXml _managerXml; 
+
+        public Settings()
+        {
+            InitializeComponent();
+
+            _managerXml = new ManagerXml(_configFilePath);
+
+            //读取任务计划配置
+            checkBoxUseTask.Checked = _managerXml.Get("UseTask") == "true" ? true : false;
+            textBoxDaysInterval.Text = _managerXml.Get("TaskDaysInterval");
+            maskedTextBoxStartBoundary.Text = _managerXml.Get("TaskStartBoundary");
+        }
+
+        private void OkBtn_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                //写入计划任务
+                _managerXml.Set("UseTask",checkBoxUseTask.Checked?"true":"false");
+                _managerXml.Set("TaskDaysInterval",textBoxDaysInterval.Text);
+                _managerXml.Set("TaskStartBoundary",maskedTextBoxStartBoundary.Text);
+                if (checkBoxUseTask.Checked)
+                {
+                    bool taskSeted = TaskControl.SetTask(short.Parse(textBoxDaysInterval.Text),maskedTextBoxStartBoundary.Text);
+                    if (!taskSeted)
+                    {
+                        MessageBox.Show("计划任务添加失败");
+                    }
+                }
+                else {
+                    TaskControl.DeleteTestTask();
+                }
+
+                this.Close();
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message, "保存配置文件错误", MessageBoxButtons.OK);
+            }
+        }
+
+        private void CancleBtn_Click(object sender, EventArgs e)
+        {
+            this.Close();
+        }
+
+    }
+}

+ 120 - 0
ServiceHelper/Settings.resx

@@ -0,0 +1,120 @@
+<?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>
+</root>

+ 228 - 0
ServiceHelper/TaskControl.cs

@@ -0,0 +1,228 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Win32.TaskScheduler;
+using System.IO;
+
+namespace ServiceHelper
+{
+    /// <summary>
+    /// 计划任务处理类
+    /// </summary>
+    public static class TaskControl
+    {
+        //触发时间
+        private static short _daysInterval;
+        //触发间隔
+        private static string _startBoundary;
+        private const string STOP = "sc stop Aca.Certain.MiddleService";
+        private const string START = "sc start Aca.Certain.MiddleService";
+        /// <summary>
+        /// 设置计划任务
+        /// </summary>
+        /// <param name="daysInterval">触发间隔</param>
+        /// <param name="startBoundary">触发时间</param>
+        public static bool SetTask(short daysInterval, string startBoundary)
+        {
+            _daysInterval = daysInterval;
+            _startBoundary = startBoundary;
+            TaskService taskService = new TaskService();
+            Task t = taskService.GetTask(@"Aca.Certain.MiddleServiceRestart");
+            if (t == null)
+            {
+                return CreateTask(taskService);
+            }
+            else
+            {
+                return ChangeTask(taskService);
+            }
+        }
+        /// <summary>
+        /// 创建计划任务
+        /// </summary>
+        /// <param name="taskService"></param>
+        private static bool CreateTask(TaskService taskService)
+        {
+            if (CreatBat())
+            {
+                // 创建一个计划任务
+                TaskDefinition taskDefinition = taskService.NewTask();
+                //描述
+                taskDefinition.RegistrationInfo.Description = "Aca.Certain.MiddleServiceRestart服务重启计划";
+                //创建者
+                taskDefinition.RegistrationInfo.Author = "CERTAIN";
+                //设置最高权限
+                taskDefinition.Principal.RunLevel = TaskRunLevel.Highest;
+                //设置并行运行新实例
+                taskDefinition.Settings.MultipleInstances = TaskInstancesPolicy.Parallel;
+                //每天启动
+                Trigger dailyTrigger = new DailyTrigger
+                {
+                    DaysInterval = _daysInterval
+                };
+                //限制计划任务每次执行时间不能超过1小时
+                dailyTrigger.ExecutionTimeLimit = TimeSpan.FromHours(1);
+                //启动时间
+                dailyTrigger.StartBoundary = DateTime.Parse(_startBoundary);
+                //全天重复执行
+                //dt.Repetition.Duration = TimeSpan.FromHours(24);
+                //每隔30分钟重复一次
+                //dt.Repetition.Interval = TimeSpan.FromMinutes(30);
+                //将触发器添加到计划任务td的触发器中
+                taskDefinition.Triggers.Add(dailyTrigger);
+
+                //创建一个执行操作
+                var bat = new ExecAction(System.Environment.CurrentDirectory + "\\restart.bat", "", null);
+                //添加执行操作到计划任务的操作中
+                taskDefinition.Actions.Add(bat);
+
+                //注册计划任务
+                taskService.RootFolder.RegisterTaskDefinition(@"Aca.Certain.MiddleServiceRestart", taskDefinition);
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 修改计划任务
+        /// </summary>
+        /// <param name="taskService"></param>
+        private static bool ChangeTask(TaskService taskService)
+        {
+            DeleteTestTask();
+            return CreateTask(taskService);
+        }
+        /// <summary>
+        /// 删除计划任务
+        /// </summary>
+        public static void DeleteTestTask()
+        {
+            TaskService ts = new TaskService();
+            Task t = ts.GetTask(@"Aca.Certain.MiddleServiceRestart");
+            if (t != null)
+            {
+                // 计划任务服务
+                ts.RootFolder.DeleteTask("Aca.Certain.MiddleServiceRestart");
+            }
+        }
+
+        /// <summary>
+        /// 查询计划任务
+        /// </summary>
+        private static Dictionary<string,string> RetrieveTestTask()
+        {
+            Dictionary<string,string> dt=new Dictionary<string,string>();
+            // 计划任务服务
+            TaskService ts = new TaskService();
+            Task t = ts.GetTask(@"DicomeServiceRestart");
+            if (null != t)
+            {
+                Console.WriteLine("Task Name={0}", t.Name);
+                Console.WriteLine("Task Execution Time={0}", t.LastRunTime);
+                Console.WriteLine("Task Last Run Result={0}", t.LastTaskResult);
+                Console.WriteLine("Task Next Execution Time={0}", t.NextRunTime);
+                return dt;
+            }
+            else
+            {
+                return null;
+            }
+        }
+        /// <summary>
+        /// 创建重启服务bat文件
+        /// </summary>
+        /// <returns>创建成功返回true,失败返回false</returns>
+        private static bool CreatBat()
+        {
+            FileStream fs = null;
+            StreamReader sr = null;
+            StreamWriter sw = null;
+            try
+            {
+                fs = new FileStream(System.Environment.CurrentDirectory + "\\restart.bat", FileMode.OpenOrCreate);
+                try
+                {
+                    sr = new StreamReader(fs);
+                    string stop = sr.ReadLine();
+                    if (STOP.Equals(stop))
+                    {
+                        string start = sr.ReadLine();
+                        if (START.Equals(start))
+                        {
+                            if (string.IsNullOrEmpty(sr.ReadLine()))
+                            {
+                                //文件已存在并且数据正确,返回true
+                                return true;
+                            }
+                        }
+                    }
+                    fs.SetLength(0);
+                }
+                catch (Exception)
+                {
+                    fs.SetLength(0);
+                    try
+                    {
+                        sr.Close();
+                    }
+                    catch
+                    {
+                    }
+                    //文件流打开失败,返回false
+                    return false;
+                    throw;
+                }
+                try
+                {
+                    sw = new StreamWriter(fs);
+                    sw.WriteLine(STOP);
+                    sw.WriteLine(START);
+                }
+                catch (Exception)
+                {
+                    //文件流打开失败,返回false
+                    return false;
+                    throw;
+                }
+                finally
+                {
+                    try
+                    {
+                        sw.Close();
+                    }
+                    catch
+                    {
+                    }
+                    try
+                    {
+                        sr.Close();
+                    }
+                    catch
+                    {
+                    }
+                    
+                }
+            }
+            catch (Exception)
+            {
+                //文件流打开失败,返回false
+                return false;
+                throw;
+            }
+            finally
+            {
+                try
+                {
+                    fs.Close();
+                }
+                catch
+                {
+                }
+            }
+            return true;
+        }
+    }
+}