public void DeleteCookie(Cookie cookie)
        {
            var nc = ToNativeCookie(cookie);

            //cookieManager.CookieStore.Remove(new URI(nc.Domain), nc);
            CookieStore.Remove(new URI(nc.Domain), nc);
        }
示例#2
0
        /// <summary>
        /// Build a pipeline of HttpMessageHandlers.
        /// </summary>
        internal HttpMessageHandler BuildHandlerPipeline(CookieStore store, IRetryStrategy retryStrategy)
        {
            #if __MOBILE__
            var handler = new HttpClientHandler {
                CookieContainer = store,
                UseCookies      = true
            };
            #else
            var handler = new WebRequestHandler {
                CookieContainer  = store,
                UseCookies       = true,
                ReadWriteTimeout = (int)SocketTimeout.TotalMilliseconds
            };
            #endif

            if (handler.SupportsAutomaticDecompression)
            {
                handler.AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate;
            }

            var authHandler = new DefaultAuthHandler(handler, store, SocketTimeout);
            if (retryStrategy == null)
            {
                return(authHandler);
            }

            var retryHandler = new TransientErrorRetryHandler(authHandler, retryStrategy);
            return(retryHandler);
        }
示例#3
0
        public void TestSetCookieSessionOnly()
        {
            var cookieStore = new CookieStore(database, "cookie_store_unit_test");

            Assert.AreEqual(0, cookieStore.Count);

            // No expires date specified for a cookie v0:
            var cookie1 = new Cookie("whitechoco", "sweet", "/", "mycookie.com");

            Assert.AreEqual(DateTime.MinValue, cookie1.Expires);
            cookieStore.Add(cookie1);

            // No max age specified for a cookie v1:
            var cookie2 = new Cookie("oatmeal_raisin", "sweet", "/", ".mycookie.com")
            {
                Version = 1
            };

            Assert.AreEqual(DateTime.MinValue, cookie2.Expires);
            cookieStore.Add(cookie2);

            Assert.AreEqual(2, cookieStore.Count);
            var cookies = cookieStore.GetCookies(new Uri("http://mycookie.com"));

            CollectionAssert.AreEquivalent(new[] { cookie1, cookie2 }, cookies);

            cookieStore = new CookieStore(database, "cookie_store_unit_test");
            Assert.AreEqual(0, cookieStore.Count);
        }
        /// <summary>
        /// Build a pipeline of HttpMessageHandlers.
        /// </summary>
        internal HttpMessageHandler BuildHandlerPipeline(CookieStore store, IRetryStrategy retryStrategy)
        {
            var handler = new WebRequestHandler {
                CookieContainer  = store,
                UseCookies       = true,
                ReadWriteTimeout = (int)SocketTimeout.TotalMilliseconds
            };

            // For now, we are not using the client cert for identity verification, just to
            // satisfy Mono so it doesn't matter if the user doesn't choose it.
            //handler.ClientCertificates.Add(SSLGenerator.GetOrCreateClientCert());

            if (handler.SupportsAutomaticDecompression)
            {
                handler.AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate;
            }

            var authHandler = new DefaultAuthHandler(handler, store, SocketTimeout);

            if (retryStrategy == null)
            {
                return(authHandler);
            }

            var retryHandler = new TransientErrorRetryHandler(authHandler, retryStrategy);

            return(retryHandler);
        }
        public CouchbaseLiteHttpClient GetHttpClient(CookieStore cookieStore, IRetryStrategy retryStrategy)
