private static void GetVatsimClientRecordsFromLines(string[] lines) { bool client_section = false; Console.Write("Processing Vatsim Client Records from File... "); using (var progress = new ConsoleProgressBar()) { int count = 0; int total = lines.Length; foreach (string line in lines) { if (!IgnoreThisLine(line)) { progress.Report((double)count++ / total); Thread.Sleep(20); if (line.StartsWith("!CLIENTS:")) { client_section = true; continue; } if (line.StartsWith("!SERVERS:") || line.StartsWith("!PREFILE:")) { client_section = false; return; } if (client_section) { CurrentVatsimData.VatsimClientRecords.Add(VatsimClientRecord.GetVatsimClientRecord(line)); } } } } Console.WriteLine("Done."); }
private static async Task TestProgressBar(ConsoleProgressBar progress, int num) { Console.Write($"{num}. Performing some task... "); using (progress) { for (var i = 0; i <= 150; i++) { progress.Report((double)i / 150); await Task.Delay(20); } progress.Report(1); await Task.Delay(200); } Console.WriteLine(); }
private void JobItem_PropertyChanged(object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(JobItemStatus.Progress): _progressBar.Report(_jobItem.Progress); break; default: break; } }
/// <summary> /// Run through the list of clients to parse out ATC and Pilots /// </summary> public void ProcessVatsimClientRecords() { // are there any clients to process? if(VatsimClientRecords != null && VatsimClientRecords.Count > 0) { Console.Write("Writing Vatsim Objects to Database... "); // progress bar using(var progress = new ConsoleProgressBar()) { // get total count int count = 0; int total = VatsimClientRecords.Count; try { foreach (VatsimClientRecord record in VatsimClientRecords) { progress.Report((double)count++ / total); Thread.Sleep(20); switch(record.Clienttype) { case "ATC": VatsimDbHelper.UpdateOrCreateATCAsync(record.GetVatsimClientATCFromRecord()); break; case "PILOT": // only process IFR flights if(IFRONLY) { // check to see that this pilot has an IFR Plan Active if(IFRFlightPlanActive(record)) { VatsimDbHelper.UpdateOrCreatePilotAsync(record.GetVatsimClientPilotFromRecord()); VatsimDbHelper.UpdateOrCreateFlightAsync(record.GetVatsimClientPlannedFlightFromRecord()); VatsimDbHelper.CreatePositionAsync(record.GetVatsimClientPilotSnapshotFromRecord()); } } break; } } } catch(Exception exp) { Console.WriteLine($"{exp.Message}"); } } Console.WriteLine("Done."); } }
/// <summary> /// Execute the list of url test that have been setup /// </summary> /// <returns>True if no errors occurred / False if an error has occurred during testing.</returns> public virtual bool TestLinks() { ErrorMessages = new List <ErrorMessage>(); var returnValue = true; var i = 1; using (var progress = new ConsoleProgressBar(UrlList.Count())) { foreach (var item in UrlList) { var retval = TestLink(item); if (returnValue && !retval) { returnValue = retval; } progress.Report(i, item.Url); i++; } } return(returnValue); }
public override bool TestLinks() { ErrorMessages = new List <ErrorMessage>(); var returnValue = true; var i = 1; using (var progress = new ConsoleProgressBar(UrlList.Count())) { Parallel.ForEach(UrlList, (item) => { var retval = TestLink(item); if (returnValue && !retval) { returnValue = retval; } progress.Report(i, item.Url); Interlocked.Increment(ref i); }); } return(returnValue); }
static async Task Main(string[] args) { FileInfo fileInfo; if (args.Length < 1 || !(fileInfo = new FileInfo(args[0])).Exists) { Console.WriteLine("File not found!"); return; } Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var fname = Path.GetFileName(args[0]); CookieContainer cookieContainer = new CookieContainer(); cookieContainer.Add(new Cookie("member_id", Settings.MemberId, "/", "4pda.ru")); cookieContainer.Add(new Cookie("pass_hash", Settings.PassHash, "/", "4pda.ru")); HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli, UseCookies = true, CookieContainer = cookieContainer }; var httpClient = new HttpClient(handler).AddHeaders($"https://4pda.ru/forum/index.php?showtopic={Settings.TopicId}"); httpClient.Timeout = TimeSpan.FromSeconds(30); var req = new HttpRequestMessage(HttpMethod.Post, "https://4pda.ru/forum/index.php?act=attach") { Content = new FormUrlEncodedContent(new Dictionary <string, string> { { "allowExt", "" }, { "code", "check" }, { "forum-attach-files", "" }, { "index", "1" }, { "maxSize", "201326592" }, { "md5", GetMD5(fileInfo) }, { "name", fname }, { "relId", "0" }, { "size", fileInfo.Length.ToString() }, { "topic_id", Settings.TopicId } }) }; var res = await httpClient.SendAsync(req); var response = (await res.Content.ReadAsStringAsync()) .Replace("", "") .Replace('', ''); if (response != "0") { var result = response.Split(''); if (result.Length < 6) { Console.WriteLine($"UNACCEPTABLE FILE: {fname}"); return; } Console.WriteLine($"File {fname} exist on server"); } else { Console.Write(fname); Console.Write(" "); var progressBar = new ConsoleProgressBar { ForegroundColor = ConsoleColor.Cyan, NumberOfBlocks = 52, IncompleteBlock = " ", AnimationSequence = UniversalProgressAnimations.Explosion }; var client = new MyWebClient(cookieContainer, 30000).AddHeaders($"https://4pda.ru/forum/index.php?showtopic={Settings.TopicId}"); var multipart = new MultipartFormBuilder(); multipart.AddField("topic_id", Settings.TopicId); multipart.AddField("index", "1"); multipart.AddField("relId", "0"); multipart.AddField("maxSize", "201326592"); multipart.AddField("allowExt", ""); multipart.AddField("forum-attach-files", ""); multipart.AddField("code", "upload"); multipart.AddFile("FILE_UPLOAD", fileInfo); var totalBytes = multipart.GetStream().Length; client.UploadProgressChanged += (o, e) => { //progressBar.Report((double)e.BytesSent / e.TotalBytesToSend); // e.TotalBytesToSend is always -1 progressBar.Report((double)e.BytesSent / totalBytes); }; var tcs = new TaskCompletionSource <byte[]>(); client.UploadDataCompleted += (o, e) => { if (e.Cancelled) { progressBar.Report(0); } else { progressBar.Report(1); } response = Encoding.UTF8.GetString(e.Result) .Replace("", "") .Replace('', ''); var result = response.Split(''); if (response != "1" && result.Length < 6) { Console.WriteLine($"UNACCEPTABLE FILE: {fname}"); tcs.SetResult(e.Result); return; } Console.WriteLine(); Console.WriteLine($"File {fname} uploaded"); tcs.SetResult(e.Result); }; client.UploadMultipartAsync(new Uri("https://4pda.ru/forum/index.php?act=attach"), multipart); await tcs.Task; } }
public static async Task Main(string[] args) { ServiceLocator.Default.RegisterType <ILoggerService, LoggerService>(); ServiceLocator.Default.RegisterType <IMainController, MainController>(); var logger = ServiceLocator.Default.ResolveType <ILoggerService>(); // get csv data Console.WriteLine("Loading Hashes..."); await Loadhashes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources/archivehashes.csv")); #region commands var rootCommand = new RootCommand(); var archive = new Command("archive", "Target an archive to extract files or dump information.") { new Option <string>(new [] { "--path", "-p" }, "Input path to .archive."), new Option <string>(new [] { "--outpath", "-o" }, "Output directory to extract files to."), new Option <string>(new [] { "--pattern", "-w" }, "Use optional search pattern, e.g. *.ink. If bith regex and pattern is definedm, pattern will be used first"), new Option <string>(new [] { "--regex", "-r" }, "Use optional regex pattern."), new Option <bool>(new [] { "--extract", "-e" }, "Extract files from archive."), new Option <bool>(new [] { "--dump", "-d" }, "Dump archive information."), new Option <bool>(new [] { "--list", "-l" }, "List contents of archive."), new Option <bool>(new [] { "--uncook", "-u" }, "Uncooks textures from archive."), new Option <EUncookExtension>(new [] { "--uext" }, "Uncook extension (tga, bmp, jpg, png, dds). Default is tga."), new Option <ulong>(new [] { "--hash" }, "Extract single file with given hash."), }; rootCommand.Add(archive); archive.Handler = CommandHandler.Create <string, string, bool, bool, bool, bool, EUncookExtension, ulong, string, string> (ConsoleFunctions.ArchiveTask); var dump = new Command("dump", "Target an archive or a directory to dump archive information.") { new Option <string>(new [] { "--path", "-p" }, "Input path to .archive or to a directory (runs over all archives in directory)."), new Option <bool>(new [] { "--imports", "-i" }, "Dump all imports (all filenames that are referenced by all files in the archive)."), new Option <bool>(new [] { "--missinghashes", "-m" }, "List all missing hashes of all input archives."), new Option <bool>(new [] { "--texinfo" }, "Dump all xbm info."), new Option <bool>(new [] { "--classinfo" }, "Dump all class info."), }; rootCommand.Add(dump); dump.Handler = CommandHandler.Create <string, bool, bool, bool, bool>(ConsoleFunctions.DumpTask); var cr2w = new Command("cr2w", "Target a specific cr2w (extracted) file and dumps file information.") { new Option <string>(new [] { "--path", "-p" }, "Input path to a cr2w file."), new Option <bool>(new [] { "--all", "-a" }, "Dump all information."), new Option <bool>(new [] { "--chunks", "-c" }, "Dump all class information of file."), }; rootCommand.Add(cr2w); cr2w.Handler = CommandHandler.Create <string, bool, bool>(ConsoleFunctions.Cr2wTask); var hashTask = new Command("hash", "Some helper functions related to hashes.") { new Option <string>(new [] { "--input", "-i" }, "Create FNV1A hash of given string"), new Option <bool>(new [] { "--missing", "-m" }, ""), }; rootCommand.Add(hashTask); hashTask.Handler = CommandHandler.Create <string, bool>(ConsoleFunctions.HashTask); var oodleTask = new Command("oodle", "Some helper functions related to oodle compression.") { new Option <string>(new [] { "--path", "-p" }, ""), new Option <bool>(new [] { "--decompress", "-d" }, ""), }; rootCommand.Add(oodleTask); oodleTask.Handler = CommandHandler.Create <string, bool>(ConsoleFunctions.OodleTask); #endregion // Run if (args == null || args.Length == 0) { // write welcome message rootCommand.InvokeAsync("-h").Wait(); while (true) { string line = System.Console.ReadLine(); if (line == "q()") { return; } var parsed = CommandLineExtensions.ParseText(line, ' ', '"'); using var pb = new ConsoleProgressBar() { DisplayBars = true, DisplayAnimation = false }; logger.PropertyChanged += delegate(object?sender, PropertyChangedEventArgs args) { if (sender is LoggerService _logger) { switch (args.PropertyName) { case "Progress": { pb.Report(_logger.Progress.Item1); break; } default: break; } } }; rootCommand.InvokeAsync(parsed.ToArray()).Wait(); await WriteLog(); } } else { rootCommand.InvokeAsync(args).Wait(); await WriteLog(); } async Task WriteLog() { if (string.IsNullOrEmpty(logger.ErrorLogStr)) { return; } var t = DateTime.Now.ToString("yyyyMMddHHmmss"); var fi = new FileInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), $"errorlogs/log_{t}.txt")); if (fi.Directory != null) { Directory.CreateDirectory(fi.Directory.FullName); var log = logger.ErrorLogStr; await File.WriteAllTextAsync(fi.FullName, log); } else { } } }
public async void BatchProcessVatsimClientRecords() { // are there any clients to process? if(VatsimClientRecords != null && VatsimClientRecords.Count > 0) { Console.Write("Writing Vatsim Objects to Database... "); // progress bar using(var progress = new ConsoleProgressBar()) { // get total count int count = 0; int total = VatsimClientRecords.Count; //lists for controllers List<VatsimClientATCV1> controllerAddList = new List<VatsimClientATCV1>(); List<VatsimClientATCV1> controllerUpdateList = new List<VatsimClientATCV1>(); List<VatsimClientPilotV1> pilotsAddList = new List<VatsimClientPilotV1>(); List<VatsimClientPilotV1> pilotsUpdateList = new List<VatsimClientPilotV1>(); List<VatsimClientPlannedFlightV1> flightsAddList = new List<VatsimClientPlannedFlightV1>(); List<VatsimClientPlannedFlightV1> flightsUpdateList = new List<VatsimClientPlannedFlightV1>(); List<VatsimClientPilotSnapshotV1> positionsList = new List<VatsimClientPilotSnapshotV1>(); try { foreach (VatsimClientRecord record in VatsimClientRecords) { progress.Report((double)count++ / total); Thread.Sleep(20); switch(record.Clienttype) { case "ATC": var _controller = await VatsimDbHelper.FindControllerAsync(record.Cid, record.Callsign, record.TimeLogon); var controller = record.GetVatsimClientATCFromRecord(); if(_controller != null) { if(VatsimDbHelper.LogonTimeIsMoreRecent(_controller.TimeLogon, record.TimeLogon)) { controllerAddList.Add(controller); } else { _controller.Update(controller); controllerUpdateList.Add(_controller); } } else { controllerAddList.Add(controller); } break; case "PILOT": // only process IFR flights if(IFRONLY) { // check to see that this pilot has an IFR Plan Active if(IFRFlightPlanActive(record)) { //VatsimDbHepler.UpdateOrCreatePilotAsync(record.GetVatsimClientPilotFromRecord()); //look for pilot var _pilot = await VatsimDbHelper.FindPilotAsync(record.Cid, record.Callsign, record.TimeLogon); var pilot = record.GetVatsimClientPilotFromRecord(); if(_pilot != null) { if(VatsimDbHelper.LogonTimeIsMoreRecent(_pilot.TimeLogon, pilot.TimeLogon)) { pilotsAddList.Add(pilot); } else { _pilot.Update(pilot); pilotsUpdateList.Add(_pilot); } } else { pilotsAddList.Add(pilot); } //look for flight plan //VatsimDbHepler.UpdateOrCreateFlightAsync(record.GetVatsimClientPlannedFlightFromRecord()); var _flight = await VatsimDbHelper.FindFlightAsync(record.Cid, record.Callsign, record.TimeLogon, record.PlannedDepairport, record.PlannedDestairport); var flight = record.GetVatsimClientPlannedFlightFromRecord(); if(_flight != null) { if(VatsimDbHelper.LogonTimeIsMoreRecent(_flight.TimeLogon, flight.TimeLogon)) { flightsAddList.Add(flight); } else { _flight.Update(flight); flightsUpdateList.Add(_flight); } } else { flightsAddList.Add(flight); } //create position update positionsList.Add(record.GetVatsimClientPilotSnapshotFromRecord()); } } break; } } // make db changes // controllers VatsimDbHelper.UpdateControllersFromListAsync(controllerUpdateList); VatsimDbHelper.CreateControllersFromListAsync(controllerAddList); //pilots VatsimDbHelper.UpdatePilotsFromListAsync(pilotsUpdateList); VatsimDbHelper.CreatePilotsFromListAsync(pilotsAddList); //flights VatsimDbHelper.UpdateFlightsFromListAsync(flightsUpdateList); VatsimDbHelper.CreateFlightsFromListAsync(flightsAddList); //positions VatsimDbHelper.CreatePositionsFromListAsync(positionsList); } catch(Exception exp) { Console.WriteLine($"{exp.StackTrace}"); } } Console.WriteLine("Done."); } }