Пример #1
0
        /// <summary>
        /// 更新数据存到本地
        /// </summary>
        /// <param name="jsonData">{"Name": "","Data": {},"Url": "地址"}</param>
        public void SaveLocal(ControlReflex.PassModel model)
        {
            JObject obj = JObject.Parse(model.JsonData);

            try
            {
                //需要存储的数据
                byte[] btData = JsonConvert.DeserializeObject <byte[]>(obj["Data"].ToString());

                //应该存储的地址
                string url = obj["Url"].ToString();

                //数据备份
                if (File.Exists(url))
                {
                    CommonTool.TheBackup(url);
                }
                else
                {
                }

                #region 拆分判断是否地址存在 ->不存在则创建
                string[] str = url.Split('\\');
                str[str.Length - 1] = null;
                string path = string.Join(@"\", str);

                //判断文件夹是否存在
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                #endregion

                //本地写入
                File.WriteAllBytes(url, btData);
            }
            catch (Exception ex)
            {
                Log.WriteLine(string.Format("时间:{0}\r\n异常信息{1}\r\n接受到的JsonData{2}", DateTime.Now, ex.Message, model.JsonData));
                model.MainForm.Close_This();
            }
        }
Пример #2
0
 /// <summary>
 /// 界面
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Client_Load(object sender, EventArgs e)
 {
     beingUpdated.Visible  = false;
     requestLatest.Visible = true;
     //版本号赋值
     VersionNumber    = ConfigurationManager.AppSettings["VersionNumber"];
     this.FormClosed += (object sen, FormClosedEventArgs d) =>
     {
         try
         {
             //判断版本号是否改变
             if (VersionNumber.Equals(ConfigurationManager.AppSettings["VersionNumber"]))
             {
                 //数据回滚
                 CommonTool.DataRollback();
             }
             //判断是否更新成功  更新失败则回滚原来数据
             string url = ConfigurationManager.AppSettings["OpenProgramUrl"].Trim('\\') + @"\" + ConfigurationManager.AppSettings["ProgramName"];
             //判断程序是否存在
             if (File.Exists(url))
             {
                 System.Diagnostics.Process.Start("explorer.exe", url);
             }
             else
             {
                 MessageBox.Show(null, "配置文件中程序路径有误", "紧急提示");
             }
         }
         catch (Exception ex)
         {
             Log.WriteLine(string.Format("时间:{0}\r\n异常信息{1}", DateTime.Now, ex.Message));
             MessageBox.Show(ex.Message);
         }
     };
     OpenSocketClient();
 }