#endif
        {
#if __ANDROID__
            var authHandler = BuildHandlerPipeline(cookieStore, retryStrategy, selfSignedCert);
#else
            var authHandler = BuildHandlerPipeline(cookieStore, retryStrategy);
#endif

            // As the handler will not be shared, client.Dispose() needs to be
            // called once the operation is done to release the unmanaged resources
            // and disposes of the managed resources.
            var client = new HttpClient(authHandler, true)
            {
                Timeout = ReplicationOptions.DefaultRequestTimeout
            };

            client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", String.Format("CouchbaseLite/{0} ({1})", Replication.SyncProtocolVersion, Manager.VersionString));
            client.DefaultRequestHeaders.Connection.Add("keep-alive");

            var transientHandler   = authHandler as TransientErrorRetryHandler;
            var defaultAuthHandler = default(DefaultAuthHandler);
            if (transientHandler != null)
            {
                defaultAuthHandler = transientHandler.InnerHandler as DefaultAuthHandler;
            }
            else
            {
                defaultAuthHandler = authHandler as DefaultAuthHandler;
            }

            return(new CouchbaseLiteHttpClient(client, defaultAuthHandler));
        }
示例#6
0
        public void TestCreateHelloWorldCookieForFlowSteps()
        {
            CookieStore store  = new CookieStore();
            var         cookie = store.CreateHelloWorldCookie();

            TestFlowSteps(cookie);
        }
示例#7
0
        /// <summary>
        /// Initializes a Manager that stores Databases in the given directory.
        /// </summary>
        /// <param name="directoryFile"><see cref="System.IO.DirectoryInfo"/> object for initializing the Manager object.</param>
        /// <param name="options">Option flags for initialization.</param>
        /// <exception cref="T:System.IO.DirectoryNotFoundException">Thrown when there is an error while accessing or creating the given directory.</exception>
        public Manager(DirectoryInfo directoryFile, ManagerOptions options)
        {
            Log.I(Tag, "Starting Manager version: " + VersionString);

            this.directoryFile = directoryFile;
            this.options       = options ?? DefaultOptions;
            this.databases     = new Dictionary <string, Database>();
            this.replications  = new List <Replication>();

            //create the directory, but don't fail if it already exists
            if (!directoryFile.Exists)
            {
                directoryFile.Create();
                directoryFile.Refresh();
                if (!directoryFile.Exists)
                {
                    throw new  DirectoryNotFoundException("Unable to create directory " + directoryFile);
                }
            }

            UpgradeOldDatabaseFiles(directoryFile);

            var scheduler = options.CallbackScheduler;

            CapturedContext = new TaskFactory(scheduler);
            workExecutor    = new TaskFactory(new SingleTaskThreadpoolScheduler());
            Log.D(Tag, "New Manager uses a scheduler with a max concurrency level of {0}".Fmt(workExecutor.Scheduler.MaximumConcurrencyLevel));

            this.NetworkReachabilityManager = new NetworkReachabilityManager();

            SharedCookieStore = new CookieStore(this.directoryFile.FullName);
        }
        public CouchbaseLiteHttpClient GetHttpClient(CookieStore cookieStore, IRetryStrategy strategy)
#endif
        {
            var mockHttpClient = new HttpClient(HttpHandler);

            return(new CouchbaseLiteHttpClient(mockHttpClient, null));
        }
        public ActionResult DeleteCartItem(int ID, string Url)
        {
            TimeSpan cookieexpire = new TimeSpan(1000, 0, 0, 0);

            CookieStore.DeleteCookieItem(cookiekey, ID, cookieexpire);
            return(RedirectToAction(Url, "UserAccount"));
        }
        private void AddRequestHeaders(HttpRequestMessage request)
        {
            foreach (var requestHeaderKey in RequestHeaders.Keys)
            {
                if (requestHeaderKey.ToLowerInvariant() == "cookie")
                {
                    Cookie cookie;
                    var    cookieStr = RequestHeaders[requestHeaderKey];
                    if (!CookieParser.TryParse(cookieStr, request.RequestUri.Host, out cookie))
                    {
                        Log.To.Sync.W(Tag, "Invalid cookie string received, {0}",
                                      new SecureLogString(cookieStr, LogMessageSensitivity.Insecure));
                    }
                    else
                    {
                        try {
                            CookieStore.Add(cookie);
                        } catch (CookieException e) {
                            var headerValue = new SecureLogString(cookieStr, LogMessageSensitivity.Insecure);
                            Log.To.Sync.W(Tag, $"Invalid cookie string received, {headerValue}", e);
                        }
                    }

                    request.Headers.Add("Cookie", CookieStore.GetCookieHeader(request.RequestUri));
                    continue;
                }


                request.Headers.Add(requestHeaderKey, RequestHeaders.Get(requestHeaderKey));
            }
        }
