using System; using System.Collections.Generic; using System.Reflection; using System.Text; using System.IO; using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.Core.Services; using Host; namespace MCEdit { using Mesnac.Core.Service; using Mesnac.Gui.Workbench; class Program { [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //初始化服务管理器 MesnacServiceManager.Init(); #region 授权处理 #if (!DEBUG) //MesnacServiceManager.Instance.LoggingService.Info("软件授权..."); //if (!Mesnac.Basic.Register.IsExist("MCEdit") || Mesnac.Basic.Register.GetRegData("MCEdit") != Mesnac.Basic.Register.GetRegCode()) //{ // Mesnac.Gui.Edit.FrmRegister frmRegister = new Mesnac.Gui.Edit.FrmRegister(); // frmRegister.ShowDialog(); // if (frmRegister.DialogResult == DialogResult.Cancel) // { // Application.Exit(); // return; // } //} #endif #endregion ICSharpCode.Core.LoggingService.Info("starting the application..."); Assembly exe = typeof(Program).Assembly; FileUtility.ApplicationRootPath = Path.GetDirectoryName(exe.Location); CoreStartup cs = new CoreStartup("MCEdit"); //设备配置文件目录 cs.ConfigDirectory = Path.Combine(FileUtility.ApplicationRootPath, "Data", "Config"); ICSharpCode.Core.LoggingService.Info("starting core services..."); cs.StartCoreServices(); //注册资源文件,文本和图片 ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCEdit.Properties.SDRes", exe)); ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCEdit.Properties.SDRes", exe)); ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCEdit.Properties.MesnacResource", exe)); ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCEdit.Properties.MesnacResource", exe)); ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCEdit.Properties.Mesnac.Common", exe)); ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCEdit.Properties.Mesnac.Common", exe)); ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCEdit.Properties.Mesnac.Controls.Default", exe)); ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCEdit.Properties.Mesnac.Controls.Default", exe)); ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCEdit.Properties.Mesnac.Action.Default", exe)); ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCEdit.Properties.Mesnac.Action.Default", exe)); ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCEdit.Properties.Mesnac.Action.ChemicalWeighing", exe)); ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCEdit.Properties.Mesnac.Action.ChemicalWeighing", exe)); //设置初始语言区域 string cultureName = ICSharpCode.Core.PropertyService.Get(ResourceService.CultureProperty, "zh-CN"); if (!String.IsNullOrEmpty(cultureName)) { System.Globalization.CultureInfo currentUICulture = new System.Globalization.CultureInfo(cultureName); System.Threading.Thread.CurrentThread.CurrentUICulture = currentUICulture; } AddInTree.Doozers.TryAdd("Pad", new Mesnac.PlugIn.Pad.PadDoozer()); ICSharpCode.Core.LoggingService.Debug("searing plugins..."); cs.AddAddInsFromDirectory(Path.Combine(FileUtility.ApplicationRootPath, "Data\\SharpPlugIn")); ICSharpCode.Core.LoggingService.Debug("loading plugins..."); cs.RunInitialization(); ICSharpCode.Core.LoggingService.Debug("initialing workbench..."); WorkbenchSingleton.InitFinished += delegate(object sender, EventArgs e) { Mesnac.Gui.Edit.Common.FormDesignerHelper.Init(); }; WorkbenchSingleton.InitializeWorkbench(); ICSharpCode.Core.LoggingService.Debug("starting workbench..."); //Mesnac.Communication.TcpService.StartService(); //启动通信服务器 //Mesnac.Basic.SocketClient.Instance.Connect(); Mesnac.Basic.UserInfo.Instance.RoleGUID = "-99"; //设置用户角色 //Mesnac.Basic.UserInfo.Instance.UserGUID = ""; //Mesnac.Basic.UserInfo.Instance.UserName = "mesnac"; //退出系统之前,关闭相关文档 WorkbenchSingleton.Workbench.ShutDown += delegate(object sender, EventArgs e) { Mesnac.Gui.Edit.ViewContent.DisplayUtil.ClearProject(); }; Form frmMain = WorkbenchSingleton.Workbench as Form; Application.Run(frmMain); PropertyService.Save(); //Mesnac.Communication.TcpService.StopService(); //停止通信服务器 //Mesnac.Basic.SocketClient.Instance.Disconnect(); //退出系统之前,关闭组态工程 Mesnac.Gui.Edit.ViewContent.DisplayUtil.ClearProject(); ICSharpCode.Core.LoggingService.Info("closed the application."); //关闭当前线程 Application.ExitThread(); Application.Exit(); System.Environment.Exit(System.Environment.ExitCode); } } }