public void AddEntity(IdentifiedObject _entity) { string fileName = _entity.Type.ToString() + ".xml"; bool fileExist = true; if (!File.Exists(fileName)) { CrFSMLogger.CrFSMLogger.Instance.WriteToLog(string.Format("Creating new data file {0}", path + fileName)); File.Create(fileName).Close(); fileExist = false; } Hashtable idObjCollXml = new Hashtable(); if (fileExist) { SharpDeserialization(_entity.Type, ref idObjCollXml); } idObjCollXml.Add(_entity.GlobalId, _entity); SharpSerialization(_entity.Type, ref idObjCollXml); Message data = new Message(); data.TopicName = _entity.Type.ToString(); data.IdObjCollection.AddRange(idObjCollXml.Values.Cast <IdentifiedObject>().ToList()); SendEvent(data, data.TopicName); }
bool TryGetEntity(long gid, out IdentifiedObject io) { Container container; io = null; return(containers.TryGetValue(ModelCodeHelper.GetTypeFromGID(gid), out container) && container.Get(gid, out io)); }
bool HandleMeasurementValuesChange(MeasurementValuesChanged msg) { measurements.Update(msg); NetworkModel model = this.Model; foreach (KeyValuePair <long, int> dInput in msg.DiscreteInputs) { IdentifiedObject io = model.Get(dInput.Key); Discrete d = io as Discrete; if (d == null) { continue; } if (d.MeasurementType == MeasurementType.SwitchState) { Notify(new ObservableMessage(EObservableMessageType.SwitchStatusChanged)); break; } } Notify(new ObservableMessage(EObservableMessageType.MeasurementValuesChanged)); return(true); }
/// <summary> /// Converts the specified content. /// </summary> /// <param name="content">The content.</param> /// <returns>The converted reference.</returns> protected override ProjectedCoordinateReferenceSystem Convert(String[] content) { switch (content[3]) { case "projected": AreaOfUse areaOfUse = this.areaOfUseCollection[Authority, Int32.Parse(content[2])]; GeographicCoordinateReferenceSystem baseReferenceSystem = this.baseCoordinateReferenceSystemCollection[Authority, Int32.Parse(content[6])]; CoordinateSystem coordinateSystem = this.coordinateSystemCollection[Authority, Int32.Parse(content[4])]; // the projection should use the ellipsoid with the unit specified by the coordinate system CoordinateProjection projection = this.coordinateProjectionCollection[Authority, Int32.Parse(content[7]), baseReferenceSystem.Datum.Ellipsoid.ToUnit(coordinateSystem.GetAxis(0).Unit)]; // TODO: remove condition, once all projections are implemented if (projection == null) { return(null); } return(new ProjectedCoordinateReferenceSystem(IdentifiedObject.GetIdentifier(Authority, content[0]), content[1], content[11], this.GetAliases(Int32.Parse(content[0])), content[10], baseReferenceSystem, coordinateSystem, areaOfUse, projection)); default: return(null); } }
/// <summary> /// Gets resource description for entity requested by globalId. /// </summary> /// <param name="globalId">Id of the entity</param> /// <param name="properties">List of requested properties</param> /// <returns>Resource description of the specified entity</returns> public ResourceDescription GetValues(long globalId, List <ModelCode> properties) { CommonTrace.WriteTrace(CommonTrace.TraceVerbose, String.Format("Getting values for GID = 0x{0:x16}.", globalId)); try { IdentifiedObject io = GetEntity(globalId); ResourceDescription rd = new ResourceDescription(globalId); Property property = null; // insert specified properties foreach (ModelCode propId in properties) { property = new Property(propId); io.GetProperty(property); rd.AddProperty(property); } CommonTrace.WriteTrace(CommonTrace.TraceVerbose, String.Format("Getting values for GID = 0x{0:x16} succedded.", globalId)); return(rd); } catch (Exception ex) { string message = string.Format("Failed to get values for entity with GID = 0x{0:x16}. {1}", globalId, ex.Message); throw new Exception(message); } }
public void WellKnownTextConverterToIdentifiedObjectTest() { for (Int32 index = 0; index < this.identifiedObjects.Length; index++) { IdentifiedObject identifiedObject = WellKnownTextConverter.ToIdentifiedObject(this.identifiedObjectsText[index], TestUtilities.ReferenceProvider); Assert.AreEqual(this.identifiedObjects[index], identifiedObject); } Meridian meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM[\"Greenwich\",0.0]", TestUtilities.ReferenceProvider) as Meridian; Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]); meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM(\"Greenwich\",0.0)", TestUtilities.ReferenceProvider) as Meridian; Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]); meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM(Greenwich,0.0)", TestUtilities.ReferenceProvider) as Meridian; Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]); meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\", 8901]]", TestUtilities.ReferenceProvider) as Meridian; Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]); meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM [\"Greenwich\", 0.0, AUTHORITY [\"EPSG\", 8901]])", TestUtilities.ReferenceProvider) as Meridian; Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]); meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM[Greenwich, 0.0, AUTHORITY[EPSG, 8901]]", TestUtilities.ReferenceProvider) as Meridian; Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]); Assert.Throws <ArgumentNullException>(() => WellKnownTextConverter.ToIdentifiedObject(null, null)); Assert.Throws <ArgumentException>(() => WellKnownTextConverter.ToIdentifiedObject(String.Empty, TestUtilities.ReferenceProvider)); Assert.Throws <ArgumentException>(() => WellKnownTextConverter.ToIdentifiedObject("UNDEFINED[\"something\"]", TestUtilities.ReferenceProvider)); }
public NodeData(IdentifiedObject identified, bool isroot) { this.idenetifiedObj = identified; this.isRoot = isroot; this.energized = Energized.NotEnergized; this.type = DMSType.GEOGRAPHICALREGION; }
public NodeData(IdentifiedObject identified, DMSType type, bool isroot) { this.idenetifiedObj = identified; this.isRoot = isroot; this.energized = Energized.NotEnergized; this.type = type; }
/// <summary> /// Returns a collection with items matching the specified identifier. /// </summary> /// <param name="identifier">The identifier.</param> /// <returns>A collection containing the items that match the specified identifier.</returns> /// <exception cref="System.ArgumentNullException">The identifier is null.</exception> public IEnumerable <ReferenceType> WithIdentifier(String identifier) { if (identifier == null) { throw new ArgumentNullException(nameof(identifier)); } this.EnsureAliases(); this.EnsureReferences(); // match exact code String authority = IdentifiedObject.GetAuthority(identifier); Int32 code = IdentifiedObject.GetCode(identifier); if (authority == Authority && this.referenceDictionary.ContainsKey(code)) { yield return(this.referenceDictionary[code]); } // match contained code foreach (ReferenceType reference in this.referenceDictionary.Values.Where(reference => reference.Identifier.IndexOf(identifier, StringComparison.OrdinalIgnoreCase) >= 0)) { yield return(reference); } }
public void UpdateEntity(IdentifiedObject _entity) { Hashtable idObjCollection = new Hashtable(); SharpDeserialization(_entity.Type, ref idObjCollection); idObjCollection[_entity.GlobalId] = _entity; SharpSerialization(_entity.Type, ref idObjCollection); }
/// <summary> /// Converts the specified content. /// </summary> /// <param name="content">The content.</param> /// <returns>The converted reference.</returns> protected override CoordinateSystem Convert(String[] content) { CoordinateSystemType type = (CoordinateSystemType)Enum.Parse(typeof(CoordinateSystemType), content[2], true); return(new CoordinateSystem(IdentifiedObject.GetIdentifier(Authority, content[0]), content[1], content[4], this.GetAliases(Int32.Parse(content[0])), type, this.GetAxes(content[0]))); }
public bool PersistDelta(List <IdentifiedObject> inserted, List <IdentifiedObject> updatedNew, List <IdentifiedObject> deleted, Dictionary <DMSType, int> newCounters) { try { using (DBContext context = new DBContext()) { for (int i = 0; i < inserted.Count; ++i) { IdentifiedObject io = inserted[i]; IEFTable table = tables[(int)ModelCodeHelper.GetTypeFromGID(io.GID)]; object entity = io.ToDBEntity(); table.Insert(context, entity); } for (int i = 0; i < updatedNew.Count; ++i) { IdentifiedObject io = updatedNew[i]; IEFTable table = tables[(int)ModelCodeHelper.GetTypeFromGID(io.GID)]; object entity = io.ToDBEntity(); table.Update(context, entity); } for (int i = 0; i < deleted.Count; ++i) { IdentifiedObject io = deleted[i]; IEFTable table = tables[(int)ModelCodeHelper.GetTypeFromGID(io.GID)]; object entity = io.ToDBEntity(); table.Delete(context, entity); } foreach (KeyValuePair <DMSType, int> pair in newCounters) { IEFTable table = tables[0]; ModelCounterDBModel oldCounter = (ModelCounterDBModel)table.Get(context, pair.Key); if (oldCounter != null) { oldCounter.Counter = pair.Value; } else { table.Insert(context, new ModelCounterDBModel() { Type = pair.Key, Counter = pair.Value }); } } context.SaveChanges(); } } catch (Exception e) { return(false); } return(true); }
public override IdentifiedObject DeepCopy(IdentifiedObject copy = null) { if (copy == null) { copy = new RegulatingCondEq(this.GlobalId); } return(base.DeepCopy(copy)); }
/// <summary> /// Returns related gids with source according to the association /// </summary> /// <param name="source">source id</param> /// <param name="association">desinition of association</param> /// <returns>related gids</returns> private List <long> ApplyAssocioationOnSource(long source, Association association) { List <long> relatedGids = new List <long>(); if (association == null) { association = new Association(); } lock (SmartContainer.Instance.Lock2PC) { IdentifiedObject io = smartContainer.GetEntity(smartContainer.Original, source); if (!io.HasProperty(association.PropertyId)) { throw new Exception(string.Format("Entity with GID = 0x{0:x16} does not contain prperty with Id = {1}.", source, association.PropertyId)); } Property propertyRef = null; if (Property.GetPropertyType(association.PropertyId) == PropertyType.Reference) { propertyRef = io.GetProperty(association.PropertyId); long relatedGidFromProperty = propertyRef.AsReference(); if (relatedGidFromProperty != 0) { if (association.Type == 0 || (short)ModelCodeHelper.GetTypeFromModelCode(association.Type) == ModelCodeHelper.ExtractTypeFromGlobalId(relatedGidFromProperty)) { relatedGids.Add(relatedGidFromProperty); } } } else if (Property.GetPropertyType(association.PropertyId) == PropertyType.ReferenceVector) { propertyRef = io.GetProperty(association.PropertyId); List <long> relatedGidsFromProperty = propertyRef.AsReferences(); if (relatedGidsFromProperty != null) { foreach (long relatedGidFromProperty in relatedGidsFromProperty) { if (association.Type == 0 || (short)ModelCodeHelper.GetTypeFromModelCode(association.Type) == ModelCodeHelper.ExtractTypeFromGlobalId(relatedGidFromProperty)) { relatedGids.Add(relatedGidFromProperty); } } } } else { throw new Exception(string.Format("Association propertyId = {0} is not reference or reference vector type.", association.PropertyId)); } } return(relatedGids); }
public override IdentifiedObject DeepCopy(IdentifiedObject copy = null) { if (copy == null) { copy = new DiscreteValue(this.GlobalId); } ((DiscreteValue)copy).value = this.value; return(base.DeepCopy(copy)); }
/// <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); }
bool Get(INetworkModelGDAContract nms) { Dictionary <DMSType, List <ModelCode> > typeToPropertiesMap = ModelResourcesDesc.GetTypeToPropertiesMap(); Dictionary <DMSType, List <ModelCode> > typeToPropertiesMapMeas = new Dictionary <DMSType, List <ModelCode> >(2) { { DMSType.Analog, typeToPropertiesMap[DMSType.Analog] }, { DMSType.Discrete, typeToPropertiesMap[DMSType.Discrete] } }; List <IdentifiedObject> inserted = new List <IdentifiedObject>(insertedGids.Count); List <IdentifiedObject> updated = new List <IdentifiedObject>(updatedGids.Count); List <ResourceDescription> result; int iterator = nms.GetMultipleValues(insertedGids, typeToPropertiesMapMeas, true); do { result = nms.IteratorNext(iteratorCount, iterator, true); if (result == null) { return(false); } foreach (ResourceDescription rd in result) { inserted.Add(IdentifiedObject.Create(rd, true)); } }while(result.Count >= iteratorCount); nms.IteratorClose(iterator); iterator = nms.GetMultipleValues(updatedGids, typeToPropertiesMapMeas, true); do { result = nms.IteratorNext(iteratorCount, iterator, true); if (result == null) { return(false); } foreach (ResourceDescription rd in result) { updated.Add(IdentifiedObject.Create(rd, true)); } }while(result.Count >= iteratorCount); nms.IteratorClose(iterator); Inserted = inserted; Updated = updated; Deleted = deletedGids; return(true); }
public override void Update() { io = PubSub.Model.Get(GID); properties.Update(); if (!initialized) { panel.Children.Add(properties.Element); initialized = true; } }
public override bool Equals(object obj) { IdentifiedObject other = obj as IdentifiedObject; if (other == null) { return(false); } return(this.Id == other.Id); }
void PopulateIdentifiedObjectProperties(IdentifiedObject x, ResourceDescription rd) { if (x.MRIDHasValue) { rd.AddProperty(new StringProperty(ModelCode.IDENTIFIEDOBJECT_MRID, x.MRID)); } if (x.NameHasValue) { rd.AddProperty(new StringProperty(ModelCode.IDENTIFIEDOBJECT_NAME, x.Name)); } }
/// <summary> /// Gets the instance with the specified authority and code. /// </summary> /// <param name="authority">The authority.</param> /// <param name="code">The code.</param> /// <returns>The instance with the specified authority and code.</returns> public UnitOfMeasurement this[String authority, Int32 code] { get { if (authority == null) { return(null); } return(this[IdentifiedObject.GetIdentifier(authority, code)]); } }
/// <summary> /// Gets the instance with the specified authority and code. /// </summary> /// <param name="authority">The authority.</param> /// <param name="code">The code.</param> /// <returns>The instance with the specified authority and code.</returns> public CoordinateOperationParameter this[String authority, Int32 code] { get { if (authority == null) { return(null); } return(this[IdentifiedObject.GetIdentifier(authority, code)]); } }
PropertyModification[] GetModifications(IdentifiedObject identifiedObject) { var type = identifiedObject.GetType(); var propertyNames = GetPropertyNames(type).Except(new[] { nameof(IdentifiedObject.mRID) }); var accessor = TypeAccessor.Create(type); return(propertyNames.Select(property => new PropertyModification { Name = property, Value = accessor[identifiedObject, property] }).ToArray()); }
public override IdentifiedObject DeepCopy(IdentifiedObject copy = null) { if (copy == null) { copy = new MeasurementValue(this.GlobalId); } ((MeasurementValue)copy).timestamp = this.timestamp; ((MeasurementValue)copy).synchronousMachine = this.synchronousMachine; ((MeasurementValue)copy).powerType = this.powerType; ((MeasurementValue)copy).address = this.address; return(base.DeepCopy(copy)); }
/// <summary> /// Converts the specified content. /// </summary> /// <param name="content">The content.</param> /// <returns>The converted reference.</returns> protected override AreaOfUse Convert(String[] content) { Double south = Double.NaN, west = Double.NaN, north = Double.NaN, east = Double.NaN; Double.TryParse(content[3], out south); Double.TryParse(content[4], out west); Double.TryParse(content[5], out north); Double.TryParse(content[6], out east); return(AreaOfUse.FromDegrees(IdentifiedObject.GetIdentifier(Authority, content[0]), content[1], content[2], null, this.GetAliases(Int32.Parse(content[0])), south, west, north, east)); }
/// <summary> /// Adds entity on the first free position in the container. /// </summary> /// <param name="io">Entity (identified object) that should be added</param> /// <returns>Index of the entity that is just added.</returns> public void AddEntity(IdentifiedObject io) { if (!EntityExists(io.GID)) { entities[io.GID] = io; } else { string message = String.Format("Entity (GID = 0x{1:x16}) already exists.", io.GID); CommonTrace.WriteTrace(CommonTrace.TraceError, message); throw new Exception(message); } }
/// <summary> /// Adds entity on the first free position in the container. /// </summary> /// <param name="io">Entity (identified object) that should be added</param> /// <returns>Index of the entity that is just added.</returns> public void AddEntity(IdentifiedObject io) { if (!EntityExists(io.GlobalId)) { entities[io.GlobalId] = io; } else { string message = String.Format("Entity (GID = 0x{1:x16}) already exists.", io.GlobalId); Logger.LogError(message); throw new Exception(message); } }
public void WellKnownTextConverterToWellKnownTextTest() { for (Int32 index = 0; index < this.identifiedObjects.Length - 1; index++) { String text = WellKnownTextConverter.ToWellKnownText(this.identifiedObjects[index]); IdentifiedObject identifiedObject = WellKnownTextConverter.ToIdentifiedObject(text, TestUtilities.ReferenceProvider); Assert.AreEqual(this.identifiedObjects[index], identifiedObject); } Assert.Throws <ArgumentNullException>(() => WellKnownTextConverter.ToWellKnownText((IdentifiedObject)null)); Assert.Throws <ArgumentNullException>(() => WellKnownTextConverter.ToWellKnownText((IReferenceSystem)null)); }
/// <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.CURVE: io = new Curve(globalId); break; case DMSType.CURVEDATA: io = new CurveData(globalId); break; case DMSType.DISCONNECTOR: io = new Disconnector(globalId); break; case DMSType.IRREGULARTIMEPOINT: io = new IrregularTimePoint(globalId); break; case DMSType.OUTAGESCHEDULE: io = new OutageSchedule(globalId); break; case DMSType.PROTSWITCH: io = new ProtectedSwitch(globalId); break; case DMSType.REGULARTIMEPOINT: io = new RegularTimePoint(globalId); break; case DMSType.REGULARINTERVALSCHEDULE: io = new RegularIntervalSchedule(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); }
/// <summary> /// Converts the specified content. /// </summary> /// <param name="content">The content.</param> /// <returns>The converted reference.</returns> protected override VerticalDatum Convert(String[] content) { switch (content[2]) { case "vertical": return(new VerticalDatum(IdentifiedObject.GetIdentifier(Authority, content[0]), content[1], content[9], this.GetAliases(Int32.Parse(content[0])), content[3], content[4], content[8], this.areaOfUseCollection[Authority, Int32.Parse(content[7])])); default: return(null); } }