Beispiel #1
0
        string ListCacheEntries()
        {
            System.Collections.ArrayList cacheKeys = new System.Collections.ArrayList();

            System.Collections.IDictionaryEnumerator enumerator = System.Web.HttpContext.Current.Cache.GetEnumerator();
            while (enumerator.MoveNext())
            {
                System.Collections.DictionaryEntry de = enumerator.Entry;
                cacheKeys.Add(de.Key);
            }
            cacheKeys.Sort();
            System.Collections.IEnumerator e      = cacheKeys.GetEnumerator();
            System.Text.StringBuilder      output = new System.Text.StringBuilder();
            output.Append("<table width=100%>\n");

            if (cacheKeys.Count > 0 || OnRefresh != null)
            {
                if (_authenticated)
                {
                    output.AppendFormat("<tr><td><form method=post action=''>");
                    output.AppendFormat("<tr><td><input type=submit value='Remove' />");
                    output.AppendFormat("<input type=button value='Check all' onClick='value=check(form.cache)'>");
                    output.AppendFormat("</td></tr>");

                    output.Append("<SCRIPT LANGUAGE='JavaScript'><!-- \n");
                    output.Append("var checkflag = 'false';function check(field) {if (checkflag == 'false') {  for (i = 0; i < field.length; i++) {  field[i].checked = true;}  checkflag = 'true';  return 'Uncheck all'; }else {  for (i = 0; i < field.length; i++) {  field[i].checked = false; }  checkflag = 'false';  return 'Check all'; }}\n");
                    output.Append("//  End --></script>");
                }

                if (OnRefresh != null)
                {
                    output.AppendFormat("<tr><td colspan=3>");
                    if (_authenticated)
                    {
                        output.AppendFormat("<input type=checkbox name='custom' value='true' />");
                    }
                    output.AppendFormat(OnRefresh.GetInvocationList().Length + " Custom Cached Object(s)</td></tr>");
                }

                while (e.MoveNext())
                {
                    output.AppendFormat("<tr>");
                    int columns = 0;
                    do
                    {
                        output.AppendFormat("<td width=33% nowrap>");
                        if (_authenticated)
                        {
                            output.AppendFormat("<input type=checkbox name='cache' value='{0}' /> ", e.Current);
                        }
                        output.AppendFormat("{0}</td>", e.Current);
                        columns++;
                    } while (columns < 3 && e.MoveNext());
                    output.AppendFormat("</tr>\r");
                }

                if (_authenticated)
                {
                    output.AppendFormat("<tr><td><input type=submit value='Remove' />");
                    output.AppendFormat("</form></td></tr>");
                }
            }
            else
            {
                output.Append("<tr><td>Cache is empty.</tr></td>\n");
            }
            output.Append("</table>\n");
            return(output.ToString());
        }