Exemple #1
0
    /// <summary>
    /// 生成组件代码
    /// </summary>
    /// <param name="trans"></param>
    /// <returns></returns>
    internal static string GetComponentCode(List <TranDto> trans, IniTool iniTool)
    {
        StringBuilder sb = new StringBuilder();

        foreach (var item in trans)
        {
            string typeName     = UIEditorUtils.GetExportType(item.Tran.name, iniTool);
            string mvvmTypeName = UIEditorUtils.GetMVVMExportType(typeName);
            if (typeName == typeof(Transform).Name)
            {
                sb.AppendLine($"        this.{item.Tran.name} = this.transform.Find(\"{item.ParentPath}{item.Tran.name}\");");
            }
            else if (typeName == typeof(GameObject).Name)
            {
                sb.AppendLine($"        this.{item.Tran.name} = this.transform.Find(\"{item.ParentPath}{item.Tran.name}\").gameObject;");
            }
            else
            {
                if (string.IsNullOrWhiteSpace(mvvmTypeName))
                {
                    sb.AppendLine($"        this.{item.Tran.name} = this.transform.Find(\"{item.ParentPath}{item.Tran.name}\").GetComponent<{typeName}>();");
                }
                else
                {
                    sb.AppendLine($"        this.raw_{item.Tran.name} = this.transform.Find(\"{item.ParentPath}{item.Tran.name}\").GetComponent<{typeName}>();");
                    sb.AppendLine();
                    sb.AppendLine($"        this.BindingElement(this.raw_{item.Tran.name}, out this.{item.Tran.name});");
                }
            }
            sb.AppendLine();
        }

        return(sb.ToString());
    }
Exemple #2
0
        private void Do()
        {
            Task.Factory.StartNew(() =>
            {
                List <int> ports = CMDNetstatTool.GetAvailablePorts(10, 52810);
                if (Ls.Ok(ports))
                {
                    foreach (var p in ports)
                    {
                        try
                        {
                            R.Tx.TcppPort   = p;
                            R.Tx.TcppServer = new TcppServer(R.Tx.TcppPort, TcppEvent.ReceiveMessage,
                                                             TcppEvent.OnConnect, TcppEvent.OnDisconnect);
                            R.Tx.TcppServer.Start();//启动 Socket Tcp 通信机制
                            IniTool.Set(R.Files.Settings, "Tx", "TcppPort", R.Tx.TcppPort);
                            IniTool.Set(R.Files.Settings, "Tx", "StartTime", DateTime.Now.ToString());
                            break;
                        }
                        catch { }
                    }
                }

                R.USBListener.Start();        // 启动USB监控
                R.USBStorageListener.Start(); // 启动U盘监控
            });
        }
Exemple #3
0
        /// <summary>
        /// 读取各个相机的曝光值到ini
        /// </summary>
        public void ReadExposureTime(string strStep, out string strExp)
        {
            int    nExp    = 0;
            string strFile = m_strConfigDir /*+ strStep + "/" + strStep*/ + "param.ini";

            IniTool.GetString(strFile, "ExposureTime", "nExp", nExp.ToString());
            //IniOperation.GetStringValue(strFile, strStep, "ExposureTime", nExp.ToString());
            string strTemp = IniTool.GetString(strFile, strStep, "ExposureTime", null);

            nExp = Convert.ToInt32(strTemp);

            VisionBase vb;

            if (m_dicVision.TryGetValue(strStep, out vb))
            {
                if (nExp == 0)
                {
                    nExp = vb.m_ExposureTime;  //未读到将值设置成初始值
                    WriteExposureTime(strStep, nExp);
                }
                vb.SetExposureTime(nExp);
                strExp = nExp.ToString();
            }
            else
            {
                throw new Exception("系统指定的视觉处理步骤:" + strStep + "未找到");
            }
        }