示例#11
0
        public CouchbaseLiteHttpClientFactory(CookieStore cookieStore)
        {
            this.cookieStore = cookieStore;
            Headers          = new ConcurrentDictionary <string, string>();

            // Disable SSL 3 fallback to mitigate POODLE vulnerability.
            ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;

            //
            // Source: http://msdn.microsoft.com/en-us/library/office/dd633677(v=exchg.80).aspx
            // ServerCertificateValidationCallback returns true if either of the following criteria are met:
            // The certificate is valid and signed with a valid root certificate.
            // The certificate is self-signed by the server that returned the certificate.
            //
            ServicePointManager.ServerCertificateValidationCallback =
                (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
            {
                // If the certificate is a valid, signed certificate, return true.
                if (sslPolicyErrors == SslPolicyErrors.None)
                {
                    return(true);
                }

                // If there are errors in the certificate chain, look at each error to determine the cause.
                if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) != 0)
                {
                    if (chain != null && chain.ChainStatus != null)
                    {
                        foreach (X509ChainStatus status in chain.ChainStatus)
                        {
                            if ((certificate.Subject == certificate.Issuer) &&
                                (status.Status == X509ChainStatusFlags.UntrustedRoot))
                            {
                                // Self-signed certificates with an untrusted root are valid.
                                continue;
                            }
                            else
                            {
                                if (status.Status != X509ChainStatusFlags.NoError)
                                {
                                    // If there are any other errors in the certificate chain, the certificate is invalid,
                                    // so the method returns false.
                                    return(false);
                                }
                            }
                        }
                    }

                    // When processing reaches this line, the only errors in the certificate chain are
                    // untrusted root errors for self-signed certificates. These certificates are valid
                    // for default Exchange server installations, so return true.
                    return(true);
                }
                else
                {
                    // In all other cases, return false.
                    return(false);
                }
            };
        }
示例#12
0
        public void TestMigration()
        {
            var cookie1 = new Cookie {
                Name    = "whitechoco",
                Domain  = ".mycookie.com",
                Path    = "/",
                Value   = "sweet",
                Expires = DateTime.Now.AddSeconds(3600)
            };

            var cookie2 = new Cookie {
                Name    = "oatmeal_raisin",
                Domain  = ".mycookie.com",
                Path    = "/",
                Value   = "sweet",
                Expires = DateTime.Now.AddSeconds(3600),
                Version = 1
            };

            const string LocalCheckpointCookiesKey = "cbl_cookie_storage_xxxxx";

            database.PutLocalCheckpointDoc(LocalCheckpointCookiesKey, new[] { cookie1, cookie2 });
            var cookies = database.GetLocalCheckpointDocValue(LocalCheckpointCookiesKey).AsList <Cookie>();

            Assert.AreEqual(2, cookies.Count);

            var cookieStore = new CookieStore(database, null);

            var newCookies = cookieStore.GetCookies(new Uri("http://mycookie.com"));

            Assert.AreEqual(2, cookieStore.Count);
            Assert.AreEqual(cookie1, newCookies[0]);
            Assert.AreEqual(cookie2, newCookies[1]);
            Assert.IsNull(database.GetLocalCheckpointDocValue(LocalCheckpointCookiesKey));
        }
        public void SetCookie(Cookie cookie)
        {
            var nc = ToNativeCookie(cookie);

            //cookieManager.CookieStore.Add(new URI(nc.Domain), nc);
            CookieStore.Add(new URI(nc.Domain), nc);
        }
        public IList <Square.OkHttp3.Cookie> LoadForRequest(Square.OkHttp3.HttpUrl p0)
        {
            var cookies = new List <Square.OkHttp3.Cookie>();

            var nc = CookieStore.Get(p0.Uri());

            foreach (var cookie in nc)
            {
                if (PathMatches(p0.EncodedPath(), cookie.Path))
                {
                    var builder = new Square.OkHttp3.Cookie.Builder();
                    builder.Name(cookie.Name)
                    .Value(cookie.Value)
                    .Domain(cookie.Domain)
                    .Path(cookie.Path);
                    if (cookie.Secure)
                    {
                        builder.Secure();
                    }

                    cookies.Add(builder.Build());
                }
            }

            return(cookies);
        }
