Program.cs 4.7 KB
using System;
using System.Windows.Forms;

namespace AGVControl_Steel
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            log4net.Config.XmlConfigurator.Configure();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (Asa.WindowsForm.IsRun())
            {
                MessageBox.Show("IsRun");
                return;
            }

            if (!Asa.WindowsForm.IsAdmin())
            {
                Asa.WindowsForm.AdminRun();
                return;
            }

            Common.appConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
            Common.log = log4net.LogManager.GetLogger("AGVControl_Steel");
            Common.log.Info("=====程序开始=====");
            ReadConfig();
            Common.steelManage = new BLL.SteelManage();
            //Common.steelManage.OldSteelWorkLoad();
            //Common.steelManage.NewSteelWorkLoad();
            Common.control = new BLL.Control();
            Common.mir = new Model.MiR_API { FleetIP = Common.appConfig.AppSettings.Settings["FLEET_IP"].Value, MissionList = Common.agvMissions };

            Application.Run(new FrmMain());

            Common.control.Stop();
            Common.log.Info("=====程序结束=====\r\n");
        }

        private static void ReadConfig()
        {
            try
            {
                //AGV小车信息
                Common.agvInfos = new System.Collections.Generic.List<Model.AgvInfo>();
                string[] lines = System.IO.File.ReadAllLines(Common.PATH_AGV_NAME, System.Text.Encoding.UTF8);
                for (int i = 0; i < lines.Length; i++)
                {
                    string[] str = lines[i].Split(',');
                    if (str.Length != 4) continue;
                    string isUse = "false";
                    if (Common.appConfig.AppSettings.Settings[str[0]] == null)
                    {
                        Common.appConfig.AppSettings.Settings.Add(str[0], "false");
                        Common.appConfig.Save();
                        System.Configuration.ConfigurationManager.RefreshSection("appSettings");
                    }
                    else
                    {
                        isUse = Common.appConfig.AppSettings.Settings[str[0]].Value;
                    }
                    Model.AgvInfo info = new Model.AgvInfo
                    {
                        FleetID = str[0],
                        Name = str[1],
                        IP = str[2],
                        Authorization = str[3],
                        IsAuto = Convert.ToBoolean(isUse),
                        BatteryMax = Convert.ToInt32(Common.appConfig.AppSettings.Settings["AGV_BATTERY_MAX"].Value),
                        BatteryMin = Convert.ToInt32(Common.appConfig.AppSettings.Settings["AGV_BATTERY_MIN"].Value)
                    };
                    Common.agvInfos.Add(info);
                }
                Common.log.Info("读取配置文件 " + Common.PATH_AGV_NAME);

                //AGV任务ID号
                Common.agvMissions = new System.Collections.Generic.Dictionary<string, string>();
                lines = System.IO.File.ReadAllLines(Common.PATH_AGV_MISSION, System.Text.Encoding.UTF8);
                for (int i = 0; i < lines.Length; i++)
                {
                    string[] str = lines[i].Split(',');
                    if (str.Length != 2) continue;
                    Common.agvMissions.Add(str[0], str[1]);
                }
                Common.log.Info("读取配置文件 " + Common.PATH_AGV_MISSION);


                Common.LINE_NAME_4D = Common.appConfig.AppSettings.Settings["4D_Line"].Value.Split(',');
                Common.LINE_NAME_4C = Common.appConfig.AppSettings.Settings["4C_Line"].Value.Split(',');
                Common.STORE_NAME = Common.appConfig.AppSettings.Settings["Store"].Value.Split(',');


                string id = Common.appConfig.AppSettings.Settings["4D_AGV"].Value;
                int idx = Common.agvInfos.FindIndex(match => match.FleetID == id);
                if (idx > -1) Common.agvInfos[idx].Workshop = Common.WORKSHOP_4D;
                id = Common.appConfig.AppSettings.Settings["4C_AGV"].Value;
                idx = Common.agvInfos.FindIndex(match => match.FleetID == id);
                if (idx > -1) Common.agvInfos[idx].Workshop = Common.WORKSHOP_4C;




            }
            catch (Exception ex)
            {
                Common.log.Error("ReadConfig()", ex);
            }
        }

    }
}