private void SetProfilers(IoEventType eventTypes) { if ((eventTypes & IoEventType.MessageReceived) == IoEventType.MessageReceived) { _messageReceivedTimerWorker = new TimerWorker(); _profileMessageReceived = true; } if ((eventTypes & IoEventType.MessageSent) == IoEventType.MessageSent) { _messageSentTimerWorker = new TimerWorker(); _profileMessageSent = true; } if ((eventTypes & IoEventType.SessionCreated) == IoEventType.SessionCreated) { _sessionCreatedTimerWorker = new TimerWorker(); _profileSessionCreated = true; } if ((eventTypes & IoEventType.SessionOpened) == IoEventType.SessionOpened) { _sessionOpenedTimerWorker = new TimerWorker(); _profileSessionOpened = true; } if ((eventTypes & IoEventType.SessionIdle) == IoEventType.SessionIdle) { _sessionIdleTimerWorker = new TimerWorker(); _profileSessionIdle = true; } if ((eventTypes & IoEventType.SessionClosed) == IoEventType.SessionClosed) { _sessionClosedTimerWorker = new TimerWorker(); _profileSessionClosed = true; } }
private void ContinueTimer() { try { //Check if Exceess Errors if (_ExceptionCounts >= 60) { Logger.LogWarning("Terminating Service Due to Exceeding Error Counts"); this.CurrentStatus = QueueProcessorStatus.Stopping; StopServiceAsync(); return; } if (TimerWorker == null) { return; } if (this.CurrentStatus == QueueProcessorStatus.Stopped || this.CurrentStatus == QueueProcessorStatus.Stopping) { return; } //Continue Timer TimerWorker.Start(); this.CurrentStatus = QueueProcessorStatus.Running; } catch (Exception ex) { Logger.LogError(ex.Message); } }
private void StatusForm_Load(object sender, EventArgs e) { WireMessage myLogger = new WireMessage(WriteMessage); output = new OutputWorker(myLogger); timerWorker = new TimerWorker(); timerWorker.Run(output); }
private void Profile(Boolean profile, TimerWorker worker, Action action) { if (profile) { Int64 start = TimeNow(); action(); Int64 end = TimeNow(); worker.AddNewDuration(end - start); } else { action(); } }
public Task StopServiceAsync() { Logger.LogInformation("Stopping Service"); this.CurrentStatus = QueueProcessorStatus.Stopping; if (TimerWorker != null) { TimerWorker.Stop(); } //Stop Client if (TorrentEngine != null) { this.TorrentEngine.StopAllAsync(); } this.CurrentStatus = QueueProcessorStatus.Stopped; Logger.LogInformation("Service Stopped"); return(Task.CompletedTask); }
/// <summary> /// Start this timer. /// </summary> public void Start () { if (timer != null) timer.Enabled = false; timer = new TimerWorker (interval, timerHandler, this); }
private async void OnTimedEvent(object source, ElapsedEventArgs e) { try { if (TorrentEngine == null) { throw new Exception("Torrent Engine has not been started yet"); } TimerWorker.Stop(); this.CurrentStatus = QueueProcessorStatus.Seeding; Logger.LogInformation($"Running AT: {DateTime.UtcNow} UTC"); using (var scope = ScopeFactory.CreateScope()) { var Db = scope.ServiceProvider.GetRequiredService <HostedRepository>(); var allQueues = Db.BitClientProcessorQueues.Where(x => x.ExecutionStatus == ExecutionStatus.Queued).ToList(); if (allQueues != null && allQueues.Count > 0) { foreach (var queue in allQueues) { //Mark as Seeding queue.ExecutionStatus = ExecutionStatus.Seeding; queue.LastUpdatedTimeUTC = DateTime.UtcNow; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { Logger.LogInformation($"Processing, Queue Tracking ID:{queue.TrackingId} AT: {DateTime.UtcNow} UTC"); #region ExecutionMain // Load a .torrent file into memory if (queue.TorrentFileBytes == null) { throw new Exception("Torrent Content in Bytes is Empty"); } Torrent torrent = await Torrent.LoadAsync(queue.TorrentFileBytes); // Set all the files to not download //foreach (TorrentFile file in torrent.Files) // file.Priority = Priority.High; ////Set First File Prioroty //torrent.Files[1].Priority = Priority.Highest; string subPath = $"\\{queue.UserId}\\{queue.TrackingId}".ToUpper(); string saveDirectory = GetTorrentDownloadPath() + subPath; UserTorrentManager manager = new UserTorrentManager(torrent, saveDirectory, new TorrentSettings()); //Asssign manager.UserId = queue.UserId; manager.TrackingId = queue.TrackingId; manager.AvailableDownloadPath = $"{this.options.TorrentDownloadPath}{subPath}"; await TorrentEngine.Register(manager); Db.UserTorrentManagers.Enqueue(manager); // Disable rarest first and randomised picking - only allow priority based picking (i.e. selective downloading) PiecePicker picker = new StandardPicker(); picker = new PriorityPicker(picker); await manager.ChangePickerAsync(picker); await this.TorrentEngine.StartAll(); #endregion queue.ExecutionFeedBack = "Torrent added to Queue Successfully"; queue.ExecutionStatus = ExecutionStatus.Processed; Logger.LogInformation($"Torrent added to Queue Successfully, Tracking Id :{queue.TrackingId} AT: {DateTime.UtcNow} UTC"); } catch (Exception ex) { queue.ErrorsCount++; if (queue.ErrorsCount >= 5) { queue.ExecutionStatus = ExecutionStatus.ErrorOccurred; queue.ExecutionFeedBack = ex.Message; } else { queue.ExecutionStatus = ExecutionStatus.Queued; queue.ExecutionFeedBack = $"Requeued Attempt ({queue.ErrorsCount})"; } Logger.LogError($"ERROR: {ex.Message}, Tracking Id :{queue.TrackingId} AT: {DateTime.UtcNow} UTC"); } //**************** DONE ********************* stopWatch.Stop(); queue.LastUpdatedTimeUTC = DateTime.UtcNow; queue.ExecutionInMiliseconds = stopWatch.ElapsedMilliseconds; } } //Exception Count Reset _ExceptionCounts = 0; } } catch (Exception ex) { _ExceptionCounts++; Logger.LogError($"Processing Exception: {ex.Message}"); } finally { ContinueTimer(); } }