private static void Main(string[] args)
        {
            // Declare credentials to be used with the Stage Transaction Request
            string credentialsName   = "TEST MERCHANT";
            string credentialsSiteID = "XXXXXXXX";
            string credentialsKey    = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX";

            // Build Transport request details
            Console.WriteLine("Staging Transaction{0}", Environment.NewLine);
            TransportServiceSoapClient transportServiceSoapClient = new TransportServiceSoapClient();
            TransportRequest           transportRequest           = new TransportRequest
            {
                TransactionType = "sale",
                Amount          = 1.01M,
                ClerkId         = "1",
                OrderNumber     = "1126",
                Dba             = "Test DBA",
                SoftwareName    = "Test Software",
                SoftwareVersion = "1.0",
                TransactionId   = "102911",
                TerminalId      = "01",
                PoNumber        = "PO12345",
                ForceDuplicate  = true,
            };

            // Stage Transaction
            TransportResponse transportResponse = transportServiceSoapClient.CreateTransaction(credentialsName, credentialsSiteID, credentialsKey, transportRequest);
            string            transportKey      = transportResponse.TransportKey;

            Console.WriteLine("TransportKey Received = {0}{1}", transportKey, Environment.NewLine);

            // Close application
            Console.WriteLine("Press Any Key to Close");
            Console.ReadKey();
        }
        public void DecodeResponse()
        {
            CollectionResponseDecoder <Greeting, EmptyRecord> decoder = new CollectionResponseDecoder <Greeting, EmptyRecord>();

            Dictionary <string, object> data = new Dictionary <string, object>()
            {
                {
                    "elements", new List <object>()
                    {
                        new Dictionary <string, object>()
                        {
                            { "id", 123 },
                            { "message", "hello" },
                            { "tone", "FRIENDLY" }
                        },
                        new Dictionary <string, object>()
                        {
                            { "id", 234 },
                            { "message", "world" },
                            { "tone", "SINCERE" }
                        }
                    }
                },
                {
                    "paging", new Dictionary <string, object>()
                    {
                        { "count", 0 },
                        { "start", 0 },
                        { "links", new List <object>()
                          {
                          } }
                    }
                }
            };

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "foo", "bar" }
            };

            HttpResponse      httpResponse      = new HttpResponse(200, headers, null, null);
            TransportResponse transportResponse = new TransportResponse(data, httpResponse);

            CollectionResponse <Greeting, EmptyRecord> response = decoder.DecodeResponse(transportResponse);

            Assert.AreEqual(2, response.elements.Count);
            Assert.AreEqual("bar", response.headers["foo"][0]);

            Assert.IsNotNull(response.paging);
            Assert.IsNull(response.metadata);

            Assert.AreEqual(123, response.elements[0].id);
            Assert.AreEqual("hello", response.elements[0].message);
            Assert.AreEqual(Tone.Symbol.FRIENDLY, response.elements[0].tone.symbol);

            Assert.AreEqual(234, response.elements[1].id);
            Assert.AreEqual("world", response.elements[1].message);
            Assert.AreEqual(Tone.Symbol.SINCERE, response.elements[1].tone.symbol);
        }
