예제 #1
0
파일: Program.cs 프로젝트: bollylu/eLibMan
        static void Main(string[] args)
        {
            TraceFactory.AddTraceConsole();
            SplitArgs Args = new SplitArgs(args);

            string SourceDir = Args.GetValue("sourcedir", "");

            Trace.WriteLine($"Source directory = {SourceDir}");

            if (string.IsNullOrWhiteSpace(SourceDir) || !Directory.Exists(SourceDir))
            {
                Usage($"Missing source directory : directory is missing or access is denied");
            }

            InitTitle($"Processing {SourceDir}");

            EProcessStatus ProcessStatus = ProcessDirectory(new DirectoryInfo(SourceDir));

            if (ProcessStatus != EProcessStatus.Ok)
            {
                ConsoleExtension.Pause();
                Environment.Exit(1);
            }

            //ConsoleExtension.Pause();
            Environment.Exit(0);
        }
예제 #2
0
        static void Main(string[] args)
        {
            SplitArgs oArgs = new SplitArgs(args);

            string        SourceOpml     = oArgs.GetValue <string>("source");
            TOpmlDocument ImportDocument = new TOpmlDocument(SourceOpml);

            Console.WriteLine(ImportDocument.Outlines.ToString(true));
            ConsoleExtension.Pause();

            TConfigDocument ConfigDocument = new TConfigDocument();

            ConfigDocument.Import(SourceOpml);
            Console.WriteLine(ConfigDocument.ToString());
            ConsoleExtension.Pause();
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            SplitArgs Args = new SplitArgs(args);

            if (Args.Count == 0)
            {
                Console.WriteLine("No argument specified");
            }

            foreach (ArgElement ArgItem in Args)
            {
                Console.WriteLine($"{ArgItem.Name}={ArgItem.Value}");
            }

            Console.WriteLine(ApplicationInfo.BuildRuntimeInfo());

            Console.WriteLine();

            string folder = Args.GetValue <string>("folder", "");

            if (!Directory.Exists(folder))
            {
                Console.WriteLine("Missing directory or access denied");
                Environment.Exit(1);
            }

            foreach (string FileItem in Directory.EnumerateFiles(folder))
            {
                Console.WriteLine(FileItem);
            }

            int i = 1;

            foreach (string DirectoryItem in Directory.EnumerateDirectories(folder).OrderBy(x => x))
            {
                Console.WriteLine($"{i++:000}.{DirectoryItem}");
            }

            Environment.Exit(0);
        }
예제 #4
0
        public void DownloadItems()
        {
            try {
                Trace.WriteLine(string.Format("Downloading items for channel {0} ...", Title));
                Trace.Indent();
                WebClient CurrentClient = new WebClient();

                CurrentClient.Headers.Add("user-agent", "RssWatcher/1.0");
                byte[] Data = CurrentClient.DownloadData(Link.Value);

                #region Discover the encoding
                if (ChannelEncoding == null || string.IsNullOrWhiteSpace(ChannelEncoding.WebName))
                {
                    string    ContentType      = CurrentClient.ResponseHeaders.Get("Content-Type");
                    string[]  ContentTypeItems = ContentType.Split(';');
                    SplitArgs oArgs            = new SplitArgs(ContentTypeItems);
                    ChannelEncoding = Encoding.GetEncoding(oArgs.GetValue <string>("charset", DefaultChannelEncoding));
                }
                Trace.WriteLine(string.Format("Encoding for {0} : {1}", Name, ChannelEncoding.WebName));
                #endregion Discover the encoding

                #region If content is gzipped, then decompress
                string ContentEncoding = CurrentClient.ResponseHeaders.Get("Content-Encoding");
                if (!string.IsNullOrWhiteSpace(ContentEncoding) && ContentEncoding.ToLower() == "gzip")
                {
                    using (MemoryStream TempStream = new MemoryStream()) {
                        using (GZipStream CompressedStream = new GZipStream(new MemoryStream(Data), CompressionMode.Decompress)) {
                            CompressedStream.CopyTo(TempStream);
                        }
                        TempStream.Flush();
                        Data = new byte[TempStream.Length];
                        Buffer.BlockCopy(TempStream.GetBuffer(), 0, Data, 0, (int)TempStream.Length);
                    }
                }
                #endregion If content is gzipped, then decompress

                #region Read and parse the data
                XDocument SourceXml;
                try {
                    #region Skip the BOM code if it exists
                    string TempXml = ChannelEncoding.GetString(Data);
                    if (TempXml.IndexOf('<') > 0)
                    {
                        TempXml = TempXml.Substring(TempXml.IndexOf("<"));
                    }
                    #endregion Skip the BOM code if it exists
                    SourceXml = XDocument.Parse(TempXml);
                    XElement        XChannel          = SourceXml.Element("rss").Element("channel");
                    TItemCollection TempItems         = new TItemCollection(XChannel.Elements("item"));
                    DateTime        TempLastBuildDate = LastBuildDate;
                    Trace.WriteLine(string.Format("Found {0} item(s)", TempItems.Count));
                    List <TItem> NewItems = TempItems.Where(i => i.PubDate > LastBuildDate).ToList();
                    Trace.WriteLine(string.Format("{0} new item(s)", NewItems.Count));
                    foreach (TItem ItemItem in NewItems)
                    {
                        if (ItemItem.PubDate > TempLastBuildDate)
                        {
                            TempLastBuildDate = ItemItem.PubDate;
                        }
                        Items.Add(ItemItem);
                    }
                    LastBuildDate = TempLastBuildDate;

                    Description = XChannel.SafeReadElementValue <string>("description", "");
                    if (XChannel.Elements().Any(x => x.Name == "image"))
                    {
                        Picture = new TChannelImage(XChannel.SafeReadElement("image"));
                    }
                    if (XChannel.Elements().Any(x => x.Name == "category"))
                    {
                        Category = XChannel.SafeReadElementValue <string>("category", "");
                    }
                    if (XChannel.Elements().Any(x => x.Name == "language"))
                    {
                        Language = XChannel.SafeReadElementValue <string>("language", "");
                    }
                    if (XChannel.Elements().Any(x => x.Name == "copyright"))
                    {
                        Copyright = XChannel.SafeReadElementValue <string>("copyright", "");
                    }
                    Title = XChannel.SafeReadElementValue <string>("title", "");
                } catch (Exception ex) {
                    Trace.WriteLine(string.Format("Error while reading items for channel {0} : {1}", Name, ex.Message), Severity.Error);
                }
                #endregion Read and parse the data

                if (DownloadCompleted != null)
                {
                    ItemsDownloadedEventArgs Args = new ItemsDownloadedEventArgs(Data, CurrentClient.ResponseHeaders, Encoding.UTF8.GetString(Data));
                    DownloadCompleted(this, Args);
                }

                return;
            } finally {
                Trace.Unindent();
                Trace.WriteLine("Done.");
            }
        }
