Beispiel #1
0
        private string processData(HttpListenerRequest request)
        {
            string theURL = request.Url.OriginalString;

            theURL = theURL.ToLower();
            theURL = theURL.Replace("https://", "");
            theURL = theURL.Replace("http://", "");
            string[] uParts = theURL.Split('/');
            string   output = "";

            //Console.WriteLine("Request for: " + theURL);
            if (uParts.Length >= 3)
            {
                if (uParts[2] == "source")
                {
                    output = dresser.getSourceCode();
                }
                else if (uParts[2] == "report")
                {
                    string text;
                    using (StreamReader reader = new StreamReader(request.InputStream, request.ContentEncoding))    {
                        text = reader.ReadToEnd();
                    }
                    text = HttpUtility.UrlDecode(text);
                    processReport(text);
                }
                else if (uParts[2] == "collections")
                {
                    string collData = "<ul>\n";
                    lock (collections) {
                        foreach (HydraCollection cc in collections)
                        {
                            string created = cc.getCreatedDate().ToString("F");
                            collData += "<li><a href=\"http://localhost:9999/hydra/collection/" + cc.getID() + "\">Collection #" + cc.getID() + "</a> (" + created + ")</li>\n";
                        }
                    }
                    collData += "</ul>\n";
                    output    = template;
                    output    = output.Replace("[title]", "Hydra Collections");
                    output    = output.Replace("[content]", collData);
                }
                else if (uParts[2] == "collection")
                {
                    if (uParts.Length > 3)
                    {
                        int             collID = Convert.ToInt32(uParts[3]);
                        HydraCollection c      = null;
                        lock (collections) {
                            foreach (HydraCollection cc in collections)
                            {
                                if (cc.getID() == collID)
                                {
                                    c = cc;
                                    break;
                                }
                            }
                        }
                        if (null != c)
                        {
                            string collData = "<div>\n";
                            collData += "<p><a href=\"http://localhost:9999/hydra/collections/\">Back</a></p>\n";
                            int    hit   = c.getTotalItemsHit();
                            int    total = c.getTotalItems();
                            double ratio = ((double)hit / total);
                            collData += "<p>Item hit-rate: " + hit + "/" + total + "<br />";
                            collData += "Coverage: " + string.Format("{0:0.00%}", ratio) + "</p>\n";
                            collData += "</div>\n";
                            output    = template;
                            output    = output.Replace("[title]", "Hydra Collection #" + collID);
                            output    = output.Replace("[content]", collData);
                        }
                    }
                }
            }
            return(output);
        }