Example #1
0
        public UpdateResult Prepare(ref Delta delta)
        {
            transactionCallback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            string message = string.Empty;

            networkDataModelCopy.Clear();
            foreach (KeyValuePair <DMSType, Container> pair in networkDataModel)
            {
                networkDataModelCopy.Add(pair.Key, pair.Value.Clone() as Container);
            }
            UpdateResult applyResult = ApplyDelta(delta);

            if (applyResult.Result == ResultType.Succeeded)
            {
                message = "OK";
            }
            else
            {
                message = "ERROR";
            }

            transactionCallback.Response(message);
            return(applyResult);
        }
Example #2
0
        public UpdateResult Prepare(ref Delta delta)
        {
            try
            {
                transactionCallback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();
                updateResult        = new UpdateResult();

                generatorAnalogsCopy.Clear();
                energyConsumerAnalogsCopy.Clear();
                generatorDscretesCopy.Clear();
                energyConsumerDiscretesCopy.Clear();

                // napravi kopiju od originala
                foreach (AnalogLocation alocation in generatorAnalogs)
                {
                    generatorAnalogsCopy.Add(alocation.Clone() as AnalogLocation);
                }

                foreach (AnalogLocation alocation in energyConsumerAnalogs)
                {
                    energyConsumerAnalogsCopy.Add(alocation.Clone() as AnalogLocation);
                }
                foreach (DiscreteLocation dlocation in generatorDscretes)
                {
                    generatorDscretesCopy.Add(dlocation.Clone() as DiscreteLocation);
                }

                foreach (DiscreteLocation dlocation in energyConsumerDiscretes)
                {
                    energyConsumerDiscretesCopy.Add(dlocation.Clone() as DiscreteLocation);
                }

                Analog   analog   = null;
                Discrete discrete = null;
                foreach (ResourceDescription rd in delta.InsertOperations)
                {
                    if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rd.Id) == (DMSType.ANALOG))
                    {
                        foreach (Property prop in rd.Properties)
                        {
                            analog = ResourcesDescriptionConverter.ConvertTo <Analog>(rd);

                            if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(analog.PowerSystemResource) == DMSType.ENERGY_CONSUMER)
                            {
                                energyConsumerAnalogsCopy.Add(new AnalogLocation()
                                {
                                    Analog        = analog,
                                    StartAddress  = Int32.Parse(analog.ScadaAddress.Split('_')[1]),
                                    Length        = 2,
                                    LengthInBytes = 4
                                });
                            }
                            else
                            {
                                generatorAnalogsCopy.Add(new AnalogLocation()
                                {
                                    Analog        = analog,
                                    StartAddress  = Int32.Parse(analog.ScadaAddress.Split('_')[1]), // float value 4 bytes
                                    Length        = 2,
                                    LengthInBytes = 4
                                });
                            }
                            break;
                        }
                    }
                    else if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rd.Id) == (DMSType.DISCRETE))
                    {
                        foreach (Property prop in rd.Properties)
                        {
                            discrete = ResourcesDescriptionConverter.ConvertTo <Discrete>(rd);

                            if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(discrete.PowerSystemResource) == DMSType.ENERGY_CONSUMER)
                            {
                                energyConsumerDiscretesCopy.Add(new DiscreteLocation()
                                {
                                    Discrete      = discrete,
                                    StartAddress  = Int32.Parse(discrete.ScadaAddress.Split('_')[1]),
                                    Length        = 1,
                                    LengthInBytes = 2
                                });
                            }
                            else
                            {
                                generatorDscretesCopy.Add(new DiscreteLocation()
                                {
                                    Discrete      = discrete,
                                    StartAddress  = Int32.Parse(discrete.ScadaAddress.Split('_')[1]), // float value 4 bytes
                                    Length        = 1,
                                    LengthInBytes = 2
                                });
                            }
                            break;
                        }
                    }
                }

                foreach (ResourceDescription rd in delta.UpdateOperations)
                {
                    if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rd.Id) == (DMSType.ANALOG))
                    {
                        foreach (Property prop in rd.Properties)
                        {
                            analog = ResourcesDescriptionConverter.ConvertTo <Analog>(rd);
                            if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(analog.PowerSystemResource) == DMSType.ENERGY_CONSUMER)
                            {
                                if (ContainsMrid(analog, energyConsumerAnalogsCopy))
                                {
                                    foreach (AnalogLocation al in energyConsumerAnalogsCopy)
                                    {
                                        if (al.Analog.Mrid.Equals(analog.Mrid))
                                        {
                                            if (analog.MaxValue != al.Analog.MaxValue && analog.MaxValue != 0)
                                            {
                                                al.Analog.MaxValue = analog.MaxValue;
                                            }
                                            else if (analog.MeasurmentType != al.Analog.MeasurmentType && analog.MeasurmentType.ToString() != "")
                                            {
                                                al.Analog.MeasurmentType = analog.MeasurmentType;
                                            }
                                            else if (analog.MinValue != al.Analog.MinValue && analog.MinValue != 0)
                                            {
                                                al.Analog.MinValue = analog.MinValue;
                                            }
                                            else if (analog.Name != al.Analog.Name && analog.Name.ToString() != "")
                                            {
                                                al.Analog.Name = analog.Name;
                                            }
                                            else if (analog.AliasName != al.Analog.AliasName && analog.AliasName.ToString() != "")
                                            {
                                                al.Analog.AliasName = analog.AliasName;
                                            }
                                            else if (analog.NormalValue != al.Analog.NormalValue && analog.NormalValue != 0)
                                            {
                                                al.Analog.NormalValue = analog.NormalValue;
                                            }
                                            else if (analog.PowerSystemResource != al.Analog.PowerSystemResource && analog.PowerSystemResource.ToString() != "")
                                            {
                                                al.Analog.PowerSystemResource = analog.PowerSystemResource;
                                            }
                                            else if (analog.Direction != al.Analog.Direction && analog.Direction.ToString() != "")
                                            {
                                                al.Analog.Direction = analog.Direction;
                                            }
                                            else if (analog.ScadaAddress != al.Analog.ScadaAddress && analog.ScadaAddress.ToString() != "")
                                            {
                                                al.Analog.ScadaAddress = analog.ScadaAddress;
                                            }
                                        }
                                    }
                                }
                            }
                            else if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(analog.PowerSystemResource) == DMSType.GENERATOR)
                            {
                                if (ContainsMrid(analog, generatorAnalogsCopy))
                                {
                                    foreach (AnalogLocation al in generatorAnalogsCopy)
                                    {
                                        if (al.Analog.Mrid.Equals(analog.Mrid))
                                        {
                                            if (analog.MaxValue != al.Analog.MaxValue && analog.MaxValue != 0)
                                            {
                                                al.Analog.MaxValue = analog.MaxValue;
                                            }
                                            else if (analog.MeasurmentType != al.Analog.MeasurmentType && analog.MeasurmentType.ToString() != "")
                                            {
                                                al.Analog.MeasurmentType = analog.MeasurmentType;
                                            }
                                            else if (analog.MinValue != al.Analog.MinValue && analog.MinValue != 0)
                                            {
                                                al.Analog.MinValue = analog.MinValue;
                                            }
                                            else if (analog.Name != al.Analog.Name && analog.Name.ToString() != "")
                                            {
                                                al.Analog.Name = analog.Name;
                                            }
                                            else if (analog.AliasName != al.Analog.AliasName && analog.AliasName.ToString() != "")
                                            {
                                                al.Analog.AliasName = analog.AliasName;
                                            }
                                            else if (analog.NormalValue != al.Analog.NormalValue && analog.NormalValue != 0)
                                            {
                                                al.Analog.NormalValue = analog.NormalValue;
                                            }
                                            else if (analog.PowerSystemResource != al.Analog.PowerSystemResource && analog.PowerSystemResource.ToString() != "")
                                            {
                                                al.Analog.PowerSystemResource = analog.PowerSystemResource;
                                            }
                                            else if (analog.Direction != al.Analog.Direction && analog.Direction.ToString() != "")
                                            {
                                                al.Analog.Direction = analog.Direction;
                                            }
                                            else if (analog.ScadaAddress != al.Analog.ScadaAddress && analog.ScadaAddress.ToString() != "")
                                            {
                                                al.Analog.ScadaAddress = analog.ScadaAddress;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rd.Id) == (DMSType.DISCRETE))
                    {
                        foreach (Property prop in rd.Properties)
                        {
                            discrete = ResourcesDescriptionConverter.ConvertTo <Discrete>(rd);
                            if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(discrete.PowerSystemResource) == DMSType.ENERGY_CONSUMER)
                            {
                                if (ContainsMridDiscrete(discrete, energyConsumerDiscretesCopy))
                                {
                                    foreach (DiscreteLocation al in energyConsumerDiscretesCopy)
                                    {
                                        if (al.Discrete.Mrid.Equals(discrete.Mrid))
                                        {
                                            if (discrete.MaxValue != al.Discrete.MaxValue && discrete.MaxValue != 0)
                                            {
                                                al.Discrete.MaxValue = discrete.MaxValue;
                                            }
                                            else if (discrete.MeasurmentType != al.Discrete.MeasurmentType && discrete.MeasurmentType.ToString() != "")
                                            {
                                                al.Discrete.MeasurmentType = discrete.MeasurmentType;
                                            }
                                            else if (discrete.MinValue != al.Discrete.MinValue && discrete.MinValue != 0)
                                            {
                                                al.Discrete.MinValue = discrete.MinValue;
                                            }
                                            else if (discrete.Name != al.Discrete.Name && discrete.Name.ToString() != "")
                                            {
                                                al.Discrete.Name = discrete.Name;
                                            }
                                            else if (discrete.AliasName != al.Discrete.AliasName && discrete.AliasName.ToString() != "")
                                            {
                                                al.Discrete.AliasName = discrete.AliasName;
                                            }
                                            else if (discrete.NormalValue != al.Discrete.NormalValue && discrete.NormalValue != 0)
                                            {
                                                al.Discrete.NormalValue = discrete.NormalValue;
                                            }
                                            else if (discrete.PowerSystemResource != al.Discrete.PowerSystemResource && discrete.PowerSystemResource.ToString() != "")
                                            {
                                                al.Discrete.PowerSystemResource = discrete.PowerSystemResource;
                                            }
                                            else if (discrete.Direction != al.Discrete.Direction && discrete.Direction.ToString() != "")
                                            {
                                                al.Discrete.Direction = discrete.Direction;
                                            }
                                            else if (discrete.ScadaAddress != al.Discrete.ScadaAddress && discrete.ScadaAddress.ToString() != "")
                                            {
                                                al.Discrete.ScadaAddress = discrete.ScadaAddress;
                                            }
                                        }
                                    }
                                }
                            }
                            else if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(discrete.PowerSystemResource) == DMSType.GENERATOR)
                            {
                                if (ContainsMridDiscrete(discrete, generatorDscretesCopy))
                                {
                                    foreach (DiscreteLocation al in generatorDscretesCopy)
                                    {
                                        if (al.Discrete.Mrid.Equals(discrete.Mrid))
                                        {
                                            if (discrete.MaxValue != al.Discrete.MaxValue && discrete.MaxValue != 0)
                                            {
                                                al.Discrete.MaxValue = discrete.MaxValue;
                                            }
                                            else if (discrete.MeasurmentType != al.Discrete.MeasurmentType && discrete.MeasurmentType.ToString() != "")
                                            {
                                                al.Discrete.MeasurmentType = discrete.MeasurmentType;
                                            }
                                            else if (discrete.MinValue != al.Discrete.MinValue && discrete.MinValue != 0)
                                            {
                                                al.Discrete.MinValue = discrete.MinValue;
                                            }
                                            else if (discrete.Name != al.Discrete.Name && discrete.Name.ToString() != "")
                                            {
                                                al.Discrete.Name = discrete.Name;
                                            }
                                            else if (discrete.AliasName != al.Discrete.AliasName && discrete.AliasName.ToString() != "")
                                            {
                                                al.Discrete.AliasName = discrete.AliasName;
                                            }
                                            else if (discrete.NormalValue != al.Discrete.NormalValue && discrete.NormalValue != 0)
                                            {
                                                al.Discrete.NormalValue = discrete.NormalValue;
                                            }
                                            else if (discrete.PowerSystemResource != al.Discrete.PowerSystemResource && discrete.PowerSystemResource.ToString() != "")
                                            {
                                                al.Discrete.PowerSystemResource = discrete.PowerSystemResource;
                                            }
                                            else if (discrete.Direction != al.Discrete.Direction && discrete.Direction.ToString() != "")
                                            {
                                                al.Discrete.Direction = discrete.Direction;
                                            }
                                            else if (discrete.ScadaAddress != al.Discrete.ScadaAddress && discrete.ScadaAddress.ToString() != "")
                                            {
                                                al.Discrete.ScadaAddress = discrete.ScadaAddress;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                updateResult.Message = "SCADA PR Transaction Prepare finished.";
                updateResult.Result  = ResultType.Succeeded;
                CommonTrace.WriteTrace(CommonTrace.TraceInfo, "SCADA PR Transaction Prepare finished successfully.");
                transactionCallback.Response("OK");
            }
            catch (Exception e)
            {
                updateResult.Message = "SCADA PR Transaction Prepare finished.";
                updateResult.Result  = ResultType.Failed;
                CommonTrace.WriteTrace(CommonTrace.TraceWarning, "SCADA PR Transaction Prepare failed. Message: {0}", e.Message);
                transactionCallback.Response("ERROR");
            }

            return(updateResult);
        }
Example #3
0
        public UpdateResult Prepare(ref Delta delta)
        {
            try
            {
                transactionCallback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();
                updateResult        = new UpdateResult();

                internalGeneratorsCopy.Clear();
                foreach (ResourceDescription rd in internalGenerators)
                {
                    internalGeneratorsCopy.Add(rd.Clone() as ResourceDescription);
                }

                internalEnergyConsumersCopy.Clear();
                foreach (ResourceDescription rd in internalEnergyConsumers)
                {
                    internalEnergyConsumersCopy.Add(rd.Clone() as ResourceDescription);
                }

                foreach (ResourceDescription rd in delta.InsertOperations)
                {
                    foreach (Property prop in rd.Properties)
                    {
                        if (ModelCodeHelper.GetTypeFromModelCode(prop.Id).Equals(DMSType.GENERATOR))
                        {
                            internalGeneratorsCopy.Add(rd);
                            break;
                        }
                        else if (ModelCodeHelper.GetTypeFromModelCode(prop.Id).Equals(DMSType.ENERGY_CONSUMER))
                        {
                            internalEnergyConsumersCopy.Add(rd);
                            break;
                        }
                    }
                }

                foreach (ResourceDescription rd in delta.UpdateOperations)
                {
                    foreach (Property prop in rd.Properties)
                    {
                        if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rd.Id) == (DMSType.GENERATOR))
                        {
                            foreach (ResourceDescription res in internalGeneratorsCopy)
                            {
                                if (rd.Id.Equals(res.Id))
                                {
                                    foreach (Property p in res.Properties)
                                    {
                                        if (prop.Id.Equals(p.Id))
                                        {
                                            p.PropertyValue = prop.PropertyValue;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rd.Id) == (DMSType.ENERGY_CONSUMER))
                        {
                            foreach (ResourceDescription res in internalEnergyConsumersCopy)
                            {
                                if (rd.Id.Equals(res.Id))
                                {
                                    foreach (Property p in res.Properties)
                                    {
                                        if (prop.Id.Equals(p.Id))
                                        {
                                            p.PropertyValue = prop.PropertyValue;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                updateResult.Message = "CE Transaction Prepare finished.";
                updateResult.Result  = ResultType.Succeeded;
                CommonTrace.WriteTrace(CommonTrace.TraceInfo, "CETransaction Prepare finished successfully.");
                transactionCallback.Response("OK");
            }
            catch (Exception e)
            {
                updateResult.Message = "CE Transaction Prepare finished.";
                updateResult.Result  = ResultType.Failed;
                CommonTrace.WriteTrace(CommonTrace.TraceWarning, "CE Transaction Prepare failed. Message: {0}", e.Message);
                transactionCallback.Response("ERROR");
            }

            return(updateResult);
        }