Beispiel #3
0
        private static void Main(string[] args)
        {
            // Declare credentials to be used with the Stage Transaction Request
            string credentialsName   = "TEST MERCHANT";
            string credentialsSiteID = "XXXXXXXX";
            string credentialsKey    = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX";
            string ipAddress         = "192.168.0.123";

            // Build Transport request details
            Console.WriteLine("Staging Transaction{0}", Environment.NewLine);
            TransportServiceSoapClient transportServiceSoapClient = new TransportServiceSoapClient();
            TransportRequest           transportRequest           = new TransportRequest
            {
                TransactionType = "sale",
                Amount          = 1.01M,
                ClerkId         = "1",
                OrderNumber     = "1126",
                Dba             = "Test DBA",
                SoftwareName    = "Test Software",
                SoftwareVersion = "1.0",
                TransactionId   = "102911",
                TerminalId      = "01",
                PoNumber        = "PO12345",
                ForceDuplicate  = true,
            };

            // Stage Transaction
            TransportResponse transportResponse = transportServiceSoapClient.CreateTransaction(credentialsName, credentialsSiteID, credentialsKey, transportRequest);
            string            transportKey      = transportResponse.TransportKey;

            Console.WriteLine("TransportKey Received = {0}{1}", transportKey, Environment.NewLine);

            // Initiate transaction with TransportKey
            WebRequest webReq = WebRequest.Create($"http://{ipAddress}:8080/v2/pos?TransportKey={transportKey}&Format=XML");

            using (WebResponse webResp = webReq.GetResponse())
            {
                using (Stream responseStream = webResp.GetResponseStream())
                {
                    // Validate XML to Genius XSD class
                    StreamReader      streamReader      = new StreamReader(responseStream);
                    XmlSerializer     xmlSerializer     = new XmlSerializer(typeof(TransactionResult));
                    TransactionResult transactionResult = (TransactionResult)xmlSerializer.Deserialize(streamReader);
                    Console.WriteLine("Transaction Result: {0}", transactionResult.Status);
                    Console.WriteLine("Amount: {0}", transactionResult.AmountApproved);
                    Console.WriteLine("AuthCode: {0}", transactionResult.AuthorizationCode);
                    Console.WriteLine("Token: {0}", transactionResult.Token);
                    Console.WriteLine("Account Number: {0}", transactionResult.AccountNumber);
                }
            }

            // Close application
            Console.WriteLine("Press Any Key to Close");
            Console.ReadKey();
        }
Beispiel #4
0
        public CollectionResponse <TEntity, TMeta> DecodeResponse(TransportResponse transportResponse)
        {
            List <TEntity>     elements;
            CollectionMetadata paging = null;
            TMeta metadata            = null;

            object output;

            // Decode elements
            if (transportResponse.data.TryGetValue("elements", out output))
            {
                try
                {
                    elements = (output as List <object>)
                               .Select(element => DataUtil.BuildRecord <TEntity>((Dictionary <string, object>)element))
                               .ToList();
                }
                catch
                {
                    throw new InvalidCastException("Error decoding elements from TransportResponse.");
                }
            }
            else
            {
                throw new KeyNotFoundException("Could not find elements in TransportResponse.");
            }

            // Decode paging (optional)
            if (transportResponse.data.TryGetValue("paging", out output))
            {
                try
                {
                    paging = DataUtil.BuildRecord <CollectionMetadata>((Dictionary <string, object>)output);
                }
                catch
                {
                    throw new InvalidCastException("Error decoding paging data from TransportResponse.");
                }
            }

            // Decode metadata (optional)
            if (transportResponse.data.TryGetValue("metadata", out output))
            {
                try
                {
                    metadata = DataUtil.BuildRecord <TMeta>((Dictionary <string, object>)output);
                }
                catch
                {
                    throw new InvalidCastException("Error decoding metadata from TransportResponse.");
                }
            }

            return(new CollectionResponse <TEntity, TMeta>(transportResponse.responseHeaders, transportResponse.status ?? 200, elements, paging, metadata));
        }
        private static void Main(string[] args)
        {
            // Declare credentials to be used with the Stage Transaction Request
            string credentialsName   = "TEST MERCHANT";
            string credentialsSiteID = "XXXXXXXX";
            string credentialsKey    = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX";
            string ipAddress         = "192.168.0.123";

            // Build Transport request details
            Console.WriteLine("Staging Transaction{0}", Environment.NewLine);
            TransportServiceSoapClient transportServiceSoapClient = new TransportServiceSoapClient();
            TransportRequest           transportRequest           = new TransportRequest
            {
                TransactionType = "sale",
                Amount          = 1.01M,
                ClerkId         = "1",
                OrderNumber     = "1126",
                Dba             = "Test DBA",
                SoftwareName    = "Test Software",
                SoftwareVersion = "1.0",
                TransactionId   = "102911",
                TerminalId      = "01",
                PoNumber        = "PO12345",
                ForceDuplicate  = true,
            };

            // Stage Transaction
            TransportResponse transportResponse = transportServiceSoapClient.CreateTransaction(credentialsName, credentialsSiteID, credentialsKey, transportRequest);
            string            transportKey      = transportResponse.TransportKey;

            Console.WriteLine("TransportKey Received = {0}{1}", transportKey, Environment.NewLine);
            // Initiate transaction thread with received TransportKey
            Task <object> transactionResultTask = GeniusRequest($"http://{ipAddress}:8080/v2/pos?TransportKey={transportKey}&Format=XML", typeof(TransactionResult));

            // Wait 5 seconds
            Console.WriteLine("Waiting 5 seconds before canceling transaction");
            Thread.Sleep(5000);
            CancelResult cancelResult = (CancelResult)GeniusRequest($"http://{ipAddress}:8080/pos?Action=Cancel&Format=XML", typeof(CancelResult)).Result;

            Console.WriteLine("Cancel Result: {0}", cancelResult.Status);
            // Wait for Transaction Results then output
            transactionResultTask.Wait();
            TransactionResult transactionResult = (TransactionResult)transactionResultTask.Result;

            Console.WriteLine("Transaction Result: {0}", transactionResult.Status);
            Console.WriteLine("Amount: {0}", transactionResult.AmountApproved);
            Console.WriteLine("AuthCode: {0}", transactionResult.AuthorizationCode);
            Console.WriteLine("Token: {0}", transactionResult.Token);
            Console.WriteLine("Account Number: {0}", transactionResult.AccountNumber);

            // Close application
            Console.WriteLine("Press Any Key to Close");
            Console.ReadKey();
        }
        public EntityResponse <TEntity> DecodeResponse(TransportResponse transportResponse)
        {
            TEntity record = null;
            Dictionary <string, object> dataMap = transportResponse.data;

            if (dataMap != null)
            {
                record = DataUtil.BuildRecord <TEntity>(dataMap);
            }
            return(new EntityResponse <TEntity>(transportResponse.responseHeaders, transportResponse.status ?? 200, record));
        }
