Пример #1
0
        public object Parse(object toParse)
        {
            var chain        = ParserChain.ToList();
            var param        = ValueParserParameter.ToList();
            var currentValue = toParse;

            for (var i = 0; i < chain.Count; i++)
            {
                if (currentValue == null)
                {
                    return(null);
                }
                currentValue = chain[i].ResolveParser(ComponentContext, param[i]).Parse(currentValue);
            }
            return(currentValue);
        }
Пример #2
0
        //=========================================
        //Read the Conf.cfg file
        //Chunks refers to each field in the file.
        //=========================================
        private static void readConf(ConfStore i_cs, Toolbox tIn)
        {
            //Check if file exists
            if (!File.Exists(Program.confUrl))
            {
                Program.writeLog("Conf file is missing");
                Program.exit(1);
            }

            StreamReader sr = new StreamReader(Program.confUrl, System.Text.Encoding.Default);

            string        line         = "";
            List <string> currentList  = new List <string>();
            int           currentChunk = 0;

            //Read until end of file
            while ((line = sr.ReadLine()) != null)
            {
                //Ensure the line is not empty before adding the line int the list that will form part of the settings chunk
                if (line != "")
                {
                    //Add the line to the chunk
                    currentList.Add(line);


                    //System.Console.WriteLine(line);
                }
                else
                {
                    //Make sure that the currentList is not empty
                    if (currentList.Count != 0)
                    {
                        //Add the chunk to the settings chunk
                        chunks.Add(new Chunk(currentList));
                        currentList = new List <string>();
                        currentChunk++;
                    }
                }
            }

            //Close the reader
            sr.Close();

            //Grab the final chunk that the loop did not grab
            if (currentList.Count != 0)
            {
                chunks.Add(new Chunk(currentList));
            }

            //External is a list of strings which will store the [Last Reboot Time] settings tag in a chunk
            List <string> external = new List <string>();

            if (!File.Exists("./lastreboottime.txt"))
            {
                //The [Last Reboot Time] tag exists in a seperate file
                // - Create that file if it does not exist
                //   - Could be merged into configuration file but that adds more complexity
                StreamWriter writer = new StreamWriter("./lastreboottime.txt", false);
                writer.WriteLine("[Last Reboot Time]");

                PerformanceCounter uptime = new PerformanceCounter("System", "System Up Time");
                uptime.NextValue();
                TimeSpan t     = TimeSpan.FromSeconds(uptime.NextValue());
                DateTime final = DateTime.Now.Subtract(t);
                //System.Console.WriteLine(final);
                //tools.setLastReboot(final);
                writer.WriteLine(final);
                writer.Close();
            }


            //
            StreamReader sr_b = new StreamReader("./lastreboottime.txt");

            external.Add(sr_b.ReadLine());
            external.Add(sr_b.ReadLine());

            sr_b.Close();
            //Send chunks to functions here

            Toolbox   tb     = tIn;
            ConfStore cStore = i_cs;

            foreach (Chunk c in chunks)
            {
                ParserChain ts = new ParserChain(c.getChunk(), tb, cStore);
            }

            ParserChain tc = new ParserChain(external, tb, cStore);


            //Debugging lines
            //string strTest = tb.ToString();
            //System.Console.WriteLine(tb.checkSql());
            //System.Console.WriteLine(startupChunk[1]);
            //Process.Start(startupChunk[1]);

            //ParserChain ts = new ParserChain(chunks[0].getChunk(), new Toolbox());
        }