Esempio n. 1
0
 public static void RemoveEventListener(MessageCommand type, MyEventHandler handler)
 {
     RemoveEventListener(type.ToString(), handler);
 }
Esempio n. 2
0
 public static void AddEventOneOffListener(MessageCommand type, MyEventHandler handler)
 {
     AddEventOneOffListener(type.ToString(), handler);
 }
Esempio n. 3
0
        /// <summary>
        /// Creates a formatted string containing information about the message.
        /// </summary>
        /// <returns>A formatted string containing information about the message.</returns>
        public override string ToString()
        {
            string ret = "";

            ret += " | Created " + (CreatedUtc != null ? Convert.ToDateTime(CreatedUtc).ToString("MM/dd/yyyy HH:mm:ss") : "null") +
                   " Expiration " + (ExpirationUtc != null ? Convert.ToDateTime(ExpirationUtc).ToString("MM/dd/yyyy HH:mm:ss") : "null") + Environment.NewLine;

            ret += " | Message ID " + (!String.IsNullOrEmpty(MessageID) ? MessageID : "null") +
                   " Conversation ID " + (!String.IsNullOrEmpty(ConversationID) ? ConversationID : "null") + Environment.NewLine;

            ret += " | Command " + Command.ToString() +
                   " Success " + Success + Environment.NewLine;

            ret += " | Sync Request " + SyncRequest +
                   " Sync Timeout " + SyncTimeoutMs +
                   " Sync Response " + SyncResponse +
                   " Persist " + Persist + Environment.NewLine;

            ret += " | Sender Name " + SenderName + " Sender GUID " + SenderGUID + Environment.NewLine;

            ret += " | Recipient GUID " + RecipientGUID + Environment.NewLine;

            ret += " | Channel GUID " + (!String.IsNullOrEmpty(ChannelGUID) ? ChannelGUID : "null") +
                   " Channel Name " + (!String.IsNullOrEmpty(ChannelName) ? ChannelName : "null") + Environment.NewLine;

            ret += " | Content Type " + (!String.IsNullOrEmpty(ContentType) ? ContentType : "null") + " Content Length " + ContentLength + Environment.NewLine;

            if (UserHeaders != null)
            {
                if (UserHeaders.Count > 0)
                {
                    ret += " | User Headers: " + Environment.NewLine;
                    foreach (KeyValuePair <string, string> currUserHeader in UserHeaders)
                    {
                        ret += "   | " + currUserHeader.Key + ": " + currUserHeader.Value + Environment.NewLine;
                    }
                }
            }

            if (Data != null)
            {
                if (ContentLength > 0)
                {
                    string DataString = Encoding.UTF8.GetString(Data);
                    ret += " | Data (" + ContentLength + " bytes)";
                    ret += Environment.NewLine + Environment.NewLine + DataString + Environment.NewLine;
                }
                else
                {
                    string DataString = Encoding.UTF8.GetString(Data);
                    ret += " | Data (no content length specified)";
                    ret += Environment.NewLine + Environment.NewLine + DataString + Environment.NewLine;
                }
            }
            else
            {
                ret += " | Data: (null)" + Environment.NewLine;
            }

            return(ret);
        }
Esempio n. 4
0
 public static void DispatchEvent(MessageCommand evt, params object[] objs)
 {
     DispatchEvent(evt.ToString(), objs);
 }
