Exemplo n.º 1
0
        protected virtual void AddPending()
        {
            var prefix = DescendantPrefix[0] == '.'
                ? DescendantPrefix.Substring(1)
                : DescendantPrefix;

            Pending.Add(XPath + prefix);
        }
Exemplo n.º 2
0
        private void OnContentsChanged(object sender, FileSystemEventArgs e)
        {
            var file = new FileInfo(e.FullPath);

            if (!Pending.Has(x => x.Name == file.Name))
            {
                _ui.Send(x => Pending.Add(file), null);
            }

            ProcessExistingFiles();
        }
Exemplo n.º 3
0
        private void ProcessExistingFiles()
        {
            var dir = new DirectoryInfo(Target.Source);

            foreach (var file in dir.GetFiles(Target.Filter))
            {
                if (!Pending.Has(x => x.Name == file.Name))
                {
                    _ui.Send(x => Pending.Add(file), null);
                }
            }
        }
Exemplo n.º 4
0
        private async void AddNewItem()
        {
            var dialog = new CoreModules.Dialogs.NewToDoItem();
            var item   = new ToDoItem();
            var result = await _application.ShowDialog("New To Do Item", dialog, DialogButtons.OkCancel, true, item);

            if (result)
            {
                Pending.Add(item);
                _db.Todo.Save(item);
            }
        }
Exemplo n.º 5
0
        public void ExecuteOperation(OperationBase operation)
        {
            Pending.Add(operation);
            operation.Finished += operation_Finished;
            operation.Error    += operation_Error;
            if (operation.IsComplexOperation)
            {
                operation.Progressed += operation_Progressed;
            }

            AreAnyOperationsOngoing = true;
            operation.Start();
        }
Exemplo n.º 6
0
        internal override void MapResponse(Element response)
        {
            base.MapResponse(response);

            string category = response.GetValue <string>("TableCategory") ?? "";

            if (category == null)
            {
                category = LastCategory;
            }
            var fieldValues = new Dictionary <string, string>();

            foreach (Element field in response.GetAll("Field"))
            {
                fieldValues.Add(field.GetValue <string>("Key"), field.GetValue <string>("Value"));
            }

            if (category.EndsWith("SUMMARY", StringComparison.OrdinalIgnoreCase))
            {
                var summary = new SummaryResponse {
                    SummaryType      = MapSummaryType(category),
                    Count            = fieldValues.GetValue <int>("Count"),
                    Amount           = fieldValues.GetAmount("Amount"),
                    TotalAmount      = fieldValues.GetAmount("Total Amount"),
                    AuthorizedAmount = fieldValues.GetAmount("Authorized Amount"),
                    AmountDue        = fieldValues.GetAmount("Balance Due Amount"),
                };

                if (category.Contains("APPROVED"))
                {
                    if (Approved == null)
                    {
                        Approved = new Dictionary <SummaryType, SummaryResponse>();
                    }
                    Approved.Add(summary.SummaryType, summary);
                }
                else if (category.StartsWith("PENDING"))
                {
                    if (Pending == null)
                    {
                        Pending = new Dictionary <SummaryType, SummaryResponse>();
                    }
                    Pending.Add(summary.SummaryType, summary);
                }
                else if (category.StartsWith("DECLINED"))
                {
                    if (Declined == null)
                    {
                        Declined = new Dictionary <SummaryType, SummaryResponse>();
                    }
                    Declined.Add(summary.SummaryType, summary);
                }
            }
            else if (category.EndsWith("RECORD", StringComparison.OrdinalIgnoreCase))
            {
                TransactionSummary trans;
                if (category.Equals(LastCategory, StringComparison.OrdinalIgnoreCase))
                {
                    trans = LastTransactionSummary;
                }
                else
                {
                    trans = new TransactionSummary {
                        TransactionId         = fieldValues.GetValue <string>("TransactionId"),
                        OriginalTransactionId = fieldValues.GetValue <string>("OriginalTransactionId"),
                        TransactionDate       = fieldValues.GetValue <string>("TransactionTime").ToDateTime(),
                        TransactionType       = fieldValues.GetValue <string>("TransactionType"),
                        MaskedCardNumber      = fieldValues.GetValue <string>("MaskedPAN"),
                        CardType              = fieldValues.GetValue <string>("CardType"),
                        CardEntryMethod       = fieldValues.GetValue <string>("CardAcquisition"),
                        AuthCode              = fieldValues.GetValue <string>("ApprovalCode"),
                        IssuerResponseCode    = fieldValues.GetValue <string>("ResponseCode"),
                        IssuerResponseMessage = fieldValues.GetValue <string>("ResponseText"),
                        HostTimeout           = (bool)fieldValues.GetBoolean("HostTimeOut"),
                        // BaseAmount - Not doing this one
                        TaxAmount        = fieldValues.GetAmount("TaxAmount"),
                        GratuityAmount   = fieldValues.GetAmount("TipAmount"),
                        Amount           = fieldValues.GetAmount("RequestAmount"),
                        AuthorizedAmount = fieldValues.GetAmount("Authorized Amount"),
                        AmountDue        = fieldValues.GetAmount("Balance Due Amount")
                    };
                }
                if (!(category.Equals(LastCategory)))
                {
                    if (category.StartsWith("APPROVED"))
                    {
                        var summary = Approved[SummaryType.Approved];
                        summary.Transactions.Add(trans);
                    }
                    else if (category.StartsWith("PENDING"))
                    {
                        var summary = Pending[SummaryType.Pending];
                        summary.Transactions.Add(trans);
                    }
                    else if (category.StartsWith("DECLINED"))
                    {
                        var summary = Declined[SummaryType.Declined];
                        summary.Transactions.Add(trans);
                    }
                }
                LastTransactionSummary = trans;
            }
            LastCategory = category;
        }
