Ejemplo n.º 1
0
 public Action<Message> timeQuery(DBEngine<int, DBElement<int, string>> db)
 {
     Action<Message> TimeQuery = (msg) =>
     {
         QueryEngine<int, string> qe = new QueryEngine<int, string>(db);
         XDocument doc = XDocument.Parse(msg.content);
         string FirstTime = doc.Descendants("Msg").Descendants("Data").Descendants("firstTime").ElementAt(0).Value;
         string SecondTime = doc.Descendants("Msg").Descendants("Data").Descendants("secondTime").ElementAt(0).Value;
         DateTime firstTime = Convert.ToDateTime(FirstTime);
         DateTime secondTime = Convert.ToDateTime(SecondTime);
         string name = doc.Descendants("Msg").Descendants("DBName").ElementAt(0).Value;
         Func<int, bool> timequery = qe.defineTimeQuery(firstTime, secondTime);
         List<int> keys;
         StringBuilder result = new StringBuilder(string.Format("<Msg><Reply>timeQuery</Reply><DBName>{0}</DBName><Data>",name));
         if (qe.processQuery(timequery, out keys))
         {
             foreach (var key in keys)
                 result.Append(string.Format("<key>{0}</key>", key.ToString()));
         }
         else
             result.Append("There is no element written in a specified time-date interval");
         result.Append("</Data></Msg>");
         msg.content = result.ToString();
         Utilities.swapUrls(ref msg);
     }; 
     return TimeQuery;
 }
Ejemplo n.º 2
0
 public Action<Message> specPatternQuery(DBEngine<int, DBElement<int, string>> db)
 {
     Action<Message> SpecPatternQuery = (msg) =>
     {
         QueryEngine<int, string> qe = new QueryEngine<int, string>(db);
         XDocument doc = XDocument.Parse(msg.content);
         Func<int, bool> f = qe.defineSpecPatternQuery();
         string name=doc.Descendants("Msg").Descendants("DBName").ElementAt(0).Value;
         List<int> keys;
         StringBuilder result = new StringBuilder(string.Format("<Msg><Reply>specPatternQuery</Reply><DBName>{0}</DBName><Data>",name));
         if (qe.processQuery(f, out keys))
         {
             foreach (var key in keys)
                 result.Append(string.Format("<key>{0}</key>", key.ToString()));
         }
         else
             result.Append("There is no key that matching a specified pattern");
         result.Append("</Data></Msg>");
         msg.content = result.ToString();
         Utilities.swapUrls(ref msg);
     };
     return SpecPatternQuery;
 }