Exemplo n.º 1
0
        /// <summary>
        /// Update this object based on another.
        /// </summary>
        /// <param name="obj">The object to draw updates from.</param>
        public override void Update(GuardianObject obj)
        {
            WorkingOrder workingOrder = obj as WorkingOrder;

            if (!workingOrder.Modified)
            {
                this.rowVersion   = workingOrder.rowVersion;
                this.modifiedTime = workingOrder.ModifiedTime;
                this.securityId   = workingOrder.SecurityId;
                this.symbol       = workingOrder.Symbol;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Populates trading support records for the securities of each working order in a set.
        /// </summary>
        /// <param name="orders">The working orders to populate records for.</param>
        /// <returns>The populated records.</returns>
        protected virtual BaseRecord[] PopulateSecurityRecords(List <IMovableObject> orders)
        {
            BaseRecord[] records = new BaseRecord[orders.Count];

            for (Int32 index = 0; index < orders.Count; ++index)
            {
                WorkingOrder order = orders[index] as WorkingOrder;

                records[index] = new BaseRecord {
                    RowId = order.WorkingOrderId, RowVersion = order.RowVersion
                };
            }

            return(records);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Delete an set of working orders.
        /// </summary>
        /// <param name="workingOrders">The set of working orders.</param>
        /// <returns>The actual bulk size used.</returns>
        protected override Int32 Delete(List <GuardianObject> workingOrders)
        {
            Int32          attemptedBulkSize = workingOrders.Count;
            Int32          actualBulkSize    = attemptedBulkSize;
            GuardianObject failedObject      = null;

            TradingSupportReference.WorkingOrderRecord[] records;
            Dictionary <TradingSupportReference.WorkingOrderRecord, WorkingOrder> recordsToOrders =
                new Dictionary <TradingSupportReference.WorkingOrderRecord, WorkingOrder>();

            records = new TradingSupportReference.WorkingOrderRecord[workingOrders.Count];

            // Convert the GuardianObjects to records we can push up to the server.
            for (Int32 index = 0; index < records.Length; ++index)
            {
                WorkingOrder workingOrder = workingOrders[0] as WorkingOrder;

                records[index] = new TradingSupportReference.WorkingOrderRecord();
                workingOrder.PopulateRecord(records[index]);
                recordsToOrders[records[index]] = workingOrder;
                workingOrders.RemoveAt(0);
            }

            try
            {
                Int32 sentSize;
                MethodResponseErrorCode response;

                response = NetworkHelper.Attempt <MethodResponseErrorCode>(
                    (client, a) =>
                    client.DeleteWorkingOrder(a as TradingSupportReference.WorkingOrderRecord[]),
                    records,
                    true,
                    out sentSize);

                if (sentSize < attemptedBulkSize)
                {
                    actualBulkSize = sentSize;
                }

                if (!response.IsSuccessful)
                {
                    foreach (ErrorInfo errorInfo in response.Errors)
                    {
                        // The bulk index is an index into the set we sent, which may be smaller than the set passed in.
                        failedObject = recordsToOrders[records[errorInfo.BulkIndex]];

                        // If the error's "just" a deadlock, add it to the retry list we can attempt it again.
                        if (errorInfo.ErrorCode == ErrorCode.RecordExists)
                        {
                            throw new IsSettledException(this.ToString() + " is settled");
                        }
                        // We can safely ignore not-found errors (we are deleting after all), but if the error's more severe, forget the whole
                        // thing and throw up the error.
                        else if (errorInfo.ErrorCode != ErrorCode.RecordNotFound)
                        {
                            GuardianObject.ThrowErrorInfo(response.Errors[0]);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Warning("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace);
                throw new DeleteException(failedObject, exception);
            }

            return(actualBulkSize);
        }