示例#15
0
        /// <summary>
        /// Initializes a Manager that stores Databases in the given directory.
        /// </summary>
        /// <param name="directoryFile"><see cref="System.IO.DirectoryInfo"/> object for initializing the Manager object.</param>
        /// <param name="options">Option flags for initialization.</param>
        /// <exception cref="T:System.IO.DirectoryNotFoundException">Thrown when there is an error while accessing or creating the given directory.</exception>
        public Manager(DirectoryInfo directoryFile, ManagerOptions options)
        {
            Log.I(TAG, "Starting Manager version: " + VersionString);

            this.directoryFile = directoryFile;
            this.options       = options ?? DefaultOptions;
            this.databases     = new Dictionary <string, Database>();
            this.replications  = new List <Replication>();

            //create the directory, but don't fail if it already exists
            if (!directoryFile.Exists)
            {
                directoryFile.Create();
                directoryFile.Refresh();
                if (!directoryFile.Exists)
                {
                    throw new  DirectoryNotFoundException("Unable to create directory " + directoryFile);
                }
            }

            UpgradeOldDatabaseFiles(directoryFile);

            #if __IOS__
            Foundation.NSString protection;
            switch (options.FileProtection & Foundation.NSDataWritingOptions.FileProtectionMask)
            {
            case Foundation.NSDataWritingOptions.FileProtectionNone:
                protection = Foundation.NSFileManager.FileProtectionNone;
                break;

            case Foundation.NSDataWritingOptions.FileProtectionComplete:
                protection = Foundation.NSFileManager.FileProtectionComplete;
                break;

            case Foundation.NSDataWritingOptions.FileProtectionCompleteUntilFirstUserAuthentication:
                protection = Foundation.NSFileManager.FileProtectionCompleteUntilFirstUserAuthentication;
                break;

            default:
                protection = Foundation.NSFileManager.FileProtectionCompleteUnlessOpen;
                break;
            }

            var attributes = new Foundation.NSDictionary(Foundation.NSFileManager.FileProtectionKey, protection);
            Foundation.NSError error;
            Foundation.NSFileManager.DefaultManager.SetAttributes(attributes, directoryFile.FullName, out error);
            #endif

            var scheduler = options.CallbackScheduler;
            CapturedContext = new TaskFactory(scheduler);
            workExecutor    = new TaskFactory(new SingleTaskThreadpoolScheduler());
            Log.D(TAG, "New Manager uses a scheduler with a max concurrency level of {0}".Fmt(workExecutor.Scheduler.MaximumConcurrencyLevel));

            this.NetworkReachabilityManager = new NetworkReachabilityManager();

            SharedCookieStore = new CookieStore(this.directoryFile.FullName);
            StorageType       = "SQLite";
            Shared            = new SharedState();
        }
 public void SetCookies(IEnumerable <Cookie> cookies)
 {
     foreach (var nc in cookies.Select(ToNativeCookie))
     {
         //cookieManager.CookieStore.Add(new URI(nc.Domain), nc);
         CookieStore.Add(new URI(nc.Domain), nc);
     }
 }