Beispiel #7
0
        public TResponse RestRequestSync <TResponse>(Request <TResponse> request) where TResponse : Response
        {
            HttpRequest       httpRequest       = ClientUtil.BuildHttpRequest(request, urlPrefix);
            HttpResponse      httpResponse      = transportClient.RestRequestSync(httpRequest);
            TransportResponse transportResponse = new TransportResponse(httpResponse);

            if (transportResponse.hasError())
            {
                throw transportResponse.getError().error;
            }

            return(request.responseDecoder.DecodeResponse(transportResponse));
        }
Beispiel #8
0
        public ClientErrorResponse DecodeResponse(TransportResponse transportResponse)
        {
            ErrorResponse data = null;
            Dictionary <string, object> dataMap = transportResponse.data;

            if (dataMap != null && transportResponse.headers.ContainsKey(RestConstants.kHeaderRestliErrorResponse))
            {
                data = DataUtil.BuildRecord <ErrorResponse>(dataMap);
                transportResponse.error.details = data;
                transportResponse.status        = data.status;
            }
            return(new ClientErrorResponse(transportResponse.responseHeaders, transportResponse.status ?? RestConstants.httpStatusInternalServerError, transportResponse.error));
        }
        public CreateResponse <TKey, TEntity> DecodeResponse(TransportResponse transportResponse)
        {
            // Decode key
            TKey   key = default(TKey);
            string headerString;

            transportResponse.headers.TryGetValue(RestConstants.kHeaderRestliId, out headerString);
            if (headerString != null)
            {
                key = DataUtil.CoerceString <TKey>(headerString);
            }

            // Possible future support for returning entity in addition to just the key
            TEntity record = null;

            return(new CreateResponse <TKey, TEntity>(transportResponse.responseHeaders, transportResponse.status ?? 200, key, record));
        }
        public void DecodeResponse_EnumKey()
        {
            CreateResponseDecoder <TestEnum, Greeting> decoder = new CreateResponseDecoder <TestEnum, Greeting>();

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "foo", "bar" },
                { RestConstants.kHeaderRestliId, "SYMBOL_1" }
            };

            HttpResponse      httpResponse      = new HttpResponse(RestConstants.httpStatusCreated, headers, null, null);
            TransportResponse transportResponse = new TransportResponse(null, httpResponse);

            CreateResponse <TestEnum, Greeting> response = decoder.DecodeResponse(transportResponse);

            Assert.AreEqual(TestEnum.Symbol.SYMBOL_1, response.key.symbol);
            Assert.AreEqual("SYMBOL_1", response.headers[RestConstants.kHeaderRestliId][0]);
            Assert.AreEqual("bar", response.headers["foo"][0]);
            Assert.AreEqual(RestConstants.httpStatusCreated, response.status);
        }
        public void DecodeResponse_PrimitiveKey()
        {
            CreateResponseDecoder <int, Greeting> decoder = new CreateResponseDecoder <int, Greeting>();

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "foo", "bar" },
                { RestConstants.kHeaderRestliId, "123" }
            };

            HttpResponse      httpResponse      = new HttpResponse(RestConstants.httpStatusCreated, headers, null, null);
            TransportResponse transportResponse = new TransportResponse(null, httpResponse);

            CreateResponse <int, Greeting> response = decoder.DecodeResponse(transportResponse);

            Assert.AreEqual(123, response.key);
            Assert.AreEqual("123", response.headers[RestConstants.kHeaderRestliId][0]);
            Assert.AreEqual("bar", response.headers["foo"][0]);
            Assert.AreEqual(RestConstants.httpStatusCreated, response.status);
        }