Exemplo n.º 7
0
 public void Add(T newVal)
 {
     Pending.Add(newVal);
 }
Exemplo n.º 8
0
        public UpaSAFResponse(JsonDoc root)
        {
            Approved = new Dictionary <SummaryType, SummaryResponse>();
            Pending  = new Dictionary <SummaryType, SummaryResponse>();
            Declined = new Dictionary <SummaryType, SummaryResponse>();

            var firstDataNode = root.Get("data");

            if (firstDataNode == null)
            {
                throw new MessageException(INVALID_RESPONSE_FORMAT);
            }

            var cmdResult = firstDataNode.Get("cmdResult");

            if (cmdResult == null)
            {
                throw new MessageException(INVALID_RESPONSE_FORMAT);
            }

            Status = cmdResult.GetValue <string>("result");
            if (string.IsNullOrEmpty(Status))
            {
                var errorCode = cmdResult.GetValue <string>("errorCode");
                var errorMsg  = cmdResult.GetValue <string>("errorMessage");
                DeviceResponseText = $"Error: {errorCode} - {errorMsg}";
            }
            else
            {
                // If the Status is not "Success", there is either nothing to process, or something else went wrong.
                // Skip the processing of the rest of the message, as we'll likely hit null reference exceptions
                if (Status == "Success")
                {
                    var secondDataNode = firstDataNode.Get("data");
                    if (secondDataNode == null)
                    {
                        throw new MessageException(INVALID_RESPONSE_FORMAT);
                    }
                    Multiplemessage = secondDataNode.GetValue <string>("multipleMessage");
                    var safDetailsList = secondDataNode.GetEnumerator("SafDetails");

                    if (safDetailsList != null)
                    {
                        foreach (var detail in safDetailsList)
                        {
                            if (TotalAmount == null)
                            {
                                TotalAmount = 0.00m;
                            }

                            TotalAmount += detail.GetValue <decimal>("SafTotal");
                            TotalCount  += detail.GetValue <int>("SafCount");

                            SummaryResponse summaryResponse = new SummaryResponse()
                            {
                                TotalAmount  = detail.GetValue <decimal>("SafTotal"),
                                Count        = detail.GetValue <int>("SafCount"),
                                SummaryType  = MapSummaryType(detail.GetValue <string>("SafType")),
                                Transactions = new List <TransactionSummary>()
                            };

                            if (detail.Has("SafRecords"))
                            {
                                foreach (var record in detail.GetEnumerator("SafRecords"))
                                {
                                    TransactionSummary transactionSummary = new TransactionSummary()
                                    {
                                        TransactionType   = record.GetValue <string>("transactionType"),
                                        TerminalRefNumber = record.GetValue <string>("transId"), // The sample XML says tranNo?
                                        ReferenceNumber   = record.GetValue <string>("referenceNumber"),
                                        GratuityAmount    = record.GetValue <decimal>("tipAmount"),
                                        TaxAmount         = record.GetValue <decimal>("taxAmount"),
                                        Amount            = record.GetValue <decimal>("baseAmount"),
                                        AuthorizedAmount  = record.GetValue <decimal>("authorizedAmount"),
                                        //AmountDue = record.GetValue<decimal>("totalAmount"),
                                        CardType         = record.GetValue <string>("cardType"),
                                        MaskedCardNumber = record.GetValue <string>("maskedPan"),
                                        TransactionDate  = record.GetValue <DateTime>("transactionTime"),
                                        AuthCode         = record.GetValue <string>("approvalCode"),
                                        HostTimeout      = record.GetValue <bool>("hostTimeOut"),
                                        CardEntryMethod  = record.GetValue <string>("cardAcquisition"),
                                        Status           = record.GetValue <string>("responseCode"),
                                        //record.GetValue<decimal>("requestAmount")
                                    };
                                    summaryResponse.Transactions.Add(transactionSummary);
                                }
                            }

                            if (summaryResponse.SummaryType == SummaryType.Approved)
                            {
                                if (Approved == null)
                                {
                                    Approved = new Dictionary <SummaryType, SummaryResponse>();
                                }
                                Approved.Add(summaryResponse.SummaryType, summaryResponse);
                            }
                            else if (summaryResponse.SummaryType == SummaryType.Pending)
                            {
                                if (Pending == null)
                                {
                                    Pending = new Dictionary <SummaryType, SummaryResponse>();
                                }
                                Pending.Add(summaryResponse.SummaryType, summaryResponse);
                            }
                            else if (summaryResponse.SummaryType == SummaryType.Declined)
                            {
                                if (Declined == null)
                                {
                                    Declined = new Dictionary <SummaryType, SummaryResponse>();
                                }
                                Declined.Add(summaryResponse.SummaryType, summaryResponse);
                            }
                        }
                    }
                }
                else   // the only other option is "Failed"
                {
                    var errorCode = cmdResult.GetValue <string>("errorCode");
                    var errorMsg  = cmdResult.GetValue <string>("errorMessage");
                    DeviceResponseText = $"Error: {errorCode} - {errorMsg}";
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>Handle a request to place a market order</summary>
        private void HandleMsg(OutMsg.PlaceMarketOrder msg)
        {
            var order = msg.Order;

            // Find the transmitter of the instrument that the order is for
            Transmitter trans;

            if (!Transmitters.TryGetValue(order.SymbolCode, out trans))
            {
                Model.DispatchMsg(new InMsg.MarketOrderChangeResult(false, EErrorCode.Failed));
                return;
            }

            // Check the volume is valid
            if (order.Volume < trans.PriceData.VolumeMin ||
                order.Volume > trans.PriceData.VolumeMax ||
                order.Volume % trans.PriceData.VolumeStep != 0)
            {
                Model.DispatchMsg(new InMsg.MarketOrderChangeResult(false, EErrorCode.InvalidVolume));
                return;
            }

            // Place an immediate order
            if (msg.Position != null)
            {
                var res = ActionTrade(msg.Position);
                if (res != EErrorCode.NoError)
                {
                    Model.DispatchMsg(new InMsg.MarketOrderChangeResult(false, res));
                    return;
                }
            }

            // Place a limit order
            else if (msg.PendingLimit != null)
            {
                // Limit orders are rejected if the price is not on the profit side of the order
                if (msg.PendingLimit.TradeType == ETradeType.Long && trans.PriceData.AskPrice < msg.PendingLimit.EntryPrice)
                {
                    Model.DispatchMsg(new InMsg.MarketOrderChangeResult(false, EErrorCode.Failed));
                    return;
                }
                if (msg.PendingLimit.TradeType == ETradeType.Short && trans.PriceData.BidPrice > msg.PendingLimit.EntryPrice)
                {
                    Model.DispatchMsg(new InMsg.MarketOrderChangeResult(false, EErrorCode.Failed));
                    return;
                }

                // Add the pending order
                Pending.Add(msg.PendingLimit);
            }

            // Place a stop order
            else if (msg.PendingStop != null)
            {
                // Stop orders are rejected if the price is not on the loss side of the order
                if (msg.PendingStop.TradeType == ETradeType.Long && trans.PriceData.AskPrice > msg.PendingStop.EntryPrice)
                {
                    Model.DispatchMsg(new InMsg.MarketOrderChangeResult(false, EErrorCode.Failed));
                    return;
                }
                if (msg.PendingStop.TradeType == ETradeType.Short && trans.PriceData.BidPrice < msg.PendingStop.EntryPrice)
                {
                    Model.DispatchMsg(new InMsg.MarketOrderChangeResult(false, EErrorCode.Failed));
                    return;
                }

                // Add the pending order
                Pending.Add(msg.PendingStop);
            }

            // Send an update of the current/pending positions
            SendCurrentPositions();
            SendPendingPositions();
        }