示例#17
0
        //
        // GET: /Cart/
        public ActionResult Index()
        {
            var productList         = _productBusiness.GetListWT();
            var assignedProductList = new List <AddToCart>();
            var currentUserId       = Convert.ToInt32(GlobalUser.getGlobalUser().UserId);

            if (currentUserId > 0)
            {
                assignedProductList = _AddToCartBusiness.GetListWT(c => c.UserId == currentUserId);
            }
            else
            {
                CookieStore mycookie = new CookieStore();
                var         products = mycookie.GetCookie(Enumerator.CustomerAction.AddToCart.ToString());
                if (!string.IsNullOrEmpty(products))
                {
                    assignedProductList = (from p in products.Split(',')
                                           select new AddToCart
                    {
                        ProductId = Convert.ToInt32(p.Split('~')[0]),
                        Quantity = Convert.ToInt32(p.Split('~')[1]),
                        Size = Convert.ToInt32(p.Split('~')[2]),
                        Attributes = p.Split('~')[3]
                    }).ToList();
                }
            }

            var imgList       = _ImageBusiness.GetListWT();
            var vmProductList = (from c in productList
                                 join ap in assignedProductList
                                 on c.ProductID equals ap.ProductId
                                 select new CartWishlistViewModel
            {
                ProductID = c.ProductID,
                ProductCode = c.ProductCode,
                ProductName = c.ProductName,
                TokenKey = c.TokenKey,
                ShortDescription = c.ShortDescription,
                Price = _productBusiness.GetSelectedPrice(c.ProductID, ap.Size.Value, ap.Attributes),
                DiscountPercent = c.DiscountPercent,
                DiscountedPrice = Math.Round(_productBusiness.GetSelectedPrice(c.ProductID, ap.Size.Value, ap.Attributes) - Decimal.Divide(c.DiscountPercent ?? 0, 100) * _productBusiness.GetSelectedPrice(c.ProductID, ap.Size.Value, ap.Attributes)),
                SizeId = ap.Size.Value,
                Size = _productBusiness.GetSizeName(c.ProductID, ap.Size.Value),
                AttributeId = ap.Attributes,
                Attributes = _productBusiness.GetAttributes(c.ProductID, ap.Attributes),
                quantity = ap.Quantity,

                ImageList = (from il in imgList
                             where (il.ProductId == c.ProductID)
                             select new ImageViewModel
                {
                    ProductId = c.ProductID,
                    Images = "/ProductImage/" + il.Images
                }).ToList()
            }).ToList();

            return(View(vmProductList));
        }
示例#18
0
        public void TestSaveEmptyCookieStore()
        {
            var cookieStore = new CookieStore(GetCookiesDirectory().FullName);

            Assert.AreEqual(0, cookieStore.Count);
            cookieStore.Save();

            cookieStore = new CookieStore(GetCookiesDirectory().FullName);
            Assert.AreEqual(0, cookieStore.Count);
        }
示例#19
0
        public void TestSaveEmptyCookieStore()
        {
            var cookieStore = new CookieStore(database, "cookie_store_unit_test");

            Assert.AreEqual(0, cookieStore.Count);
            cookieStore.Save();

            cookieStore = new CookieStore(database, "cookie_store_unit_test");
            Assert.AreEqual(0, cookieStore.Count);
        }
        public MockHttpClientFactory(DirectoryInfo cookieStoreDirectory)
        {
            cookieStore = new CookieStore(cookieStore != null
                ? cookieStoreDirectory.FullName
                : null);
            HttpHandler = new MockHttpRequestHandler();
            HttpHandler.CookieContainer = cookieStore;
            HttpHandler.UseCookies      = true;

            Headers = new Dictionary <string, string>();
        }