Exemple #4
0
    internal static void GenerateItem()
    {
        try
        {
            if (!UIEditorUtils.CheckUIConfig())
            {
                EditorUtility.DisplayDialog("错误", "配置表路径没有配置,请配置与Asset同级的config文件", "OK");
                return;
            }
            InitData();

            if (!Directory.Exists(_itemCodePath))
            {
                Directory.CreateDirectory(_itemCodePath);
            }
            EditorUtility.DisplayProgressBar("生成Item", "正在生成Item", 0);
            UIEditorUtils.ErrorList = new List <string>();
            Thread.Sleep(200);
            string[] strs   = Directory.GetFiles(Path.Combine(Application.dataPath, _itemUIPath), "*.prefab");
            float    length = strs.Length;
            float    index  = 0;
            foreach (var item in strs)
            {
                index++;
                EditorUtility.DisplayProgressBar("生成Item", $"正在生成{Path.GetFileNameWithoutExtension(item)}", index / length);
                GameObject     obj   = AssetDatabase.LoadAssetAtPath <GameObject>(Path.Combine("Assets", _itemUIPath, Path.GetFileName(item)));
                List <TranDto> trans = new List <TranDto>();
                UIEditorUtils.GetTrans(obj.transform, "", trans);
                trans.Reverse();
                GenerateUserCode(obj.name);
                GenerateCode(obj.name + ".gen.cs", ItemTemplate, trans, _itemCodePath, Path.Combine(_itemUIResPath, Path.GetFileNameWithoutExtension(item)));
                Thread.Sleep(200);
            }
            EditorUtility.DisplayProgressBar("生成Item", "生成Item完成", 1);
            Thread.Sleep(200);
            EditorUtility.ClearProgressBar();
            if (UIEditorUtils.ErrorList.Count > 0)
            {
                foreach (var item in UIEditorUtils.ErrorList)
                {
                    EditorUtility.DisplayDialog("警告", item, "OK");
                }
            }
            AssetDatabase.Refresh();
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
        finally
        {
            if (_iniTool != null)
            {
                _iniTool.Close();
            }
            _iniTool = null;
            EditorUtility.ClearProgressBar();
        }
    }
Exemple #5
0
    private static void InitData()
    {
        _iniTool = new IniTool();
        _iniTool.Open(UIEditorUtils._configFilePath);
        _panelUIPath   = _iniTool.ReadValue("UI", "PanelPath", "");
        _panelCodePath = _iniTool.ReadValue("UIScript", "PanelGeneratedScriptPath", "");
        _panelCodePath = Path.Combine(Application.dataPath, _panelCodePath);
        int index = _panelUIPath.IndexOf("Resources");

        _panelUIResPath = _panelUIPath.Substring(index + UIEditorUtils.RESOURCES_LENGTH, _panelUIPath.Length - index - UIEditorUtils.RESOURCES_LENGTH);
    }
Exemple #6
0
    internal static string GetExportType(string name, IniTool ini)
    {
        int    index    = name.IndexOf("_");
        string str      = name.Substring(0, index + 1);
        string typeName = ini.ReadValue("UIExport", str, "");

        if (string.IsNullOrWhiteSpace(typeName))
        {
            return(typeof(GameObject).Name);
        }
        return(typeName);
    }
Exemple #7
0
        /// <summary>
        /// 写出资源配置信息
        /// </summary>
        private void WriteConfig()
        {
            //记录固定资源信息
            string path = DirTool.Combine(LogPath, "resource");
            string file = DirTool.Combine(path, "computer.ini");

            //创建目录
            DirTool.Create(path);
            //写出信息
            IniTool.WriteValue(file, "system", "ram", ComputerInfoTool.TotalPhysicalMemory().ToString());
            IniTool.WriteValue(file, "system", "drive", ComputerInfoTool.GetSystemDriveTotalSize().ToString());
        }
Exemple #8
0
        /// <summary>
        /// 保存bartender配置
        /// </summary>
        /// <param name="ba"></param>
        /// <returns></returns>
        public bool SaveBatenderIniConfig(IBarTenderTool ba)
        {
            bool   ok       = false;
            string filename = "BartenderConfig";

            IniLibrary.IniTool initool = new IniTool(ref filename, "BartenderConfig", null);
            initool.WriteString(ba.ToString(), "IdenticalCopiesOfLabel1", ba.IdenticalCopiesOfLabel1.ToString());
            initool.WriteString(ba.ToString(), "NumberSerializedLabels1", ba.NumberSerializedLabels1.ToString());
            initool.WriteString(ba.ToString(), "PathFileName", ba.PathFileName);
            ok = true;
            return(ok);
        }
        private void AutoForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            SaveParam();

            //获取相机名称
            string fileName = $@"{System.Environment.CurrentDirectory}\Product\CameraName.ini";

            IniTool.Set(fileName, "CameraName", "MainCamera", CameraName.MainCamera);
            IniTool.Set(fileName, "CameraName", "SideCamera", CameraName.SideCamera);

            //关闭所有相机
            VisionMgr.GetInstance().CloseCameraAll();
        }
        public override bool SaveParam()
        {
            string fileName = $@"{m_strDir}param.ini";

            if (!System.IO.Directory.Exists(m_strDir))
            {
                System.IO.Directory.CreateDirectory(m_strDir);
            }

            IniTool.Set(fileName, "camera", "exposure", m_ExposureTime);

            return(true);
        }
