bool IsTransformerWindingPrimary(TransformerWinding tw) { PowerTransformer pt = Get(tw.PowerTransformer) as PowerTransformer; TransformerWinding other = null; for (int i = 0; i < pt.TransformerWindings.Count; ++i) { long otherGID = pt.TransformerWindings[i]; if (otherGID == tw.GID) { continue; } TransformerWinding tw2 = Get(otherGID) as TransformerWinding; if (tw2 != null) { other = tw2; break; } } BaseVoltage bv1 = Get(tw.BaseVoltage) as BaseVoltage; BaseVoltage bv2 = Get(other.BaseVoltage) as BaseVoltage; return(bv1.NominalVoltage > bv2.NominalVoltage); }
double GetPowerTransformerRatio(PowerTransformer pt) { if (pt.TransformerWindings.Count != 2) { return(1); } TransformerWinding tw1 = Get(pt.TransformerWindings[0]) as TransformerWinding; TransformerWinding tw2 = Get(pt.TransformerWindings[1]) as TransformerWinding; BaseVoltage bv1 = Get(tw1.BaseVoltage) as BaseVoltage; BaseVoltage bv2 = Get(tw2.BaseVoltage) as BaseVoltage; Pair <double, double> u = MinMax(bv1.NominalVoltage, bv2.NominalVoltage); RatioTapChanger rt = null; if (tw1.RatioTapChanger.Count == 1) { rt = Get(tw1.RatioTapChanger[0]) as RatioTapChanger; } else if (tw2.RatioTapChanger.Count == 1) { rt = Get(tw2.RatioTapChanger[0]) as RatioTapChanger; } return(rt != null ? (u.Second + (GetRatioTapChangerStep(rt) - rt.NominalStep) * rt.VoltageStep) / u.First : u.Second / u.First); }
public static string TranformerToString(PowerTransformer transformer, string num) { StringBuilder sb = new StringBuilder(); sb.AppendLine($"PT {num}\n\t NAME: {transformer.Name}"); sb.AppendLine($"\tMRDI: {transformer.MRID}"); sb.AppendLine($"\tDESCRIPTION: { transformer.Description}"); return(sb.ToString()); }
public static void Postfix(PowerTransformer __instance, Battery ___battery) { var pta = __instance.gameObject.GetComponent <PowerTransformerAdjustable>(); if (pta != null && ___battery.joulesLostPerSecond > 0) { ___battery.joulesLostPerSecond *= pta.Efficiency; } }
/// <summary> /// Creates entity for specified global inside the container. /// </summary> /// <param name="globalId">Global id of the entity for insert</param> /// <returns>Created entity (identified object).</returns> public IdentifiedObject CreateEntity(long globalId) { short type = ModelCodeHelper.ExtractTypeFromGlobalId(globalId); IdentifiedObject io = null; switch ((DMSType)type) { case DMSType.BASEVOLTAGE: io = new BaseVoltage(globalId); break; case DMSType.CONNECTIVITYNODE: io = new ConnectivityNode(globalId); break; case DMSType.ENERGYCONSUMER: io = new EnergyConsumer(globalId); break; case DMSType.ENERGYSOURCE: io = new EnergySource(globalId); break; case DMSType.POWERTRANSFORMER: io = new PowerTransformer(globalId); break; case DMSType.PTRANSFORMEREND: io = new PowerTransformerEnd(globalId); break; case DMSType.SWITCH: io = new Switch(globalId); break; case DMSType.ACLINESEGMENT: io = new ACLineSegment(globalId); break; case DMSType.TERMINAL: io = new Terminal(globalId); break; default: string message = String.Format("Failed to create entity because specified type ({0}) is not supported.", type); Logger.LogError(message); throw new Exception(message); } // Add entity to map this.AddEntity(io); return(io); }
public override void ConfigureBuildingTemplate(GameObject go, Tag prefab_tag) { go.GetComponent<KPrefabID>().AddTag(RoomConstraints.ConstraintTags.IndustrialMachinery); go.AddComponent<RequireInputs>(); BuildingDef def = go.GetComponent<Building>().Def; Battery battery = go.AddOrGet<Battery>(); battery.powerSortOrder = 1000; battery.capacity = def.GeneratorWattageRating; battery.chargeWattage = def.GeneratorWattageRating; PowerTransformer powerTransformer = go.AddComponent<PowerTransformer>(); powerTransformer.powerDistributionOrder = 9; }
private ResourceDescription CreatePowerTransformerResourceDescription(PowerTransformer cimPowerTransformer) { ResourceDescription rd = null; if (cimPowerTransformer != null) { long gid = ModelCodeHelper.CreateGlobalId(0, (short)DMSType.POWERTRANSFORMER, importHelper.CheckOutIndexForDMSType(DMSType.POWERTRANSFORMER)); rd = new ResourceDescription(gid); importHelper.DefineIDMapping(cimPowerTransformer.ID, gid); SCADAConverter.PopulatePowerTransformerProperties(cimPowerTransformer, rd, importHelper, report); } return(rd); }
private string CheckIfPropertyNeedsId(string updated_property_info_name, object data) { switch (updated_property_info_name) { case "ConnectivityNode.ConnectivityNodeContainer": Circuit c = (Circuit)data; return(c.MRID); case "UsagePoint.ServiceLocation": ServiceLocation sl = (ServiceLocation)data; return(sl.MRID); case "PowerSystemResource.PSRType": PSRType psr = (PSRType)data; return(psr.Name); case "ACLineSegment.PerLengthImpedance": PerLengthImpedance pli = (PerLengthImpedance)data; return(pli.MRID); case "Equipment.EquipmentContainer": EquipmentContainer eq = (EquipmentContainer)data; return(eq.MRID); case "PowerSystemResource.AssetDatasheet": AssetInfo ad = (AssetInfo)data; return(ad.MRID); case "TransformerEnd.Terminal": Terminal t = (Terminal)data; return(t.MRID); case "PowerTransformerEnd.PowerTransformer": PowerTransformer pst = (PowerTransformer)data; return(pst.MRID); case "Terminal.ConductingEquipment": ConductingEquipment ce = (ConductingEquipment)data; return(ce.MRID); case "Terminal.ConnectivityNode": ConnectivityNode cn = (ConnectivityNode)data; return(cn.MRID); } return(""); }
public override void UpdateMeasurements(MeasurementModel newMeasurement) { if (newMeasurement.ObjectMrid == PowerTransformer.MRID) { PowerTransformer.UpdateMeasurements(newMeasurement); return; } if (newMeasurement.ObjectMrid == RatioTapChanger.MRID) { RatioTapChanger.UpdateMeasurements(newMeasurement); return; } base.UpdateMeasurements(newMeasurement); }
private void TestTransformers() { List <string> singleFieldList = new List <string>() { "f1" }; List <string> twoFieldsList = new List <string>() { "f1", "f2" }; ITransformer transformer; //Difference transformer transformer = new DiffTransformer(singleFieldList, new DiffTransformerSettings(singleFieldList[0], 2)); TestSingleFieldTransformer(transformer); //CDiv transformer transformer = new CDivTransformer(singleFieldList, new CDivTransformerSettings(singleFieldList[0], 1d)); TestSingleFieldTransformer(transformer); //Log transformer transformer = new LogTransformer(singleFieldList, new LogTransformerSettings(singleFieldList[0], 10)); TestSingleFieldTransformer(transformer); //Exp transformer transformer = new ExpTransformer(singleFieldList, new ExpTransformerSettings(singleFieldList[0])); TestSingleFieldTransformer(transformer); //Power transformer transformer = new PowerTransformer(singleFieldList, new PowerTransformerSettings(singleFieldList[0], 0.5d, true)); TestSingleFieldTransformer(transformer); //YeoJohnson transformer transformer = new YeoJohnsonTransformer(singleFieldList, new YeoJohnsonTransformerSettings(singleFieldList[0], 0.5d)); TestSingleFieldTransformer(transformer); //MWStat transformer transformer = new MWStatTransformer(singleFieldList, new MWStatTransformerSettings(singleFieldList[0], 5, BasicStat.StatisticalFigure.RootMeanSquare)); TestSingleFieldTransformer(transformer); //Mul transformer transformer = new MulTransformer(twoFieldsList, new MulTransformerSettings(twoFieldsList[0], twoFieldsList[1])); TestTwoFieldsTransformer(transformer); //Div transformer transformer = new DivTransformer(twoFieldsList, new DivTransformerSettings(twoFieldsList[0], twoFieldsList[1])); TestTwoFieldsTransformer(transformer); //Linear transformer transformer = new LinearTransformer(twoFieldsList, new LinearTransformerSettings(twoFieldsList[0], twoFieldsList[1], 0.03, 0.2)); TestTwoFieldsTransformer(transformer); return; }
/// <summary> /// Creates entity for specified global inside the container. /// </summary> /// <param name="globalId">Global id of the entity for insert</param> /// <returns>Created entity (identified object).</returns> public IdentifiedObject CreateEntity(long globalId) { short type = ModelCodeHelper.ExtractTypeFromGlobalId(globalId); IdentifiedObject io = null; switch ((DMSType)type) { case DMSType.BASEVOLTAGE: io = new BaseVoltage(globalId); break; case DMSType.LOCATION: io = new Location(globalId); break; case DMSType.POWERTR: io = new PowerTransformer(globalId); break; case DMSType.POWERTRWINDING: io = new TransformerWinding(globalId); break; case DMSType.WINDINGTEST: io = new WindingTest(globalId); break; case DMSType.TERMINAL: io = new Terminal(globalId); break; default: string message = String.Format("Failed to create entity because specified type ({0}) is not supported.", type); CommonTrace.WriteTrace(CommonTrace.TraceError, message); throw new Exception(message); } // Add entity to map this.AddEntity(io); return(io); }
private void ImportPowerTransformer() { SortedDictionary <string, object> cimPowerTransformers = concreteModel.GetAllObjectsOfType("FTN.PowerTransformer"); if (cimPowerTransformers != null) { foreach (KeyValuePair <string, object> item in cimPowerTransformers) { PowerTransformer cimPowerTransformer = item.Value as PowerTransformer; ResourceDescription rd = CreatePowerTransformerResourceDescription(cimPowerTransformer); if (rd != null) { delta.AddDeltaOperation(DeltaOpType.Insert, rd, true); report.Report.Append("PowerTransformer ID = ").Append(cimPowerTransformer.ID).Append(" SUCCESSFULLY converted to GID = ").AppendLine(rd.Id.ToString()); } else { report.Report.Append("PowerTransformer ID = ").Append(cimPowerTransformer.ID).AppendLine(" FAILED to be converted"); } } report.Report.AppendLine(); } }
public void Rebuild() { for (int i = 0; i < this.circuitInfo.Count; i++) { CircuitInfo value = this.circuitInfo[i]; value.generators.Clear(); value.consumers.Clear(); value.batteries.Clear(); value.inputTransformers.Clear(); value.outputTransformers.Clear(); value.minBatteryPercentFull = 1f; for (int j = 0; j < value.bridgeGroups.Length; j++) { value.bridgeGroups[j].Clear(); } this.circuitInfo[i] = value; } consumersShadow.AddRange(consumers); List <IEnergyConsumer> .Enumerator enumerator = consumersShadow.GetEnumerator(); while (enumerator.MoveNext()) { IEnergyConsumer current = enumerator.Current; int powerCell = current.PowerCell; ushort circuitID = GetCircuitID(powerCell); if (circuitID != 65535) { Battery battery = current as Battery; if ((Object)battery != (Object)null) { Operational component = battery.GetComponent <Operational>(); if ((Object)component == (Object)null || component.IsOperational) { CircuitInfo value2 = this.circuitInfo[circuitID]; PowerTransformer powerTransformer = battery.powerTransformer; if ((Object)powerTransformer != (Object)null) { value2.inputTransformers.Add(battery); } else { value2.batteries.Add(battery); CircuitInfo circuitInfo = this.circuitInfo[circuitID]; value2.minBatteryPercentFull = Mathf.Min(circuitInfo.minBatteryPercentFull, battery.PercentFull); } this.circuitInfo[circuitID] = value2; } } else { CircuitInfo circuitInfo2 = this.circuitInfo[circuitID]; circuitInfo2.consumers.Add(current); } } } consumersShadow.Clear(); for (int k = 0; k < this.circuitInfo.Count; k++) { CircuitInfo circuitInfo3 = this.circuitInfo[k]; circuitInfo3.consumers.Sort((IEnergyConsumer a, IEnergyConsumer b) => a.WattsNeededWhenActive.CompareTo(b.WattsNeededWhenActive)); } HashSet <Generator> .Enumerator enumerator2 = generators.GetEnumerator(); while (enumerator2.MoveNext()) { Generator current2 = enumerator2.Current; int powerCell2 = current2.PowerCell; ushort circuitID2 = GetCircuitID(powerCell2); if (circuitID2 != 65535) { if (current2.GetType() == typeof(PowerTransformer)) { CircuitInfo circuitInfo4 = this.circuitInfo[circuitID2]; circuitInfo4.outputTransformers.Add(current2); } else { CircuitInfo circuitInfo5 = this.circuitInfo[circuitID2]; circuitInfo5.generators.Add(current2); } } } HashSet <WireUtilityNetworkLink> .Enumerator enumerator3 = bridges.GetEnumerator(); while (enumerator3.MoveNext()) { WireUtilityNetworkLink current3 = enumerator3.Current; current3.GetCells(out int linked_cell, out int _); ushort circuitID3 = GetCircuitID(linked_cell); if (circuitID3 != 65535) { Wire.WattageRating maxWattageRating = current3.GetMaxWattageRating(); CircuitInfo circuitInfo6 = this.circuitInfo[circuitID3]; circuitInfo6.bridgeGroups[(int)maxWattageRating].Add(current3); } } dirty = false; }
Node BuildSubGraph(EnergySource source) { Dictionary <long, IdentifiedObject> terminals = containers[DMSType.Terminal]; Dictionary <long, IdentifiedObject> cNodes = containers[DMSType.ConnectivityNode]; Node sourceNode = new Node(source, 0, 0); Queue <Tuple <Node, Node> > queue = new Queue <Tuple <Node, Node> >(); queue.Enqueue(new Tuple <Node, Node>(null, sourceNode)); Dictionary <long, Node> visited = new Dictionary <long, Node>(); visited.Add(source.GID, sourceNode); while (queue.Count > 0) { Tuple <Node, Node> tuple = queue.Dequeue(); Node node = tuple.Item2; node.AdjacentOffset = adjacency.Count; adjacency.Add(tuple.Item1); ++node.AdjacentCount; DMSType type = ModelCodeHelper.GetTypeFromGID(node.IO.GID); if (type == DMSType.ConnectivityNode) { foreach (long tGID in ((ConnectivityNode)node.IO).Terminals) { IdentifiedObject terminal; if (!terminals.TryGetValue(tGID, out terminal)) { continue; } long ceGID = ((Terminal)terminal).ConductingEquipment; if (ceGID == 0) { continue; } Node adjacentNode; if (!visited.TryGetValue(ceGID, out adjacentNode)) { DMSType ceType = ModelCodeHelper.GetTypeFromGID(ceGID); IdentifiedObject ce; if (!containers[ceType].TryGetValue(ceGID, out ce)) { continue; } adjacentNode = new Node(ce, 0, 0); queue.Enqueue(new Tuple <Node, Node>(node, adjacentNode)); visited.Add(ceGID, adjacentNode); } adjacency.Add(adjacentNode); ++node.AdjacentCount; } } else if (type == DMSType.TransformerWinding) { TransformerWinding tw = node.IO as TransformerWinding; PowerTransformer pt = Get(tw.PowerTransformer) as PowerTransformer; if (pt == null) { continue; } foreach (long twGID in pt.TransformerWindings) { if (twGID == tw.GID) { continue; } Node adjacentNode; if (!visited.TryGetValue(twGID, out adjacentNode)) { TransformerWinding twAdjacent = Get(twGID) as TransformerWinding; if (twAdjacent == null) { continue; } adjacentNode = new Node(twAdjacent, 0, 0); queue.Enqueue(new Tuple <Node, Node>(node, adjacentNode)); visited.Add(twGID, adjacentNode); } adjacency.Add(adjacentNode); ++node.AdjacentCount; break; } foreach (long tGID in tw.Terminals) { IdentifiedObject terminal; if (!terminals.TryGetValue(tGID, out terminal)) { continue; } long cNodeGID = ((Terminal)terminal).ConnectivityNode; if (cNodeGID == 0) { continue; } Node adjacentNode; if (!visited.TryGetValue(cNodeGID, out adjacentNode)) { IdentifiedObject cNode; if (!cNodes.TryGetValue(cNodeGID, out cNode)) { continue; } adjacentNode = new Node(cNode, 0, 0); queue.Enqueue(new Tuple <Node, Node>(node, adjacentNode)); visited.Add(cNodeGID, adjacentNode); } adjacency.Add(adjacentNode); ++node.AdjacentCount; } } else { foreach (long tGID in ((ConductingEquipment)node.IO).Terminals) { IdentifiedObject terminal; if (!terminals.TryGetValue(tGID, out terminal)) { continue; } long cNodeGID = ((Terminal)terminal).ConnectivityNode; if (cNodeGID == 0) { continue; } Node adjacentNode; if (!visited.TryGetValue(cNodeGID, out adjacentNode)) { IdentifiedObject cNode; if (!cNodes.TryGetValue(cNodeGID, out cNode)) { continue; } adjacentNode = new Node(cNode, 0, 0); queue.Enqueue(new Tuple <Node, Node>(node, adjacentNode)); visited.Add(cNodeGID, adjacentNode); } adjacency.Add(adjacentNode); ++node.AdjacentCount; } } } return(sourceNode); }
double CalculateVoltageForTransformerWinding(Node node, Dictionary <long, LoadFlowResult> lf, Dictionary <long, Complex> currents) { TransformerWinding tw = node.IO as TransformerWinding; if (IsTransformerWindingPrimary(tw)) { return(0); } if (!currents.ContainsKey(node.IO.GID)) { return(double.MaxValue); } PowerTransformer pw = Get(tw.PowerTransformer) as PowerTransformer; TransformerWinding tw1 = null; for (int i = 0; i < pw.TransformerWindings.Count; ++i) { long twGid = pw.TransformerWindings[i]; if (twGid != tw.GID) { tw1 = Get(twGid) as TransformerWinding; break; } } long node1Gid = (Get(tw1.Terminals[0]) as Terminal).ConnectivityNode; long node2Gid = (Get(tw.Terminals[0]) as Terminal).ConnectivityNode; LoadFlowResult lfr1; if (!lf.TryGetValue(node1Gid, out lfr1)) { return(0); } Complex u1 = new Complex(lfr1.Get(LoadFlowResultType.UR), lfr1.Get(LoadFlowResultType.UI)); Complex u2 = u1.Scale(1.0 / GetPowerTransformerRatio(pw)); LoadFlowResult lfr2; double relDelta = double.MaxValue; if (!lf.TryGetValue(node2Gid, out lfr2)) { lfr2 = new LoadFlowResult(); lf[node2Gid] = lfr2; } else { relDelta = GetVoltageRelativeDifference(new Complex(lfr2.Get(LoadFlowResultType.UR), lfr2.Get(LoadFlowResultType.UI)), u2); } lfr2.Remove(LoadFlowResultType.UR); lfr2.Remove(LoadFlowResultType.UI); lfr2.Add(new LoadFlowResultItem(u2.X, LoadFlowResultType.UR)); lfr2.Add(new LoadFlowResultItem(u2.Y, LoadFlowResultType.UI)); return(relDelta); }
public NetworkModel(NetworkModelDownload download) { Dictionary <long, IdentifiedObject> terminalContainer = download.Containers[DMSType.Terminal]; Dictionary <long, IdentifiedObject> conNodeContainer = download.Containers[DMSType.ConnectivityNode]; List <Node> trees = new List <Node>(); Dictionary <long, RecloserNode> reclosers = new Dictionary <long, RecloserNode>(); foreach (KeyValuePair <long, IdentifiedObject> source in download.Containers[DMSType.EnergySource]) { if (source.Value == null) { continue; } Node root = new Node(null, source.Value); Stack <Node> stack = new Stack <Node>(); stack.Push(root); while (stack.Count > 0) { Node node = stack.Pop(); IdentifiedObject io = node.io; DMSType type = ModelCodeHelper.GetTypeFromGID(io.GID); switch (type) { case DMSType.ConnectivityNode: { foreach (long terminalGID in ((ConnectivityNode)io).Terminals) { long condEqGID = ((Terminal)terminalContainer[terminalGID]).ConductingEquipment; if (condEqGID == node.parent.io.GID) { continue; } DMSType condEqType = ModelCodeHelper.GetTypeFromGID(condEqGID); ConductingEquipment condEq = (ConductingEquipment)download.Containers[condEqType][condEqGID]; if (condEq is Recloser) { RecloserNode rn; if (reclosers.TryGetValue(condEqGID, out rn)) { if (rn.node2 == null) { rn.node2 = node; } } else { reclosers.Add(condEqGID, new RecloserNode(condEq) { node1 = node }); } continue; } Node childNode = new Node(node, condEq); node.children.Add(childNode); stack.Push(childNode); } } break; case DMSType.TransformerWinding: { TransformerWinding tw = io as TransformerWinding; if (tw == null) { break; } PowerTransformer pt = GetInternal(download.Containers, tw.PowerTransformer) as PowerTransformer; if (pt == null) { break; } foreach (long twGID in pt.TransformerWindings) { if (twGID == tw.GID || (node.parent != null && twGID == node.parent.io.GID)) { continue; } TransformerWinding twChild = GetInternal(download.Containers, twGID) as TransformerWinding; if (twChild == null) { continue; } Node childNode = new Node(node, twChild); node.children.Add(childNode); stack.Push(childNode); } foreach (long terminalGID in tw.Terminals) { long conNodeGID = ((Terminal)terminalContainer[terminalGID]).ConnectivityNode; if (node.parent != null && conNodeGID == node.parent.io.GID) { continue; } Node childNode = new Node(node, conNodeContainer[conNodeGID]); node.children.Add(childNode); stack.Push(childNode); } } break; default: { ConductingEquipment condEq = io as ConductingEquipment; if (condEq == null) { break; } foreach (long terminalGID in condEq.Terminals) { long conNodeGID = ((Terminal)terminalContainer[terminalGID]).ConnectivityNode; if (node.parent != null && conNodeGID == node.parent.io.GID) { continue; } Node childNode = new Node(node, conNodeContainer[conNodeGID]); node.children.Add(childNode); stack.Push(childNode); } } break; } } trees.Add(root); } this.trees = trees; this.reclosers = reclosers; this.containers = download.Containers; }
void PopulatePowerTransformerProperties(PowerTransformer x, ResourceDescription rd) { PopulateEquipmentProperties(x, rd); }
public Dictionary <Type, Dictionary <string, IdentifiedObject> > CreateObjectModel(Dictionary <string, DataVertex> globalVertices, Dictionary <string, List <DataEdge> > globalEdges, Dictionary <string, CableConfiguration> globalCableConfiguration, Dictionary <string, SpotLoad> globalSpotLoads) { globalComponentDictionary = new Dictionary <Type, Dictionary <string, IdentifiedObject> >(); terminalPairsContainer = new List <TerminalPair>(); perLengthImpedanceContainer = new Dictionary <string, PerLengthImpedance>(); wireInfoContainer = new Dictionary <string, WireInfo>(); usagePointContainer = new Dictionary <string, SpotLoad>(); powerTransformerEnding = new Dictionary <string, DataVertexTransformer>(); PSRType local_psr_pt = new PSRType(); circuit = new Circuit(); string mrid = Guid.NewGuid().ToString(); PSRType psrTypeCircuit = new PSRType() { MRID = "Feeder", Name = "Feeder" }; circuit.PSRType = psrTypeCircuit; circuit.ID = mrid; circuit.MRID = mrid; circuit.Name = "Feeder_36"; addComponentToGlobalDictionary(circuit, circuit.GetType()); addComponentToGlobalDictionary(psrTypeCircuit, psrTypeCircuit.GetType()); Dictionary <string, ConnectivityNode> connectivityNodeContainer = new Dictionary <string, ConnectivityNode>(); foreach (DataVertex dataVertex in globalVertices.Values) { if (dataVertex.typeOfVertex == DataVertex.TypeOfVertex.TRANSFORMER_VERTEX) { PowerTransformer powerTransformer = new PowerTransformer(); DataVertexTransformer dvt = (DataVertexTransformer)dataVertex; string power_transformer_mrid = Guid.NewGuid().ToString(); powerTransformer.ID = power_transformer_mrid; powerTransformer.MRID = power_transformer_mrid; powerTransformer.Name = "2 winding power transformer"; local_psr_pt = new PSRType() { Name = "Consumer Transformer", MRID = "Consumer Transformer" }; powerTransformer.PSRType = local_psr_pt; powerTransformer.EquipmentContainer = circuit; addComponentToGlobalDictionary(local_psr_pt, local_psr_pt.GetType()); ConnectivityNode w1T_cn = new ConnectivityNode(); string connectivity_node_mrid = Guid.NewGuid().ToString(); w1T_cn.ID = connectivity_node_mrid; w1T_cn.MRID = connectivity_node_mrid; w1T_cn.ConnectivityNodeContainer = circuit; if ((dataVertex as DataVertexTransformer).Line_from == null) { continue; } ; w1T_cn.Name = (dataVertex as DataVertexTransformer).Line_from; connectivityNodeContainer.Add((dataVertex as DataVertexTransformer).Line_from, w1T_cn); addComponentToGlobalDictionary(w1T_cn, w1T_cn.GetType()); ConnectivityNode w2T_cn = new ConnectivityNode(); connectivity_node_mrid = Guid.NewGuid().ToString(); w2T_cn.ID = connectivity_node_mrid; w2T_cn.MRID = connectivity_node_mrid; w2T_cn.ConnectivityNodeContainer = circuit; w2T_cn.Name = (dataVertex as DataVertexTransformer).Line_to; connectivityNodeContainer.Add((dataVertex as DataVertexTransformer).Line_to, w2T_cn); if ((dataVertex as DataVertexTransformer).Line_to == null) { continue; } ; addComponentToGlobalDictionary(w2T_cn, w2T_cn.GetType()); Terminal w1T = new Terminal(); w1T.MRID = power_transformer_mrid + ".W1.T"; w1T.ID = power_transformer_mrid + ".W1.T"; w1T.SequenceNumber = 1; w1T.ConductingEquipment = powerTransformer; w1T.ConnectivityNode = w1T_cn; w1T.Phases = PhaseCode.s2N; w1T.Name = "Transformer end terminal 1"; Terminal w2T = new Terminal(); w2T.MRID = power_transformer_mrid + ".W2.T"; w2T.ID = power_transformer_mrid + ".W2.T"; w2T.SequenceNumber = 2; w2T.ConductingEquipment = powerTransformer; w2T.ConnectivityNode = w2T_cn; w2T.Phases = PhaseCode.s2N; w2T.Name = "Transformer end terminal 2"; terminalPairsContainer.Add(new TerminalPair() { terminalA = w1T, terminalB = w2T }); addComponentToGlobalDictionary(w1T, w1T.GetType()); addComponentToGlobalDictionary(w2T, w2T.GetType()); PowerTransformerEnd powerTransformerEnd1 = new PowerTransformerEnd(); powerTransformerEnd1.ID = power_transformer_mrid + ".W1"; powerTransformerEnd1.MRID = power_transformer_mrid + ".W1"; powerTransformerEnd1.Name = dvt.NameA; powerTransformerEnd1.Terminal = w1T; powerTransformerEnd1.Grounded = false; powerTransformerEnd1.EndNumber = 1; powerTransformerEnd1.PowerTransformer = powerTransformer; powerTransformerEnd1.ConnectionKind = WindingConnection.D; powerTransformerEnd1.PhaseAngleClock = 0; powerTransformerEnd1.RatedS = (float)dvt._kVA_A; powerTransformerEnd1.RatedU = (float)dvt._kV_LowA; PowerTransformerEnd powerTransformerEnd2 = new PowerTransformerEnd(); powerTransformerEnd2.ID = power_transformer_mrid + ".W2"; powerTransformerEnd2.MRID = power_transformer_mrid + ".W2"; powerTransformerEnd2.Name = dvt.NameB; powerTransformerEnd2.Terminal = w2T; powerTransformerEnd2.Grounded = false; powerTransformerEnd2.EndNumber = 1; powerTransformerEnd2.PowerTransformer = powerTransformer; powerTransformerEnd2.ConnectionKind = WindingConnection.D; powerTransformerEnd2.PhaseAngleClock = 0; powerTransformerEnd2.RatedS = (float)dvt._kVA_B; powerTransformerEnd2.RatedU = (float)dvt._kV_LowB; addComponentToGlobalDictionary(powerTransformer, powerTransformer.GetType()); addComponentToGlobalDictionary(powerTransformerEnd1, powerTransformerEnd1.GetType()); addComponentToGlobalDictionary(powerTransformerEnd2, powerTransformerEnd2.GetType()); } if (dataVertex.typeOfVertex == DataVertex.TypeOfVertex.REGULATOR_VERTEX) { string sync_machine = Guid.NewGuid().ToString(); PSRType psr_sync_machine = new PSRType() { MRID = "Generator", Name = "Generator" }; SynchronousMachine sm = new SynchronousMachine() { Name = dataVertex.Text, MRID = sync_machine, ID = sync_machine, EquipmentContainer = circuit }; addComponentToGlobalDictionary(sm, sm.GetType()); addComponentToGlobalDictionary(psr_sync_machine, psr_sync_machine.GetType()); } } foreach (List <DataEdge> dataEdgeCollection in globalEdges.Values) { foreach (DataEdge dataEdge in dataEdgeCollection) { string acLineSegment_mrid = Guid.NewGuid().ToString(); ConnectivityNode T1_cn = new ConnectivityNode(); string connectivity_node_mrid = Guid.NewGuid().ToString(); T1_cn.ID = connectivity_node_mrid; T1_cn.MRID = connectivity_node_mrid; T1_cn.ConnectivityNodeContainer = circuit; T1_cn.Name = (dataEdge.Source as DataVertex).Element_id; if (connectivityNodeContainer.ContainsKey((dataEdge.Source as DataVertex).Element_id) == false) { connectivityNodeContainer.Add(dataEdge.Source.Element_id, T1_cn); addComponentToGlobalDictionary(T1_cn, T1_cn.GetType()); } ConnectivityNode T2_cn = new ConnectivityNode(); connectivity_node_mrid = Guid.NewGuid().ToString(); T2_cn.ID = connectivity_node_mrid; T2_cn.MRID = connectivity_node_mrid; T2_cn.ConnectivityNodeContainer = circuit; T2_cn.Name = (dataEdge.Target as DataVertex).Element_id; if (connectivityNodeContainer.ContainsKey((dataEdge.Target as DataVertex).Element_id) == false) { connectivityNodeContainer.Add(dataEdge.Target.Element_id, T2_cn); addComponentToGlobalDictionary(T2_cn, T2_cn.GetType()); } Terminal T1 = new Terminal(); //string terminal_mrid = Guid.NewGuid().ToString(); T1.ID = acLineSegment_mrid + ".T1"; T1.MRID = acLineSegment_mrid + ".T1"; T1.Name = dataEdge.Source.Element_id; T1.Phases = PhaseCode.ABC; ACDCTerminal acdc_terminal = new ACDCTerminal() { SequenceNumber = 1 }; T1.SequenceNumber = acdc_terminal.SequenceNumber; T1.ConnectivityNode = T1_cn; Terminal T2 = new Terminal(); T2.ID = acLineSegment_mrid + ".T2"; T2.MRID = acLineSegment_mrid + ".T2"; T2.Name = dataEdge.Target.Element_id; T2.Phases = PhaseCode.ABC; ACDCTerminal acdc_terminal2 = new ACDCTerminal() { SequenceNumber = 2 }; T2.SequenceNumber = acdc_terminal2.SequenceNumber; T2.ConnectivityNode = T2_cn; string perLengthImpedance_mrid = Guid.NewGuid().ToString(); PerLengthImpedance pli = createPerLengthImpedanceObject(dataEdge.Configuration, perLengthImpedance_mrid); AssetInfo wi = createWireInfoObject(dataEdge.Configuration, perLengthImpedance_mrid); PSRType acPSRType = new PSRType() { MRID = "Section", Name = "Section" }; if (!globalComponentDictionary[acPSRType.GetType()].ContainsKey(acPSRType.Name)) { addComponentToGlobalDictionary(acPSRType, acPSRType.GetType()); } ACLineSegment acLineSegment = new ACLineSegment() { ID = acLineSegment_mrid, MRID = acLineSegment_mrid, Name = T1.Name.Split(' ').Last() + "-" + T2.Name.Split(' ').Last(), PSRType = acPSRType, EquipmentContainer = circuit, Length = (float)feetsToMeters(dataEdge.Length), PerLengthImpedance = pli, AssetDatasheet = wi }; addComponentToGlobalDictionary(acLineSegment, acLineSegment.GetType()); TerminalPair terminalPair = new TerminalPair() { terminalA = T1, terminalB = T2 }; terminalPairsContainer.Add(terminalPair); addComponentToGlobalDictionary(T1, T1.GetType()); addComponentToGlobalDictionary(T2, T2.GetType()); } } UsagePoint usagePoint = new UsagePoint(); foreach (DataVertex dv in globalVertices.Values) { if (dv.typeOfVertex == DataVertex.TypeOfVertex.SPOT_LOAD_VERTEX) { SpotLoad sl = (SpotLoad)dv; usagePoint = CreateSpotLoad(sl); addComponentToGlobalDictionary(usagePoint, usagePoint.GetType()); } } return(globalComponentDictionary); }
/// <summary> /// Creates entity for specified global inside the container. /// </summary> /// <param name="globalId">Global id of the entity for insert</param> /// <returns>Created entity (identified object).</returns> public IdentifiedObject CreateEntity(long globalId) { short type = ModelCodeHelper.ExtractTypeFromGlobalId(globalId); IdentifiedObject io = null; switch ((DMSType)type) { case DMSType.TERMINAL: io = new Terminal(globalId); break; case DMSType.ANALOG: io = new Analog(globalId); break; case DMSType.ASYNCHRONOUSMACHINE: io = new AsynchronousMachine(globalId); break; case DMSType.BREAKER: io = new Breaker(globalId); break; case DMSType.CONNECTIVITYNODE: io = new ConnectivityNode(globalId); break; case DMSType.DISCONNECTOR: io = new Disconnector(globalId); break; case DMSType.DISCRETE: io = new Discrete(globalId); break; case DMSType.POWERTRANSFORMER: io = new PowerTransformer(globalId); break; case DMSType.RATIOTAPCHANGER: io = new RatioTapChanger(globalId); break; case DMSType.SUBSTATION: io = new Substation(globalId); break; case DMSType.TRANSFORMERWINDING: io = new TransformerWinding(globalId); break; default: string message = String.Format("Failed to create entity because specified type ({0}) is not supported.", type); CommonTrace.WriteTrace(CommonTrace.TraceError, message); throw new Exception(message); } // Add entity to map this.AddEntity(io); return(io); }
private void addComponentToGlobalDictionary(IdentifiedObject component, Type type) { if (!globalComponentDictionary.ContainsKey(type)) { globalComponentDictionary.Add(type, new Dictionary <string, IdentifiedObject>()); } if (type.Equals(typeof(ACLineSegment))) { ACLineSegment acl = (ACLineSegment)component; globalComponentDictionary[type].Add(acl.MRID, acl); } else if (type.Equals(typeof(Terminal))) { Terminal tp = (Terminal)component; globalComponentDictionary[tp.GetType()].Add(tp.MRID, tp); } else if (type.Equals(typeof(Circuit))) { Circuit cr = (Circuit)component; globalComponentDictionary[cr.GetType()].Add(cr.MRID, cr); } else if (type.Equals(typeof(WireInfo))) { WireInfo wi = (WireInfo)component; globalComponentDictionary[wi.GetType()].Add(wi.MRID, wi); } else if (type.Equals(typeof(PerLengthSequenceImpedance))) { PerLengthSequenceImpedance pli = (PerLengthSequenceImpedance)component; globalComponentDictionary[pli.GetType()].Add(pli.MRID, pli); } else if (type.Equals(typeof(ConnectivityNode))) { ConnectivityNode cn = (ConnectivityNode)component; globalComponentDictionary[cn.GetType()].Add(cn.MRID, cn); } else if (type.Equals(typeof(PowerTransformer))) { PowerTransformer pt = (PowerTransformer)component; globalComponentDictionary[pt.GetType()].Add(pt.MRID, pt); } else if (type.Equals(typeof(PowerTransformerEnd))) { PowerTransformerEnd pt = (PowerTransformerEnd)component; globalComponentDictionary[pt.GetType()].Add(pt.MRID, pt); } else if (type.Equals(typeof(UsagePoint))) { UsagePoint us = (UsagePoint)component; globalComponentDictionary[us.GetType()].Add(us.MRID, us); } else if (type.Equals(typeof(PSRType))) { PSRType psr = (PSRType)component; globalComponentDictionary[psr.GetType()].Add(psr.Name, psr); } else if (type.Equals(typeof(SynchronousMachine))) { SynchronousMachine sm = (SynchronousMachine)component; globalComponentDictionary[sm.GetType()].Add(sm.Name, sm); } }
/// <summary> /// Creates entity for specified global inside the container. /// </summary> /// <param name="globalId">Global id of the entity for insert</param> /// <returns>Created entity (identified object).</returns> public IdentifiedObject CreateEntity(long globalId) { short type = ModelCodeHelper.ExtractTypeFromGlobalId(globalId); IdentifiedObject io = null; switch ((DMSType)type) { case DMSType.BASEVOLTAGE: { io = new BaseVoltage(globalId); break; } case DMSType.TERMINAL: { io = new Terminal(globalId); break; } case DMSType.CONNECTIVITYNODE: { io = new ConnectivityNode(globalId); break; } case DMSType.POWERTRANSFORMER: { io = new PowerTransformer(globalId); break; } case DMSType.ENERGYSOURCE: { io = new EnergySource(globalId); break; } case DMSType.ENERGYCONSUMER: { io = new EnergyConsumer(globalId); break; } case DMSType.TRANSFORMERWINDING: { io = new TransformerWinding(globalId); break; } case DMSType.FUSE: { io = new Fuse(globalId); break; } case DMSType.DISCONNECTOR: { io = new Disconnector(globalId); break; } case DMSType.BREAKER: { io = new Breaker(globalId); break; } case DMSType.LOADBREAKSWITCH: { io = new LoadBreakSwitch(globalId); break; } case DMSType.ACLINESEGMENT: { io = new ACLineSegment(globalId); break; } case DMSType.DISCRETE: { io = new Discrete(globalId); break; } case DMSType.ANALOG: { io = new Analog(globalId); break; } case DMSType.SYNCHRONOUSMACHINE: { io = new SynchronousMachine(globalId); break; } default: { string message = String.Format("Failed to create entity because specified type ({0}) is not supported.", type); Logger.LogError(message); throw new Exception(message); } } // Add entity to map this.AddEntity(io); return(io); }
public static SubstationsCollection PointToBalanceSubstations(EmcosPoint root) { var result = new SubstationsCollection(null); if (root.Children == null) { return(null); } foreach (EmcosPoint departamentPoint in root.Children) // департаменты (РЭС) { if (departamentPoint.ElementType == ElementTypes.DEPARTAMENT && departamentPoint.TypeCode == "RES" && departamentPoint.Children != null) { foreach (EmcosPoint substationPoint in departamentPoint.Children) // подстанции { var substation = new Substation(); substation.Departament = departamentPoint.Name; // название имеет формат вида ПС 35кВ Бакшты var nameParts = substationPoint.Name.Split(' '); if (nameParts.Length < 3) { throw new System.ArgumentException(string.Format("Неверный формат названия подстанции - '{0}'", substationPoint.Name)); } // выделяем название var name = ""; for (int i = 2; i < nameParts.Length; i++) { name += nameParts[i]; } substation.Name = name; // выделяем напряжение substation.Voltage = nameParts[1]; substation.Code = substationPoint.Code; substation.Id = substationPoint.Id; if (substationPoint.Children != null) { foreach (EmcosPoint groupPoint in substationPoint.Children) // группы { if (groupPoint.Children == null) { continue; } IBalanceGroupItem group; IBalanceItem item; switch (groupPoint.TypeCode) { case "AUXILIARY": group = new SubstationAuxiliary(); foreach (var subgroupPoint in groupPoint.Children) { if (subgroupPoint.ElementType == ElementTypes.UNITTRANSFORMER) { item = new UnitTransformer(); } else { item = new UnitTransformerBus(); } item.Name = subgroupPoint.Name; item.Code = subgroupPoint.Code; item.Id = subgroupPoint.Id; item.Description = subgroupPoint.Description; item.SetSubstation(substation); group.Children.Add(item); } substation.Children.Add(group); break; case "POWERTRANSFORMERS": group = new SubstationPowerTransformers(); foreach (var subgroupPoint in groupPoint.Children) { item = new PowerTransformer { Name = subgroupPoint.Name, Code = subgroupPoint.Code, Id = subgroupPoint.Id, Description = subgroupPoint.Description }; item.SetSubstation(substation); group.Children.Add(item); } substation.Children.Add(group); break; case "SECTIONS": // проход по ступеням напряжения foreach (var subgroupPoint in groupPoint.Children) { SubstationSection highSection = null; // по секциям if (subgroupPoint.Children != null) { foreach (var sectionPoint in subgroupPoint.Children) { if (sectionPoint.TypeCode == "SECTIONBUS") { var substationSection = new SubstationSection { Voltage = subgroupPoint.Name, Name = sectionPoint.Name, Code = sectionPoint.Code, Id = sectionPoint.Id, Description = sectionPoint.Description }; substationSection.SetSubstation(substation); if (sectionPoint.Children != null) { foreach (var sectionChildPoint in sectionPoint.Children) { IBalanceItem childItem = null; switch (sectionChildPoint.ElementType) { case ElementTypes.FIDER: childItem = new Fider(); break; case ElementTypes.POWERTRANSFORMER: childItem = new PowerTransformer(); break; case ElementTypes.UNITTRANSFORMERBUS: childItem = new UnitTransformerBus(); break; case ElementTypes.UNITTRANSFORMER: childItem = new UnitTransformer(); break; } if (childItem == null) { System.Diagnostics.Debugger.Break(); } childItem.Name = sectionChildPoint.Name; childItem.Code = sectionChildPoint.Code; childItem.Id = sectionChildPoint.Id; childItem.Description = sectionChildPoint.Description; childItem.SetSubstation(substation); substationSection.Children.Add(childItem); } } substation.Children.Add(substationSection); } else { if (highSection == null) { highSection = new SubstationSection { Voltage = subgroupPoint.Name, Name = subgroupPoint.Name, Code = subgroupPoint.Code, Id = subgroupPoint.Id, Description = subgroupPoint.Description }; highSection.SetSubstation(substation); } switch (sectionPoint.EcpName) { case "TRANSFORMER": var pt = new PowerTransformer { Id = sectionPoint.Id, Code = sectionPoint.Code, Name = sectionPoint.Name, Description = sectionPoint.Description }; pt.SetSubstation(substation); highSection.Children.Add(pt); break; case "LINE": var f = new Fider { Id = sectionPoint.Id, Code = sectionPoint.Code, Name = sectionPoint.Name, Description = sectionPoint.Description }; f.SetSubstation(substation); highSection.Children.Add(f); break; } } } } if (highSection != null) { substation.Children.Add(highSection); } } break; } } } result.Add(substation); } } } return(result); }
private static void Main(string[] args) { var base1 = new BaseVoltage() { Name = "BaseVoltage1", NominalVoltage = 5, MRID = Guid.NewGuid().ToString() }; var base2 = new BaseVoltage() { Name = "BaseVoltage2", NominalVoltage = 15, MRID = Guid.NewGuid().ToString() }; List <PowerTransformer> transformers = new List <PowerTransformer>(); List <TransformerWinding> windings = new List <TransformerWinding>(); List <WindingTest> windingTests = new List <WindingTest>(); for (int i = 0; i < 20; i++) { PowerTransformer transformer = new PowerTransformer { Name = $"Transformer {i}", MRID = Guid.NewGuid().ToString(), Description = $"Description for power transformer {i}" }; transformers.Add(transformer); List <TransformerWinding> windingList = new List <TransformerWinding> { new TransformerWinding { Name = $"Winding {2 * i}", MRID = Guid.NewGuid().ToString(), BaseVoltage = base1, Description = $"Description for transformer winding {2 * i}", PowerTransformer = transformer }, new TransformerWinding { Name = $"Winding {2 * i + 1}", MRID = Guid.NewGuid().ToString(), BaseVoltage = base2, Description = $"Description for transformer winding {2 * i + 1}", PowerTransformer = transformer } }; windings.AddRange(windingList); List <WindingTest> windingTestList = new List <WindingTest> { new WindingTest { Name = $"Winding test {2 * i}", MRID = Guid.NewGuid().ToString(), From_TransformerWinding = windingList[0], Description = $"Description for winding test {2 * i}" }, new WindingTest { Name = $"Winding test {2 * i + 1}", MRID = Guid.NewGuid().ToString(), From_TransformerWinding = windingList[1], Description = $"Description for winding test {2 * i + 1}" } }; windingTests.AddRange(windingTestList); } StringBuilder sb = new StringBuilder(); sb.AppendLine(BaseVoltageToString(base1, "1")); sb.AppendLine(BaseVoltageToString(base2, "2")); for (int i = 0; i < 20; i++) { sb.AppendLine(TranformerToString(transformers[i], i.ToString())); sb.AppendLine(WindingToString(windings[2 * i], $"{i}, 1")); sb.AppendLine(WindingTestToString(windingTests[2 * i], $"{i}, 1")); sb.AppendLine(WindingToString(windings[2 * i + 1], $"{i}, 2")); sb.AppendLine(WindingTestToString(windingTests[2 * i + 1], $"{i}, 2")); } //Console.WriteLine(sb.ToString()); System.IO.File.WriteAllText("pisi.txt", sb.ToString()); Console.ReadLine(); }
/// <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(); } }