Ejemplo n.º 1
0
        // Method is used to process and send the query for operation on databases as it is received by receiver of server
        public void ProcessMessageQuery(ref Message ServerQuery, ref Sender ServerSender, ref HiResTimer HRTimer)
        {
            XDocument     XMLDoc = XDocument.Parse(ServerQuery.MessageContent);
            var           Queries = XMLDoc.Element("QueryType").Elements();     //////
            string        QueryType = null, DBType = null;                      //
            List <string> Results           = new List <string>();              //
            XElement      Query             = XMLDoc.Root;                      //
            List <string> ParameterSelected = new List <string>();              // Query is forwarded as string of XML message to server from client
            List <string> ParameterValue    = new List <string>();              // It fetches paramaters and values required to process the query on DB.

            QueryType = Query.Nodes().OfType <XText>().FirstOrDefault().Value;  //
            DBType    = Query.FirstAttribute.Value.ToString();                  //
            if (Query.Elements("Parameters").Any())                             //
            {                                                                   //////////
                foreach (var Param in Query.Element("Parameters").Descendants())
                {
                    ParameterSelected.Add(Param.Name.ToString());
                    ParameterValue.Add(Param.Value.ToString());
                }
            }
            HRTimer.Start();            // Timer is started as it is forwarded to process the query on database
            Results = TestExecutive.QueryProcessing(DBType, QueryType, ParameterSelected, ParameterValue);
            HRTimer.Stop();             // Timer is stopped as database is done with the processing of query
            ServerQuery.ServerProcessTime = HRTimer.ElapsedMicroseconds;
            TimeKeeper(QueryType, HRTimer.ElapsedMicroseconds);
            foreach (string result in Results)
            {
                Query.Add(new XElement("Result", result));      // Results of query are added in the same received message
            }
            UtilityMethods.swapUrls(ref ServerQuery);           // Same message is sent back with no update on TimeSent or TimeReceived property in order to
            ServerQuery.MessageContent = XMLDoc.ToString();     // calculate the round-trip time of the message, and that's the reason why same message is used instead of creating a new one
            ServerSender.sendMessage(ServerQuery);
        }
Ejemplo n.º 2
0
        // This method is not used when WPF communicates via clients but it would come handy when user wishes WPF to communicate directly to server instead of any client in-between
        // It basically processes whole streams instead of individual messages
        public XDocument ProcessMessageStream(string XMLMessage)
        {
            XMLDoc = XDocument.Parse(XMLMessage);
            int    NumberofQ = XMLDoc.Element("MessageStream").Elements().Count();
            var    Queries   = XMLDoc.Element("MessageStream").Elements();
            string QueryType = null;
            string DBType    = null;

            List <string> Results = new List <string>();

            foreach (var Query in Queries)
            {
                List <string> ParameterSelected = new List <string>();
                List <string> ParameterValue    = new List <string>();

                if (Query.Name.ToString().Equals("QueryType"))
                {
                    QueryType = Query.Nodes().OfType <XText>().FirstOrDefault().Value;
                    DBType    = Query.FirstAttribute.Value.ToString();

                    foreach (var Param in Query.Element("Parameters").Descendants())
                    {
                        ParameterSelected.Add(Param.Name.ToString());
                        ParameterValue.Add(Param.Value.ToString());
                    }
                    Results = TestExecutive.QueryProcessing(DBType, QueryType, ParameterSelected, ParameterValue);
                }
                foreach (string result in Results)
                {
                    Query.Add(new XElement("Result", result));
                }
            }
            XMLDoc.Save("Results.xml");
            return(XMLDoc);
        }
        static void Main(string[] args)
        {
            Console.Title = "Test Executive";
            "  Project 2: Implementation of Remote NoSQL database".Wrap();
            TestExecutive T = new TestExecutive();

            T.DemoR10();
            T.DemoR2();
            T.DemoR3();
            T.DemoR4();
            T.DemoR5and7();
            T.DemoR6();
            T.DemoR8();
            T.DisplayDBafterProcessing();
            Console.ReadKey();
        }