Exemplo n.º 1
0
        public void fetchRecord(string type)
        {
            int value = 0;

            Console.WriteLine("Incomming Request From Application B with parameter : {0} - {1} {2}", type, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString());

            if (Server.processFilesList.Count != 0)
            {
                string path = Server.processFilesList[0];

                if (!ReadXml.startRead)
                {
                    ReadXml.StartReading(path);
                    ReadXml.startRead = true;
                }


                if (type.Equals("red"))
                {
                    if (ReadXml.red.Count != 0)
                    {
                        value = ReadXml.red.Dequeue().value;
                    }
                    else
                    {
                        value = -1;
                    }
                }
                else if (type.Equals("blue"))
                {
                    if (ReadXml.blue.Count != 0)
                    {
                        value = ReadXml.blue.Dequeue().value;
                    }
                    else
                    {
                        value = -1;
                    }
                }
                else if (type.Equals("green"))
                {
                    if (ReadXml.green.Count != 0)
                    {
                        value = ReadXml.green.Dequeue().value;
                    }
                    else
                    {
                        value = -1;
                    }
                }
                else
                {
                    value = -1;
                }

                if (value >= 0)
                {
                    Clients.Caller.PrintValueToConsole(value);
                    Console.WriteLine("Send Response to Application B with parameter : {0} & value : {1} - {2} {3}", type, value, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString());
                    Console.WriteLine("File : {0}", path);
                    Console.WriteLine("");
                }
                else
                {
                    Clients.Caller.PrintValueToConsole(value);

                    Console.WriteLine("Record already consumed with parameter : {0} - {1} {2}", type, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString());
                    Console.WriteLine("File : {0}", path);
                    Console.WriteLine("");
                }


                if (ReadXml.checkFullyConsume())
                {
                    ReadXml.startRead = false;
                    Server.RemoveProcessedFile(path);
                }
            }
            else
            {
                Clients.Caller.PrintValueToConsole(-1);
                Console.WriteLine("Currently no file is available for processing {0} {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString());
                Console.WriteLine("");
            }

            if (Server.mode.Equals("slow"))
            {
                Thread.Sleep(1500);
            }
        }