Beispiel #12
0
        private async Task <IActionResult> ProcessMessage(ProcessingContext ctx)
        {
            var response    = new TransportResponse();
            var headers     = ctx.MessageHeaders;
            var dbTokenData = ctx.CurrentDbTokenData;

            IList <TransferedPacketResponse> responses = new List <TransferedPacketResponse>();
            // при изменении токена надо конфиги по-новой
            IReadOnlyCollection <ConfigurationRequestDataItem> configurationsOnAgent = new List <ConfigurationRequestDataItem>();

            if (headers.DbToken != dbTokenData.DbToken)
            {
                // TODO удалять пакеты для старого токена
                response.SetDbTokenData(dbTokenData);
            }
            else
            {
                // сохраняем пакеты
                var savePacketsResult = await this.packageRequestParser.ParseBodyAndSavePackets(headers, this.Request);

                configurationsOnAgent = savePacketsResult.ConfigurationsStats;
                response.SetPacketResponses(savePacketsResult.TransferedPackets);
            }

            // добавляем "динамическую" конфигурацию - конфиг аннотаций, развёртываний и тп
            var configurations = this.agentConfigurationsHandler
                                 .GetConfigurationResponses(headers, configurationsOnAgent);

            // для dispose-а потоков конфигураций по окончании запроса
            foreach (var conf in configurations)
            {
                this.HttpContext.Response.RegisterForDispose(conf.Stream);
            }

            response.SetConfigurations(configurations);

            return(this.Ok(response));
        }
Beispiel #13
0
        public void DecodeResponse()
        {
            ErrorResponseDecoder decoder = new ErrorResponseDecoder();

            Dictionary <string, object> data = new Dictionary <string, object>()
            {
                { "exceptionClass", "com.linkedin.restli.server.RestLiServiceException" },
                { "message", "Example message" },
                { "stackTrace", "Example stack trace" },
                { "status", 400 }
            };

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { RestConstants.kHeaderRestliErrorResponse, "true" }
            };

            RestliException   exception         = new RestliException("Server returned Rest.li error response", null);
            HttpResponse      httpResponse      = new HttpResponse(RestConstants.httpStatusInternalServerError, headers, null, exception);
            TransportResponse transportResponse = new TransportResponse(data, httpResponse);

            ClientErrorResponse response = decoder.DecodeResponse(transportResponse);

            ErrorResponse error = response.error.details;

            Assert.IsNotNull(error);

            Assert.IsTrue(error.hasExceptionClass);
            Assert.IsTrue(error.hasMessage);
            Assert.IsTrue(error.hasStackTrace);
            Assert.IsTrue(error.hasStatus);

            Assert.AreEqual("com.linkedin.restli.server.RestLiServiceException", error.exceptionClass);
            Assert.AreEqual("Example message", error.message);
            Assert.AreEqual("Example stack trace", error.stackTrace);
            Assert.AreEqual(400, error.status);
        }
