Beispiel #1
0
 private void processReport(string reportText)
 {
     string[] reportLines = reportText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
     lock (collections) {
         HydraCollection c;
         foreach (string rLine in reportLines)
         {
             string[] lineSections = rLine.Split('|');
             if (lineSections.Length == 3)
             {
                 int  pointID         = Convert.ToInt32(lineSections[0]);
                 int  timeMS          = Convert.ToInt32(lineSections[1]);
                 int  hydraID         = Convert.ToInt32(lineSections[2]);
                 bool foundCollection = false;
                 //HydraCollection c;
                 foreach (HydraCollection cc in collections)
                 {
                     if (cc.getID() == hydraID)
                     {
                         foundCollection = true;
                         c = cc;
                         break;
                     }
                 }
                 if (foundCollection == false)
                 {
                     c = new HydraCollection(hydraID, dresser.getPointCount());
                     collections.Add(c);
                 }
                 c.addItem(pointID, timeMS);
             }
         }
         int    hit   = c.getTotalItemsHit();
         int    total = c.getTotalItems();
         double ratio = ((double)hit / total);
         Console.WriteLine("Collection #" + c.getID() + " coverage: " + string.Format("{0:0.00%}", ratio));
     }
 }
Beispiel #2
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);
        }