You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
8.5 KiB
C#
179 lines
8.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using System.Xml;
|
|
using ICSharpCode.Core;
|
|
using ICSharpCode.Core.Services;
|
|
using Mesnac.Gui.Run.Global;
|
|
namespace MCRun
|
|
{
|
|
using Mesnac.Core.Service;
|
|
using Mesnac.DoUtils;
|
|
using Mesnac.Gui.Workbench;
|
|
using Mesnac.PlcUtils;
|
|
using Mesnac.PlcUtils.common;
|
|
using Mesnac.PlcUtils.enumInfo;
|
|
using Mesnac.PlcUtils.Impl;
|
|
using System.Drawing.Drawing2D;
|
|
|
|
class Program
|
|
{
|
|
[STAThread]
|
|
static void Main(string[] args)
|
|
{
|
|
if (Mesnac.Basic.ProcessHelper.HaveRunningInstance())
|
|
{
|
|
Mesnac.Basic.MessageBoxTimeOut.Show("The application is running, Please be patient...", "Caption", 2000);
|
|
Application.Exit();
|
|
return;
|
|
}
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
//初始化服务管理器
|
|
MesnacServiceManager.Init();
|
|
|
|
#region 授权处理
|
|
|
|
#if (!DEBUG)
|
|
//MesnacServiceManager.Instance.LoggingService.Info("软件授权...");
|
|
//if (!Mesnac.Basic.Register.IsExist("MCRun") || Mesnac.Basic.Register.GetRegData("MCRun") != Mesnac.Basic.Register.GetRegCode())
|
|
//{
|
|
// Mesnac.Gui.Run.FrmRegister frmRegister = new Mesnac.Gui.Run.FrmRegister();
|
|
// frmRegister.ShowDialog();
|
|
// if (frmRegister.DialogResult == DialogResult.Cancel)
|
|
// {
|
|
// Application.Exit();
|
|
// return;
|
|
// }
|
|
//}
|
|
#endif
|
|
|
|
#endregion
|
|
|
|
ICSharpCode.Core.LoggingService<Program>.Info("starting the application...");
|
|
//MesnacServiceManager.Instance.LoggingService.Info("starting the application...");
|
|
//ICSharpCode.Core.LoggingService.Info("starting the application...");
|
|
Assembly exe = typeof(Program).Assembly;
|
|
FileUtility.ApplicationRootPath = Path.GetDirectoryName(exe.Location);
|
|
|
|
CoreStartup cs = new CoreStartup("MCRun");
|
|
//设备配置文件目录
|
|
cs.ConfigDirectory = Path.Combine(FileUtility.ApplicationRootPath, "Data", "Config");
|
|
|
|
ICSharpCode.Core.LoggingService<Program>.Info("starting core services...");
|
|
cs.StartCoreServices();
|
|
//注册资源文件,文本和图片
|
|
ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCRun.Properties.SDRes", exe));
|
|
ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCRun.Properties.SDRes", exe));
|
|
|
|
ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCRun.Properties.MesnacResource", exe));
|
|
ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCRun.Properties.MesnacResource", exe));
|
|
|
|
ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCRun.Properties.Mesnac.Common", exe));
|
|
ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCRun.Properties.Mesnac.Common", exe));
|
|
|
|
ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCRun.Properties.Mesnac.Run", exe));
|
|
ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCRun.Properties.Mesnac.Run", exe));
|
|
|
|
ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCRun.Properties.Mesnac.Controls.Default", exe));
|
|
ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCRun.Properties.Mesnac.Controls.Default", exe));
|
|
|
|
ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCRun.Properties.Mesnac.Action.Default", exe));
|
|
ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCRun.Properties.Mesnac.Action.Default", exe));
|
|
|
|
ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("MCRun.Properties.Mesnac.Action.ChemicalWeighing", exe));
|
|
ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("MCRun.Properties.Mesnac.Action.ChemicalWeighing", exe));
|
|
|
|
AddInTree.Doozers.TryAdd("Pad", new Mesnac.PlugIn.Pad.PadDoozer());
|
|
|
|
ICSharpCode.Core.LoggingService<Program>.Debug("searching plugins...");
|
|
cs.AddAddInsFromDirectory(Path.Combine(FileUtility.ApplicationRootPath, "Data", "SharpPlugIn"));
|
|
|
|
ICSharpCode.Core.LoggingService<Program>.Debug("loadding plugins...");
|
|
cs.RunInitialization();
|
|
|
|
ICSharpCode.Core.LoggingService<Program>.Debug("initializing workbench...");
|
|
WorkbenchSingleton.InitFinished += delegate(object sender, EventArgs e)
|
|
{
|
|
ICSharpCode.Core.LoggingService<Program>.Debug("initializing run engine...");
|
|
string projectPath = Path.Combine(Application.StartupPath, AppConfigHandler.Instance.MCProjectPath); //组态工程路径
|
|
if (Mesnac.Gui.Common.RunEngine.Instance.Init(projectPath, true, true, true)) //初始化运行引擎
|
|
{
|
|
AppConfigHandler.Instance.InitCustomerMenuAndToolStrip(WorkbenchSingleton.Workbench.TopMenu, WorkbenchSingleton.Workbench.ToolStrip); //初始化自定义系统菜单和工具栏
|
|
|
|
try
|
|
{
|
|
var instance = Mesnac.Equips.Factory.Instance.ConfigFile;
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(instance);
|
|
var nodes = doc.ChildNodes[1].ChildNodes[0].ChildNodes[0].ChildNodes[4].ChildNodes[0];
|
|
var ip = nodes.Attributes["value"].Value;
|
|
//初始化HslCommunication 11.0.6.0
|
|
PlcBusiness.Instance.InitPlcConnect(PlcType.SiemensPlc,ip, 102);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
ICSharpCode.Core.LoggingService<Program>.Debug("HSLPlc读取失败");
|
|
}
|
|
//初始化连接报警器
|
|
DoControl.Instance.ComOn();
|
|
}
|
|
|
|
//if (!Mesnac.Basic.InfluxDbHelper.Instance.IsStartDbServer)
|
|
//{
|
|
// ICSharpCode.Core.LoggingService<Program>.Debug("starting InfluxDb server...");
|
|
// Mesnac.Basic.InfluxDbHelper.Instance.StartDbServer();
|
|
//}
|
|
//else
|
|
//{
|
|
// ICSharpCode.Core.LoggingService<Program>.Debug("InfluxDb server is started...");
|
|
//}
|
|
|
|
ICSharpCode.Core.LoggingService<Program>.Debug("starting communication server...");
|
|
//Mesnac.Communication.TcpService.StartService(); //启动通信服务器
|
|
//Mesnac.Basic.SocketClient.Instance.Connect();
|
|
};
|
|
WorkbenchSingleton.InitializeWorkbench();
|
|
|
|
ICSharpCode.Core.LoggingService<Program>.Debug("starting workbench...");
|
|
Form frmMain = WorkbenchSingleton.Workbench as Form;
|
|
|
|
if (String.IsNullOrEmpty(Mesnac.Basic.UserInfo.Instance.RoleGUID) || String.IsNullOrEmpty(Mesnac.Basic.UserInfo.Instance.UserName))
|
|
{
|
|
Mesnac.Basic.UserInfo.Instance.RoleGUID = "-99"; //设置用户角色
|
|
//Mesnac.Basic.UserInfo.Instance.UserGUID = "";
|
|
//Mesnac.Basic.UserInfo.Instance.UserName = "mesnac";
|
|
}
|
|
|
|
#region 显示当前用户
|
|
|
|
Mesnac.Basic.UserInfo.Instance.TriggerReLoginEvent();
|
|
|
|
#endregion
|
|
|
|
WorkbenchSingleton.Workbench.CloseFlag = true;
|
|
|
|
Application.Run(frmMain);
|
|
|
|
PropertyService.Save();
|
|
//Mesnac.Communication.TcpService.StopService(); //停止通信服务器
|
|
//Mesnac.Basic.SocketClient.Instance.Disconnect();
|
|
//退出系统之前,关闭相关文档
|
|
Mesnac.Gui.Common.RunEngine.Instance.CloseAllForms();
|
|
Mesnac.Gui.Workbench.WorkbenchSingleton.Workbench.CloseAllViews();
|
|
|
|
ICSharpCode.Core.LoggingService<Program>.Info("closed the application.");
|
|
//关闭当前线程
|
|
System.Environment.Exit(System.Environment.ExitCode);
|
|
Application.ExitThread();
|
|
Application.Exit();
|
|
}
|
|
|
|
|
|
}
|
|
}
|