|
|
|
|
using log4net;
|
|
|
|
|
using SOA.Config;
|
|
|
|
|
using SOA.Objects;
|
|
|
|
|
using SOA.Registry;
|
|
|
|
|
using SOA.Schedule;
|
|
|
|
|
using SOA.Service;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace SlabHandle
|
|
|
|
|
{
|
|
|
|
|
internal class Program
|
|
|
|
|
{
|
|
|
|
|
//日志记录
|
|
|
|
|
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
private static System.Timers.Timer Tm = new System.Timers.Timer(15000);
|
|
|
|
|
|
|
|
|
|
private static ConfigHandler config;
|
|
|
|
|
|
|
|
|
|
private static ServiceFactory serviceFactory = new ServiceFactory();
|
|
|
|
|
|
|
|
|
|
private static List<IAppService> appServiceContainer = new List<IAppService>();
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
|
|
|
|
|
private static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
|
|
|
|
|
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
|
|
|
|
|
|
|
|
|
//主程序
|
|
|
|
|
private static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
//AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
|
|
|
|
|
|
|
|
|
|
if (args.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
#region 隐藏运行
|
|
|
|
|
|
|
|
|
|
var currentProcess = System.Diagnostics.Process.GetCurrentProcess();
|
|
|
|
|
Console.WriteLine(currentProcess.MainWindowTitle);
|
|
|
|
|
IntPtr hWnd = currentProcess.MainWindowHandle;
|
|
|
|
|
if (hWnd != IntPtr.Zero)
|
|
|
|
|
{
|
|
|
|
|
//Hide the window
|
|
|
|
|
ShowWindow(hWnd, 0); // 0 = SW_HIDE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion 隐藏运行
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.InfoFormat("验证授权...");
|
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
|
logger.InfoFormat("SOA ServiceHost initializing");
|
|
|
|
|
config = (ConfigHandler)ConfigurationManager.GetSection("soa");
|
|
|
|
|
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
|
|
|
|
ServiceRepository.LoadServices(baseDirectory);
|
|
|
|
|
if (config.Objects.ElementInformation.IsPresent)
|
|
|
|
|
{
|
|
|
|
|
ObjectContainer objectContainer = new ObjectContainer(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServiceRegistry.Initialize(config);
|
|
|
|
|
|
|
|
|
|
ServiceRegistry.Start();
|
|
|
|
|
if (config.Schedule.ElementInformation.IsPresent)
|
|
|
|
|
{
|
|
|
|
|
ScheduleService.Initialize(config);
|
|
|
|
|
ScheduleService.Start();
|
|
|
|
|
}
|
|
|
|
|
foreach (Protocol value in ServiceRepository.protocols.Values)
|
|
|
|
|
{
|
|
|
|
|
value.Start();
|
|
|
|
|
}
|
|
|
|
|
if (config.AppServiceConfigCollection.ElementInformation.IsPresent)
|
|
|
|
|
{
|
|
|
|
|
foreach (AppServiceConfigElement item2 in config.AppServiceConfigCollection)
|
|
|
|
|
{
|
|
|
|
|
IAppService appService = ObjectContainer.GetObject(item2.ObjectReference) as IAppService;
|
|
|
|
|
if (appService != null)
|
|
|
|
|
{
|
|
|
|
|
appServiceContainer.Add(appService);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach (IAppService item3 in appServiceContainer)
|
|
|
|
|
{
|
|
|
|
|
item3.Start();
|
|
|
|
|
logger.InfoFormat("Startup up service '{0}'", item3.ToString());
|
|
|
|
|
}
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
|
|
|
|
|
logger.InfoFormat("SOA ServiceHost startuped");
|
|
|
|
|
|
|
|
|
|
string strSlabNo = string.Empty;
|
|
|
|
|
if (args.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
strSlabNo = "'" + args[0] + "'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Environment.ExitCode = 0;//初始返回结果是0
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (SlabControler.reqBulkSlabSupersede(strSlabNo).code == "1")
|
|
|
|
|
{
|
|
|
|
|
Environment.ExitCode = 1;//处理成功
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
Environment.ExitCode = 2;//处理失败
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//string strSlabNo = string.Empty;
|
|
|
|
|
//if (args.Count() > 1)
|
|
|
|
|
//{
|
|
|
|
|
// strSlabNo = args[1];
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//if (args.Length > 0)
|
|
|
|
|
//{
|
|
|
|
|
// if (args[0] == "C3")
|
|
|
|
|
// {
|
|
|
|
|
// SlabControler.reqBulkSlabSupersede(strSlabNo);
|
|
|
|
|
// }
|
|
|
|
|
// if (args[0] == "C2")
|
|
|
|
|
// {
|
|
|
|
|
// SlabControler.reqBulkSlabSupersede(strSlabNo);
|
|
|
|
|
// }
|
|
|
|
|
// if (args[0] == "C1")
|
|
|
|
|
// {
|
|
|
|
|
// SlabCoilControler.reqBulkSlabSupersede(Tm);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// SlabControler.reqBulkSlabSupersede(strSlabNo);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//SurMatSubController.AddSurplusMaterial(null, Tm);
|
|
|
|
|
|
|
|
|
|
//Tm.Elapsed += new System.Timers.ElapsedEventHandler(TimeOut);//Timer线程执行的方法
|
|
|
|
|
//Tm.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
|
|
|
|
|
//Tm.Enabled = true; //初始化是否可用
|
|
|
|
|
//Tm.Interval = 6 * 60000;//起始10秒
|
|
|
|
|
//logger.Info("Timer周期:" + Tm.Interval);
|
|
|
|
|
//logger.Info("当前时间:" + DateTime.Now.ToString());
|
|
|
|
|
|
|
|
|
|
//Console.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
logger.ErrorFormat("SOA ServiceHost unhandle exception: {0}", e.ExceptionObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void TimeOut(object source, System.Timers.ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string strSql = string.Empty;
|
|
|
|
|
logger.Info("Timer周期:" + Tm.Interval);
|
|
|
|
|
logger.Info("当前时间:" + DateTime.Now.ToString());
|
|
|
|
|
//SurMatSubController.AddSurplusMaterial(null, Tm);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.Error("******错误信息:" + ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|