/// <summary> /// Commit this payment method to the server. /// </summary> public void Commit() { DataModelClient dataModelClient = new DataModelClient(FluidTrade.Guardian.Properties.Settings.Default.DataModelEndpoint); if (this.Delete) { // Could be the user added and then deleted a user to the list, so makes sure the row actually exists. if (!this.New) { dataModelClient.DestroyDebtRulePaymentMethod(new object[] { this.PaymentMethodId }, this.RowVersion); } } else if (this.Dirty) { if (!this.New) { dataModelClient.UpdateDebtRulePaymentMethod(this.DebtRuleId, this.PaymentMethodId, new object[] { this.PaymentMethodId }, this.PaymentMethodTypeId, this.RowVersion); } else { // If the list item doesn't exist, that means the user added it, and we need to Create a new AccessControl row for it. this.paymentMethodId = Guid.NewGuid(); dataModelClient.CreateDebtRulePaymentMethod(this.DebtRuleId, this.PaymentMethodId, this.PaymentMethodTypeId); } this.dirty = false; } dataModelClient.Close(); }
/// <summary> /// Create a new DebtHolder in the data model. /// </summary> /// <param name="dataModel">The data model client to create the debt holder with.</param> /// <param name="typeId">The type-id of the DebtHolder type.</param> /// <param name="parentId">The entityId of the parent entity.</param> /// <param name="tenantId"></param> /// <returns>The entity-id of the new debt holder.</returns> public static new Guid Create(DataModelClient dataModel, Guid typeId, Guid parentId, Guid tenantId) { Guid entityId = Guid.Empty; TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint); try { TradingSupportReference.DebtHolder record = new TradingSupportReference.DebtHolder(); lock (DataModel.SyncRoot) { DebtClassRow parent = DataModel.DebtClass.DebtClassKey.Find(parentId); record.ConfigurationId = "Default"; record.Name = "New Debt Holder"; record.Address1 = parent.IsAddress1Null()? null : parent.Address1; record.Address2 = parent.IsAddress2Null()? null : parent.Address2; record.BankAccountNumber = parent.IsBankAccountNumberNull()? null : parent.BankAccountNumber; record.BankRoutingNumber = parent.IsBankRoutingNumberNull()? null : parent.BankRoutingNumber; record.City = parent.IsCityNull()? null : parent.City; record.CompanyName = parent.IsCompanyNameNull()? null : parent.CompanyName; record.ContactName = parent.IsContactNameNull()? null : parent.ContactName; record.Department = parent.IsDepartmentNull()? null : parent.Department; record.Email = parent.IsEmailNull()? null : parent.Email; record.Fax = parent.IsFaxNull()? null : parent.Fax; record.ForBenefitOf = parent.IsForBenefitOfNull()? null : parent.ForBenefitOf; record.ParentId = parent.DebtClassId; record.Phone = parent.IsPhoneNull()? null : parent.Phone; record.PostalCode = parent.IsPostalCodeNull()? null : parent.PostalCode; record.Province = parent.IsProvinceIdNull() ? null : (Guid?)parent.ProvinceId; } record.TenantId = tenantId; MethodResponseArrayOfguid response = tradingSupportClient.CreateDebtHolder(new TradingSupportReference.DebtHolder[] { record }); if (response.IsSuccessful) { entityId = response.Result[0]; } else { throw new Exception(String.Format("Server error: {0}, {1}", response.Errors[0].ErrorCode, response.Errors[0].Message)); } } catch (Exception exception) { // Any issues trying to communicate to the server are logged. EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); throw; } finally { if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened) { tradingSupportClient.Close(); } } return(entityId); }
/// <summary> /// Destroy the executions and destination orders on the shared data model. /// </summary> /// <param name="sender">The generic thread initialization parameter.</param> public static void ClearCross(object sender) { DataModelClient dataModelClient = new DataModelClient(Properties.Settings.Default.DataModelEndpoint); lock (DataModel.SyncRoot) { try { // Destroy all the negotations foreach (NegotiationRow negotiationRow in DataModel.Negotiation) { dataModelClient.DestroyNegotiation(new Object[] { negotiationRow.NegotiationId }, negotiationRow.RowVersion); } // Destroy all the Chat items. foreach (ChatRow chatRow in DataModel.Chat) { dataModelClient.DestroyChat(new Object[] { chatRow.ChatId }, chatRow.RowVersion); } // Destroy all the matches foreach (MatchRow matchRow in DataModel.Match) { dataModelClient.DestroyMatch(new Object[] { matchRow.MatchId }, matchRow.RowVersion); } // Destroy all the match timers foreach (MatchTimerRow matchTimerRow in DataModel.MatchTimer) { dataModelClient.DestroyMatchTimer(new Object[] { matchTimerRow.MatchId }, matchTimerRow.RowVersion); } // Destroy all the Destionation Orders foreach (DestinationOrderRow destinationOrderRow in DataModel.DestinationOrder) { dataModelClient.DestroyDestinationOrder(new Object[] { destinationOrderRow.DestinationOrderId }, destinationOrderRow.RowVersion); } // Destroy all the Orders involved in the Consumer Trust/Consumer Debt demo. DestroyWorkingOrders(dataModelClient, "Ingrid Yeoh"); DestroyWorkingOrders(dataModelClient, "Kai Hitori"); DestroyWorkingOrders(dataModelClient, "High Risk"); DestroyWorkingOrders(dataModelClient, "Low Risk"); DestroyWorkingOrders(dataModelClient, "Medium Risk"); // Reset all the working orders in the Debt Matching Demo. ResetWorkingOrders(dataModelClient, "Russell Jackson"); ResetWorkingOrders(dataModelClient, "Kareem Rao"); } catch (Exception exception) { Console.WriteLine("{0}, {1}", exception.Message, exception.StackTrace); } } // Shut down the channel gracefully. dataModelClient.Close(); }
/// <summary> /// Clears the given blotter of all working orders. /// </summary> /// <param name="dataModelClient">Used to execute Web Services.</param> /// <param name="blotterName">The name of the blotter to be reset.</param> private static void DestroyWorkingOrders(DataModelClient dataModelClient, String blotterName) { // Destroy all the Working Orders for Kai Hitori foreach (WorkingOrderRow workingOrderRow in DataModel.WorkingOrder) { EntityRow entityRow = workingOrderRow.BlotterRow.EntityRow; if (entityRow.Name == blotterName) { dataModelClient.DestroyWorkingOrder(workingOrderRow.RowVersion, new object[] { workingOrderRow.WorkingOrderId }); } } }
/// <summary> /// Resets the matching criteria for all orders in the selected blotter. /// </summary> /// <param name="dataModelClient">Used to execute Web Services.</param> /// <param name="blotterName">The name of the blotter to be reset.</param> private static void ResetWorkingOrders(DataModelClient dataModelClient, String blotterName) { // This will reset the matching flags for the given blotter. foreach (WorkingOrderRow workingOrderRow in DataModel.WorkingOrder) { EntityRow entityRow = workingOrderRow.BlotterRow.EntityRow; if (entityRow.Name == blotterName) { if (workingOrderRow.CrossingRow.CrossingCode != Crossing.NeverMatch || workingOrderRow.StatusRow.StatusCode != Status.New) { dataModelClient.UpdateWorkingOrder(null, null, null, null, Crossing.NeverMatch, null, null, null, false, null, null, null, null, null, null, null, workingOrderRow.RowVersion, null, null, null, null, null, Status.New, null, null, null, null, null, null, null, null, new Object[] { workingOrderRow.WorkingOrderId }); } } } }
/// <summary> /// Create a new entity in the data model. /// </summary> /// <param name="dataModel">The data model client to create the entity with.</param> /// <param name="typeId">The type of the new entity.</param> /// <param name="parentId">The entityId of the parent entity.</param> /// <param name="tenantId"></param> /// <returns>The entity Id of the new entity.</returns> public static Guid Create(DataModelClient dataModel, Guid typeId, Guid parentId, Guid tenantId) { Guid entityId = Guid.NewGuid(); Guid imageId; lock (DataModel.SyncRoot) { TypeRow type = DataModel.Type.TypeKey.Find(typeId); imageId = type.IsImageIdNull() ? DataModel.Image[0].ImageId : type.ImageId;; } dataModel.CreateEntity(DateTime.UtcNow, "", entityId, null, null, null, null, null, null, null, null, imageId, false, false, DateTime.UtcNow, "New Entity", tenantId, typeId); return(entityId); }
/// <summary> /// Updates a Working Order record. /// </summary> /// <param name="state">The generic thread initialization parameter.</param> private void UpdateDataModel(object state) { // Extract the specific instructions for changing the working order from the generic argument. MatchChange matchChange = state as MatchChange; try { // Create a channel to the middle tier. DataModelClient dataModelClient = new DataModelClient(Guardian.Properties.Settings.Default.DataModelEndpoint); // Call the handler to update the working order record. matchChange.Handler(dataModelClient, matchChange.MatchRow, matchChange.Value); // At this point the client can be shut down gracefully. dataModelClient.Close(); } catch (FaultException <OptimisticConcurrencyFault> optimisticConcurrencyException) { // The record is busy. this.Dispatcher.Invoke(DispatcherPriority.Normal, (MessageDelegate)((string message) => { MessageBox.Show(message, Application.Current.MainWindow.Title); }), String.Format(FluidTrade.Core.Properties.Resources.OptimisticConcurrencyError, optimisticConcurrencyException.Detail.TableName)); } catch (FaultException <RecordNotFoundFault> recordNotFoundException) { // The record is busy. this.Dispatcher.Invoke(DispatcherPriority.Normal, (MessageDelegate)((string message) => { MessageBox.Show(message, Application.Current.MainWindow.Title); }), String.Format(FluidTrade.Core.Properties.Resources.RecordNotFoundError, CommonConversion.FromArray(recordNotFoundException.Detail.Key), recordNotFoundException.Detail.TableName)); } catch (CommunicationException communicationException) { // Log communication problems. this.Dispatcher.Invoke(DispatcherPriority.Normal, (MessageDelegate)((string message) => { MessageBox.Show(message, Application.Current.MainWindow.Title); }), communicationException.Message); } catch (Exception exception) { // Log communication problems. EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } }
/// <summary> /// Handles a request to destroy all the trades. /// </summary> /// <param name="sender">The object that originated the event.</param> /// <param name="e">The event data.</param> private void OnLoadEquityReport(object sender, RoutedEventArgs e) { // Configure the 'Open File' dialog box to look for the available XML files. OpenFileDialog openFile = new OpenFileDialog(); openFile.DefaultExt = ".xaml"; openFile.Filter = "XAML Documents (.xaml)|*.xaml"; // Show open file dialog box Nullable <bool> result = openFile.ShowDialog(); if (result == true) { XDocument xDocument = XDocument.Load(openFile.FileName); DataModelClient dataModelClient = new DataModelClient(Properties.Settings.Default.DataModelEndpoint); dataModelClient.UpdateReportEx("Default", null, null, null, new object[] { "EQUITY WORKING ORDER REPORT" }, null, xDocument.ToString()); dataModelClient.Close(); } }
public void DestroyRecords(object state) { List <WorkingOrderRow> toDeleteRows = state as List <WorkingOrderRow>; DataModelClient dataModelClient = new DataModelClient(Guardian.Properties.Settings.Default.DataModelEndpoint); try { foreach (WorkingOrderRow row in toDeleteRows) { dataModelClient.DestroyWorkingOrder(row.RowVersion, new object[] { row.WorkingOrderId }); } } finally { if (dataModelClient != null) { dataModelClient.Close(); } } }
private void DeclineTrade(object parameter) { DataModelClient dataModelClient = new DataModelClient(FluidTrade.Guardian.Properties.Settings.Default.DataModelEndpoint); lock (DataModel.SyncRoot) { // Find the Match record. MatchRow matchRow = DataModel.Match.MatchKey.Find(this.matchId); if (matchRow == null) { Guid negotiationId = Guid.NewGuid(); dataModelClient.CreateNegotiation( matchRow.WorkingOrderRow.BlotterId, null, null, matchRow.MatchId, negotiationId, 0.0M, DataModel.Status.StatusKeyStatusCode.Find(Status.Declined).StatusId); } } }
private void NegotiateTrade(object parameter) { // Extract the thread parameters Decimal quantity = (Decimal)parameter; DataModelClient dataModelClient = new DataModelClient(Guardian.Properties.Settings.Default.DataModelEndpoint); lock (DataModel.SyncRoot) { // Open up the negotiations. MatchRow matchRow = DataModel.Match.MatchKey.Find(this.matchId); Guid negotiationId = Guid.NewGuid(); dataModelClient.CreateNegotiation( matchRow.WorkingOrderRow.BlotterId, null, null, matchRow.MatchId, negotiationId, quantity, DataModel.Status.StatusKeyStatusCode.Find(Status.Pending).StatusId); } }
/// <summary> /// Create a new entity of a given type under a particular parent entity. /// </summary> /// <param name="typeId">The type-id of the new entity.</param> /// <param name="tenantId"></param> /// <param name="parentId">The entity-id of the parent entity.</param> public static Guid Create(Guid typeId, Guid parentId, Guid tenantId) { lock (DataModel.SyncRoot) { TypeRow type = DataModel.Type.TypeKey.Find(typeId); Assembly assembly; String className; try { Entity.LoadAssembly(type.Type, out assembly, out className); Type entityType = assembly.GetType(className, true); MethodInfo create = entityType.GetMethod("Create", new Type[] { typeof(DataModelClient), typeof(Guid), typeof(Guid), typeof(Guid) }); if (create != null) { DataModelClient dataModel = new DataModelClient(Properties.Settings.Default.DataModelEndpoint); // Create the entity and add it to the tree. Guid entityId = (Guid)create.Invoke(null, new object[] { dataModel, typeId, parentId, tenantId }); //dataModel.CreateEntityTree(entityId, Guid.NewGuid(), null, parentId); ; //AccessRightRow accessRightRow = DataModel.AccessRight.AccessRightKeyAccessRightCode.Find(AccessRight.FullControl); //dataModel.CreateAccessControl(Guid.NewGuid(), accessRightRow.AccessRightId, entityId, Information.UserId); dataModel.Close(); return(entityId); } else { throw new Exception(string.Format("Create method not found in type '{0}'", className)); } } catch (Exception exception) { throw new Exception(String.Format("Can't create new entity for type '{0}'", type.Description), exception); } } }