示例#21
0
        public void TestDeleteCookie()
        {
            var cookieStore = new CookieStore(database, "cookie_store_unit_test");

            Assert.AreEqual(0, cookieStore.Count);

            var cookie1 = new Cookie("whitechoco", "sweet", "/", "mycookie.com")
            {
                Expires = DateTime.Now.AddSeconds(3600),
            };

            cookieStore.Add(cookie1);

            var cookie2 = new Cookie("oatmeal_raisin", "sweet", "/", "mycookie.com")
            {
                Expires = DateTime.Now.AddSeconds(3600),
            };

            cookieStore.Add(cookie2);

            var cookie3 = new Cookie("darkchoco", "sweet", "/", "mycookie.com")
            {
                Expires = DateTime.Now.AddSeconds(3600),
            };

            cookieStore.Add(cookie3);

            Assert.AreEqual(3, cookieStore.Count);
            var cookies = cookieStore.GetCookies(new Uri("http://mycookie.com"));

            CollectionAssert.Contains(cookies, cookie1);
            CollectionAssert.Contains(cookies, cookie2);
            CollectionAssert.Contains(cookies, cookie3);

            cookieStore.Delete(new Uri("http://mycookie.com"), cookie2.Name);
            Assert.AreEqual(2, cookieStore.Count);
            cookies = cookieStore.GetCookies(new Uri("http://mycookie.com"));
            CollectionAssert.Contains(cookies, cookie1);
            CollectionAssert.Contains(cookies, cookie3);

            cookieStore = new CookieStore(database, "cookie_store_unit_test");
            Assert.AreEqual(2, cookieStore.Count);
            cookies = cookieStore.GetCookies(new Uri("http://mycookie.com"));
            CollectionAssert.Contains(cookies, cookie1);
            CollectionAssert.Contains(cookies, cookie3);

            cookieStore.Delete(new Uri("http://mycookie.com"), cookie1.Name);
            cookieStore.Delete(new Uri("http://mycookie.com"), cookie3.Name);
            Assert.AreEqual(0, cookieStore.Count);

            cookieStore = new CookieStore(database, "cookie_store_unit_test");
            Assert.AreEqual(0, cookieStore.Count);
        }
 public LogReplayAssociations(List <LogReplayAssociation> LogAssoList, CookieStore CookSt)
 {
     this.Cookies = CookSt;
     foreach (LogReplayAssociation Asso in LogAssoList)
     {
         Associations[Asso.ReplayAssociation.DestinationLog.LogId] = Asso;
         if (Asso.OriginalAssociation != null)
         {
             AssociationsByOriginalId[Asso.OriginalAssociation.DestinationLog.LogId] = Asso;
         }
     }
 }
        public MockHttpClientFactory(DirectoryInfo cookieStoreDirectory, bool defaultFail = true)
        {
            cookieStore = new CookieStore(cookieStoreDirectory != null
                ? cookieStoreDirectory.FullName
                : null);
            HttpHandler = new MockHttpRequestHandler(defaultFail);
            HttpHandler.CookieContainer        = cookieStore;
            HttpHandler.UseCookies             = true;
            HttpHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;

            Headers = new Dictionary <string, string>();
        }
        public void SaveFromResponse(Square.OkHttp3.HttpUrl p0, IList <Square.OkHttp3.Cookie> p1)
        {
            foreach (var cookie in p1)
            {
                var nc = new HttpCookie(cookie.Name(), cookie.Value());
                nc.Domain = cookie.Domain();
                nc.Path   = cookie.Path();
                nc.Secure = cookie.Secure();

                CookieStore.Add(p0.Uri(), nc);
            }
        }
        internal HttpMessageHandler BuildHandlerPipeline(CookieStore store, IRetryStrategy retryStrategy)
#endif
        {
#if __MOBILE__
            var handler = default(HttpClientHandler);
#if __ANDROID__
            if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.Lollipop)
            {
                handler = new Xamarin.Android.Net.AndroidClientHandler
                {
                    CookieContainer = store,
                    UseCookies      = true
                };

                if (selfSignedCert != null)
                {
                    ((Xamarin.Android.Net.AndroidClientHandler)handler).TrustedCerts = new List <Java.Security.Cert.Certificate> {
                        selfSignedCert
                    };
                }
            }
            else
