/// <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.WorkingOrderRecord record = new TradingSupportReference.WorkingOrderRecord(); Int32 tries = 0; MethodResponseErrorCode response; this.PopulateRecord(record); do { if (this.Deleted) { response = tradingSupportClient.DeleteWorkingOrder(new TradingSupportReference.WorkingOrderRecord[] { record }); if (this.GetFirstErrorCode(response) == ErrorCode.RecordExists) { throw new IsSettledException(this.ToString() + " is settled"); } } else { response = tradingSupportClient.UpdateWorkingOrder(new TradingSupportReference.WorkingOrderRecord[] { record }); } tries += 1; if (!response.IsSuccessful && (response.Errors.Length == 0 || response.Errors[0].ErrorCode != ErrorCode.Deadlock)) { GuardianObject.ThrowErrorInfo(response.Errors[0]); } } while (!response.IsSuccessful && tries < WorkingOrder.TotalRetries); 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); if (this.Deleted) { throw new DeleteException(this, exception); } } finally { if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened) { tradingSupportClient.Close(); } } }