天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

99 lines
3.6 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace ProcessFileSyncService
{
public partial class FileSyncService : ServiceBase
{
Dictionary<string, Type> SynchronizerMap = new Dictionary<string, Type>();
List<FileSynchronizers.IFileSynchronizer> Synchronizers = new List<FileSynchronizers.IFileSynchronizer>();
public FileSyncService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
LoadSynchronizers();
QMAPP.FJC.BLL.Basic.MachineInfoBLL machinebll = new QMAPP.FJC.BLL.Basic.MachineInfoBLL();
var machineList = machinebll.GetAllMachineInfoList();
foreach (var machine in machineList)
{
if (SynchronizerMap.ContainsKey(machine.EQUIPMENT_TYPE_CODE + ""))
{
var synctype = SynchronizerMap[machine.EQUIPMENT_TYPE_CODE + ""];
var filesync = (FileSynchronizers.IFileSynchronizer)Activator.CreateInstance(synctype, machine);
filesync.Start();
Synchronizers.Add(filesync);
}
}
QMFrameWork.Log.LogManager.LogHelper.Info(
new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "服务启动完成" });
}
catch (Exception ex)
{
QMFrameWork.Log.LogManager.LogHelper.Error(
new QMFrameWork.Log.LogInfo { Info = "服务启动失败!", ErrorInfo = ex });
}
}
protected override void OnStop()
{
foreach (var sync in Synchronizers)
{
sync.Stop();
}
}
internal void TestStart()
{
LoadSynchronizers();
QMAPP.FJC.BLL.Basic.MachineInfoBLL machinebll = new QMAPP.FJC.BLL.Basic.MachineInfoBLL();
var machineList= machinebll.GetAllMachineInfoList();
foreach (var machine in machineList)
{
if (SynchronizerMap.ContainsKey(machine.EQUIPMENT_TYPE_CODE+""))
{
var synctype = SynchronizerMap[machine.EQUIPMENT_TYPE_CODE+""];
var filesync= (FileSynchronizers.IFileSynchronizer)Activator.CreateInstance(synctype, machine);
filesync.Start();
Synchronizers.Add(filesync);
}
}
}
private void LoadSynchronizers()
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(AppDomain.CurrentDomain.BaseDirectory+"SynchronizerMap.xml");
var nodes = doc.SelectNodes("Synchronizers/Synchronizer");
foreach (System.Xml.XmlNode node in nodes)
{
var equiptype = node.Attributes["EquipmentType"].Value;
var assembly = System.Reflection.Assembly.Load(node.Attributes["AssemblyName"].Value);
var type = assembly.GetType(node.Attributes["ClassName"].Value);
if (type != null)
{
if (!SynchronizerMap.ContainsKey(equiptype))
{
SynchronizerMap.Add(equiptype, type);
}
}
}
}
}
}