Пример #1
0
        private static void ReplicateNugetRepository(SysSettings sysSettings)
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();

            string feedUrl = $"{ServiceUrlBase}{sysSettings.FeedUrl}";

            _log.Info($"download url {feedUrl}");

            while (feedUrl != null)
            {
                feedUrl = DownloadPackagesEntries(feedUrl);
            }

            timer.Stop();
            Console.WriteLine($"download took: {timer.ElapsedMilliseconds} mills");
            _log.Info($"download took: {timer.ElapsedMilliseconds} mills");

            timer.Reset();
            timer.Start();
            DeleteLastCharOfFile();
            _logFilesRep.Info($"],\"general_data\":{{\"url\":\"{ServiceUrlBase}\",\"download_time\":\"{DateTime.Now}\"}}}}");
            timer.Stop();

            Console.WriteLine($"finialize took: {timer.ElapsedMilliseconds} mills");
            _log.Info($"finialize took: {timer.ElapsedMilliseconds} mills");
        }
Пример #2
0
        private static int GetTotalPackageCount(SysSettings sysSettings)
        {
            var url = $"{ServiceUrlBase}/$count{sysSettings.FeedUrl}";

            using (var client = new WebClient())
            {
                var total = client.DownloadString(url);
                return(int.Parse(total));
            }
        }
Пример #3
0
        private static void ReplicatorInitiailizer(SysSettings sysSettings)
        {
            if (_isNewDownload)
            {
                _logFilesRep.Info(@"{""files"":[");
            }

            int totalPackages = GetTotalPackageCount(sysSettings);

            _log.Info($"Replicate {totalPackages} packages");
            Console.WriteLine($"Start replicate {totalPackages} packages");
            Thread.Sleep(2000);
        }
Пример #4
0
        private static string InitializeDownloadDir(SysSettings sysSettings)
        {
            string basePath = Path.Combine(sysSettings.DownloadDirectory, sysSettings.DownloadID.ToString());

            _dstPath = Path.Combine(basePath, sysSettings.Hash?"Hash":"Nugets");
            if (!Directory.Exists(_dstPath))
            {
                Directory.CreateDirectory(_dstPath);
                _isNewDownload = true;
            }

            return(basePath);
        }
Пример #5
0
        static void Main(string[] args)
        {
            try
            {
                Configuration conf        = Configuration.LoadFromFile("ReplicatorSettings.cfg");
                SysSettings   sysSettings = new SysSettings(conf["Sys"]);
                string        basePath    = InitializeDownloadDir(sysSettings);
                string        filename    = sysSettings.Hash ? "Hash" : "Replicator";
                log4net.GlobalContext.Properties["MetaDataLogFileName"] = $"{basePath}\\{filename}"; //log file path
                log4net.GlobalContext.Properties["GeneralLogFileName"]  = $"{basePath}\\log";        //log file path
                XmlConfigurator.Configure();

                _log.Info($"Start {filename} at {DateTime.Now}");

                ReplicatorInitiailizer(sysSettings);
                ReplicateNugetRepository(sysSettings);

                _log.Info($"Finish replicator at {DateTime.Now}");
                Console.WriteLine("Finish replicator process");

                if (sysSettings.Hash)
                {
                    _log.Info($"Increase DownloadID param by 1 to  {++sysSettings.DownloadID}");
                    conf["Sys"]["DownloadID"].IntValue = sysSettings.DownloadID;
                    conf.SaveToFile("ReplicatorSettings.cfg");
                    _log.Info($"Remove hash dir {_dstPath}");
                    Directory.Delete(_dstPath, true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"App Exception - for more details see log file");
                _log.Error($"Exception - {ex.Message}{Environment.NewLine}{ex.StackTrace}");
            }
            finally
            {
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
        }