public ListPointWithResult(ListPoint source) { this.ParentId = source.ParentId; this.ParentTypeCode = source.ParentTypeCode; this.ParentName = source.ParentName; this.Id = source.Id; this.Name = source.Name; this.IsGroup = source.IsGroup; this.TypeCode = source.TypeCode; this.EсpName = source.EсpName; this.Type = source.Type; this.IsChecked = source.IsChecked; if (source.Items != null) { this.Items = source.Items.Select(i => new ListPointWithResult(i)).ToList <ListPointWithResult>(); } string name = source.Name; if (source.ParentTypeCode == "SUBSTATION") { if (String.IsNullOrEmpty(source.ParentName) == false) { name = source.ParentName + " - " + name; } } this.ResultName = name; }
public static async Task <string> GetPoints(ListPoint parent) { ErrorMessage = String.Empty; string url = @"{0}scripts/point.asp"; string data = String.Format("refresh=true&TYPE=GROUP&action=expand&ID={0}", parent.Id.ToString()); return(await ExecuteFunctionAsync(MakeRequestAsync, url, data, true, (answer) => DecodeAnswer(answer))); }
public TreeModel(ListPoint point) : this() { Init(point); if (point.Items != null) { foreach (var item in point.Items) { Children.Add(new TreeModel(item)); } } }
public override bool Equals(object obj) { ListPoint o = obj as ListPoint; if (o == null) { return(false); } return(this.Point.Id == o.Id && this.Point.Name == o.Name); }
public ListPointWithResult(ListPoint source) { this.ParentId = source.ParentId; this.ParentTypeCode = source.ParentTypeCode; this.ParentTypeName = source.ParentTypeName; this.Id = source.Id; this.Name = source.Name; this.IsGroup = source.IsGroup; this.TypeCode = source.TypeCode; this.EсpName = source.EсpName; this.Type = source.Type; this.Checked = source.Checked; }
private void ForEachPointInTree(ListPoint point, Func <ListPoint, bool> condition, Action <ListPoint> action) { if (condition(point)) { action(point); } if (point.Items != null && point.Items.Count > 0) { foreach (var item in point.Items) { ForEachPointInTree(item, condition, action); } } }
public static async Task <IList <ListPoint> > CreatePointsListAsync(ListPoint parent) { try { string data = await GetPoints(parent); if (String.IsNullOrEmpty(data)) { return(new List <ListPoint>()); } return(GetPointsList(data, parent)); } catch (Exception ex) { ErrorMessage = App.GetExceptionDetails(ex); App.Log("Ошибка в CreatePointsListAsync: " + ErrorMessage); return(new List <ListPoint>()); } }
private async Task <IList <ListPoint> > FillPointsTree(ListPoint point) { if (cts.Token.IsCancellationRequested) { return(null); } var table = App.EmcosWebServiceClient.GetPointInfo("PSDTU_SERVER", point.Id.ToString()); IList <ListPoint> list = await ServiceHelper.CreatePointsListAsync(point); if (list != null && list.Count > 0) { for (int i = 0; i < list.Count; i++) { if (cts.Token.IsCancellationRequested) { return(null); } if (list[i].IsGroup) { list[i].Items = new ObservableCollection <ListPoint>(await FillPointsTree(list[i])); _index++; if (_index > maxItemsCount) { throw new OverflowException("Превышено максимальное количество элементов в дереве - " + maxItemsCount); } } } } if (cts.Token.IsCancellationRequested) { return(null); } return(list); }
public TreeModel() { Point = new ListPoint(); }
private void Init(ListPoint point) { this.Point = point; IsChecked = point.IsChecked; }
private void InitCommands() { App.Log("Иницилизация команд главного окна"); SettingsCommand = new DelegateCommand(o => { App.Log("Просмотр настроек"); Dialogs.IDialog dialog = null; Action updateUI = () => dialog.Close(); var control = new SettingsControl(updateUI); dialog = this.DialogCustom(control); dialog.Show(); }); UpdateCommand = new DelegateCommand(o => { cts = new CancellationTokenSource(); Dialogs.IDialog dialog = this.DialogInfo(Strings.UpdatingInProgress, null, MessageBoxImage.None, TMPApplication.WpfDialogs.DialogMode.Cancel); dialog.CloseBehavior = TMPApplication.WpfDialogs.DialogCloseBehavior.ExplicitClose; dialog.Cancel = () => { cts.Cancel(); dialog.CanCancel = false; }; dialog.Show(); if (CheckAvailability() == false) { this.ShowDialogWarning(Strings.MessageServerNotAvailability, null, () => dialog.Close()); return; } try { this.ShowDialogInfo(Strings.OnUpdatingPointsList, null, () => { App.Log("Получение списка точек от сервиса"); _rootEmcosGroup = null; try { _rootEmcosGroup = Utils.Base64StringToObject <ListPoint>(Properties.Settings.Default.RootPoint); } catch { } if (_rootEmcosGroup == null) { _rootEmcosGroup = DEFAULT_ROOT_EMCOS_GROUP; } _backgroudTask = Task.Factory.StartNew(async() => { _index = 0; var source = await FillPointsTree(_rootEmcosGroup); if (source.Count == 0 && String.IsNullOrEmpty(ServiceHelper.ErrorMessage) == false) { this.ShowDialogWarning(ServiceHelper.ErrorMessage); dialog.Close(); return; } InitModel(source); IsReadyToGetData = true; SaveList(source); dialog.Close(); }, cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }); } catch (Exception ex) { App.Log("Получение списка точек от сервиса - ошибка"); dialog.Close(); this.ShowDialogError(String.Format(Strings.Error, App.GetExceptionDetails(ex))); } }); GetReportCommand = new DelegateCommand(o => { this.ShowDialogInfo(Strings.OnGettingData, null, () => { App.Log("Получение отчёта по точкам"); if (CheckAvailability() == false) { this.ShowDialogWarning(Strings.MessageServerNotAvailability); return; } var substations = _treeModel.Point.Items .Flatten(i => i.Items) .Where(i => (i.TypeCode == "SUBSTATION" || i.TypeCode == "VOLTAGE") && i.IsChecked) .OrderBy(i => i.ParentName) .ThenBy(i => i.Name) .ToList <ListPoint>(); if (substations == null || substations.Count == 0) { this.ShowDialogWarning(Strings.EmptyList); return; } Dialogs.IDialog dialog = null; btnPanel.IsEnabled = false; try { App.Current.MainWindow.TaskbarItemInfo = new System.Windows.Shell.TaskbarItemInfo() { Description = Strings.GetDataHeader, ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal, ProgressValue = 0.01 }; Action updateUI = () => { btnPanel.IsEnabled = true; dialog.Close(); }; Action completed = () => { App.Current.MainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None; updateUI(); }; Action canceled = () => { App.Current.MainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Paused; this.ShowDialogInfo(Strings.Canceled); updateUI(); }; Action <Exception> faulted = (Exception e) => { App.Current.MainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Error; this.ShowDialogError(App.GetExceptionDetails(e)); updateUI(); }; dialog = this.DialogCustom(new GetDataControl(substations, completed, canceled, faulted)); dialog.Show(); } catch (Exception ex) { App.Log("Получение отчётов - ошибка"); this.ShowDialogError(App.GetExceptionDetails(ex), null, () => TMPApplication.DispatcherExtensions.InUi(() => btnPanel.IsEnabled = true)); dialog.Close(); } }); }, o => IsReadyToGetData); GetEnergyCommand = new DelegateCommand(o => { this.ShowDialogInfo(Strings.OnGettingData, null, () => { App.Log("Получение суточных значений"); if (CheckAvailability() == false) { this.ShowDialogWarning(Strings.MessageServerNotAvailability); return; } Dialogs.IDialog dialog = null; btnPanel.IsEnabled = false; try { App.Current.MainWindow.TaskbarItemInfo = new System.Windows.Shell.TaskbarItemInfo(); App.Current.MainWindow.TaskbarItemInfo.Description = Strings.GetDataHeader; App.Current.MainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal; App.Current.MainWindow.TaskbarItemInfo.ProgressValue = 0.01; Action updateUI = () => { TMPApplication.DispatcherExtensions.InUi(() => btnPanel.IsEnabled = true); dialog.Close(); }; Action completed = () => { App.Current.MainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None; updateUI(); }; Action canceled = () => { App.Current.MainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Paused; this.ShowDialogInfo(Strings.Canceled, Strings.Message, null); updateUI(); }; Action <Exception> faulted = (Exception e) => { App.Current.MainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Error; this.ShowDialogError(App.GetExceptionDetails(e)); updateUI(); }; dialog = this.DialogCustom(new GetEnergyControl(_treeModel.Point.Items, completed, canceled, faulted)); dialog.Show(); } catch (Exception ex) { App.Log("Получение суточных значений - ошибка"); this.ShowDialogError(App.GetExceptionDetails(ex), null, () => TMPApplication.DispatcherExtensions.InUi(() => btnPanel.IsEnabled = true)); dialog.Close(); } }); }, o => IsReadyToGetData); TreeCheckOrUncheckItemsCommand = new DelegateCommand( o => { ICSharpCode.TreeView.SharpTreeView tree = o as ICSharpCode.TreeView.SharpTreeView; if (tree != null) { ListPoint point = (ListPoint)tree.SelectedItem; if (point != null && point.Items != null) { foreach (var child in point.Items) { if (child.TypeCode == "FES" || child.TypeCode == "RES" || child.TypeCode == "SUBSTATION" || child.TypeCode == "VOLTAGE") { child.IsChecked = !child.IsChecked; } } } } }, o => _treeModel != null && _treeModel.Children != null && _treeModel.Children.Count > 0); TreeUnselectAllCommand = new DelegateCommand( o => { if (_treeModel != null) { foreach (var item in _treeModel.Point.Items) { ForEachPointInTree(item, p => true, p => p.IsChecked = false); } } }, o => _treeModel != null && _treeModel.Children != null && _treeModel.Children.Count > 0); TreeSelectAllCommand = new DelegateCommand( o => { if (_treeModel != null) { foreach (var item in _treeModel.Point.Items) { ForEachPointInTree(item, p => p.TypeCode == "SUBSTATION" || p.TypeCode == "VOLTAGE", p => p.IsChecked = true); } } }, o => _treeModel != null && _treeModel.Children != null && _treeModel.Children.Count > 0); }
public static IList <ListPoint> GetPointsList(string data, ListPoint parent) { var records = Utils.ParseRecords(data); if (records == null) { return(new List <ListPoint>()); } var list = new List <Model.IEmcosElement>(); foreach (var nvc in records) { Emcos.Model.IEmcosElement element; if (nvc.Get("Type") == "POINT") { element = new Model.EmcosPointElement(); } else { element = new Model.EmcosGrElement(); } for (int i = 0; i < nvc.Count; i++) { #region азбор полей int intValue = 0; switch (nvc.GetKey(i)) { case "GR_ID": case "POINT_ID": int.TryParse(nvc[i], out intValue); element.Id = intValue; break; case "GR_NAME": case "POINT_NAME": element.Name = nvc[i]; break; case "ECP_NAME": Model.EmcosPointElement pe = (element as Model.EmcosPointElement); pe.EcpName = nvc[i]; break; case "TYPE": Model.ElementTypes type; if (Enum.TryParse <Model.ElementTypes>(nvc[i], out type) == false) { type = Model.ElementTypes.GROUP; } element.Type = type; break; case "GR_TYPE_CODE": case "POINT_TYPE_CODE": element.TypeCode = nvc[i]; break; } #endregion } list.Add(element); } IList <ListPoint> points = list.Select(i => new ListPoint { Id = i.Id, Name = i.Name, IsGroup = i.Type == Model.ElementTypes.GROUP, TypeCode = i.TypeCode, EсpName = i is Model.EmcosPointElement ? (i as Model.EmcosPointElement).EcpName : String.Empty, Type = i.Type, IsChecked = false, ParentId = parent.Id, ParentTypeCode = parent.TypeCode, ParentName = parent.Name }).ToList(); return(points); }