public async void DisplayCmd(string command, bool unknownCommand = true) { await Dispatcher.BeginInvoke(new Action(() => { if (!unknownCommand && InternalSpeechRecognizer.DisplayUnknownCommands || unknownCommand) { ListBox.Items.Insert(0, command); } //ListBox.ScrollIntoView(command); }), DispatcherPriority.Background); if (Kernel.Tracking) { Tracking.Add("Command: " + command + " | Unknown: " + unknownCommand); } }
public ScriptInfo SetUp() { try { MethodInfo info; if (!CompiledMethods.TryGetValue(Path.GetFileName(Kernel.ActiveProfile) + "SetUp", out info)) { return(null); } if (Kernel.Tracking) { Tracking.Add("Loaded Profile: " + Kernel.ActiveProfile); } return((ScriptInfo)info.Invoke(null, null)); } catch { return(null); } }
private static string TakeJob() { if (L == null) { L = new Logger(); } string message; PendingWrites.TryDequeue(out message); if (PendingWrites.IsEmpty) { Mre.Reset(); } if (Kernel.Tracking) { Tracking.Add("Error: " + message); } return(message); }
public async Task AddNew(string temp, Action <TorrentInfo> action) { var info = new TorrentInfo(); action(info); info.Name = AuthToken.Generate(32); _lock.Wait(); try { Tracking.Add(info); } finally { _lock.Release(); } await Client.AddNewTorrent(x => { x.TorrentFilePath = temp; x.Rename = info.Name; x.Tags = new string[] { info.Lesson, $"{info.UploadedBy.Id}" }; x.Category = "lessons"; }); }
public RegisterStatus Register(string Username) { GetUsersResponse resp = api.Helix.Users.GetUsersAsync(logins: new List <string>() { Username }).Result; List <UserResponse> user = resp.Users.Select(t => new UserResponse(t)).ToList(); if (user.Count == 0) { return(RegisterStatus.UserNotFound); } if (Tracking.Contains(user[0].Id)) { return(RegisterStatus.AlreadyTracking); } Tracking.Add(user[0].Id); Offline.Add(user[0].Id); UserDatabase.Add(user[0].Id, user[0]); return(RegisterStatus.Success); }
public async Task Parse(string[] files, bool recursive, int?max, CancellationToken token) { _logger.LogInformation($"Parsing files, Recursive={recursive}, Max={max}, {(files.Select(x => $"File: {x}").ToStringVector(Environment.NewLine))}"); using var monitorToken = CancellationTokenSource.CreateLinkedTokenSource(token); Stopwatch sw = Stopwatch.StartNew(); Console.CancelKeyPress += (sender, e) => { e.Cancel = false; monitorToken.Cancel(); }; var parseOption = new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 20, BoundedCapacity = 1000 }; var batchOption = new GroupingDataflowBlockOptions { BoundedCapacity = 1000 }; var writeOption = new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 1, BoundedCapacity = 1000 }; var linkOption = new DataflowLinkOptions { PropagateCompletion = true }; TransformBlock <string, NmeaRecord?> toParse = new TransformBlock <string, NmeaRecord?>(x => _parseNmea.Parse(x), parseOption); BatchBlock <NmeaRecord?> toSaveBatch = new BatchBlock <NmeaRecord?>(100, batchOption); ActionBlock <NmeaRecord?[]> toSave = new ActionBlock <NmeaRecord?[]>(x => _store.Write(x), writeOption); toParse.LinkTo(toSaveBatch, linkOption); _ = toParse.Completion.ContinueWith(delegate { toSaveBatch.Complete(); }); toSaveBatch.LinkTo(toSave, linkOption); _ = toSaveBatch.Completion.ContinueWith(delegate { toSave.Complete(); }); _counters.Clear(); _tracking.Load(); _counters.Sampler = x => { x.Set(Counter.ToParseIn, toParse.InputCount); x.Set(Counter.ToParseOut, toParse.OutputCount); x.Set(Counter.ToSaveIn, toParse.InputCount); x.Set(Counter.ToSaveOut, toParse.OutputCount); }; // Start the process IReadOnlyList <string> readFiles = files .SelectMany(x => _fileReader.GetFiles(x !, true)) .Select(x => _tracking.Check(x)) .Where(x => x != null) .TakeWhile((x, i) => max == null || i < (int)max) .ToList() !; _counters.Monitor(monitorToken.Token); _counters.Set(Counter.FileQueued, readFiles.Count); foreach (var file in readFiles) { if (monitorToken.IsCancellationRequested) { break; } _tracking.Add(file); await _fileReader.ReadFile(file, toParse); } toParse.Complete(); await toSave.Completion; await _counters.Completion(monitorToken.Token); _logger.LogInformation("Shutting down"); monitorToken.Cancel(); _store.Close(); _tracking.Save(); // Report on performance sw.Stop(); _logger.LogInformation($"Final: {_counters.FinalScore(sw.Elapsed)}"); }