private void ProcessBalanceItemsToFloatCollection(IBalanceGroupItem item, ref List <IBalanceItem> collection) { if (item == null) { return; } if (item.Children != null) { foreach (IBalanceItem child in item.Children) { var group = child as IBalanceGroupItem; if (group == null && (item is SubstationAuxiliary || (item is SubstationSection && (item as SubstationSection).IsLowVoltage))) { if (child.ElementType == Model.ElementTypes.FIDER || child.ElementType == Model.ElementTypes.POWERTRANSFORMER || child.ElementType == Model.ElementTypes.UNITTRANSFORMER || child.ElementType == Model.ElementTypes.UNITTRANSFORMERBUS) { collection.Add(child); } } else { ProcessBalanceItemsToFloatCollection(group, ref collection); } } } }
protected override void RemoveItem(int index) { IBalanceGroupItem oldItem = base[index]; base.RemoveItem(index); if (oldItem != null) { oldItem.Parent = null; } FlatItemsList.Remove(oldItem); }
public SubstationsCollection(IBalanceGroupItem parent, IEnumerable <IHierarchicalEmcosPoint> collection) : this(parent) { if (collection == null) { throw new ArgumentNullException(); } foreach (IHierarchicalEmcosPoint point in collection) { if (point is Substation substation) { this.Add(substation); } } }
protected override void SetItem(int index, Substation item) { IBalanceGroupItem oldItem = base[index]; int ind = FlatItemsList.IndexOf(oldItem); if (oldItem != null) { oldItem.Parent = null; } if (item != null) { item.Parent = _parent; } base.SetItem(index, item); FlatItemsList[ind] = item; }
public Balance(IBalanceGroupItem group) { BalanceGroup = group; if (BalanceGroup.Formula == null) { BalanceGroup.Formula = BalanceFormula.CreateDefault(); } _BalanceItemsEnergy = new Dictionary <IBalanceItem, IEnergy>(); if (BalanceGroup.HasChildren) { foreach (IBalanceItem item in BalanceGroup.Children) { if (_BalanceItemsEnergy.ContainsKey(item) == false) { _BalanceItemsEnergy.Add(item, GetEnergyForBalanceItem(item)); } } } BalanceGroup.PropertyChanged += BalanceGroup_PropertyChanged; }
public ReactiveEnergyBalance(IBalanceGroupItem group) : base(group) { }
public BalanceGroupsCollection(IBalanceGroupItem parent) : base(parent) { }
public SubstationsCollection(IBalanceGroupItem parent) : base() { this._parent = parent; this.FlatItemsList = new List <IHierarchicalEmcosPoint>(); }
/// <summary> /// Загрузка файла сессии версии 1.0 /// </summary> /// <remarks> /// Файл сессии версии 1.0 представляет собой сериализованный в json объект BalanceSession дополнительно сжатый gzip /// </remarks> /// <param name="fileName">Имя файла</param> /// <param name="balanceSession">Ссылка на сессию</param> /// <returns>Сессия</returns> private BalanceSession LoadDataFromFileVersion_1_0(string fileName) { const string UNKNOWN_DEPARTAMENT_NAME = "<неизвестно>"; BalanceSession balanceSession = new BalanceSession(); try { dynamic obj = ParseJsonFromFile(fileName); if (obj != null) { var fi = new FileInfo(fileName); BalanceSessionInfo balanceSessionInfo = LoadSessionInfoFromOldFileFormat(obj); balanceSessionInfo.FileSize = fi.Length; balanceSession.Info = balanceSessionInfo; if (obj.Substations != null) { balanceSession.BalancePoints.Clear(); // создание списка департаментов (рэс) HashSet <string> departamentsSet = new HashSet <string>(); foreach (var item in obj.Substations) { string departament = item?.Departament?.ToString(); if (String.IsNullOrWhiteSpace(departament) == false && departamentsSet.Contains(departament) == false) { departamentsSet.Add(departament); } } Dictionary <string, IHierarchicalEmcosPoint> departamentsDictionary = new Dictionary <string, IHierarchicalEmcosPoint>(); foreach (var item in departamentsSet) { departamentsDictionary.Add(item, new EmcosPoint() { ElementType = ElementTypes.DEPARTAMENT, TypeCode = "RES", Name = item }); } departamentsDictionary.Add("?", new EmcosPoint() { ElementType = ElementTypes.DEPARTAMENT, TypeCode = "RES", Name = UNKNOWN_DEPARTAMENT_NAME }); System.Collections.IList parentList = departamentsDictionary["?"].Children; void parseBase(IHierarchicalEmcosPoint source, dynamic data) { try { source.Id = data.Id ?? 0; source.Code = data.Code; source.Name = data.Title; source.Status = data.Status; source.Description = data.Description; if (String.IsNullOrEmpty(source.Description) == false) { balanceSession.DescriptionsById.Add(source.Id, source.Description); } } catch (Exception e) { _callBackAction(e); } } object getPropertyValue(string propertyName, dynamic jObject) { if ((jObject is Newtonsoft.Json.Linq.JObject o) && (o.Property(propertyName) != null)) { return(o.Property(propertyName).Value); } else { return(null); } } double?getDoubleValue(string propertyName, dynamic jObject) { object value = getPropertyValue(propertyName, jObject); if (value == null) { return(null); } else { return(Convert.ToDouble(value)); } } bool getBoolValue(string propertyName, dynamic jObject) { object value = getPropertyValue(propertyName, jObject); if (value == null) { return(false); } else { return(Convert.ToBoolean(value)); } } void parseTokens(IEnumerable <Newtonsoft.Json.Linq.JToken> tokens) { foreach (Newtonsoft.Json.Linq.JToken jobj in tokens) { if (jobj.Children().Where(i => (i is Newtonsoft.Json.Linq.JProperty p) && p.Name == "$type").FirstOrDefault() is Newtonsoft.Json.Linq.JProperty typeProperty) { string tokenType = typeProperty.Value.ToString(); if (String.IsNullOrWhiteSpace(tokenType) == false) { string t = tokenType.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)[0]; string[] parts = t.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 1 && parts[0] == "TMP") { string part = parts[parts.Length - 1]; IBalanceGroupItem group = null; dynamic data = jobj; switch (part) { case "Substation": group = new Substation { Departament = data.Departament, Voltage = data.Voltage }; break; case "SubstationSection": group = new SubstationSection { Voltage = data.Voltage }; break; case "SubstationPowerTransformers": group = new SubstationPowerTransformers(); break; case "SubstationAuxiliary": group = new SubstationAuxiliary(); break; default: { IBalanceItem item = null; switch (part) { case "Fider": item = new Fider(); break; case "PowerTransformer": item = new PowerTransformer(); break; case "UnitTransformer": item = new UnitTransformer(); break; case "UnitTransformerBus": item = new UnitTransformerBus(); break; default: System.Diagnostics.Debugger.Break(); break; } if (item != null) { parseBase(item, data); } object value = getPropertyValue("DailyEplus", data); string daysValues = value?.ToString(); item.ActiveEnergy.Plus.DaysValues = (daysValues != null && daysValues.StartsWith("<")) ? null : (value as Newtonsoft.Json.Linq.JToken)?.ToObject <List <double?> >(); value = getPropertyValue("DailyEminus", data); daysValues = value?.ToString(); item.ActiveEnergy.Minus.DaysValues = (daysValues != null && daysValues.StartsWith("<")) ? null : (value as Newtonsoft.Json.Linq.JToken)?.ToObject <List <double?> >(); item.ActiveEnergy.Plus.MonthValue = getDoubleValue("MonthEplus", data); item.ActiveEnergy.Minus.MonthValue = getDoubleValue("MonthEminus", data); item.ActiveEnergy.Plus.CorrectionValue = getDoubleValue("Eplus", data) - getDoubleValue("DayEplusValue", data); item.ActiveEnergy.Minus.CorrectionValue = getDoubleValue("Eminus", data) - getDoubleValue("DayEminusValue", data); item.ActiveEnergy.Plus.UseMonthValue = getBoolValue("UseMonthValue", data); item.ActiveEnergy.Minus.UseMonthValue = getBoolValue("UseMonthValue", data); if (group != null) { group.Children.Add(item); } if (item == null && group == null) { System.Diagnostics.Debugger.Break(); } } break; } if (group != null) { parseBase(group, data); if (group is Substation substation) { departamentsDictionary[substation.Departament].Children.Add(substation); } else { parentList.Add(group); } var childrenProperty = jobj.Children() .Where(i => (i is Newtonsoft.Json.Linq.JProperty p) && p.Name == "Children") .FirstOrDefault() as Newtonsoft.Json.Linq.JProperty; if (childrenProperty != null && childrenProperty.Value != null && childrenProperty.Value is Newtonsoft.Json.Linq.JArray childrenArray) { System.Collections.IList oldParentList = parentList; parentList = group.Children; parseTokens(childrenArray); parentList = oldParentList; } else { System.Diagnostics.Debugger.Break(); } } } } // значение типа токена пустое else { System.Diagnostics.Debugger.Break(); } } // не найден тип токена else { System.Diagnostics.Debugger.Break(); } }