Beispiel #1
0
 public bool SetCookie(Cookie cookie)
 {
     lock (cookieJarLock)
     {
         bool flag = cookie.expirationDate < DateTime.Now;
         if (cookies.ContainsKey(cookie.name))
         {
             for (int i = 0; i < cookies[cookie.name].Count; i++)
             {
                 Cookie cookie2 = cookies[cookie.name][i];
                 if (!cookie2.CollidesWith(new CookieAccessInfo(cookie)))
                 {
                     continue;
                 }
                 if (flag)
                 {
                     cookies[cookie.name].RemoveAt(i);
                     if (cookies[cookie.name].Count == 0)
                     {
                         cookies.Remove(cookie.name);
                         if (ContentsChanged != null)
                         {
                             ContentsChanged();
                         }
                     }
                     return(false);
                 }
                 cookies[cookie.name][i] = cookie;
                 if (ContentsChanged != null)
                 {
                     ContentsChanged();
                 }
                 return(true);
             }
             if (flag)
             {
                 return(false);
             }
             cookies[cookie.name].Add(cookie);
             if (ContentsChanged != null)
             {
                 ContentsChanged();
             }
             return(true);
         }
         if (flag)
         {
             return(false);
         }
         cookies[cookie.name] = new List <Cookie>();
         cookies[cookie.name].Add(cookie);
         if (ContentsChanged != null)
         {
             ContentsChanged();
         }
         return(true);
     }
 }
        public bool SetCookie(Cookie cookie)
        {
            lock ( cookieJarLock )
            {
                bool expired = cookie.expirationDate < DateTime.Now;

                if (cookies.ContainsKey(cookie.name))
                {
                    for (int index = 0; index < cookies[cookie.name].Count; ++index)
                    {
                        Cookie collidableCookie = cookies[cookie.name][index];
                        if (collidableCookie.CollidesWith(new CookieAccessInfo(cookie)))
                        {
                            if (expired)
                            {
                                cookies[cookie.name].RemoveAt(index);
                                if (cookies[cookie.name].Count == 0)
                                {
                                    cookies.Remove(cookie.name);
                                    if (ContentsChanged != null)
                                    {
                                        ContentsChanged();
                                    }
                                }

                                return(false);
                            }
                            else
                            {
                                cookies[cookie.name][index] = cookie;
                                if (ContentsChanged != null)
                                {
                                    ContentsChanged();
                                }
                                return(true);
                            }
                        }
                    }

                    if (expired)
                    {
                        return(false);
                    }

                    cookies[cookie.name].Add(cookie);
                    if (ContentsChanged != null)
                    {
                        ContentsChanged();
                    }
                    return(true);
                }

                if (expired)
                {
                    return(false);
                }

                cookies[cookie.name] = new List <Cookie>();
                cookies[cookie.name].Add(cookie);
                if (ContentsChanged != null)
                {
                    ContentsChanged();
                }
                return(true);
            }
        }