This commit is contained in:
164
utils/GeneratorService/GeneratorService.csproj
Normal file
164
utils/GeneratorService/GeneratorService.csproj
Normal file
@@ -0,0 +1,164 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{EF51C1E7-8944-471D-A7CC-FC36DA2C0360}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>GeneratorService</RootNamespace>
|
||||
<AssemblyName>Generator</AssemblyName>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>..\..\keys\AyaNova.snk</AssemblyOriginatorKeyFile>
|
||||
<ApplicationIcon>Notify.ico</ApplicationIcon>
|
||||
<IsWebBootstrapper>true</IsWebBootstrapper>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<PublishUrl>http://localhost/Generator/</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Web</InstallFrom>
|
||||
<UpdateEnabled>true</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>3.4.2.0</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<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' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'RELEASE AND DEPLOY BUILD|AnyCPU' ">
|
||||
<OutputPath>bin\RELEASE AND DEPLOY BUILD\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=2.1.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\3rdprtylibs\firebird ado.net driver\FirebirdSql.Data.FirebirdClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Service1.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Service1.Designer.cs">
|
||||
<DependentUpon>Service1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SERVICEINSTALLER.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Service1.resx">
|
||||
<SubType>Designer</SubType>
|
||||
<DependentUpon>Service1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Notify.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\source\bizobjects\AyaLib\GZTW.AyaNova.BLL.csproj">
|
||||
<Project>{50B807B6-FC35-4CC3-B54D-91C78426A943}</Project>
|
||||
<Name>GZTW.AyaNova.BLL</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\source\csla10\CSLA.Core.Bindablebase\CSLA.Core.Bindablebase.csproj">
|
||||
<Project>{C2392355-12A9-4197-A1D3-603C390B1E62}</Project>
|
||||
<Name>CSLA.Core.Bindablebase</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\source\csla10\CSLA.Server.DataPortal\CSLA.Server.DataPortal.vbproj">
|
||||
<Project>{80828E2C-E9FB-4E73-A27C-7F9CDB96FCDE}</Project>
|
||||
<Name>CSLA.Server.DataPortal</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\source\csla10\CSLA\CSLA.vbproj">
|
||||
<Project>{1B9A38BB-461A-47A4-AD72-099C694138A0}</Project>
|
||||
<Name>CSLA</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\source\Data\Data\GZTW.Data.csproj">
|
||||
<Project>{701893AA-C042-4FB2-8643-E139372C1117}</Project>
|
||||
<Name>GZTW.Data</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\source\Profile\GZTW.Profile\GZTW.Profile.csproj">
|
||||
<Project>{EDE897E2-E2E6-441D-9F83-0B973AE09670}</Project>
|
||||
<Name>GZTW.Profile</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\keys\AyaNova.snk">
|
||||
<Link>AyaNova.snk</Link>
|
||||
</None>
|
||||
<None Include="app.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\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>
|
||||
24
utils/GeneratorService/GeneratorService.csproj.user
Normal file
24
utils/GeneratorService/GeneratorService.csproj.user
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishUrlHistory>http://localhost/Generator/</PublishUrlHistory>
|
||||
<InstallUrlHistory>
|
||||
</InstallUrlHistory>
|
||||
<SupportUrlHistory>
|
||||
</SupportUrlHistory>
|
||||
<UpdateUrlHistory>
|
||||
</UpdateUrlHistory>
|
||||
<BootstrapperUrlHistory>
|
||||
</BootstrapperUrlHistory>
|
||||
<FallbackCulture>en-US</FallbackCulture>
|
||||
<VerifyUploadedFiles>true</VerifyUploadedFiles>
|
||||
<ErrorReportUrlHistory>
|
||||
</ErrorReportUrlHistory>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<StartArguments>-i</StartArguments>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<StartArguments>-u</StartArguments>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
BIN
utils/GeneratorService/Notify.ico
Normal file
BIN
utils/GeneratorService/Notify.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
61
utils/GeneratorService/Program.cs
Normal file
61
utils/GeneratorService/Program.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
|
||||
namespace GeneratorService
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
if (args.Length > 0)
|
||||
{
|
||||
if (args[0] == "-i")
|
||||
{
|
||||
ServiceInstaller si = new ServiceInstaller();
|
||||
si.InstallService(Assembly.GetExecutingAssembly().Location, "AyaNovaGenerator", "AyaNova generator service");
|
||||
}
|
||||
else if (args[0] == "-u")
|
||||
{
|
||||
//Attempt to stop the service first
|
||||
ServiceController sc = new ServiceController("AyaNovaGenerator");
|
||||
if (sc.Status == ServiceControllerStatus.Running)
|
||||
if (sc.CanStop)
|
||||
sc.Stop();
|
||||
sc.WaitForStatus(ServiceControllerStatus.Stopped, new System.TimeSpan(0,0,30));//wait max 30 seconds to stop then just proceed anyway
|
||||
sc.Dispose();
|
||||
|
||||
ServiceInstaller si = new ServiceInstaller();
|
||||
si.UnInstallService("AyaNovaGenerator");
|
||||
}
|
||||
} else
|
||||
{
|
||||
System.ServiceProcess.ServiceBase[] ServicesToRun;
|
||||
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new AyGenSrv() };
|
||||
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//ServiceBase[] ServicesToRun;
|
||||
|
||||
//// More than one user Service may run within the same process. To add
|
||||
//// another service to this process, change the following line to
|
||||
//// create a second service object. For example,
|
||||
////
|
||||
//// ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
|
||||
////
|
||||
//ServicesToRun = new ServiceBase[] { new AyGenSrv() };
|
||||
|
||||
//ServiceBase.Run(ServicesToRun);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
33
utils/GeneratorService/Properties/AssemblyInfo.cs
Normal file
33
utils/GeneratorService/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Generator")]
|
||||
[assembly: AssemblyDescription("A windows service to process notification and preventive maintenance work orders for AyaNova")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Ground Zero Tech-Works Inc.")]
|
||||
[assembly: AssemblyProduct("Generator")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2006-2018 Ground Zero Tech-Works Inc. All rights reserved.")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("bf2b5726-6385-490a-84f1-3618892be1ba")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("7.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("7.5.0.0")]
|
||||
185
utils/GeneratorService/SERVICEINSTALLER.cs
Normal file
185
utils/GeneratorService/SERVICEINSTALLER.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
namespace GeneratorService
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for ServiceInstaller.
|
||||
/// </summary>
|
||||
class ServiceInstaller
|
||||
{
|
||||
#region Private Variables
|
||||
//private string _servicePath;
|
||||
//private string _serviceName;
|
||||
//private string _serviceDisplayName;
|
||||
#endregion Private Variables
|
||||
#region DLLImport
|
||||
[DllImport("advapi32.dll")]
|
||||
public static extern IntPtr OpenSCManager(string lpMachineName, string lpSCDB, int scParameter);
|
||||
[DllImport("Advapi32.dll")]
|
||||
public static extern IntPtr CreateService(IntPtr SC_HANDLE, string lpSvcName, string lpDisplayName,
|
||||
int dwDesiredAccess, int dwServiceType, int dwStartType, int dwErrorControl, string lpPathName,
|
||||
string lpLoadOrderGroup, int lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword);
|
||||
[DllImport("advapi32.dll")]
|
||||
public static extern void CloseServiceHandle(IntPtr SCHANDLE);
|
||||
[DllImport("advapi32.dll")]
|
||||
public static extern int StartService(IntPtr SVHANDLE, int dwNumServiceArgs, string lpServiceArgVectors);
|
||||
[DllImport("advapi32.dll", SetLastError = true)]
|
||||
public static extern IntPtr OpenService(IntPtr SCHANDLE, string lpSvcName, int dwNumServiceArgs);
|
||||
[DllImport("advapi32.dll")]
|
||||
public static extern int DeleteService(IntPtr SVHANDLE);
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern int GetLastError();
|
||||
#endregion DLLImport
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
#region Main method + testing code
|
||||
// [STAThread]
|
||||
// static void Main(string[] args)
|
||||
//{
|
||||
//// TODO: Add code to start application here
|
||||
//#region Testing
|
||||
//// Testing --------------
|
||||
//string svcPath;
|
||||
//string svcName;
|
||||
//string svcDispName;
|
||||
////path to the service that you want to install
|
||||
//svcPath = @"C:\build\service\Debug\Service.exe";
|
||||
//svcDispName="Service Display Name";
|
||||
//svcName= "Service Name";
|
||||
//ServiceInstaller c = new ServiceInstaller();
|
||||
//c.InstallService(svcPath, svcName, svcDispName);
|
||||
//Console.Read();
|
||||
//Testing --------------
|
||||
//#endregion Testing
|
||||
//}
|
||||
#endregion Main method + testing code - Commented
|
||||
/// <summary>
|
||||
/// This method installs and runs the service in the service control manager.
|
||||
/// </summary>
|
||||
/// <param name="svcPath">The complete path of the service.</param>
|
||||
/// <param name="svcName">Name of the service.</param>
|
||||
/// <param name="svcDispName">Display name of the service.</param>
|
||||
/// <returns>True if the process went thro successfully. False if there was any error.</returns>
|
||||
public bool InstallService(string svcPath, string svcName, string svcDispName)
|
||||
{
|
||||
#region Constants declaration.
|
||||
int SC_MANAGER_CREATE_SERVICE = 0x0002;
|
||||
int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
|
||||
//int SERVICE_DEMAND_START = 0x00000003;
|
||||
int SERVICE_ERROR_NORMAL = 0x00000001;
|
||||
int STANDARD_RIGHTS_REQUIRED = 0xF0000;
|
||||
int SERVICE_QUERY_CONFIG = 0x0001;
|
||||
int SERVICE_CHANGE_CONFIG = 0x0002;
|
||||
int SERVICE_QUERY_STATUS = 0x0004;
|
||||
int SERVICE_ENUMERATE_DEPENDENTS = 0x0008;
|
||||
int SERVICE_START = 0x0010;
|
||||
int SERVICE_STOP = 0x0020;
|
||||
int SERVICE_PAUSE_CONTINUE = 0x0040;
|
||||
int SERVICE_INTERROGATE = 0x0080;
|
||||
int SERVICE_USER_DEFINED_CONTROL = 0x0100;
|
||||
int SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED |
|
||||
SERVICE_QUERY_CONFIG |
|
||||
SERVICE_CHANGE_CONFIG |
|
||||
SERVICE_QUERY_STATUS |
|
||||
SERVICE_ENUMERATE_DEPENDENTS |
|
||||
SERVICE_START |
|
||||
SERVICE_STOP |
|
||||
SERVICE_PAUSE_CONTINUE |
|
||||
SERVICE_INTERROGATE |
|
||||
SERVICE_USER_DEFINED_CONTROL);
|
||||
int SERVICE_AUTO_START = 0x00000002;
|
||||
#endregion Constants declaration.
|
||||
try
|
||||
{
|
||||
if (svcPath.Contains(" "))
|
||||
svcPath = "\"" + svcPath + "\"";
|
||||
IntPtr sc_handle = OpenSCManager(null, null, SC_MANAGER_CREATE_SERVICE);
|
||||
if (sc_handle.ToInt32() != 0)
|
||||
{
|
||||
IntPtr sv_handle = CreateService(sc_handle, svcName, svcDispName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, svcPath, null, 0, null, null, null);
|
||||
|
||||
//IntPtr sv_handle = CreateService(sc_handle, svcName, svcDispName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, svcPath, null, 0, null, svcUserName, svcPassword);
|
||||
|
||||
|
||||
if (sv_handle.ToInt32() == 0)
|
||||
{
|
||||
Console.WriteLine("Error on CreateService: " + GetLastError().ToString());
|
||||
CloseServiceHandle(sc_handle);
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
////now trying to start the service
|
||||
//int i = StartService(sv_handle, 0, null);
|
||||
//// If the value i is zero, then there was an error starting the service.
|
||||
//// note: error may arise if the service is already running or some other problem.
|
||||
//if (i == 0)
|
||||
//{
|
||||
// //Console.WriteLine("Couldnt start service");
|
||||
// return false;
|
||||
//}
|
||||
//Console.WriteLine("Success");
|
||||
CloseServiceHandle(sc_handle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Error on OpenSCManager for create: " + GetLastError().ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// This method uninstalls the service from the service conrol manager.
|
||||
/// </summary>
|
||||
/// <param name="svcName">Name of the service to uninstall.</param>
|
||||
public bool UnInstallService(string svcName)
|
||||
{
|
||||
int GENERIC_WRITE = 0x40000000;
|
||||
IntPtr sc_hndl = OpenSCManager(null, null, GENERIC_WRITE);
|
||||
if (sc_hndl.ToInt32() != 0)
|
||||
{
|
||||
int DELETE = 0x10000;
|
||||
IntPtr svc_hndl = OpenService(sc_hndl, svcName, DELETE);
|
||||
//Console.WriteLine(svc_hndl.ToInt32());
|
||||
|
||||
if (svc_hndl.ToInt32() != 0)
|
||||
{
|
||||
int i = DeleteService(svc_hndl);
|
||||
if (i != 0)
|
||||
{
|
||||
CloseServiceHandle(sc_hndl);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Error in DeleteService: " + GetLastError().ToString());
|
||||
CloseServiceHandle(sc_hndl);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Error in OpenSCManager for delete: " + GetLastError().ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
41
utils/GeneratorService/Service1.Designer.cs
generated
Normal file
41
utils/GeneratorService/Service1.Designer.cs
generated
Normal file
@@ -0,0 +1,41 @@
|
||||
namespace GeneratorService
|
||||
{
|
||||
partial class AyGenSrv
|
||||
{
|
||||
/// <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 Component 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()
|
||||
{
|
||||
//
|
||||
// AyGenSrv
|
||||
//
|
||||
this.CanPauseAndContinue = true;
|
||||
this.ServiceName = "AyaNovaGenerator";
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
183
utils/GeneratorService/Service1.cs
Normal file
183
utils/GeneratorService/Service1.cs
Normal file
@@ -0,0 +1,183 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using GZTW.AyaNova.BLL;
|
||||
|
||||
namespace GeneratorService
|
||||
{
|
||||
public partial class AyGenSrv : ServiceBase
|
||||
{
|
||||
private System.Timers.Timer timer = null;
|
||||
private bool Initialized = false;
|
||||
private int maxTries = 0;
|
||||
private const int retryInterval = 60000;
|
||||
private const int processInterval = 300000;
|
||||
//case 2048
|
||||
private string eventLogSource = "AyaNovaGenerator";
|
||||
|
||||
public AyGenSrv()
|
||||
{
|
||||
InitializeComponent();
|
||||
//Init timer and set initial interval to 1 second
|
||||
//so that it starts "immediately" when the service starts
|
||||
//after it's fired it will go to it's normal cycle of 5 minutes
|
||||
timer = new System.Timers.Timer(1000);
|
||||
//set the event handler for the timer
|
||||
timer.Elapsed += new System.Timers.ElapsedEventHandler(this.ServiceTimer_Tick);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private bool TryConnecting()
|
||||
{
|
||||
//Failed to connect after maxtries?
|
||||
if (maxTries > 9)
|
||||
{
|
||||
EventLog.WriteEntry(eventLogSource,
|
||||
"Connection to AyaNova database could not be initialized after 10 attempts.\r\n" +
|
||||
"Other errors in the application error log before or after this one may provide more details.\r\n" +
|
||||
"The configuration file config.txt probably has an incorrect connection setting\r\n" +
|
||||
"to access the database (wrong path, login or password) or the database server is not running.", EventLogEntryType.Error);
|
||||
QuitNow();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GZTW.AyaNova.BLL.AyaBizUtils.AyaNovaConnectionSetting.SingleUserConnection)
|
||||
{
|
||||
EventLog.WriteEntry(eventLogSource,
|
||||
"The current database connection in the config.txt file specifies a stand alone embedded FireBird database.\r\n" +
|
||||
"Generator is not required for a single user database connection. It's required for a shared network connection only.\r\n" +
|
||||
"In a single user connection AyaNova handles the tasks of Generator automatically.\r\n" +
|
||||
"Generator will now close.\r\n" +
|
||||
"See the AyaNova manual for more details.", EventLogEntryType.Error);
|
||||
QuitNow();
|
||||
return false;
|
||||
}
|
||||
|
||||
//not timed out so try to connect
|
||||
try
|
||||
{
|
||||
GZTW.AyaNova.BLL.AyaBizUtils.Initialize();
|
||||
//case 2093 ampersand in name crashing generator service
|
||||
// eventLogSource = "AyaNovaGenerator - (" + AyaBizUtils.REGTO + ")";
|
||||
eventLogSource = "AyaNovaGenerator - (" + System.Text.RegularExpressions.Regex.Replace(AyaBizUtils.REGTO, @"[^A-Za-z0-9]+", "") +")";
|
||||
|
||||
Initialized = true;
|
||||
EventLog.WriteEntry(eventLogSource,
|
||||
"Connection established", EventLogEntryType.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Initialized = false;
|
||||
maxTries++;
|
||||
|
||||
if(maxTries < 10)
|
||||
EventLog.WriteEntry(eventLogSource,
|
||||
"Connection failed (attempt "+maxTries.ToString()+" of 10 ) - retrying in 1 minute", EventLogEntryType.Warning);
|
||||
|
||||
//Only log the last attempt, earlier ones could have been waiting for dbserver to start and not relevant
|
||||
string strMessage = ex.Message;
|
||||
if (ex.InnerException != null)
|
||||
strMessage = ex.InnerException.Message;
|
||||
if(maxTries > 9)
|
||||
EventLog.WriteEntry(eventLogSource, strMessage, EventLogEntryType.Error);
|
||||
|
||||
}
|
||||
|
||||
return Initialized;
|
||||
}
|
||||
|
||||
private void QuitNow()
|
||||
{
|
||||
timer.Stop();
|
||||
timer.AutoReset = false;
|
||||
timer.Enabled = false;
|
||||
this.Stop();
|
||||
}
|
||||
|
||||
protected override void OnStart(string[] args)
|
||||
{
|
||||
|
||||
timer.AutoReset = true;
|
||||
timer.Enabled = true;
|
||||
timer.Start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
|
||||
timer.Stop();
|
||||
timer.AutoReset = false;
|
||||
timer.Enabled = false;
|
||||
base.OnStop();
|
||||
}
|
||||
|
||||
protected override void OnPause()
|
||||
{
|
||||
timer.Stop();
|
||||
base.OnPause();
|
||||
}
|
||||
|
||||
protected override void OnContinue()
|
||||
{
|
||||
|
||||
timer.Start();
|
||||
base.OnContinue();
|
||||
}
|
||||
|
||||
|
||||
//process
|
||||
private void ServiceTimer_Tick(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
this.timer.Stop();
|
||||
|
||||
|
||||
//make an appearance of less memory for those that don't understand how .net memory allocation works
|
||||
//and bitch to us that task manager shows it's using too much memory
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process loProcess = System.Diagnostics.Process.GetCurrentProcess();
|
||||
loProcess.MaxWorkingSet = loProcess.MaxWorkingSet;//doesn't matter what you set it to, just setting it triggers re-evalutaion
|
||||
}
|
||||
catch { };
|
||||
|
||||
//If not initialized restart with a shorter timer than normal
|
||||
if (!Initialized)
|
||||
{
|
||||
if (!TryConnecting())
|
||||
{
|
||||
this.timer.Interval = retryInterval;
|
||||
this.timer.Start();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//It's initialized so process as normal
|
||||
try
|
||||
{
|
||||
GenProcess.GO("121605GENERATOR", "121605GENERATOR");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string strMessage = ex.Message;
|
||||
if (ex.InnerException != null)
|
||||
strMessage = ex.InnerException.Message;
|
||||
EventLog.WriteEntry(eventLogSource, strMessage, EventLogEntryType.Error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.timer.Interval = processInterval;
|
||||
this.timer.Start();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
123
utils/GeneratorService/Service1.resx
Normal file
123
utils/GeneratorService/Service1.resx
Normal file
@@ -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=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>
|
||||
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>False</value>
|
||||
</metadata>
|
||||
</root>
|
||||
3
utils/GeneratorService/app.config
Normal file
3
utils/GeneratorService/app.config
Normal file
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /></startup></configuration>
|
||||
Reference in New Issue
Block a user