Esempio n. 5
0
        public async Task SendDataToPie(MessageCommand messageCommand, string ZapOrderId,
                                        int pumpId             = 0, decimal authoriseLimit = 0,
                                        string transactionId   = "", string webhook_start  = "",
                                        string webhook_success = "", string webhook_error  = "")
        {
            var dataByte = new byte[1];

            byte[] buffer = dataByte;
            string dataBuffer;

            try
            {
                switch (messageCommand)
                {
                case MessageCommand.RequestPumpStatus:
                    //return;
                    buffer = new PumpStatusRequest().GetBytes();
                    break;

                case MessageCommand.Reserve:
                    if (PiePumps.Pumps[pumpId - 1].CurrentStatus == PumpStatus.Idle)
                    {
                        PiePumps.Pumps[pumpId - 1].Request           = RequestPumpStatus.RequestReserve;
                        PiePumps.Pumps[pumpId - 1].ZapOrderId        = ZapOrderId;
                        PiePumps.Pumps[pumpId - 1].RequestTriedCount = 0;

                        PiePumps.Pumps[pumpId].UnexectedPumpDispenseCompletedFlag = false;

                        buffer = new Reserve(pumpId, ZapOrderId).GetBytes();
                    }
                    else
                    {
                        // straight away to reject it
                        ReservePump(pumpId, false);
                    }
                    break;

                case MessageCommand.Authorize:
                    if (PiePumps.Pumps[pumpId - 1].Request != RequestPumpStatus.RequestAutorise)
                    {
                        Debug.WriteLine("Failed. Pump is not in RequestAutorise state");
                        AuthorizePump(pumpId, false);
                        break;
                    }

                    PiePumps.Pumps[pumpId - 1].RequestTriedCount        = 0;
                    PiePumps.Pumps[pumpId - 1].BosTransactionId         = transactionId;
                    PiePumps.Pumps[pumpId - 1].WebhookStartDispense     = webhook_start;
                    PiePumps.Pumps[pumpId - 1].WebhookCompletedDispense = webhook_success;
                    PiePumps.Pumps[pumpId - 1].WebhookError             = webhook_error;

                    buffer = new Authorise(pumpId, authoriseLimit).GetBytes();
                    break;

                case MessageCommand.GetFinalization:
                    PiePumps.Pumps[pumpId - 1].Request           = RequestPumpStatus.RequestFinalize;
                    PiePumps.Pumps[pumpId - 1].RequestTriedCount = 0;

                    buffer = new GetFinalization(pumpId).GetBytes();
                    break;

                case MessageCommand.PumpCancel2:
                    PiePumps.Pumps[pumpId - 1].PreviousRequest = PiePumps.Pumps[pumpId - 1].Request;        // probably cancel request is failed

                    if (PiePumps.Pumps[pumpId - 1].CurrentStatus == PumpStatus.Reserved ||
                        PiePumps.Pumps[pumpId - 1].CurrentStatus == PumpStatus.Authorized)
                    {
                        bool okProceed = true;
                        if (ZapOrderId != "")
                        {
                            if (PiePumps.Pumps[pumpId - 1].ZapOrderId != ZapOrderId)                                        // make sure the same order id)
                            {
                                okProceed = false;
                            }
                        }

                        if (okProceed)
                        {
                            PiePumps.Pumps[pumpId - 1].RequestTriedCount = 0;
                            PiePumps.Pumps[pumpId - 1].Request           = RequestPumpStatus.RequestCancel;
                            buffer = new CancelPump(pumpId).GetBytes();

                            break;
                        }
                    }

                    PiePumps.Pumps[pumpId - 1].RequestTriedCount = 9999;                                   // terus cancel
                    processCancel(pumpId - 1, ZapOrderId);
                    return;
                }

                if (messageCommand != MessageCommand.RequestPumpStatus)
                {
                    dataBuffer = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                    SystemLogs.LogBankServer(dataBuffer, "POS", messageCommand.ToString("G"));
                }
                await Write(buffer);

                if (DEBUG_MODE)
                {
                    if (messageCommand != MessageCommand.RequestPumpStatus)
                    {
                        Debug.WriteLine("--------> Request to Pie for " + messageCommand.ToString("G") + " Pump No:" + pumpId +
                                        " Data:" + Encoding.UTF8.GetString(buffer, 0, buffer.Length));
                    }
                }
            }
            catch (Exception ex)
            {
                dataBuffer = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                SystemLogs.LogError("SendDataToBankServer Exception", "Error Message: " + ex.Message,
                                    "Buffer:" + dataBuffer);
            }
        }