Beispiel #1
0
 /// <summary>Inserts a Order record using Metadata Parameters.</summary>
 /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
 /// <param name="remoteMethod">Contains the parameters and exceptions for this command.</param>
 public static void Insert(Transaction transaction, RemoteMethod remoteMethod)
 {
     try
     {
         // Accessor for the Order Table.
         ServerMarketData.OrderDataTable orderTable = ServerMarketData.Order;
         // Extract the parameters from the command batch.
         string         configurationId             = remoteMethod.Parameters.GetRequiredString("configurationId", "DEFAULT");
         string         externalAccountId           = remoteMethod.Parameters.GetRequiredString("accountId");
         string         externalSecurityId          = remoteMethod.Parameters.GetRequiredString("securityId");
         string         externalSettlementId        = remoteMethod.Parameters.GetRequiredString("settlementId");
         string         externalTransactionTypeCode = remoteMethod.Parameters.GetRequiredString("transactionTypeCode");
         string         externalTimeInForceCode     = remoteMethod.Parameters.GetRequiredString("timeInForceCode");
         string         externalOrderTypeCode       = remoteMethod.Parameters.GetRequiredString("orderTypeCode");
         System.Decimal quantity = remoteMethod.Parameters.GetRequiredDecimal("quantity");
         object         price1   = remoteMethod.Parameters.GetOptionalDecimal("price1");
         object         price2   = remoteMethod.Parameters.GetOptionalDecimal("price2");
         // Make sure the parameters were parsed correctly before calling the internal method. This will prevent the method
         // from being called with bad data, but provides for error checking on all the parameters.
         if ((remoteMethod.HasExceptions == false))
         {
             // The row versioning is largely disabled for external operations.  The value is returned to the caller in the
             // event it's needed for operations within the batch.
             long rowVersion = long.MinValue;
             // Resolve External Identifiers
             int accountId           = External.Account.FindRequiredKey(configurationId, "accountId", externalAccountId);
             int securityId          = External.Security.FindRequiredKey(configurationId, "securityId", externalSecurityId);
             int settlementId        = External.Security.FindRequiredKey(configurationId, "settlementId", externalSettlementId);
             int transactionTypeCode = External.TransactionType.FindRequiredKey(configurationId, "transactionTypeCode", externalTransactionTypeCode);
             int timeInForceCode     = External.TimeInForce.FindRequiredKey(configurationId, "timeInForceCode", externalTimeInForceCode);
             int orderTypeCode       = External.OrderType.FindRequiredKey(configurationId, "orderTypeCode", externalOrderTypeCode);
             // Call the internal method to complete the operation.
             Shadows.WebService.Trading.Order.Insert(transaction, null, null, accountId, securityId, settlementId, null, transactionTypeCode, timeInForceCode, orderTypeCode, null, ref rowVersion, null, quantity, price1, price2, null);
             // Return values.
             remoteMethod.Parameters.ReturnValue("rowVersion", rowVersion);
         }
     }
     catch (SqlException sqlException)
     {
         // Every exception from the SQL server call is packed into the 'RemoteMethod' structure and returned to the caller.
         for (IEnumerator iEnumerator = sqlException.Errors.GetEnumerator(); iEnumerator.MoveNext(); remoteMethod.Exceptions.Add(((SqlError)(iEnumerator.Current)).Message))
         {
         }
     }
     catch (Exception exception)
     {
         // This will pass the general exception back to the caller.
         remoteMethod.Exceptions.Add(exception);
     }
 }
Beispiel #2
0
        /// <summary>Archives a Order record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="orderId">The value for the OrderId column.</param>
        /// <param name="rowVersion">The value for the RowVersion column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public static void Archive(Transaction transaction, int orderId, long rowVersion)
        {
            // Accessor for the Order Table.
            ServerMarketData.OrderDataTable orderTable = ServerMarketData.Order;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.OrderRow orderRow = orderTable.FindByOrderId(orderId);
            if ((orderRow == null))
            {
                throw new Exception(string.Format("The Order table does not have an element identified by {0}", orderId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((orderRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < orderRow.GetOrderTreeRowsByFKOrderOrderTreeChildId().Length); index = index)
            {
                ServerMarketData.OrderTreeRow orderTreeRow = orderRow.GetOrderTreeRowsByFKOrderOrderTreeChildId()[index];
                Core.OrderTree.Archive(transaction, orderTreeRow.ParentId, orderTreeRow.ChildId, orderTreeRow.RowVersion);
            }
            for (int index = 0; (index < orderRow.GetOrderTreeRowsByFKOrderOrderTreeParentId().Length); index = index)
            {
                ServerMarketData.OrderTreeRow orderTreeRow = orderRow.GetOrderTreeRowsByFKOrderOrderTreeParentId()[index];
                Core.OrderTree.Archive(transaction, orderTreeRow.ParentId, orderTreeRow.ChildId, orderTreeRow.RowVersion);
            }
            // Delete the record in the ADO database.
            transaction.DataRows.Add(orderRow);
            orderRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update Order set Archived = 1 where \"OrderId\"=@orderId");

            sqlCommand.Connection  = transaction.SqlConnection;
            sqlCommand.Transaction = transaction.SqlTransaction;
            sqlCommand.Parameters.Add("@orderId", @orderId);
            sqlCommand.ExecuteNonQuery();
        }