Esempio n. 1
0
 /// <param name="maxSize">
 /// the maximum size of the cache before returning. May be -1
 /// to evict even 0-sized elements.
 /// </param>
 private void TrimToSize(int maxSize)
 {
     while (true)
     {
         K key;
         V value;
         lock (this)
         {
             if (size < 0 || (map.IsEmpty() && size != 0))
             {
                 throw new InvalidOperationException(GetType().FullName + ".sizeOf() is reporting inconsistent results!"
                                                     );
             }
             if (size <= maxSize)
             {
                 break;
             }
             // BEGIN LAYOUTLIB CHANGE
             // get the last item in the linked list.
             // This is not efficient, the goal here is to minimize the changes
             // compared to the platform version.
             KeyValuePair <K, V> toEvict = null;
             foreach (KeyValuePair <K, V> entry in map.EntrySet())
             {
                 toEvict = entry;
             }
             // END LAYOUTLIB CHANGE
             if (toEvict == null)
             {
                 break;
             }
             key   = toEvict.Key;
             value = toEvict.Value;
             Sharpen.Collections.Remove(map, key);
             size -= SafeSizeOf(key, value);
             evictionCount++;
         }
         EntryRemoved(true, key, value, null);
     }
 }
Esempio n. 2
0
            /// <exception cref="System.IO.IOException"></exception>
            internal override void ConfigureRequest(HttpURLConnection conn)
            {
                IDictionary <string, string> r = new LinkedHashMap <string, string>();
                string realm  = @params.Get("realm");
                string nonce  = @params.Get("nonce");
                string cnonce = @params.Get("cnonce");
                string uri    = Uri(conn.GetURL());
                string qop    = @params.Get("qop");
                string method = conn.GetRequestMethod();
                string A1     = user + ":" + realm + ":" + pass;
                string A2     = method + ":" + uri;

                r.Put("username", user);
                r.Put("realm", realm);
                r.Put("nonce", nonce);
                r.Put("uri", uri);
                string response;
                string nc;

                if ("auth".Equals(qop))
                {
                    nc       = string.Format("%08x", ++requestCount);
                    response = KD(H(A1), nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + H(A2));
                }
                else
                {
                    nc       = null;
                    response = KD(H(A1), nonce + ":" + H(A2));
                }
                r.Put("response", response);
                if (@params.ContainsKey("algorithm"))
                {
                    r.Put("algorithm", "MD5");
                }
                if (cnonce != null && qop != null)
                {
                    r.Put("cnonce", cnonce);
                }
                if (@params.ContainsKey("opaque"))
                {
                    r.Put("opaque", @params.Get("opaque"));
                }
                if (qop != null)
                {
                    r.Put("qop", qop);
                }
                if (nc != null)
                {
                    r.Put("nc", nc);
                }
                StringBuilder v = new StringBuilder();

                foreach (KeyValuePair <string, string> e in r.EntrySet())
                {
                    if (v.Length > 0)
                    {
                        v.Append(", ");
                    }
                    v.Append(e.Key);
                    v.Append('=');
                    v.Append('"');
                    v.Append(e.Value);
                    v.Append('"');
                }
                conn.SetRequestProperty(HttpSupport.HDR_AUTHORIZATION, NAME + " " + v);
            }
Esempio n. 3
0
 /// <exception cref="System.IO.IOException"></exception>
 internal override void ConfigureRequest(HttpURLConnection conn)
 {
     IDictionary<string, string> r = new LinkedHashMap<string, string>();
     string realm = @params.Get("realm");
     string nonce = @params.Get("nonce");
     string cnonce = @params.Get("cnonce");
     string uri = Uri(conn.GetURL());
     string qop = @params.Get("qop");
     string method = conn.GetRequestMethod();
     string A1 = user + ":" + realm + ":" + pass;
     string A2 = method + ":" + uri;
     r.Put("username", user);
     r.Put("realm", realm);
     r.Put("nonce", nonce);
     r.Put("uri", uri);
     string response;
     string nc;
     if ("auth".Equals(qop))
     {
         nc = string.Format("%08x", ++requestCount);
         response = KD(H(A1), nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + H(A2));
     }
     else
     {
         nc = null;
         response = KD(H(A1), nonce + ":" + H(A2));
     }
     r.Put("response", response);
     if (@params.ContainsKey("algorithm"))
     {
         r.Put("algorithm", "MD5");
     }
     if (cnonce != null && qop != null)
     {
         r.Put("cnonce", cnonce);
     }
     if (@params.ContainsKey("opaque"))
     {
         r.Put("opaque", @params.Get("opaque"));
     }
     if (qop != null)
     {
         r.Put("qop", qop);
     }
     if (nc != null)
     {
         r.Put("nc", nc);
     }
     StringBuilder v = new StringBuilder();
     foreach (KeyValuePair<string, string> e in r.EntrySet())
     {
         if (v.Length > 0)
         {
             v.Append(", ");
         }
         v.Append(e.Key);
         v.Append('=');
         v.Append('"');
         v.Append(e.Value);
         v.Append('"');
     }
     conn.SetRequestProperty(HttpSupport.HDR_AUTHORIZATION, NAME + " " + v);
 }