Пример #1
0
        /// <summary>
        /// 从服务端下载报警配置到本地
        /// </summary>
        /// <returns></returns>
        public static bool DownloadConfigFromServer()
        {
            bool b = false;

            try
            {
                SettingInfo dto = ClientAlarmServer.CheckAlarmConfigIsOnServer();
                if (!string.IsNullOrEmpty(dto.StrValue))
                {
                    byte[] by     = Convert.FromBase64String(dto.StrValue);
                    Stream stream = File.Open(_filePath, FileMode.Create, FileAccess.ReadWrite);
                    using (stream)
                    {
                        stream.Write(by, 0, by.Length);
                        stream.Close();
                    }
                    b = true;
                }
            }
            catch (Exception ex)
            {
                b = false;
                //写日志、抛异常
                LogHelper.Error("从服务端下载报警配置到本地 发生异常", ex);
            }
            return(b);
        }
Пример #2
0
 /// <summary>
 /// 从服务端下载配置应用到本地
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void barBtnItem_getFromServer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         //判断服务器是否存在报警配置
         SettingInfo dto;
         dto = ClientAlarmServer.CheckAlarmConfigIsOnServer();
         if (dto == null || string.IsNullOrEmpty(dto.StrValue))
         {
             Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "服务器上未发现配置文件,操作已取消。");
             return;
         }
         //从服务器下载配置到本地
         if (!ClientAlarmConfig.DownloadConfigFromServer())
         {
             Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "服务器上未发现配置文件,操作已取消。");
             return;
         }
         //从本地配置加载到缓存
         ClientAlarmConfig.LoadConfigToCache();
         gridCtrl.DataSource             = null;
         lookUpEditDefProperty.EditValue = null;
         lookUpEditDefCalss.EditValue    = null;
         textEditDefPoint.EditValue      = null;
         bIsChangeType  = false;
         bIsChangeAlarm = false;
         LookupLoadData();
         Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "从服务端下载配置应用到本地成功");
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
     }
 }
Пример #3
0
        /// <summary>
        /// 保存报警配置文件到数据库
        /// </summary>
        /// <returns></returns>
        public static bool SaveConfigToServer()
        {
            bool   b = true;
            string s = string.Empty;

            try
            {
                if (File.Exists(_filePath))
                {
                    Stream stream = File.Open(_filePath, FileMode.Open);
                    using (stream)
                    {
                        byte[] by = new byte[stream.Length];
                        stream.Read(by, 0, (int)stream.Length);
                        s = Convert.ToBase64String(by);
                    }
                    SettingInfo dto = ClientAlarmServer.CheckAlarmConfigIsOnServer();
                    if (!ClientAlarmServer.SaveConfigToDatabase(dto, s))
                    {
                        b = false;
                    }
                }
            }
            catch (Exception ex)
            {
                //写日志、抛异常等
                LogHelper.Error("保存报警配置文件到数据库 发生异常", ex);
                b = false;
            }
            return(b);
        }