Esempio n. 1
0
        public static void Main(string[] args)
        {
            C1.TextParser.LicenseManager.Key = License.Key;

            FileStream fst = File.Open(@"template.xml", FileMode.Open);
            FileStream fss = File.Open(@"input.txt", FileMode.Open);

            TemplateBasedExtractor templateBasedExtractor = new TemplateBasedExtractor(fst);
            IExtractionResult      extractedResult        = templateBasedExtractor.Extract(fss);

            fss.Close();
            fst.Close();

            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine("GrapeCity, inc, all rights reserved");
            Console.WriteLine("Demo of the C1TextParser library - TemplateBased extractor sample");
            Console.WriteLine("Test case: From a file containing information about the users of a specific service");
            Console.WriteLine("           extract all the fields related to each user, such as its name, age");
            Console.WriteLine("           residency address, work address and contacts.");
            Console.WriteLine("Detail: A custom format is used to specify the information about an user. The custom data");
            Console.WriteLine("        format described by the xml template is presented below.");
            Console.WriteLine("        Also, the extraction result was exported to \"ExtractUsersInfo.csv\" at the");
            Console.WriteLine("        current working directory");
            Console.WriteLine("------------------------------------------------------------------------------------------");

            Console.WriteLine("");

            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine("Template:");
            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine(new StreamReader(File.Open(@"template.xml", FileMode.Open)).ReadToEnd());
            Console.WriteLine("------------------------------------------------------------------------------------------");

            Console.WriteLine("");

            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine("Input stream:");
            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine(new StreamReader(File.Open(@"input.txt", FileMode.Open)).ReadToEnd());
            Console.WriteLine("------------------------------------------------------------------------------------------");

            Console.WriteLine("");

            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine("JSon String result:");
            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine(extractedResult.ToJsonString());
            Console.WriteLine("------------------------------------------------------------------------------------------");

            Users         t   = extractedResult.Get <Users>();
            StringBuilder sb  = CsvExportHelper.ExportList(t.User);
            string        str = sb.ToString();

            File.WriteAllText("ExtractUsersInfo.csv", sb.ToString());

            Console.ReadLine();
        }
        public static void Main(string[] args)
        {
            C1.TextParser.LicenseManager.Key = License.Key;

            FileStream fst = File.Open(@"template.xml", FileMode.Open);
            FileStream fss = File.Open(@"input.txt", FileMode.Open);

            TemplateBasedExtractor templateBasedExtractor = new TemplateBasedExtractor(fst);
            IExtractionResult      extractedResult        = templateBasedExtractor.Extract(fss);

            fss.Close();
            fst.Close();

            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine("GrapeCity, inc, all rights reserved");
            Console.WriteLine("Demo of the C1TextParser library - TemplateBased extractor sample");
            Console.WriteLine("Test case: From a server log file, extract all the ERROR logs");
            Console.WriteLine("Detail: Each log follows a predefined fixed structure, that consists in 4 major elements.");
            Console.WriteLine("        These are: The date, the time (up to ms), the log type and finally, ");
            Console.WriteLine("        the description of the log");
            Console.WriteLine("        The input stream content, the template and also the extracted result");
            Console.WriteLine("        (in Json format) are displayed down below. Also, the extracted result was");
            Console.WriteLine("        exported to \"ExtractErrorLogs.csv\" at the current working directory");
            Console.WriteLine("------------------------------------------------------------------------------------------");

            Console.WriteLine("");

            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine("Input stream:");
            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine(new StreamReader(File.Open(@"input.txt", FileMode.Open)).ReadToEnd());
            Console.WriteLine("------------------------------------------------------------------------------------------");

            Console.WriteLine("");

            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine("Template:");
            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine(new StreamReader(File.Open(@"template.xml", FileMode.Open)).ReadToEnd());
            Console.WriteLine("------------------------------------------------------------------------------------------");

            Console.WriteLine("");

            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine("JSon String result:");
            Console.WriteLine("------------------------------------------------------------------------------------------");
            Console.WriteLine(extractedResult.ToJsonString());
            Console.WriteLine("------------------------------------------------------------------------------------------");

            Logs          t   = extractedResult.Get <Logs>();
            StringBuilder sb  = CsvExportHelper.ExportList(t.ErrorLogs);
            string        str = sb.ToString();

            File.WriteAllText("ExtractErrorLogs.csv", sb.ToString());

            Console.ReadLine();
        }