// Validates the form values bool ValidatePolicyValues() { // Name if (string.IsNullOrWhiteSpace(nameTextBox.Text)) { AppForm.DisplayError("Retention Policy name cannot be blank."); return(false); } // Duration var duration = durationTextBox.Text; if (string.IsNullOrWhiteSpace(duration)) { AppForm.DisplayError("Duration cannot be blank. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc."); return(false); } duration = duration.Trim(); if (!InfluxDbHelper.IsTimeIntervalValid(duration)) { AppForm.DisplayError("Duration value is invalid. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc."); return(false); } return(true); }
private async Task updateCache1(DbActions.UploadCpmsInfluxDb instance) { if (!cpmCacheDict.ContainsKey(instance.MachineCode)) { cpmCacheDict[instance.MachineCode] = new CpmCache(1024); } var cache = cpmCacheDict[instance.MachineCode]; //缓存 foreach (var cpm in instance.Cpms) { cache.Add(cpm); } //上传周期同与mq保持一致 if ((DateTime.Now - cache.LastUploadTime).TotalMilliseconds > HmiConfig.UploadWebBoardInterval || cache.DataCount > 900) { await Task.Run(() => { var upCaches = cache.Caches; var upCount = cache.DataCount; cache.Clear(); cache.LastUploadTime = DateTime.Now; bool success = InfluxDbHelper.GetInfluxDbService().WriteCpms(instance.MachineCode, upCaches, 0, upCount); if (success) { App.Store.Dispatch(new DbActions.UploadCpmsInfluxDbSuccess()); } else { App.Store.Dispatch(new DbActions.UploadCpmsInfluxDbFailed()); } }); } }
/// <summary> /// LoggerHelper 和 Assets Helper 已经在 App.xaml.cs 中初始化了,所以这里不必要初始化了 /// </summary> bool globalConfigLoad() { updateLoadingMessage("正在准备系统资源文件", 0.15); Thread.Sleep(CmdOptions.GlobalOptions.WaitSec * 1000); updateLoadingMessage("正在检查系统启动环境...", 0.17); if (processIsStarted()) { var message = "系统重复启动异常"; App.Store.Dispatch(new SysActions.SetLoadingMessage(message, 0.18)); shutdownAppAfterSec(10, 0.18, "重复启动系统异常"); return(false); } updateLoadingMessage("正在初始化异常配置...", 0.20); ExceptionHelper.Init(); updateLoadingMessage("正在加载系统配置...", 0.23); GlobalConfig.Load(YUtil.GetAbsolutePath(".\\Profiles\\Global.xls")); updateLoadingMessage("正在初始化 ActiveMq...", 0.27); ActiveMqHelper.Init(HmiConfig.MqConn, HmiConfig.MqUserName, HmiConfig.MqUserPwd); updateLoadingMessage("正在初始化 MongoDb...", 0.30); MongoHelper.Init(HmiConfig.MongoConn); updateLoadingMessage("正在初始化 InfluxDb...", 0.33); InfluxDbHelper.Init($"http://{HmiConfig.InfluxDbIp}:8086", HmiConfig.InfluxCpmDbName); updateLoadingMessage("正在同步时间...", 0.35); syncTime(!HmiConfig.IsDevUserEnv); Logger.Debug("当前操作系统:" + YUtil.GetOsVersion()); Logger.Debug("当前版本:" + YUtil.GetAppVersion(Assembly.GetExecutingAssembly())); Logger.Debug("是否为开发环境:" + HmiConfig.IsDevUserEnv); Logger.Debug("浮点精度:" + HmiConfig.MathRound); return(true); }
/// <summary> /// 刷新缓存到 influxDb /// </summary> /// <param name="instance"></param> async void updateCache2(DbActions.UploadCpmsInfluxDb instance) { try { if (!cpmCache2Dict.ContainsKey(instance.MachineCode)) { cpmCache2Dict[instance.MachineCode] = new CpmCache2(128); } var cache = cpmCache2Dict[instance.MachineCode]; cache.Add(instance.Cpms); if ((DateTime.Now - cache.LastUploadTime).TotalMilliseconds > HmiConfig.UploadWebBoardInterval || cache.DataCount > 100) { await Task.Run(() => { List <StringBuilder> builders = new List <StringBuilder>(cache.DataCount); for (var i = 0; i < cache.DataCount; i++) { builders.Add(InfluxDbHelper.GetInfluxDbService().GetCpms2WriteString(instance.MachineCode, cache.Data[i].Cpms, cache.Data[i].pickTime)); } //清空缓存 cache.LastUploadTime = DateTime.Now; cache.Clear(); bool success = InfluxDbHelper.GetInfluxDbService().WriteMultiString(builders.ToArray()); if (success) { App.Store.Dispatch(new DbActions.UploadCpmsInfluxDbSuccess()); } else { App.Store.Dispatch(new DbActions.UploadCpmsInfluxDbFailed()); } }); } } catch (Exception e) { Logger.Error("influxDb 上传出错", e); } }
// Validates the current form values bool ValidateCqValues() { try { // Validate values var cqName = nameTextBox.Text; // CQ Name if (string.IsNullOrWhiteSpace(cqName)) { AppForm.DisplayError("Continuous Query name cannot be blank."); return(false); } // Source & Destination var destination = destinationComboBox.SelectedItem as string; if (string.IsNullOrWhiteSpace(destination)) { destination = destinationComboBox.Text; } var source = sourceComboBox.SelectedItem as string; if (string.IsNullOrWhiteSpace(source)) { source = sourceComboBox.Text; } if (string.IsNullOrWhiteSpace(destination)) { AppForm.DisplayError("Destination cannot be blank."); return(false); } if (string.IsNullOrWhiteSpace(source)) { AppForm.DisplayError("Source cannot be blank."); return(false); } if (destination == source) { if (MessageBox.Show("Source is the same as the Destination. These are typically different values for a Continous Query. Are you sure that you want to have duplicate values?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return(false); } } // Interval var interval = intervalTextBox.Text; if (string.IsNullOrWhiteSpace(interval)) { AppForm.DisplayError("Interval cannot be blank. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc."); return(false); } interval = interval.Trim(); if (!InfluxDbHelper.IsTimeIntervalValid(interval)) { AppForm.DisplayError("Interval value is invalid. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc."); return(false); } // Resample Every if (resampleCheckBox.Checked) { var resampleEvery = resampleEveryTextBox.Text; if (!string.IsNullOrWhiteSpace(resampleEvery)) { resampleEvery = resampleEvery.Trim(); if (!InfluxDbHelper.IsTimeIntervalValid(resampleEvery)) { AppForm.DisplayError("Resample Every interval value is invalid. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc."); return(false); } } } // Resample For if (resampleCheckBox.Checked) { var resampleFor = resampleForTextBox.Text; if (!string.IsNullOrWhiteSpace(resampleFor)) { resampleFor = resampleFor.Trim(); if (!InfluxDbHelper.IsTimeIntervalValid(resampleFor)) { AppForm.DisplayError("Resample For interval value is invalid. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc."); return(false); } } } // Subquery if (queryEditor.Text == null || queryEditor.Text.Length == 0 || queryEditor.Text == QueryEditorPlaceholderText) { AppForm.DisplayError("SubQuery cannot be blank."); return(false); } return(true); } catch (Exception ex) { AppForm.DisplayException(ex); return(false); } }
// Validates the current form values bool ValidateBackfillValues() { try { // Source & Destination var destination = destinationComboBox.SelectedItem as string; if (string.IsNullOrWhiteSpace(destination)) { destination = destinationComboBox.Text; } var source = sourceComboBox.SelectedItem as string; if (string.IsNullOrWhiteSpace(source)) { source = sourceComboBox.Text; } if (string.IsNullOrWhiteSpace(destination)) { AppForm.DisplayError("Destination cannot be blank."); return(false); } if (string.IsNullOrWhiteSpace(source)) { AppForm.DisplayError("Source cannot be blank."); return(false); } if (destination == source) { if (MessageBox.Show("Source is the same as the Destination. These are typically different values for a Backfill Query. Are you sure that you want to have duplicate values?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return(false); } } // Interval var interval = intervalTextBox.Text; if (string.IsNullOrWhiteSpace(interval)) { AppForm.DisplayError("Interval cannot be blank. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc."); return(false); } interval = interval.Trim(); if (!InfluxDbHelper.IsTimeIntervalValid(interval)) { AppForm.DisplayError("Interval value is invalid. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc."); return(false); } // From/To time var fromTime = fromDateTimePicker.Value; var toTime = toDateTimePicker.Value; if (fromTime >= toTime) { AppForm.DisplayError("'From Time' is later than 'To Time'. 'From Time' should come before 'To Time'."); return(false); } // Subquery if (queryEditor.Text == null || queryEditor.Text.Length == 0 || queryEditor.Text == QueryEditorPlaceholderText) { AppForm.DisplayError("SubQuery cannot be blank."); return(false); } return(true); } catch (Exception ex) { AppForm.DisplayException(ex); return(false); } }