示例#1
0
        /// <summary>
        /// Commit any changes to the access control.
        /// </summary>
        public void Commit()
        {
            TradingSupportClient client = new TradingSupportClient(FluidTrade.Guardian.Properties.Settings.Default.TradingSupportEndpoint);

            try
            {
                if (this.Deleted)
                {
                    // Could be the user added and then deleted a user to the list, so makes sure the row actually exists.
                    if (!this.newRights)
                    {
                        MethodResponseErrorCode response;

                        response = client.RevokeAccess(this.User.EntityId, this.Entity.EntityId);

                        if (response.Result != ErrorCode.Success)
                        {
                            if (response.Errors.Length > 0)
                            {
                                GuardianObject.ThrowErrorInfo(response.Errors[0]);
                            }
                            else
                            {
                                GuardianObject.ThrowErrorInfo(response.Result);
                            }
                        }
                    }
                }
                else if (this.Dirty)
                {
                    Guid accessRightId;
                    MethodResponseguid response;

                    lock (DataModel.SyncRoot)
                        accessRightId = DataModel.AccessRight.AccessRightKeyAccessRightCode.Find(this.AccessRight).AccessRightId;

                    response = client.GrantAccess(this.User.EntityId, this.Entity.EntityId, accessRightId);

                    if (response.Errors.Length > 0)
                    {
                        GuardianObject.ThrowErrorInfo(response.Errors[0]);
                    }

                    this.accessControlId = response.Result;

                    this.newRights = false;
                    this.dirty     = false;
                }
            }
            finally
            {
                if (client != null && client.State == CommunicationState.Opened)
                {
                    client.Close();
                }
            }
        }