コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Bozo9977/Master_projekat
        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();
        }
コード例 #3
0
        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();
            }
        }