コード例 #1
0
ファイル: HelperJson.cs プロジェクト: olofszymczak/EvilInc
        /// <summary>
        /// Send Customer to Url via Post
        /// </summary>
        /// <param name="c"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        static public CustomerReponse sendCustomer(Customer c, string url)
        {
            string data = Helper.HelperJson.SerializeCustomer(c);

            var response = sendPost(data, url);

            return DeSerializeCustomerResponse(response.Result);
        }
コード例 #2
0
ファイル: TestEvilAPI.cs プロジェクト: olofszymczak/EvilInc
        public void TestMethodSendCustomer()
        {
            var customer = new Customer()
            {
                property = "Olof Szymczak",
                action = "order created",
                customer = "Christene Cruz",
                value = 100,
                file = "test.csv"
            };

            var customerResponse = EvilInc.Helper.HelperJson.sendCustomer(customer, Constants.URL + Constants.RESOURCE_UPLOAD);
            Assert.AreEqual("", customerResponse);
        }
コード例 #3
0
        public void TestMethodSerializeCustomer()
        {
            var customer = new Customer()
            {
                property = "testp",
                action = "add",
                customer = "customer1",
                value = 100,
                file = "test.csv"
            };

            var result = EvilInc.Helper.HelperJson.SerializeCustomer(customer);

            string expected = "{\"action\":\"add\",\"customer\":\"customer1\",\"file\":\"test.csv\",\"property\":\"testp\",\"value\":100}";
            Assert.AreEqual(expected, result);
        }
コード例 #4
0
ファイル: HelperJson.cs プロジェクト: olofszymczak/EvilInc
        /// <summary>
        /// Serialize Customer to JSON string
        /// </summary>
        /// <param name="c"></param>
        /// <returns>Returns JSON representation of customer</returns>
        static public string SerializeCustomer(Customer c)
        {
            string result = "";
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Customer));
            using (MemoryStream ms = new MemoryStream())
            {
                js.WriteObject(ms, c);

                ms.Position = 0;
                using (StreamReader sr = new StreamReader(ms))
                {
                    result = sr.ReadToEnd();
                }
            }
            return result;
        }
コード例 #5
0
ファイル: Default.aspx.cs プロジェクト: olofszymczak/EvilInc
        private Customer buildCustomer(string[] values, string fileName)
        {
            var customer = new Customer();

            if (String.IsNullOrEmpty(values[0]))
            {
                customer.Added = false;
                customer.Errors = Constants.NO_CUSTOMER;
            }

            customer.property = Constants.PROPERTY;

            customer.customer = values[0];
            customer.action = Constants.ACTION;

            int value = 0;

            if (values.Length == 2)
            {
                customer.Actualvalue = values[1];

                if (int.TryParse(values[1], out value))
                {
                    customer.value = value;
                }
                else
                {
                    customer.Added = false;

                    if (!String.IsNullOrEmpty(customer.Errors))
                    {
                        customer.Errors += " " + Constants.INVALID_VALUE;
                    }
                    else
                    {
                        customer.Errors = Constants.INVALID_VALUE;
                    }
                }

            }

            customer.file = fileName;

            return customer;
        }
コード例 #6
0
ファイル: Default.aspx.cs プロジェクト: olofszymczak/EvilInc
        private void loadCustomer(Customer c)
        {
            var customerResponse = HelperJson.sendCustomer(c, Constants.URL + Constants.RESOURCE_UPLOAD);

            if(customerResponse.added.ToLower() == "true")
            {
                c.Added = true;

                if (customerResponse.hash.Length != 32)
                {
                    c.Hash = customerResponse.hash.Substring(0,100) + "...";
                    c.Errors = "Invalid hash has been returned by the API";
                }
                else
                {
                    c.Hash = customerResponse.hash;
                    c.Errors = "";
                }
            }
            else
            {
                c.Added = false;
                if (customerResponse.errors != null && customerResponse.errors.Length > 0)
                {
                    c.Errors = String.Join(", ", customerResponse.errors);
                }
            }
        }
コード例 #7
0
ファイル: Default.aspx.cs プロジェクト: olofszymczak/EvilInc
        private void checkCustomerExists(Customer c)
        {
            var customerGet = HelperJson.GetCustomer(c.Hash, Constants.URL + Constants.RESOURCE_CHECK);

            if (customerGet.errors != null && customerGet.errors.Length > 0)
            {
                c.Errors = String.Join(", ", customerGet.errors);
                c.CustomerExists = false;
            }
            else
            {
                c.CustomerExists = true;
            }
        }