コード例 #1
0
        public void Prepare(Delta delta)
        {
            Console.WriteLine("Pozvan je prepare na NMS-u");
            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            try
            {
                UpdateResult updateResult = gda.ApplyUpdate(delta);
                if (updateResult.Result == ResultType.Succeeded)
                {
                    callback.CallbackPrepare(true);
                }
                else
                {
                    //Rollback();
                    callback.CallbackPrepare(false);
                }
            }
            catch (Exception ex)
            {
                //Rollback();
                callback.CallbackPrepare(false); // problematicno ako se desi exception u pozivu, nece se uhvatiti
                Console.WriteLine(ex.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// Check if there is ANY free space in controller; at this point we do not know if delta will contain 1 or 10 measurements
        /// so we only check if is it possible to add minimal memory occupying element
        /// </summary>
        public void Enlist()
        {
            Console.WriteLine("\nTransaction started -> \nPozvan je Enlist na SCADA");

            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            bool isSuccessfull = false;

            // at this point, we will only check if there is a free space for any DIGITALS or any ANALOGS
            var availableRtus = dbContext.GettAllRTUs().Values.Where(r => r.FreeSpaceForDigitals == true ||
                                                                     r.FreeSpaceForAnalogs == true).ToList();

            if (availableRtus.Count != 0)
            {
                isSuccessfull = false;
            }

            try
            {
                callback.CallbackEnlist(isSuccessfull);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                callback.CallbackEnlist(false);
            }
        }
コード例 #3
0
ファイル: NetworkModel.cs プロジェクト: EMS-Master/EMS
        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);
        }
コード例 #4
0
        public void Enlist()
        {
            Console.WriteLine("Pozvan je enlist na DMS-u");
            oldTree = DMSService.Instance.Tree;
            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            callback.CallbackEnlist(true);
        }
        public void Rollback()
        {
            Console.WriteLine("Pozvan je RollBack na CommunicationEngine");

            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            callback.CallbackRollabck("Something went wrong on CommunicationEngine");
        }
        public void Enlist()
        {
            Console.WriteLine("Pozvan je enlist na CommunicationEngine-u");

            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            callback.CallbackEnlist();
        }
        public void Commit()
        {
            Console.WriteLine("Pozvan je Commit na CommunicationEngine-u");

            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            callback.CallbackCommit("Uspjesno je prosao commit na CommunicationEngine-u");
        }
コード例 #8
0
        public void Rollback()
        {
            Console.WriteLine("Pozvan je RollBack na DMSu");
            newTree = null;
            DMSService.Instance.Tree = oldTree;
            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            callback.CallbackRollback("Something went wrong on DMS");
        }
コード例 #9
0
        public void Rollback()
        {
            Console.WriteLine("Pozvan je RollBack na NMSu");
            GenericDataAccess.NewNetworkModel = null;
            GenericDataAccess.NetworkModel    = GenericDataAccess.OldNetworkModel;
            ResourceIterator.NetworkModel     = GenericDataAccess.OldNetworkModel;
            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            callback.CallbackRollback("Something went wrong on NMS");
        }
        public void Prepare(Delta delta)
        {
            Console.WriteLine("Pozvan je prepare na CommunicationEngine-u");
            //TO DO Kopije i provjera da li moze da se primjeni delta
            //NEtwork model = new Network model
            //model.AppltyDelta();...
            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            callback.CallbackPrepare(true);
        }
コード例 #11
0
        /// <summary>
        /// Setting Configuration to new file.
        /// </summary>
        public void Commit()
        {
            Console.WriteLine("Pozvan je Commit na SCADA");
            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            ScadaModelParser parser = new ScadaModelParser();

            parser.SwapConfigs(currentConfigFile, modifiedConfigFile);

            callback.CallbackCommit("Commited on SCADA");
        }
コード例 #12
0
        /// <summary>
        /// Returning to old config file, initialize database again (deserializng from file)
        /// </summary>
        public void Rollback()
        {
            Console.WriteLine("Pozvan je Rollback na SCADA");
            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            ScadaModelParser parser = new ScadaModelParser();

            //parser.SwapConfigs(newConfigFile, currentConfigFile);
            parser.DeserializeScadaModel(); // returning to old state (changed in apply delta)

            callback.CallbackRollback("Something went wrong on SCADA");
        }
コード例 #13
0
        public void Commit()
        {
            Console.WriteLine("Pozvan je Commit na NMS-u");

            if (GenericDataAccess.NewNetworkModel != null)
            {
                GenericDataAccess.NetworkModel = GenericDataAccess.NewNetworkModel;
                ResourceIterator.NetworkModel  = GenericDataAccess.NewNetworkModel;
            }

            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            callback.CallbackCommit("Uspjesno je prosao commit na NMS-u");
        }
コード例 #14
0
        public void Enlist()
        {
            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            Console.WriteLine("Pozvan je enlist na NMS-u");
            try
            {
                gda.GetCopyOfNetworkModel();
                callback.CallbackEnlist(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                callback.CallbackEnlist(false);
            }
        }
コード例 #15
0
        /// <summary>
        /// Executes the action specified by the given callback object within a transaction.
        /// </summary>
        /// <param name="action">The callback object that specifies the transactional action.</param>
        /// <returns>
        /// A result object returned by the callback, or <code>null</code> if one
        /// </returns>
        /// <remarks>Allows for returning a result object created within the transaction, that is,
        /// a domain object or a collection of domain objects.  An exception thrown by the callback
        /// is treated as a fatal exception that enforces a rollback.  Such an exception gets
        /// propagated to the caller of the template.
        /// </remarks>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// In case of initialization or system errors.
        /// </exception>
        public object Execute(ITransactionCallback action)
        {
            ITransactionStatus status = _platformTransactionManager.GetTransaction(this);
            object             result;

            try
            {
                result = action.DoInTransaction(status);
            }
            catch (Exception ex)
            {
                rollbackOnException(status, ex);
                throw;
            }
            _platformTransactionManager.Commit(status);
            return(result);
        }
コード例 #16
0
        public void Prepare(Delta delta)
        {
            Console.WriteLine("Pozvan je prepare na DMS-u");

            newTree = DMSService.Instance.InitializeNetwork(delta);
            DMSService.updatesCount += 1;
            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            if (newTree.Data.Values.Count != 0)
            {
                callback.CallbackPrepare(true);
            }
            else
            {
                callback.CallbackPrepare(false);
            }
        }
コード例 #17
0
        public void Commit()
        {
            Console.WriteLine("Pozvan je Commit na DMS-u");
            DMSService.Instance.Tree = newTree;
            if (DMSService.updatesCount >= 2)
            {
                Publisher            publisher = new Publisher();
                List <UIUpdateModel> update    = new List <UIUpdateModel>();
                Source s = (Source)DMSService.Instance.Tree.Data[DMSService.Instance.Tree.Roots[0]];
                update.Add(new UIUpdateModel(true, s.ElementGID));

                publisher.PublishUpdate(update);
            }

            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            callback.CallbackCommit("Uspjesno je prosao commit na DMS-u");
        }
コード例 #18
0
        /// <summary>
        /// Execute the given callback having optionally aquired the given lock.
        /// Because CMT assumes that the connection is already part of a managed
        /// transaction, it does not attempt to commit or rollback the
        /// enclosing transaction.
        /// </summary>
        /// <seealso cref="JobStoreSupport.ExecuteInNonManagedTXLock(string, JobStoreSupport.ITransactionCallback)" />
        /// <seealso cref="JobStoreTX.ExecuteInLock(String, JobStoreSupport.ITransactionCallback)" />
        /// <seealso cref="JobStoreSupport.GetNonManagedTXConnection()" />
        /// <seealso cref="JobStoreSupport.GetConnection()" />
        /// <param name="lockName">
        /// The name of the lock to aquire, for example
        /// "TRIGGER_ACCESS".  If null, then no lock is aquired, but the
        /// txCallback is still executed in a transaction.
        /// </param>
        /// <param name="txCallback">Callback to execute.</param>
        protected override object ExecuteInLock(
            string lockName,
            ITransactionCallback txCallback)
        {
            bool transOwner = false;
            ConnectionAndTransactionHolder conn = null;

            try
            {
                if (lockName != null)
                {
                    // If we aren't using db locks, then delay getting DB connection
                    // until after aquiring the lock since it isn't needed.
                    if (LockHandler.RequiresConnection)
                    {
                        conn = GetNonManagedTXConnection();
                    }

                    transOwner = LockHandler.ObtainLock(DbMetadata, conn, lockName);
                }

                if (conn == null)
                {
                    conn = GetNonManagedTXConnection();
                }

                return(txCallback.Execute(conn));
            }
            finally
            {
                try
                {
                    ReleaseLock(conn, LockTriggerAccess, transOwner);
                }
                finally
                {
                    CleanupConnection(conn);
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// Trying to apply, APPLYING if it is possible, and write new configuration to new file
        /// </summary>
        /// <param name="delta"></param>
        public void Prepare(ScadaDelta delta)
        {
            Console.WriteLine("Pozvan je Prepare na SCADA");

            ITransactionCallback callback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>();

            if (dbContext.ApplyDelta(delta))
            {
                try
                {
                    ScadaModelParser parser = new ScadaModelParser();

                    // to do:
                    // mozda ove serijaliyacije da budu taskovi_
                    // novu konfiguraciju cuvamo u fajlu
                    parser.SerializeScadaModel(modifiedConfigFile);

                    Console.WriteLine("Prepare true");
                    callback.CallbackPrepare(true);
                }
                catch (Exception ex)
                {
                    ScadaModelParser parser = new ScadaModelParser();
                    parser.DeserializeScadaModel(); // returning to old state (state was previosuly changed in apply delta)

                    Console.WriteLine(ex.Message);
                    Console.WriteLine("1Prepare false");
                    callback.CallbackPrepare(false);
                }
            }
            else
            {
                ScadaModelParser parser = new ScadaModelParser();
                parser.DeserializeScadaModel(); // returning to old state (state was previosuly changed in apply delta)
                Console.WriteLine("2Prepare false");
                callback.CallbackPrepare(false);
            }
        }
コード例 #20
0
 /// <summary>
 /// Executes the action specified by the given callback object within a transaction.
 /// </summary>
 /// <param name="action">The callback object that specifies the transactional action.</param>
 /// <returns>
 /// A result object returned by the callback, or <code>null</code> if one
 /// </returns>
 /// <remarks>Allows for returning a result object created within the transaction, that is,
 /// a domain object or a collection of domain objects.  An exception thrown by the callback
 /// is treated as a fatal exception that enforces a rollback.  Such an exception gets
 /// propagated to the caller of the template.
 /// </remarks>
 /// <exception cref="Spring.Transaction.TransactionException">
 /// In case of initialization or system errors.
 /// </exception>
 public object Execute(ITransactionCallback action)
 {
     ITransactionStatus status = _platformTransactionManager.GetTransaction( this );
     object result;
     try
     {
         result = action.DoInTransaction(status);
     } 
     catch ( Exception ex )
     {
         rollbackOnException( status, ex );
         throw;
     }
     _platformTransactionManager.Commit( status );
     return result;
 }
コード例 #21
0
 /// <summary>
 /// Execute the given callback having aquired the given lock.  
 /// Depending on the JobStore, the surrounding transaction may be 
 /// assumed to be already present (managed).
 /// </summary> 
 /// <param name="lockName">
 /// The name of the lock to aquire, for example 
 /// "TRIGGER_ACCESS".  If null, then no lock is aquired, but the
 /// lockCallback is still executed in a transaction. 
 /// </param>
 protected abstract object ExecuteInLock(string lockName, ITransactionCallback txCallback);
コード例 #22
0
 /// <summary>
 /// Execute the given callback in a transaction. Depending on the JobStore, 
 /// the surrounding transaction may be assumed to be already present 
 /// (managed).  
 /// </summary>
 /// <remarks>
 /// This method just forwards to ExecuteInLock() with a null lockName.
 /// </remarks>
 /// <seealso cref="ExecuteInLock(string, ITransactionCallback)" />
 protected object ExecuteWithoutLock(ITransactionCallback txCallback)
 {
     return ExecuteInLock(null, txCallback);
 }
コード例 #23
0
 /// <summary>
 /// Execute the given callback having optionally aquired the given lock.
 /// For <see cref="JobStoreTX" />, because it manages its own transactions
 /// and only has the one datasource, this is the same behavior as
 /// <see cref="JobStoreSupport.ExecuteInNonManagedTXLock(string,JobStoreSupport.ITransactionCallback)" />.
 /// </summary>
 /// <param name="lockName">
 /// The name of the lock to aquire, for example "TRIGGER_ACCESS".
 /// If null, then no lock is aquired, but the lockCallback is still
 /// executed in a transaction.
 /// </param>
 /// <param name="txCallback">Callback to execute.</param>
 /// <returns></returns>
 /// <seealso cref="JobStoreSupport.ExecuteInNonManagedTXLock(string,JobStoreSupport.ITransactionCallback)" />
 /// <sssseealso crsef="JobStoreCMT.ExecuteInLock(string, ITransactionCallback)" />
 /// <seealso cref="JobStoreSupport.GetNonManagedTXConnection()" />
 /// <seealso cref="JobStoreSupport.GetConnection()" />
 protected override object ExecuteInLock(string lockName, ITransactionCallback txCallback)
 {
     return(ExecuteInNonManagedTXLock(lockName, txCallback));
 }
コード例 #24
0
ファイル: JobStoreCMT.cs プロジェクト: kisflying/kion
        /// <summary>
        /// Execute the given callback having optionally aquired the given lock.  
        /// Because CMT assumes that the connection is already part of a managed
        /// transaction, it does not attempt to commit or rollback the 
        /// enclosing transaction.
        /// </summary>
        /// <seealso cref="JobStoreSupport.ExecuteInNonManagedTXLock(string, JobStoreSupport.ITransactionCallback)" />
        /// <seealso cref="JobStoreTX.ExecuteInLock(String, JobStoreSupport.ITransactionCallback)" />
        /// <seealso cref="JobStoreSupport.GetNonManagedTXConnection()" />
        /// <seealso cref="JobStoreSupport.GetConnection()" />
        /// <param name="lockName">
        /// The name of the lock to aquire, for example 
        /// "TRIGGER_ACCESS".  If null, then no lock is aquired, but the
        /// txCallback is still executed in a transaction.
        /// </param>
        /// <param name="txCallback">Callback to execute.</param>
        protected override object ExecuteInLock(
                string lockName,
                ITransactionCallback txCallback)
        {
            bool transOwner = false;
            ConnectionAndTransactionHolder conn = null;
            try
            {
                if (lockName != null)
                {
                    // If we aren't using db locks, then delay getting DB connection 
                    // until after aquiring the lock since it isn't needed.
                    if (LockHandler.RequiresConnection)
                    {
                        conn = GetNonManagedTXConnection();
                    }

                    transOwner = LockHandler.ObtainLock(DbMetadata, conn, lockName);
                }

                if (conn == null)
                {
                    conn = GetNonManagedTXConnection();
                }

                return txCallback.Execute(conn);
            }
            finally
            {
                try
                {
                    ReleaseLock(conn, LockTriggerAccess, transOwner);
                }
                finally
                {
                    CleanupConnection(conn);
                }
            }
        }
コード例 #25
0
ファイル: ScadaProcessing.cs プロジェクト: EMS-Master/EMS
        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);
        }
コード例 #26
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);
        }
コード例 #27
0
 /// <summary>
 /// Execute the given callback having optionally aquired the given lock.
 /// For <see cref="JobStoreTX" />, because it manages its own transactions
 /// and only has the one datasource, this is the same behavior as 
 /// <see cref="JobStoreSupport.ExecuteInNonManagedTXLock(string,JobStoreSupport.ITransactionCallback)" />.
 /// </summary>
 /// <param name="lockName">
 /// The name of the lock to aquire, for example "TRIGGER_ACCESS". 
 /// If null, then no lock is aquired, but the lockCallback is still
 /// executed in a transaction.
 /// </param>
 /// <param name="txCallback">Callback to execute.</param>
 /// <returns></returns>
 /// <seealso cref="JobStoreSupport.ExecuteInNonManagedTXLock(string,JobStoreSupport.ITransactionCallback)" />
 /// <sssseealso crsef="JobStoreCMT.ExecuteInLock(string, ITransactionCallback)" />
 /// <seealso cref="JobStoreSupport.GetNonManagedTXConnection()" />
 /// <seealso cref="JobStoreSupport.GetConnection()" />
 protected override object ExecuteInLock(string lockName, ITransactionCallback txCallback)
 {
     return ExecuteInNonManagedTXLock(lockName, txCallback);
 }
コード例 #28
0
        /// <summary>
        /// Execute the given callback having optionally aquired the given lock.
        /// This uses the non-managed transaction connection.
        /// </summary>
        /// <param name="lockName">
        /// The name of the lock to aquire, for example 
        /// "TRIGGER_ACCESS".  If null, then no lock is aquired, but the
        /// lockCallback is still executed in a non-managed transaction. 
        /// </param>
        protected object ExecuteInNonManagedTXLock(string lockName, ITransactionCallback txCallback)
        {
            bool transOwner = false;
            ConnectionAndTransactionHolder conn = null;
            try
            {
                if (lockName != null)
                {
                    // If we aren't using db locks, then delay getting DB connection 
                    // until after aquiring the lock since it isn't needed.
                    if (LockHandler.RequiresConnection)
                    {
                        conn = GetNonManagedTXConnection();
                    }

                    transOwner = LockHandler.ObtainLock(DbProvider.Metadata, conn, lockName);
                }

                if (conn == null)
                {
                    conn = GetNonManagedTXConnection();
                }

                object result = txCallback.Execute(conn);
                CommitConnection(conn, false);
                return result;
            }
            catch (JobPersistenceException)
            {
                RollbackConnection(conn);
                throw;
            }
            catch (Exception e)
            {
                RollbackConnection(conn);
                throw new JobPersistenceException("Unexpected runtime exception: " + e.Message, e);
            }
            finally
            {
                try
                {
                    ReleaseLock(conn, lockName, transOwner);
                }
                finally
                {
                    CleanupConnection(conn);
                }
            }
        }