Example #1
0
 public static void Add(ShippingCache model)
 {
     SQLDataAccess.ExecuteNonQuery("Insert into [Order].ShippingCache (ShippingMethodID,ParamHash,Options,Created) VALUES (@ShippingMethodID,@ParamHash,@Options,@Created)",
                                   CommandType.Text,
                                   new SqlParameter("@ShippingMethodID", model.ShippingMethodId),
                                   new SqlParameter("@ParamHash", model.ParamHash),
                                   new SqlParameter("@Options", model.ServerResponse),
                                   new SqlParameter("@Created", DateTime.Now));
 }
Example #2
0
 public static void Update(ShippingCache model)
 {
     SQLDataAccess.ExecuteNonQuery("Update [Order].ShippingCache set ShippingMethodID=@ShippingMethodID, ParamHash = @ParamHash, Options= @Options",
                                   CommandType.Text,
                                   new SqlParameter("@ShippingMethodID", model.ShippingMethodId),
                                   new SqlParameter("@ParamHash", model.ParamHash),
                                   new SqlParameter("@Options", model.ServerResponse),
                                   new SqlParameter("@Created", DateTime.Now));
 }
Example #3
0
        public List <ShippingOption> GetShippingOptions()
        {
            string postData = GetParam();
            var    hash     = postData.GetHashCode();
            string serverResponse;

            ShippingCacheRepositiry.Delete();
            var cached = ShippingCacheRepositiry.Get(ShippingId, hash);

            if (cached != null)
            {
                serverResponse = cached.ServerResponse;
            }
            else
            {
                try
                {
                    ServicePointManager.Expect100Continue = false;
                    var request = WebRequest.Create(Url);
                    request.Method = "POST";

                    byte[] byteArray = Encoding.GetEncoding("windows-1251").GetBytes(postData);

                    // Set the ContentType property of the WebRequest.
                    request.ContentType = "application/x-www-form-urlencoded";
                    // Set the ContentLength property of the WebRequest.
                    request.ContentLength = byteArray.Length;
                    // Get the request stream.
                    using (Stream dataStream = request.GetRequestStream())
                    {
                        // Write the data to the request stream.
                        dataStream.Write(byteArray, 0, byteArray.Length);
                        // Close the Stream object.
                        dataStream.Close();
                    }
                    using (var response = request.GetResponse())
                    {
                        // Get the stream containing all content returned by the requested server.
                        using (var dataStream = response.GetResponseStream())
                        {
                            if (dataStream == null)
                            {
                                return(new List <ShippingOption>());
                            }
                            // Open the stream using a StreamReader for easy access.
                            using (var reader = new StreamReader(dataStream))
                            {
                                // Read the content fully up to the end.
                                serverResponse = reader.ReadToEnd();

                                var model = new ShippingCache
                                {
                                    ServerResponse   = serverResponse,
                                    ShippingMethodId = ShippingId,
                                    ParamHash        = hash
                                };
                                ShippingCacheRepositiry.Add(model);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex);
                    return(null);
                }
            }
            return(ParseAnswer(serverResponse));
        }