Beispiel #14
0
        public void DecodeResponse()
        {
            EntityResponseDecoder <Greeting> decoder = new EntityResponseDecoder <Greeting>();

            Dictionary <string, object> data = new Dictionary <string, object>()
            {
                { "id", 123 },
                { "message", "hello" },
                { "tone", "FRIENDLY" }
            };
            TransportResponse transportResponse = new TransportResponse(data, null);

            EntityResponse <Greeting> response = decoder.DecodeResponse(transportResponse);

            Greeting g = response.element;

            Assert.IsTrue(g.hasId);
            Assert.IsTrue(g.hasMessage);
            Assert.IsTrue(g.hasTone);

            Assert.AreEqual(123, g.id);
            Assert.AreEqual("hello", g.message);
            Assert.AreEqual(Tone.Symbol.FRIENDLY, g.tone.symbol);
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            GeniusMethods gMethods = new GeniusMethods();
            //Ask user to input MerchantWARE Credentials
            //Console.WriteLine("Enter MerchantWARE credentials - Name, SiteID, Key" + Environment.NewLine);
            //Console.WriteLine("Press Enter after each value" + Environment.NewLine);

            //Declare credentials entered as String, to be used with the Stage Transaction Request
            string credentialsName   = "mltest";                        //Console.ReadLine();
            string credentialsSiteID = "11111111";                      // Console.ReadLine();
            string credentialsKey    = "11111-11111-11111-11111-11111"; //Console.ReadLine();

            //Console.WriteLine("" + Environment.NewLine);

            //Request for TransportKey
            Console.WriteLine("Staging Transaction" + Environment.NewLine);
            TransportServiceSoapClient TransportSoap = new TransportServiceSoapClient();
            TransportRequest           TransportReq  = new TransportRequest();
            TransportResponse          TransportRes  = new TransportResponse();

            //TransportRequest Object Parameters
            TransportReq.TransactionType = "sale";
            TransportReq.Amount          = 1.01M;
            TransportReq.ClerkId         = "1";
            TransportReq.OrderNumber     = "1126";
            TransportReq.Dba             = "Test DBA";
            TransportReq.SoftwareName    = "Test Software";
            TransportReq.SoftwareVersion = "1.0";
            TransportReq.TransactionId   = "102911";
            TransportReq.TerminalId      = "01";
            TransportReq.PoNumber        = "PO12345";
            TransportReq.ForceDuplicate  = true;

            //Stage Transaction Request Parameters
            TransportRes = TransportSoap.CreateTransaction(credentialsName, credentialsSiteID, credentialsKey, TransportReq);

            //Receive TransportKey, Declare as String, display TransportKey on-screen
            string TPKey = TransportRes.TransportKey;

            Console.WriteLine("TransportKey Received = " + TPKey + Environment.NewLine);

            //Ask user to input IP Address of Genius
            Console.WriteLine("Enter Genius IP Address and press Enter" + Environment.NewLine);
            string ipAddress = Console.ReadLine();

            Console.WriteLine(lineBreak);

            //Initiate transaction
            GeniusThreader(ipAddress, TPKey, "TransportKey", "XML");
            Thread.Sleep(200);
            GeniusThreader(ipAddress, "", "Status", "XML");
            Thread.Sleep(200);
            GeniusThreader(ipAddress, "", "Status", "XML");

            //Default function to status
            string function = "status";

            //Start loop for additional functions
            while (true)
            {
                //Request function from user. Escape the loop on a blank input
                function = Console.ReadLine();
                if (function != "")
                {
                    GeniusThreader(ipAddress, TPKey, function, "XML");
                }
                else
                {
                    break;
                }
            }

            //Close application
            Console.WriteLine("Press Enter to Close");
            Console.ReadKey();
        }