public TopologyModel(TopologyModel tm) { tm.rwLock.EnterReadLock(); try { containers = new Dictionary <DMSType, Dictionary <long, IdentifiedObject> >(tm.containers.Count); foreach (KeyValuePair <DMSType, Dictionary <long, IdentifiedObject> > container in tm.containers) { containers.Add(container.Key, new Dictionary <long, IdentifiedObject>(container.Value)); } analogInputs = new ConcurrentDictionary <long, float>(); discreteInputs = new ConcurrentDictionary <long, int>(); measurementsOfInterest = new HashSet <long>(tm.measurementsOfInterest); markedSwitchStates = new ConcurrentDictionary <long, bool>(tm.markedSwitchStates); typeToModelCode = ModelResourcesDesc.GetTypeToModelCodeMap(); loadProfiles = new List <DailyLoadProfile>(tm.loadProfiles); graph = tm.graph; } finally { tm.rwLock.ExitReadLock(); } rwLock = new ReaderWriterLockSlim(); }
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); } }
public void Rollback() { lock (updateLock) { transactionModel = null; inserted = null; updated = null; deleted = null; } }
public void Commit() { lock (updateLock) { if (transactionModel == null) { return; } TopologyModel.Instance = transactionModel; transactionModel.DownloadMeasurements(null); transactionModel = null; } }
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(); }