Exemple #11
0
        private void AutoForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            SaveParam();

            //获取相机名称
            string fileName = $@"{System.Environment.CurrentDirectory}\Product\CameraName.ini";

            IniTool.Set(fileName, "CameraName", "MainCamera", CameraName.MainCamera);
            IniTool.Set(fileName, "CameraName", "SideCamera", CameraName.SideCamera);

            foreach (var cam in VisionMgr.GetInstance().m_dicCamera.Values)
            {
                cam.Close();
            }
        }
        /// <summary>
        /// 设定曝光值
        /// </summary>
        /// <param name="nExp"></param>
        public override void SetExposureTime(int nExp)
        {
            try
            {
                m_Camera.SetGrabParam("ExposureTimeAbs", nExp);
                m_ExposureTime = nExp;

                if (!System.IO.Directory.Exists(m_strDir))
                {
                    System.IO.Directory.CreateDirectory(m_strDir);
                }

                IniTool.Set($@"{m_strDir}param.ini", "camera", "exposure", m_ExposureTime);
            }
            catch (Exception)
            {
            }
        }
Exemple #13
0
        private static void InitConfig()
        {
            //通讯接受 Tx
            R.Tx.Port = IniTool.GetInt(R.Files.Settings, "Tx", "Port", 52830);
            IniTool.Set(R.Files.Settings, "Tx", "Port", R.Tx.Port);

            R.Tx.ConnectKey = IniTool.GetString(R.Files.Settings, "Tx", "ConnectKey", R.Tx.ConnectKey);
            IniTool.Set(R.Files.Settings, "Tx", "ConnectKey", R.Tx.ConnectKey);

            //通讯转发 TxConvert
            R.TxConvert.IP = IniTool.GetString(R.Files.Settings, "TxConvert", "IP", "vaselee.com");
            IniTool.Set(R.Files.Settings, "TxConvert", "IP", R.TxConvert.IP);

            R.TxConvert.Port = IniTool.GetInt(R.Files.Settings, "TxConvert", "Port", 0);
            IniTool.Set(R.Files.Settings, "TxConvert", "Port", R.TxConvert.Port);

            R.TxConvert.ConnectKey = IniTool.GetString(R.Files.Settings, "TxConvert", "ConnectKey", R.TxConvert.ConnectKey);
            IniTool.Set(R.Files.Settings, "TxConvert", "ConnectKey", R.TxConvert.ConnectKey);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override bool SaveParam()
        {
            string fileName = $@"{m_strDir}param.ini";

            if (!System.IO.Directory.Exists(m_strDir))
            {
                System.IO.Directory.CreateDirectory(m_strDir);
            }

            //if (MeasureHandle != null)
            //{
            //    HOperatorSet.WriteMeasure(MeasureHandle, $"{m_strDir}MeasureHandle.mea");
            //    HOperatorSet.WriteObject(MeasureRect, $"{MeasureRect}MeasureRect.hobj");
            //}

            IniTool.Set(fileName, "camera", "exposure", m_ExposureTime);

            return(true);
        }
Exemple #15
0
    internal static bool CheckUIConfig()
    {
        if (!File.Exists(_configFilePath))
        {
            First();
        }
        IniTool iniTool = new IniTool();

        iniTool.Open(_configFilePath);
        string panelPath       = iniTool.ReadValue("UI", "PanelPath", "");
        string itemPath        = iniTool.ReadValue("UI", "ItemPath", "");
        string panelScriptPath = iniTool.ReadValue("UIScript", "PanelGeneratedScriptPath", "");
        string itemScriptPath  = iniTool.ReadValue("UIScript", "ItemGeneratedScriptPath", "");

        if (string.IsNullOrWhiteSpace(panelPath) || string.IsNullOrWhiteSpace(itemPath) || string.IsNullOrWhiteSpace(panelScriptPath) || string.IsNullOrWhiteSpace(itemScriptPath))
        {
            return(false);
        }
        return(true);
    }
Exemple #16
0
        /// <summary>
        /// 保存各个相机的曝光值到ini
        /// </summary>
        public void WriteExposureTime(string strStep, int nExp)
        {
            string strFile = m_strConfigDir /*/* + strStep + "/"*/ + /*strStep+*/ "param.ini";

            IniTool.Set(strFile, "ExposureTime", "nExp", nExp.ToString());

            //IniOperation.WriteValue(strFile, "ExposureTime", "nExp", nExp.ToString());
            //  IniOperation.WriteValue(strFile, strStep, "ExposureTime", nExp.ToString());

            VisionBase vb;

            if (m_dicVision.TryGetValue(strStep, out vb))
            {
                vb.SetExposureTime(nExp);
            }
            else
            {
                throw new Exception("系统指定的视觉处理步骤:" + strStep + "未找到");
            }
        }
 private void BTConnect_Click(object sender, EventArgs e)
 {
     if (RBLocal.Checked)
     {
         int port = IniTool.GetInt(R.Files.Settings, "Tx", "TcppPort", 0);
         if (port > 0)
         {
             Connect("127.0.0.1", port);
             Close();
         }
     }
     else if (RBRemote.Checked)
     {
         if (Str.Ok(TBIP.Text, TBPort.Text) && int.TryParse(TBPort.Text, out int port))
         {
             Connect(TBIP.Text, port);
             Close();
         }
     }
 }
Exemple #18
0
        //[Command]
        //IP=127.0.0.1
        //Port=8001
        //Type=40002000
        //Data={"Item1":"127.0.0.1","Item2":8001}

        public static void Start()
        {
            Task.Factory.StartNew(() =>
            {
                while (!R.MainUI.IsDisposed)
                {
                    if (Ls.Ok(R.Tx.Hosts))
                    {
                        List <string> cmd_files = FileTool.GetAllFile(R.Paths.Command, new[] { "*.cmd.ini" });
                        string tuple_string     = Json.Object2String(new Tuple <string, int>("abc", 123));
                        if (Ls.Ok(cmd_files))
                        {
                            foreach (var file in cmd_files)
                            {
                                string ip   = IniTool.GetString(file, "Command", "IP", "");
                                int port    = IniTool.GetInt(file, "Command", "Port", 0);
                                int type    = IniTool.GetInt(file, "Command", "Type", 0);
                                string data = IniTool.GetString(file, "Command", "Data", "");

                                if (Str.Ok(ip) && type > 0)
                                {
                                    List <string> hosts = TxHostMapTool.GetHost($"{ip}");
                                    if (Ls.Ok(hosts))
                                    {
                                        foreach (var host in hosts)
                                        {
                                            Tuple <string, int> info = new Tuple <string, int>(ip, port);
                                            string ss = Json.Object2String(info);
                                            R.Tx.TcppServer.Write(host, type, Json.Object2Byte(ss));
                                        }
                                    }
                                }
                                R.Log.I($"处理指令:{type},IP:{ip},Port:{port},Data:{data}");
                                FileTool.Delete(file);
                            }
                        }
                    }
                    Sleep.S(10);
                }
            });
        }
Exemple #19
0
        /// <summary>
        /// 加载bartender配置
        /// </summary>
        /// <param name="ba">传入修改的数据</param>
        /// <returns></returns>
        public bool LoadBartenderIniConfig(IBarTenderTool ba)
        {
            bool ok = false;

            string filename = "BartenderConfig";

            IniLibrary.IniTool initool = new IniTool(ref filename, "BartenderConfig", null);

            if (File.Exists(initool.FileName_Path1))
            {
                ba.IdenticalCopiesOfLabel1 = Convert.ToInt32(initool.ReadString(ba.ToString(), "IdenticalCopiesOfLabel1", "1"));
                ba.NumberSerializedLabels1 = Convert.ToInt32(initool.ReadString(ba.ToString(), "NumberSerializedLabels1", "1"));
                ba.PathFileName            = initool.ReadString(ba.ToString(), "PathFileName", ba.PathFileName);
            }
            else
            {
                initool.WriteString(ba.ToString(), "IdenticalCopiesOfLabel1", ba.IdenticalCopiesOfLabel1.ToString());
                initool.WriteString(ba.ToString(), "NumberSerializedLabels1", ba.NumberSerializedLabels1.ToString());
                initool.WriteString(ba.ToString(), "PathFileName", ba.PathFileName);
            }
            ok = true;
            return(ok);
        }
 private void ConnectLocalByProcess()
 {
     try
     {
         Process[] process = Process.GetProcessesByName("USBManager.Service");
         if (Ls.Ok(process))
         {
             string file = process[0].MainModule.FileName;
             if (File.Exists(file))
             {
                 string path     = DirTool.Parent(file);
                 string set_file = DirTool.Combine(path, "USBManagerServiceSettings.ini");
                 int    port     = IniTool.GetInt(set_file, "Tx", "TcppPort", 0);
                 if (port > 0)
                 {
                     Connect("127.0.0.1", port);
                     Close();
                 }
             }
         }
     }
     catch { }
 }
Exemple #21
0
    /// <summary>
    /// 获取变量名代码
    /// </summary>
    /// <param name="trans"></param>
    /// <param name="iniTool"></param>
    /// <returns></returns>
    internal static string GetVarCode(List <TranDto> trans, IniTool iniTool)
    {
        StringBuilder sb = new StringBuilder();

        foreach (var item in trans)
        {
            string typeName     = GetExportType(item.Tran.name, iniTool);
            string mvvmTypeName = GetMVVMExportType(typeName);

            if (string.IsNullOrWhiteSpace(mvvmTypeName))
            {
                sb.AppendLine($"    private {typeName} {item.Tran.name} = null;");
            }
            else
            {
                sb.AppendLine($"    private {typeName} raw_{item.Tran.name} = null;");
                sb.AppendLine($"    private {mvvmTypeName} {item.Tran.name} = null;");
            }
            sb.AppendLine();
        }

        return(sb.ToString());
    }
Exemple #22
0
        /// <summary>
        /// 初始化Ini配置信息
        /// </summary>
        static void InitIni()
        {
            DirTool.Create(R.Paths.Settings);
            DirTool.Create(R.Paths.Projects);
            DirTool.Create(R.Paths.DefaultPublishStorage);
            DirTool.Create(R.Paths.DefaultNewStorage);

            R.Paths.PublishStorage = IniTool.GetString(R.Files.Settings, "Paths", "PublishStorage", R.Paths.DefaultPublishStorage);
            if (string.IsNullOrWhiteSpace(R.Paths.PublishStorage))
            {
                R.Paths.PublishStorage = R.Paths.DefaultPublishStorage;
            }

            R.Paths.NewStorage = IniTool.GetString(R.Files.Settings, "Paths", "NewStorage", R.Paths.DefaultNewStorage);
            if (string.IsNullOrWhiteSpace(R.Paths.NewStorage))
            {
                R.Paths.NewStorage = R.Paths.DefaultNewStorage;
            }

            R.Tx.IP                  = IniTool.GetString(R.Files.Settings, "Console", "IP", "");
            R.Tx.Port                = IniTool.GetInt(R.Files.Settings, "Console", "Port", 0);
            R.Tx.LocalIP             = IniTool.GetString(R.Files.Settings, "Local", "IP", "");
            R.Tx.LocalName           = IniTool.GetString(R.Files.Settings, "Local", "Name", "");
            R.IsAutoDeleteExpiredLog = IniTool.GetBool(R.Files.Settings, "Settings", "AutoDeleteExpiredLog", false);
            R.AppID                  = IniTool.GetString(R.Files.Settings, "App", "ID", "");

            if (!Str.Ok(R.AppID))
            {
                R.AppID = GuidTool.Short();
                IniTool.Set(R.Files.Settings, "App", "ID", R.AppID);
            }

            if (!File.Exists(R.Files.NewStorageReadme))
            {
                TxtTool.Create(R.Files.NewStorageReadme, R.NewStorageReadmeTxt);
            }
        }
        /// <summary>
        /// 加载参数
        /// </summary>
        /// <returns></returns>
        public override bool LoadParam()
        {
            string fileName = $@"{m_strDir}param.ini";

            if (!System.IO.Directory.Exists(m_strDir))
            {
                System.IO.Directory.CreateDirectory(m_strDir);
                SaveParam();
            }

            m_ExposureTime = IniTool.GetInt(fileName, "camera", "exposure", 1000);

            //if (System.IO.File.Exists($"{m_strDir}MeasureHandle.mea"))
            //{
            //    HOperatorSet.ReadMeasure($"{m_strDir}MeasureHandle.mea", out MeasureHandle);
            //}

            //if (System.IO.File.Exists($"{m_strDir}MeasureRect.hobj"))
            //{
            //    HOperatorSet.ReadObject(out MeasureRect, $"{m_strDir}MeasureRect.hobj");
            //}

            return(true);
        }
        /// <summary>
        /// 接受消息
        /// </summary>
        /// <param name="host"></param>
        /// <param name="model"></param>
        public static void ReceiveMessage(string host, TcpDataModel model)
        {
            switch (model.Type)
            {
            case 10001000:
                R.Tx.IsAuth      = true;
                R.Tx.ConnectTime = DateTime.Now;
                R.MainUI.UITxStatus();
                TxSendQueue.Start();
                break;

            //状态信息
            case 20001000:     /* 普通应答 */
                break;

            case 20001001:     /* 状态 */
                //R.MainUI.UIStatus(model);
                break;

            case 20001002:     /* 状态(二维码) */
                break;

            case 20002000:
                //R.MainUI.UILog(Json.Byte2Object<string>(model.Data));
                break;

            case 20003000:
                //R.MainUI.UIScreen(model);
                break;

            case 20004000:     /* 系统信息 */
                //R.MainUI.UIInfo(model);
                break;

            case 20004001:     /* 软件信息 */
                //R.MainUI.UIInfo(model);
                break;

            case 20004002:     /* 硬件信息 */
                //R.MainUI.UIInfo(model);
                break;

            case 20004003:     /* 共享信息 */
                //R.MainUI.UIInfo(model);
                break;

            case 20004004:     /* APP信息 */
                //R.MainUI.UIInfo(model);
                break;

            case 30001000:
                //R.MainUI.UIConsole(Json.Byte2Object<List<string>>(model.Data));
                break;

            //指令操作
            case 40001000:     /* 清除过期日志 */
                R.Log.I("收到指令操作:40001000:清除过期日志:15天之前日志");
                LogCleaner.CleanLogFile();
                break;

            case 40002000:     /* 重启服务 */
                try
                {
                    R.Log.I("收到指令操作:40002000:重启服务");
                    string ss = Json.Byte2Object <string>(model.Data);
                    Tuple <string, int> info = Json.String2Object <Tuple <string, int> >(ss);
                    if (R.Tx.LocalIP == info.Item1 && R.ProjectItems.Any(x => x.Port == info.Item2))
                    {
                        Parts.ProjectItemPart item = R.ProjectItems.FirstOrDefault(x => x.Port == info.Item2);
                        if (item != null)
                        {
                            item.Restart();
                        }
                    }
                }
                catch { }
                break;

            //更新操作
            case 90001000:    /* 获取更新文件基本信息 */
                try
                {
                    Tuple <string, string> data = Json.Byte2Object <Tuple <string, string> >(model.Data);
                    if (Str.Ok(data.Item1, data.Item2))
                    {
                        R.AppointName = data.Item1;
                        R.AppointMD5  = data.Item2;
                        TxSendQueue.Add(90001000, "Fire in the hole");
                    }
                }
                catch { }
                break;

            case 90002000:    /* 获取更新文件 */
                try
                {
                    if (Str.Ok(R.AppointName, R.AppointMD5))
                    {
                        if (File.Exists(DirTool.Combine(R.Paths.App, R.AppointName)))
                        {
                            FileTool.Delete(DirTool.Combine(R.Paths.App, R.AppointName));
                        }

                        if (BinaryFileTool.write(DirTool.Combine(R.Paths.App, R.AppointName), model.Data))
                        {
                            IniTool.Set(R.Files.Settings, "Appoint", "Name", R.AppointName);
                            IniTool.Set(R.Files.Settings, "Appoint", "MD5", R.AppointMD5);

                            // 判断文件存在,并且MD5相符,则退出并运行新版本(否则删除不一致文件)
                            if (File.Exists(DirTool.Combine(R.Paths.App, R.AppointName)) &&
                                FileTool.GetMD5(DirTool.Combine(R.Paths.App, R.AppointName)) == R.AppointMD5)
                            {
                                ProcessTool.Start(R.Files.App);
                                R.MainUI.UIExitApp();
                            }
                            else
                            {
                                FileTool.Delete(DirTool.Combine(R.Paths.App, R.AppointName));
                            }
                        }
                    }
                }
                catch { }
                break;

            default: break;
            }
        }
Exemple #25
0
        private void AutoForm_Load(object sender, EventArgs e)
        {
            //btnSystemConfig.Enabled = false;
            btnSideCamera.Enabled             = false;
            RoundButton_Communication.Enabled = false;
            btnImageFile.Enabled      = false;
            BtnRun.Enabled            = false;
            RoundButton_Login.Enabled = false;
            //BtnRun.BaseColorEnd = BtnRun.BaseColor = Color.FromArgb(230, 216, 216);

            //btnSystemConfig.BaseColor = Color.DarkGray;
            RoundButton_Communication.BaseColor = Color.DarkGray;
            btnImageFile.BaseColor      = Color.DarkGray;
            BtnRun.BaseColor            = Color.DarkGray;
            RoundButton_Login.BaseColor = Color.DarkGray;

            tlbVer.Alignment = ToolStripItemAlignment.Right;
            tlbVer.Text      = $"V2.1:{System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location)}";

            _autoForm = this;

            //获取相机名称
            string fileName = $@"{System.Environment.CurrentDirectory}\Product\CameraName.ini";

            CameraName.MainCamera = IniTool.GetString(fileName, "CameraName", "MainCamera", "MainCam");
            CameraName.SideCamera = IniTool.GetString(fileName, "CameraName", "SideCamera", "HE012A1GM");

#if JAI
            //添加相机并绑定到窗口
            foreach (var cam in CameraJai.FindCamera())
            {
                if (cam.ModelName == CameraName.MainCamera || cam.ModelName == CameraName.SideCamera)
                {
                    VisionMgr.GetInstance().AddCamera(new CameraJai(cam.ModelName, cam));
                }
            }
#else
            //添加相机并绑定到窗口
            //VisionMgr.GetInstance().AddCamera(new CameraGige(CameraName.MainCamera));
            //VisionMgr.GetInstance().AddCamera(new CameraGige(CameraName.SideCamera));
            VisionMgr.GetInstance().AddCamera(new CameraMVision(CameraName.MainCamera));
            VisionMgr.GetInstance().AddCamera(new CameraMVision(CameraName.SideCamera));
#endif

            //添加视觉步骤
            VisionMgr.GetInstance().AddVisionStep(CameraName.MainCamera, new ProcessMainPos(VisionStepName.MainPos));
            VisionMgr.GetInstance().AddVisionStep(CameraName.MainCamera, new ProcessMainMea(VisionStepName.MainMea));
            VisionMgr.GetInstance().AddVisionStep(CameraName.SideCamera, new ProcessSideMea(VisionStepName.SideMea));

            //加载系统参数
            LoadParam();

            //切换产品
            ProductMgr.GetInstance().ProductChangedMethod += ChangeProduct;
            ProductMgr.GetInstance().ChangeProduct(Param.ProductName);

            //关联页面和按钮
            m_dicForm.Add(btnMainCamera, new MainCameraForm());
            //m_dicForm.Add(RoundButton_Login, new LoginForm());
            m_dicForm.Add(RoundButton_Communication, new CommunicationForm());
            m_dicForm.Add(btnSideCamera, new SideCameraForm());
            m_dicForm.Add(btnSystemConfig, new SystemConfigForm());

            //初始化页面属性
            foreach (KeyValuePair <RoundButton, Form> kp in m_dicForm)
            {
                kp.Value.TopLevel = false;
                kp.Value.Parent   = this.panel_main;
                kp.Value.Dock     = DockStyle.Fill;
            }

            btnMainCamera.PerformClick();

            //切换用户
            //((LoginForm)m_dicForm[RoundButton_Login]).UserChangingMethod = ChangeUser;
            //ChangeUser(UserMode.Operator, Param.OperatorPassword);

            //设置日志显示
            Log.Show  = ((MainCameraForm)m_dicForm[btnMainCamera]).ShowLog;
            Data.Show = ((MainCameraForm)m_dicForm[btnMainCamera]).ShowData;

            //连接服务器
            ((SystemConfigForm)m_dicForm[btnSystemConfig]).SetServerMethod = SetServer;
            ConnectServer();
        }
Exemple #26
0
 static void InitSettings()
 {
     R.Switch.ShowNotifyIcon = IniTool.GetBool(R.Files.Settings, "Switch", "ShowNotifyIcon", true);
     R.Switch.ShowToast      = IniTool.GetBool(R.Files.Settings, "Switch", "ShowToast", true);
 }
        private bool SaveSettings()
        {
            bool flag = false;

            if (StringTool.Ok(TBPublishStorage.Text))
            {
                if (Directory.Exists(TBPublishStorage.Text))
                {
                    R.Paths.PublishStorage = TBPublishStorage.Text;
                    IniTool.Set(R.Files.Settings, "Paths", "PublishStorage", R.Paths.PublishStorage);
                    flag = true;
                }
                else
                {
                    LBDesc.Text = "发布资料库目录不存在";
                }
            }
            else
            {
                R.Paths.PublishStorage = R.Paths.DefaultPublishStorage;
                //IniTool.WriteValue(R.Files.Settings, "Paths", "PublishStorage", R.Paths.PublishStorage);
                flag = true;
            }

            if (StringTool.Ok(TBNewStorage.Text))
            {
                if (Directory.Exists(TBNewStorage.Text))
                {
                    R.Paths.NewStorage = TBNewStorage.Text;
                    IniTool.Set(R.Files.Settings, "Paths", "NewStorage", R.Paths.NewStorage);
                    flag = true;
                }
                else
                {
                    LBDesc.Text = "新增资料库目录不存在";
                }
            }
            else
            {
                R.Paths.NewStorage = R.Paths.DefaultNewStorage;
                //IniTool.WriteValue(R.Files.Settings, "Paths", "NewStorage", R.Paths.NewStorage);
                flag = true;
            }

            if (Str.Ok(TBConsoleIP.Text))
            {
                R.Tx.IP = TBConsoleIP.Text;
                IniTool.Set(R.Files.Settings, "Console", "IP", R.Tx.IP);
            }

            if (Str.Ok(TBConsolePort.Text))
            {
                if (int.TryParse(TBConsolePort.Text, out int port))
                {
                    R.Tx.Port = port;
                    IniTool.Set(R.Files.Settings, "Console", "Port", R.Tx.Port);
                }
            }

            if (Str.Ok(TBLocalIP.Text))
            {
                R.Tx.LocalIP = TBLocalIP.Text;
                IniTool.Set(R.Files.Settings, "Local", "IP", R.Tx.LocalIP);
            }

            if (Str.Ok(TBLocalName.Text))
            {
                R.Tx.LocalName = TBLocalName.Text;
                IniTool.Set(R.Files.Settings, "Local", "Name", R.Tx.LocalName);
            }


            R.IsAutoDeleteExpiredLog = CBAutoDeleteExpiredLog.Checked;
            IniTool.Set(R.Files.Settings, "Settings", "AutoDeleteExpiredLog", R.IsAutoDeleteExpiredLog);

            return(flag);
        }
Exemple #28
0
        static void InitSettings()
        {
            int level = IniTool.GetIntValue(R.Files.Settings, "Log", "Level");

            R.LogLevel = (LogLevel)level;
        }
Exemple #29
0
        static void Main()
        {
            //taskkill /IM BigBirdDeployer-1.exe /F
            //启动自动运行指定最新版本
            string appoint_name = IniTool.GetString(R.Files.Settings, "Appoint", "Name", "");
            string appoint_md5  = IniTool.GetString(R.Files.Settings, "Appoint", "MD5", "");
            string current_file = Path.GetFileName(R.Files.App);

            if (Str.Ok(appoint_name, appoint_md5))
            {
                string file = DirTool.Combine(R.Paths.App, appoint_name);
                if (File.Exists(file) && FileTool.GetMD5(file) == appoint_md5)
                {
                    R.Log.V($"appoint:{appoint_name}   current:{current_file}");
                    R.Log.V($"appoint:{file}   current:{R.Files.App}");

                    if (appoint_name != current_file)
                    {
                        if (ProcessTool.Start(file))
                        {
                            return;
                        }
                    }
                }
            }

            //var a = FileTool.GetAllFile(@"F:\Temp\logs", new[] { "*.log"});
            //解决进程互斥
            if (!AppUnique.IsUnique(R.AppName))
            {
                return;
            }

            try
            {
                //处理未捕获的异常
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理UI线程异常
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                R.Log.i("========== 程序启动:BigBirdDeployer(正常启动) ==========");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                R.MainUI = new MainForm();

                InitIni();                           //初始化Ini配置信息
                StatusLog.Instance.Start();          //启动计算机状态日志记录
                R.Log.SetCacheDays(10);              //保存最近10天的普通日志信息
                StatusLog.Instance.SetCacheDays(10); //保存最近10天的状态日志信息
                SystemSleepAPI.PreventSleep(false);  //禁用计算机息屏和待机
                PlanTaskCore.Start();                //启动定时任务

                Application.Run(R.MainUI);           //启动主UI
            }
            catch (Exception ex)
            {
                R.Log.e("应用程序异常 App Main Exception");
                WriteExceptionAndRestart(ex);
            }
        }