示例#1
0
        public bool ModelUpdate(AffectedEntities model)
        {
            Console.WriteLine("New update request!");
            NetworkModelGDAProxy proxy = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");

            if (CeDataBase.Model == null)
            {
                CeDataBase.Model = new Dictionary <DMSType, Container>();
            }
            if (model.Insert.Count > 0)
            {
                var dataInsert = proxy.GetValues(model.Insert);
                foreach (var item in dataInsert)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!CeDataBase.Model.ContainsKey(dmsType))
                    {
                        CeDataBase.Model.Add(dmsType, new Container());
                    }
                    CeDataBase.Model[dmsType].AddEntity(item);
                }
            }

            if (model.Update.Count > 0)
            {
                var dataUpdate = proxy.GetValues(model.Update);
                foreach (var item in dataUpdate)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!CeDataBase.Model.ContainsKey(dmsType))
                    {
                        CeDataBase.Model.Add(dmsType, new Container());
                    }
                    CeDataBase.Model[dmsType].RemoveEntity(item.GID);
                    CeDataBase.Model[dmsType].AddEntity(item);
                }
            }

            if (model.Delete.Count > 0)
            {
                var dataDelete = proxy.GetValues(model.Delete);
                foreach (var item in dataDelete)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!CeDataBase.Model.ContainsKey(dmsType))
                    {
                        CeDataBase.Model.Add(dmsType, new Container());
                    }
                    CeDataBase.Model[dmsType].RemoveEntity(item.GID);
                }
            }


            //dobio si model, javi se TM-u da ucestvujes u transakciji
            EnList();
            return(true);
        }
        public async Task <ResourceDescription> GetValues(long resourceId, List <ModelCode> propIds)
        {
            ResourceDescription resource;

            using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (gdaQueryProxy == null)
                {
                    string message = "GetValues() => NetworkModelGDAProxy is null.";
                    Logger.LogError(message);
                    throw new NullReferenceException(message);
                }

                try
                {
                    resource = gdaQueryProxy.GetValues(resourceId, propIds);
                }
                catch (Exception e)
                {
                    string message = $"Failed to get values for elemnt with GID {resourceId}.";
                    Logger.LogError(message, e);
                    throw e;
                }
            }

            return(resource);
        }
        private void buttonQuery1_Click(object sender, EventArgs e)
        {
            richTextBoxOutput.Text = string.Empty;
            long             resourceID  = Convert.ToInt64(textBoxTargetGID1.Text, 16);
            List <ModelCode> propertyIDs = new List <ModelCode>();

            foreach (object selectedItem in listBoxProperties1.SelectedItems)
            {
                propertyIDs.Add((ModelCode)selectedItem);
            }
            NetworkModelGDAProxy networkModelGDAProxy = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");

            try
            {
                ResourceDescription resourceDescription = networkModelGDAProxy.GetValues(resourceID, propertyIDs);
                using (StringWriter stringWriter = new StringWriter())
                {
                    using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
                    {
                        xmlTextWriter.Formatting = Formatting.Indented;
                        resourceDescription.ExportToXml(xmlTextWriter);
                    }
                    richTextBoxOutput.Text = stringWriter.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Get Values - ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#4
0
        public ResourceDescription GetValues(long globalId, List <ModelCode> properties)
        {
            string message = "Getting values method started.";

            Logger.LogInfo(message);

            ResourceDescription rd = null;

            try
            {
                using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
                {
                    if (gdaQueryProxy == null)
                    {
                        string errMsg = "NetworkModelGDAProxy is null.";
                        Logger.LogWarn(errMsg);
                        throw new NullReferenceException(errMsg);
                    }

                    rd      = gdaQueryProxy.GetValues(globalId, properties);
                    message = "Getting values method successfully finished.";
                    Logger.LogInfo(message);
                }
            }
            catch (Exception e)
            {
                message = string.Format("Getting values method for entered id = {0} failed.\n\t{1}", globalId, e.Message);
                Logger.LogError(message);
            }

            return(rd);
        }
        public bool CheckIfBreakerIsRecloser(long elementId)
        {
            bool isRecloser = false;

            try
            {
                using (NetworkModelGDAProxy gda = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
                {
                    ResourceDescription resourceDescription = gda.GetValues(elementId, new List <ModelCode>()
                    {
                        ModelCode.BREAKER_NORECLOSING
                    });

                    Property property = resourceDescription.GetProperty(ModelCode.BREAKER_NORECLOSING);

                    if (property != null)
                    {
                        isRecloser = !property.AsBool();
                    }
                    else
                    {
                        throw new Exception($"Element with id 0x{elementId:X16} is not a breaker.");
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(isRecloser);
        }
示例#6
0
        public ResourceDescription GetStaticDataForElement(long gid)
        {
            List <ModelCode> properties;

            try
            {
                properties = modelResourcesDesc.GetAllPropertyIds(ModelCodeHelper.ExtractTypeFromGlobalId(gid));
                return(gdaQueryProxy.GetValues(gid, properties));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
示例#7
0
        public List <Equipment> CreateEquipementEntitiesFromNmsData(List <long> entityIds)
        {
            List <Equipment> equipements = new List <Equipment>();

            List <ModelCode> propIds = new List <ModelCode>()
            {
                ModelCode.IDOBJ_MRID
            };

            using (NetworkModelGDAProxy proxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (proxy == null)
                {
                    string message = "OutageModel::CreateEquipementEntitiesFromNmsData => NetworkModelGDAProxy is null";
                    Logger.LogError(message);
                    throw new NullReferenceException();
                }

                foreach (long gid in entityIds)
                {
                    ResourceDescription rd = null;

                    try
                    {
                        rd = proxy.GetValues(gid, propIds);
                    }
                    catch (Exception e)
                    {
                        //TODO: Kad prvi put ovde bude puklo, alarmirajte me. Dimitrije
                        throw e;
                    }

                    if (rd == null)
                    {
                        continue;
                    }

                    Equipment createdEquipement = new Equipment()
                    {
                        EquipmentId   = rd.Id,
                        EquipmentMRID = rd.Properties[0].AsString(),
                    };

                    equipements.Add(createdEquipement);
                }
            }

            return(equipements);
        }
        public bool ModelUpdate(AffectedEntities model)
        {
            Console.WriteLine("New update request!");
            ScadaStorageProxy    proxy = ScadaProxyFactory.Instance().ScadaStorageProxy();
            NetworkModelGDAProxy nms   = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");
            var cimModel = proxy.GetCimModel();

            if (cimModel == null)
            {
                cimModel = new Dictionary <DMSType, Container>();
            }

            model.Insert = model.Insert.Where(x => this.GetDMSType(x) == DMSType.ANALOG || this.GetDMSType(x) == DMSType.DISCRETE ||
                                              this.GetDMSType(x) == DMSType.BREAKER || this.GetDMSType(x) == DMSType.DISCONNECTOR).ToList();
            model.Update = model.Update.Where(x => this.GetDMSType(x) == DMSType.ANALOG || this.GetDMSType(x) == DMSType.DISCRETE ||
                                              this.GetDMSType(x) == DMSType.BREAKER || this.GetDMSType(x) == DMSType.DISCONNECTOR).ToList();
            model.Delete = model.Delete.Where(x => this.GetDMSType(x) == DMSType.ANALOG || this.GetDMSType(x) == DMSType.DISCRETE ||
                                              this.GetDMSType(x) == DMSType.BREAKER || this.GetDMSType(x) == DMSType.DISCONNECTOR).ToList();

            if (model.Insert.Count > 0)
            {
                var dataInsert = nms.GetValues(model.Insert);
                foreach (var item in dataInsert)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!cimModel.ContainsKey(dmsType))
                    {
                        cimModel.Add(dmsType, new Container());
                    }
                    cimModel[dmsType].AddEntity(item);
                }
            }
            if (model.Update.Count > 0)
            {
                var dataUpdate = nms.GetValues(model.Update);
                foreach (var item in dataUpdate)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!cimModel.ContainsKey(dmsType))
                    {
                        cimModel.Add(dmsType, new Container());
                    }
                    cimModel[dmsType].RemoveEntity(item.GID);
                    cimModel[dmsType].AddEntity(item);
                }
            }
            if (model.Delete.Count > 0)
            {
                var dataDelete = nms.GetValues(model.Delete);
                foreach (var item in dataDelete)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!cimModel.ContainsKey(dmsType))
                    {
                        cimModel.Add(dmsType, new Container());
                    }
                    cimModel[dmsType].RemoveEntity(item.GID);
                }
            }

            proxy.SetCimModel(cimModel);
            //dobio si model, javi se da ucestvujes u transakciji
            EnList();
            return(true);
        }