Exemple #1
0
        /// <summary>
        /// Commit any changes to this object to the server.
        /// </summary>
        public override void Commit()
        {
            TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint);

            try
            {
                TradingSupportReference.Entity record = new TradingSupportReference.Entity();
                MethodResponseErrorCode        response;

                this.PopulateRecord(record);

                if (this.Deleted)
                {
                    throw new NotImplementedException("Cannot delete from Entity.Commit. You must override Commit in a derived class");
                }
                else
                {
                    response = tradingSupportClient.UpdateEntity(new TradingSupportReference.Entity[] { record });
                }

                if (!response.IsSuccessful)
                {
                    Entity.ThrowErrorInfo(response.Errors[0]);
                }

                this.Modified = false;
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Error("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace);
                throw;
            }
            finally
            {
                if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened)
                {
                    tradingSupportClient.Close();
                }
            }
        }
Exemple #2
0
        public static MethodResponseErrorCode UpdateEntity(Entity entity)
        {
            MethodResponseErrorCode response = null;
            // Update the database.
            TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint);

            try
            {
                lock (DataModel.SyncRoot)
                {
                    EntityRow row = DataModel.Entity.EntityKey.Find(entity.RowId);

                    if (TradingSupportWebService.ColumnChanged(row, entity))
                    {
                        response = tradingSupportClient.UpdateEntity(new Entity[] { entity });
                    }
                    else
                    {
                        response = null;
                    }
                }
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
            }
            finally
            {
                if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened)
                {
                    tradingSupportClient.Close();
                }
            }
            return(response);
        }