Esempio n. 1
0
        /// <summary>
        /// reload cookies
        /// </summary>
        public void Reload()
        {
            cookies.Clear();

            foreach (var ipDir in Directory.GetDirectories(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "cookies")))
            {
                foreach (var uaDir in Directory.GetDirectories(ipDir))
                {
                    foreach (var file in Directory.GetFiles(uaDir))
                    {
                        var json       = File.ReadAllText(file, Encoding.UTF8);
                        var cookieFile = JsonConvert.DeserializeObject <CookieFile>(json);
                        var host       = file.Substring(file.LastIndexOf(@"\") + 1);
                        host = host.Substring(0, host.LastIndexOf("."));
                        host = "http://" + host + "/";

                        if (!cookies.ContainsKey(cookieFile.Key))
                        {
                            var cookie = new ManagedCookie(cookieFile.UserAgent);
                            cookie.Update(host, cookieFile.Cookie);

                            cookies.Add(cookieFile.Key, cookie);
                        }
                        else
                        {
                            cookies[cookieFile.Key].Update(host, cookieFile.Cookie);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// update cookie
        /// </summary>
        /// <param name="ip">ip address</param>
        /// <param name="ua">user agent</param>
        /// <param name="url">url</param>
        /// <param name="setCookie">cookie content</param>
        public void UpdateCookie(string ip, string ua, string url, string setCookie)
        {
            lock (_lck)
            {
                var cookie = "";
                var key    = ip + "_" + EncryptHelper.GetMD5Hash(ua);

                if (cookies.ContainsKey(key))
                {
                    cookie = cookies[key].Update(url, setCookie);
                }
                else
                {
                    var manager = new ManagedCookie(ua);
                    cookie = manager.Update(url, setCookie);

                    cookies.Add(key, manager);
                }

                SaveCookieFile(ip, ua, url, cookie);
            }
        }