コード例 #1
0
        public static Messages.Response EpaymentProcess(Messages.Request request)
        {
            float  amount   = request.Parameters.Value <float>("amount");
            string device   = request.Parameters.Value <string>("device");
            string protocol = request.Parameters.Value <string>("protocol");
            string port     = request.Parameters.Value <string>("port");
            string data     = request.Parameters.Value <string>("data");
            int    pos      = request.Parameters.Value <int>("pos");

            PaymentRequest paymentRequest = new PaymentRequest(amount);

            ConcertProtocol concertProtocol = ConcertProtocol.find(protocol);

            concertProtocol.Terminal = new SerialTerminal(port);

            Issue issue = concertProtocol.SendPaymentRequest(paymentRequest);

            if (issue.Type == Issue.SUCCESS)
            {
                return(request.Success(issue.Response));
            }
            else
            {
                return(request.Failure("", issue.Message));
            }
        }
コード例 #2
0
        public static Messages.Response PrintersTest(Messages.Request request)
        {
            string printerName = request.Parameters.Value <string>("printerName");

            Utils.ShellPrintTestDocument(printerName);
            return(request.Success(printerName));
        }
コード例 #3
0
        public static Messages.Response DocumentPrint(Messages.Request request)
        {
            string printerName = request.Parameters.Value <string>("printerName");
            string path        = request.Parameters.Value <string>("path");

            Utils.ShellPrintDocument(printerName, path);
            return(request.Success(path));
        }
コード例 #4
0
        public static Messages.Response EpaymentSupportedTerminals(Messages.Request request)
        {
            Dictionary <string, string> map = new Dictionary <string, string>();

            map.Add("Ingenico-ICT220", "Ingenico ICT 220");
            map.Add("Ingenico-ICT250", "Ingenico ICT 250");
            return(request.Success(map));
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_request"></param>
        private void ActionForRequest(object _request)
        {
            Messages.Request request = _request as Messages.Request;

            if (request.Delay > 0)
            {
                Thread.Sleep(request.Delay);
            }

            Messages.Response response = ProcessRequest(request);
            responseQueue.Enqueue(response);
        }
コード例 #6
0
        public static Messages.Response EpaymentPing(Messages.Request request)
        {
            string device   = request.Parameters.Value <string>("device");
            string port     = request.Parameters.Value <string>("port");
            string protocol = request.Parameters.Value <string>("protocol");

            ConcertProtocol concertProtocol = ConcertProtocol.find(protocol);

            concertProtocol.Terminal = new SerialTerminal(port);
            concertProtocol.SendTest();

            return(request.Success(true));
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        public void Test(Messages.Request request)
        {
            state = EndpointState.Listening;

            // All exceptions until a valid request was read
            // causes a message to be sent
            try {
                HandleRequest(request);
            } catch (Exception e) {
                SendException(e);
            }

            state = EndpointState.Idle;
        }
コード例 #8
0
        public static Messages.Response EpaymentTest(Messages.Request request)
        {
            Concert2Protocol protocol = new Concert2Protocol(new SerialTerminal(""));

            string payload = request.Parameters.Value <string>("payload");

            payload += ConcertProtocol.FromCharCode(ConcertProtocol.ETX).ToString();

            string message = ConcertProtocol.FromCharCode(ConcertProtocol.STX);

            message += payload;
            message += ConcertProtocol.FromCharCode(ConcertProtocol.LRC(payload));

            protocol.PrepareResponse(ConcertProtocol.ToBytes(message));

            return(request.Success("OK"));
        }
コード例 #9
0
        public static Messages.Response LocationOpen(Messages.Request request)
        {
            string filepath = request.Parameters.First.ToObject <string>();

            ProcessStartInfo info = new ProcessStartInfo {
                Verb            = "open",
                FileName        = filepath,
                CreateNoWindow  = false,
                UseShellExecute = true,
                WindowStyle     = ProcessWindowStyle.Normal
            };

            using Process process = new Process()
                  {
                      StartInfo = info
                  };
            process.Start();

            return(request.Success(filepath));
        }
コード例 #10
0
        /// <summary>
        ///
        /// </summary>
        private void MainJob()
        {
            // All exceptions until a valid request was read
            // causes a message to be sent
            while (true)
            {
                try {
                    Messages.Request request = WaitForMessage();

                    // State has changed ?
                    if (state != EndpointState.Listening)
                    {
                        break;;
                    }

                    HandleRequest(request);
                } catch (Exception e) {
                    SendException(e);
                    continue;
                }
            }
        }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private Messages.Response ProcessRequest(Messages.Request request)
        {
            Messages.Response response = null;
            if (Handlers.ContainsKey(request.Name))
            {
                Log.Debug("Route request to {0} ", request.Name);

                try {
                    Handlers.TryGetValue(request.Name, out Handler handler);
                    response = handler.Invoke(request);
                } catch (Exception e) {
                    response = request.Failure(e.GetType().Name, e.Message);
                }
            }
            else
            {
                Log.Debug("No handler defined for {0}", request.Name);
                response = request.Unknown(String.Format("Unknown request {0}", request.Name));
            }

            return(response);
        }
コード例 #12
0
        /// <summary>
        /// Handles a request. if that request is async, enqueues in the request queue for later treatment
        /// otherwise process the request immediatly
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private void HandleRequest(Messages.Request request)
        {
            if (request == null)
            {
                Log.Debug("No route : Empty Request body");
                throw new BadNativeMessagingProtocol("D'oh! Invalid request format : Empty request body");
            }

            if (request.Async)
            {
                Log.Debug("Async-Request received: {0}", request.ToString());
                requestQueue.Enqueue(request);
            }
            else
            {
                Log.Debug("Sync-Request received: {0}", request.ToString());

                processRequestMutex.WaitOne();
                Messages.Response response = ProcessRequest(request);
                SendMessage(response);
                processRequestMutex.ReleaseMutex();
            }
        }
コード例 #13
0
        public static Messages.Response CompanionVersion(Messages.Request request)
        {
            Version version = Assembly.GetEntryAssembly().GetName().Version;

            return(request.Success(version.ToString()));
        }
コード例 #14
0
 public static Messages.Response EpaymentSupportedProtocols(Messages.Request request)
 {
     return(request.Success(ConcertProtocol.SupportedProtocols()));
 }
コード例 #15
0
 public static Messages.Response SerialPortsList(Messages.Request request)
 {
     return(request.Success(SerialPort.GetPortNames()));
 }
コード例 #16
0
 public static Messages.Response CompanionExit(Messages.Request request)
 {
     NativeHost.StopService("Receveid request companion.exit");
     return(request.Success(true));
 }
コード例 #17
0
 public static Messages.Response CompanionPause(Messages.Request request)
 {
     Thread.Sleep(5000);
     return(request.Success("Had a nice pause !"));
 }
コード例 #18
0
 public static Messages.Response Echo(Messages.Request request)
 {
     return(request.Success("Companion-echo : " + request.Parameters.ToString()));
 }
コード例 #19
0
 public static Messages.Response Ping(Messages.Request request)
 {
     return(request.Success("companion-pong"));
 }
コード例 #20
0
 public static Messages.Response PrintersList(Messages.Request request)
 {
     return(request.Success(PrinterSettings.InstalledPrinters));
 }