예제 #5
0
        static async Task MainAsync(string[] args)
        {
            TChrono chrono = new TChrono();

            chrono.Start();

            SplitArgs Args = new SplitArgs(args);

            string        SourceRepository = Args.GetValue <string>("source", "");
            string        RepositoryName   = Args.GetValue <string>("name", SourceRepository.AfterLast(Path.DirectorySeparatorChar));
            string        OutputFilename   = Args.GetValue <string>("output", "bdindex");
            string        OutputFormat     = Args.GetValue <string>("outputformat", "txt").ToLower();
            List <string> AllowedFormats   = new List <string>()
            {
                "txt", "json", "xml"
            };

            if (!AllowedFormats.Contains(OutputFormat))
            {
                OutputFormat = "txt";
            }

            Console.WriteLine(TextBox.BuildDynamic($"Index folder {SourceRepository}..."));
            Console.WriteLine($"  Name = {RepositoryName}");
            Console.WriteLine($"  Output to {OutputFilename}.{OutputFormat}");
            Console.WriteLine();

            if (!Directory.Exists(SourceRepository))
            {
                Usage("Missing source directory");
            }

            TRepository CurrentRepository = new TRepository(SourceRepository, RepositoryName);
            await CurrentRepository.BuildIndex();

            Console.WriteLine($"Total folders : {CurrentRepository.Books.EnumerateCollections().Count()}");
            Console.WriteLine($"Found (...) folders : {CurrentRepository.Books.EnumerateCollections().Count(x => x.HasArticle)}");

            Console.WriteLine("------------------ Display name -----------------");

            foreach (IEnumerable <TBookCollection> BookCollectionItems in CurrentRepository.Books.EnumerateCollections().OrderBy(x => x.DisplayName).GroupBy(x => x.DisplayName.First()))
            {
                Console.Write($"{BookCollectionItems.First().DisplayName.First()} : ");
                Console.WriteLine(new string('#', BookCollectionItems.Count()));
            }

            Console.WriteLine("------------------ Name -----------------");

            foreach (IEnumerable <TBookCollection> BookCollectionItems in CurrentRepository.Books.EnumerateCollections().OrderBy(x => x.Name).GroupBy(x => x.Name.First()))
            {
                Console.Write($"{BookCollectionItems.First().Name.First()} : ");
                Console.WriteLine(new string('#', BookCollectionItems.Count()));
            }

            OutputFilename += $".{OutputFormat}";
            if (File.Exists(OutputFilename))
            {
                File.Delete(OutputFilename);
            }

            switch (OutputFormat)
            {
            case "txt":
                foreach (TBookCollection BookCollectionItem in CurrentRepository.Books.EnumerateCollections())
                {
                    File.AppendAllText(OutputFilename, BookCollectionItem.ToString());
                    File.AppendAllText(OutputFilename, Environment.NewLine);
                }
                break;

            case "json":
                JsonValue.Save(OutputFilename, CurrentRepository.ToJson());
                break;

            case "xml":
                File.AppendAllText(OutputFilename, CurrentRepository.ToXml().ToString());
                break;
            }



            //TBookCollection MissingInBrilly = new TBookCollection(BdBrilly.Books.GetMissingFrom(BdLuc.Books));
            //TBookCollection MissingInLuc = new TBookCollection(BdLuc.Books.GetMissingFrom(BdBrilly.Books));

            //Console.WriteLine("=== Missing in Luc =================================================");
            //string OutputMissingLuc = @"i:\# BDS\MissingInLuc.txt";
            //File.Delete(OutputMissingLuc);
            //File.AppendAllText(OutputMissingLuc, $"{MissingInLuc.Count()} books{Environment.NewLine}");
            //foreach ( TBookCollection BookCollectionItem in MissingInLuc.EnumerateCollections() ) {
            //  File.AppendAllText(OutputMissingLuc, BookCollectionItem.ToString());
            //  File.AppendAllText(OutputMissingLuc, Environment.NewLine);
            //}
            //Console.WriteLine("=== Missing in Brilly ==============================================");
            //foreach ( TBookCollection BookCollectionItem in MissingInBrilly.EnumerateCollections() ) {
            //  Console.WriteLine(BookCollectionItem.ToString());
            //}

            Console.WriteLine($"Indexing process completed in {chrono.ElapsedTime.TotalSeconds} secs");
            //ConsoleExtension.Pause();

            //Environment.Exit(0);
        }