#endif
            {
                handler = new HttpClientHandler
                {
                    CookieContainer = store,
                    UseCookies      = true
                };
            }
#else
            var handler = new WebRequestHandler {
                CookieContainer  = store,
                UseCookies       = true,
                ReadWriteTimeout = (int)SocketTimeout.TotalMilliseconds
            };
#endif

            if (handler.SupportsAutomaticDecompression)
            {
                handler.AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate;
            }

            var authHandler = new DefaultAuthHandler(handler, store, SocketTimeout);
            if (retryStrategy == null)
            {
                return(authHandler);
            }

            var retryHandler = new TransientErrorRetryHandler(authHandler, retryStrategy);
            return(retryHandler);
        }
示例#26
0
 public virtual void AddCookies(IList <Apache.Http.Cookie.Cookie> cookies)
 {
     lock (this)
     {
         if (cookieStore == null)
         {
             cookieStore = new BasicCookieStore();
         }
         foreach (Apache.Http.Cookie.Cookie cookie in cookies)
         {
             cookieStore.AddCookie(cookie);
         }
     }
 }
 public JsonResult AddItemToCart(int ID, int Quantity)
 {
     if (CookieStore.GetCookie(cookiekey).Contains(ID.ToString()))
     {
         return(Json(new { Added = 2 }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         string   cookievalue  = ID + ":" + Quantity;
         TimeSpan cookieexpire = new TimeSpan(1000, 0, 0, 0);
         CookieStore.SetCookie(cookiekey, cookievalue, cookieexpire);
         return(Json(new { Added = 1 }, JsonRequestBehavior.AllowGet));
     }
 }
示例#28
0
        internal void SetupHttpClientFactory(IHttpClientFactory newValue, Database db, string checkpointId)
        {
            if (newValue != null)
            {
                ClientFactory = newValue;
            }
            else
            {
                var manager = db?.Manager;
                var managerClientFactory = manager?.DefaultHttpClientFactory;
                ClientFactory = managerClientFactory ?? new CouchbaseLiteHttpClientFactory();
            }

            CookieStore = new CookieStore(db, checkpointId);
        }
示例#29
0
        /// <summary>
        /// Create a new cookie manager with specified cookie store and cookie policy.
        /// </summary>
        /// <param name="store">     a {@code CookieStore} to be used by cookie manager.
        ///                  if {@code null}, cookie manager will use a default one,
        ///                  which is an in-memory CookieStore implementation. </param>
        /// <param name="cookiePolicy">      a {@code CookiePolicy} instance
        ///                          to be used by cookie manager as policy callback.
        ///                          if {@code null}, ACCEPT_ORIGINAL_SERVER will
        ///                          be used. </param>
        public CookieManager(CookieStore store, CookiePolicy cookiePolicy)
        {
            // use default cookie policy if not specify one
            PolicyCallback = (cookiePolicy == null) ? CookiePolicy.ACCEPT_ORIGINAL_SERVER : cookiePolicy;

            // if not specify CookieStore to use, use default one
            if (store == null)
            {
                CookieJar = new InMemoryCookieStore();
            }
            else
            {
                CookieJar = store;
            }
        }
示例#30
0
        public void TestCreateHelloWorldCookiePerf()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            CookieStore store = new CookieStore();

            for (int i = 0; i < 3; i++)
            {
                store.CreateHelloWorldCookie();
            }

            sw.Stop();
            Console.WriteLine("Time taken: " + sw.Elapsed);
        }
 /// <summary>Constructor</summary>
 public CouchbaseLiteHttpClientFactory(CookieStore cookieStore)
 {
     this.cookieStore = cookieStore;
 }
		public virtual void AddCookies(IList<Apache.Http.Cookie.Cookie> cookies)
		{
			lock (this)
			{
				if (cookieStore == null)
				{
					cookieStore = new BasicCookieStore();
				}
				foreach (Apache.Http.Cookie.Cookie cookie in cookies)
				{
					cookieStore.AddCookie(cookie);
				}
			}
		}