public bool Prepare() { lock (updateLock) { if (inserted == null) { return(false); } TopologyModelDownload download = new TopologyModelDownload(inserted, updated, deleted); if (!download.Download()) { return(false); } TopologyModel tModel = new TopologyModel(TopologyModel.Instance); if (!tModel.ApplyUpdate(download)) { return(false); } transactionModel = tModel; inserted = null; updated = null; deleted = null; return(true); } }
static void Main(string[] args) { Console.WriteLine("Waiting for NMS, press [Enter] to quit."); TopologyModelDownload download = new TopologyModelDownload(); while (!download.Download()) { while (Console.KeyAvailable) { if (Console.ReadKey().Key == ConsoleKey.Enter) { return; } } Thread.Sleep(1000); } Console.WriteLine("Downloaded network model from NMS."); TopologyModel model = new TopologyModel(DailyLoadProfile.LoadFromXML("Daily_load_profiles.xml")); if (!model.ApplyUpdate(download)) { return; } TopologyModel.Instance = model; ServiceHost host = new ServiceHost(typeof(CalculationEngineService)); host.Open(); foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { Console.WriteLine(endpoint.ListenUri); } model.DownloadMeasurements(null); Console.WriteLine("[Press Enter to stop]"); Console.ReadLine(); host.Close(); }
public bool ApplyUpdate(TopologyModelDownload download) { rwLock.EnterWriteLock(); try { foreach (IdentifiedObject io in download.Inserted) { DMSType type = ModelCodeHelper.GetTypeFromGID(io.GID); Dictionary <long, IdentifiedObject> container; if (!containers.TryGetValue(type, out container)) { continue; } int oldCount = container.Count; container[io.GID] = io; if (container.Count != oldCount + 1) { return(false); } measurementsOfInterest.Add(io.GID); } foreach (IdentifiedObject io in download.Updated) { DMSType type = ModelCodeHelper.GetTypeFromGID(io.GID); Dictionary <long, IdentifiedObject> container; if (!containers.TryGetValue(type, out container)) { continue; } int oldCount = container.Count; container[io.GID] = io; if (container.Count != oldCount) { return(false); } measurementsOfInterest.Add(io.GID); } foreach (long gid in download.Deleted) { DMSType type = ModelCodeHelper.GetTypeFromGID(gid); Dictionary <long, IdentifiedObject> container; if (!containers.TryGetValue(type, out container)) { continue; } if (!container.Remove(gid)) { return(false); } measurementsOfInterest.Remove(gid); markedSwitchStates.TryRemove(gid, out _); } foreach (long switchGID in markedSwitchStates.Keys) { if (!IsSwitchWithoutSCADA(switchGID)) { markedSwitchStates.TryRemove(switchGID, out _); } } graph = new TopologyGraph(containers, analogInputs, discreteInputs, markedSwitchStates, loadProfiles); return(true); } finally { rwLock.ExitWriteLock(); } }