/// <summary>
 /// Show an exeption alert
 /// </summary>
 /// <param name="recordNotFoundException"></param>
 public void Show(FaultException <RecordNotFoundFault> recordNotFoundException)
 {
     Display(String.Format(FluidTrade.Core.Properties.Resources.RecordNotFoundError,
                           CommonConversion.FromArray(recordNotFoundException.Detail.Key),
                           recordNotFoundException.Detail.TableName),
             AlertMessageBoxType.RecordNotFoundError);
 }
Esempio n. 2
0
        /// <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);
            }
        }
        private void ExecuteSlice(object state)
        {
            List <WorkingOrderRow> workingOrders = state as List <WorkingOrderRow>;

            try
            {
                List <TradingSupportReference.DestinationOrderInfo> destinationOrders = new List <TradingSupportReference.DestinationOrderInfo>();

                lock (DataModel.SyncRoot)
                {
                    DestinationRow destinationRow = DataModel.Destination.DestinationKeyExternalId0.Find("GUARDIAN ECN");

                    foreach (WorkingOrderRow workingOrderRow in workingOrders)
                    {
                        decimal sourceOrderQuantity = 0.0M;
                        foreach (SourceOrderRow sourceOrderRow in workingOrderRow.GetSourceOrderRows())
                        {
                            sourceOrderQuantity += sourceOrderRow.OrderedQuantity;
                        }

                        Decimal destinationOrderQuantity = 0.0M;
                        foreach (DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                        {
                            destinationOrderQuantity += destinationOrderRow.OrderedQuantity;
                        }

                        if (sourceOrderQuantity > destinationOrderQuantity)
                        {
                            TradingSupportReference.DestinationOrderInfo destinationOrderInfo = new TradingSupportReference.DestinationOrderInfo();
                            destinationOrderInfo.BlotterId         = workingOrderRow.BlotterId;
                            destinationOrderInfo.DestinationId     = destinationRow.DestinationId;
                            destinationOrderInfo.OrderedQuantity   = sourceOrderQuantity - destinationOrderQuantity;
                            destinationOrderInfo.OrderTypeId       = workingOrderRow.OrderTypeId;
                            destinationOrderInfo.SecurityId        = workingOrderRow.SecurityId;
                            destinationOrderInfo.SettlementId      = workingOrderRow.SettlementId;
                            destinationOrderInfo.SideCodeId        = workingOrderRow.SideId;
                            destinationOrderInfo.TimeInForceCodeId = workingOrderRow.TimeInForceId;
                            destinationOrderInfo.WorkingOrderId    = workingOrderRow.WorkingOrderId;

                            destinationOrders.Add(destinationOrderInfo);
                        }
                    }
                }

                // Create a channel to the middle tier.
                TradingSupportReference.TradingSupportClient tradingSupportClient = new TradingSupportReference.TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint);
                tradingSupportClient.CreateDestinationOrders(destinationOrders.ToArray());

                // At this point the client can be shut down gracefully.
                tradingSupportClient.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);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a method plan from the parameters listed.
        /// </summary>
        /// <param name="methodElement">An XML node where the method and parameters are found.</param>
        bool ExecuteMethod(XElement methodElement)
        {
            // Indicates the success or failure of an individual method execution.
            bool isSuccessful = false;

            try
            {
                // The client channel on which this method is to be executed is described by the 'client' attribute.
                XAttribute    clientAttribte = methodElement.Attribute("client");
                String        clientName     = clientAttribte == null ? String.Empty : clientAttribte.Value;
                ClientChannel client;
                if (!this.clientTable.TryGetValue(clientName, out client))
                {
                    throw new Exception(String.Format("The client {0} hasn't been defined", clientName == String.Empty ? "<default>" : clientName));
                }

                // Reflection is used here to find the method to be executed.
                XAttribute methodNameAttribute = methodElement.Attribute("name");
                String     methodName          = methodNameAttribute == null ? String.Empty : methodNameAttribute.Value;
                MethodInfo methodInfo          = client.ChannelType.GetMethod(methodNameAttribute.Value);
                if (methodInfo == null)
                {
                    throw new Exception(String.Format("The method {0} isn't part of the library", methodNameAttribute.Value));
                }

                // This will pull apart the XML that contains the parameters and construct a dictionary of method arguments.
                Dictionary <String, XElement> parameterDictionary = new Dictionary <String, XElement>();
                foreach (XElement parameterElement in methodElement.Elements("parameter"))
                {
                    XAttribute parameterNameAttribute = parameterElement.Attribute("name");
                    parameterDictionary.Add(parameterNameAttribute.Value, parameterElement);
                }

                // This will correlate the parameter in the XML with the parameter of the actual method found through reflection and convert the parameter into the
                // proper destination type.  The end result is a parameter array that is compatible with a reflection call to the method specified in the XML.
                ParameterInfo[] parameterInfoArray = methodInfo.GetParameters();
                Object[]        parameterArray     = new Object[parameterInfoArray.Length];
                for (int index = 0; index < parameterInfoArray.Length; index++)
                {
                    ParameterInfo parameterInfo = parameterInfoArray[index];
                    XElement      parameterElement;
                    if (parameterDictionary.TryGetValue(parameterInfo.Name, out parameterElement))
                    {
                        parameterArray[index] = ScriptLoader.ConvertElement(parameterInfo.ParameterType, parameterElement, Path.GetDirectoryName(this.FileName));
                    }
                }

                try
                {
                    // At this point, the only thing left to do is call the method using the parsed parameters.
                    methodInfo.Invoke(client.ChannelObject, parameterArray);
                }
                catch (TargetInvocationException targetInvocationException)
                {
                    // We use reflection to execute the method, so naturally we're going to get a reflection error.  This will dig out the real reason that this
                    // method failed and throw it.
                    throw targetInvocationException.InnerException;
                }

                // The method invocation was successful at this point.
                isSuccessful = true;
            }
            catch (FaultException <IndexNotFoundFault> indexNotFoundException)
            {
                // The record wasn't found.
                Console.WriteLine(Teraque.Properties.Resources.IndexNotFoundError, indexNotFoundException.Detail.IndexName,
                                  indexNotFoundException.Detail.TableName);
            }
            catch (FaultException <RecordNotFoundFault> recordNotFoundException)
            {
                // The record wasn't found.
                Console.WriteLine(Teraque.Properties.Resources.RecordNotFoundError,
                                  CommonConversion.FromArray(recordNotFoundException.Detail.Key),
                                  recordNotFoundException.Detail.TableName);
            }
            catch (FaultException <ConstraintFault> constraintFaultException)
            {
                // The arguments weren't in the proper range.
                Console.WriteLine(constraintFaultException.Detail.Message);
            }
            catch (FaultException <ArgumentFault> argumentFaultException)
            {
                // The arguments weren't in the proper range.
                Console.WriteLine(argumentFaultException.Detail.Message);
            }
            catch (FaultException <FormatFault> formatFaultException)
            {
                // The arguments weren't in the proper range.
                Console.WriteLine(formatFaultException.Detail.Message);
            }
            catch (FaultException <ExceptionDetail> exceptionDetail)
            {
                // This is a general purpose exception for debugging.
                Console.WriteLine(exceptionDetail.Message);
            }

            // This is the final indication of whether the method was successful or not.
            return(isSuccessful);
        }