public async Task Smoke(bool fastSync, bool fastBlocks) { ISyncModeSelector selector = Substitute.For <ISyncModeSelector>(); ISyncPeerPool pool = Substitute.For <ISyncPeerPool>(); pool.InitializedPeersCount.Returns(1); Queue <SyncMode> _syncModes = new Queue <SyncMode>(); _syncModes.Enqueue(SyncMode.WaitingForBlock); _syncModes.Enqueue(SyncMode.FastSync); _syncModes.Enqueue(SyncMode.Full); _syncModes.Enqueue(SyncMode.FastBlocks); _syncModes.Enqueue(SyncMode.StateNodes); _syncModes.Enqueue(SyncMode.Disconnected); SyncConfig syncConfig = new SyncConfig(); syncConfig.FastBlocks = fastBlocks; syncConfig.FastSync = fastSync; SyncReport syncReport = new SyncReport(pool, Substitute.For <INodeStatsManager>(), selector, syncConfig, LimboLogs.Instance, 10); selector.Current.Returns((ci) => _syncModes.Count > 0 ? _syncModes.Dequeue() : SyncMode.Full); await Task.Delay(200); syncReport.FastBlocksHeaders.MarkEnd(); syncReport.FastBlocksBodies.MarkEnd(); syncReport.FastBlocksReceipts.MarkEnd(); await Task.Delay(20); }
/// <summary> /// Displays the given <see cref="SyncReport"/>. /// </summary> /// <param name="syncReport">The <see cref="SyncReport"/>.</param> public void Process(SyncReport syncReport) { this.resultViewModel.SyncReport = syncReport; this.resultViewModel.SelectedFileList = 0; this.startViewModel.SelectedTasklist.LastSyncDate = DateTime.Now; this.MainViewModel.CurrentSyncView = this.resultViewModel; }
/// <summary> /// Called when the result should be displayed. /// </summary> /// <param name="syncReport">The sync report.</param> protected virtual void OnResult(SyncReport syncReport) { if (Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.IsPlatformSupported) { var taskbarManager = Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance; taskbarManager.SetProgressState(Microsoft.WindowsAPICodePack.Taskbar.TaskbarProgressBarState.NoProgress); } if (this.Result != null) { this.Result(syncReport); } }
/// <summary> /// Shows the results. /// </summary> /// <param name="syncReport">The sync report.</param> private static void ShowResults(SyncReport syncReport) { System.Console.WriteLine(Common.Statistics + ":"); System.Console.WriteLine(" " + Common.CreateFilesSuccess + ": " + syncReport.SuccessCopyFiles + " / " + syncReport.TotalCopyFiles); System.Console.WriteLine(" " + Common.DeleteFilesSuccess + ": " + syncReport.SuccessDeleteFiles + " / " + syncReport.TotalDeleteFiles); System.Console.WriteLine(" " + Common.CreateDirectoriesSuccess + ": " + syncReport.SuccessCreateDirectories + " / " + syncReport.TotalCreateDirectories); System.Console.WriteLine(" " + Common.DeleteDirectoriesSuccess + ": " + syncReport.SuccessDeleteDirectories + " / " + syncReport.TotalDeleteDirectories); if (!string.IsNullOrEmpty(syncReport.LogFilePath)) { System.Console.WriteLine(); System.Console.WriteLine(Common.Logfile + ":"); System.Console.WriteLine(" " + syncReport.LogFilePath); } }
public void Smoke() { SyncReport syncReport = new SyncReport(Substitute.For <IEthSyncPeerPool>(), Substitute.For <INodeStatsManager>(), new SyncConfig(), Substitute.For <ISyncProgressResolver>(), Substitute.For <ISyncModeSelector>(), LimboLogs.Instance, 10); Thread.Sleep(20); syncReport.CurrentSyncMode = SyncMode.FastSync; Thread.Sleep(20); syncReport.CurrentSyncMode = SyncMode.Full; Thread.Sleep(20); syncReport.CurrentSyncMode = SyncMode.FastBlocks; Thread.Sleep(20); syncReport.CurrentSyncMode = SyncMode.StateNodes; Thread.Sleep(20); syncReport.CurrentSyncMode = SyncMode.WaitForProcessor; Thread.Sleep(20); syncReport.FastBlocksHeaders.MarkEnd(); syncReport.FastBlocksBodies.MarkEnd(); syncReport.FastBlocksReceipts.MarkEnd(); syncReport.CurrentSyncMode = SyncMode.WaitForProcessor; Thread.Sleep(20); }
public async Task <SyncReport> ApplyAsync(SyncPlan syncPlan) { var syncReport = new SyncReport(); if (syncPlan.ToAdd.Any() && _options.Value.AgreeToAdd(syncPlan.ToAdd)) { foreach (var workLog in syncPlan.ToAdd) { syncReport.AddedEntries.Add(await _target.AddWorkLogAsync(workLog)); } } if (syncPlan.ToUpdate.Any() && _options.Value.AgreeToUpdate(syncPlan.ToUpdate)) { foreach (var workLog in syncPlan.ToUpdate) { syncReport.UpdatedEntries.Add(await _target.UpdateWorkLogAsync(workLog)); } } if (syncPlan.ToDeleteOrphaned.Any() && _options.Value.AgreeToDeleteOrphaned(syncPlan.ToDeleteOrphaned)) { foreach (var workLog in syncPlan.ToDeleteOrphaned) { syncReport.DeletedOrphanedEntries.Add(await _target.DeleteWorkLogAsync(workLog)); } } if (syncPlan.ToDeleteDuplicates.Any() && _options.Value.AgreeToDeleteDuplicates(syncPlan.ToDeleteDuplicates)) { foreach (var workLog in syncPlan.ToDeleteDuplicates) { syncReport.DeletedDuplicateEntries.Add(await _target.DeleteWorkLogAsync(workLog)); } } syncReport.NoChanges = syncPlan.NoChanges; return(syncReport); }
private async Task <SyncReport> SendMessage <T>(string endpoint, Guid clientId, T message) { SyncReport report = null; SynchronizeClientsResponse result = null; string jsonMessage = string.Empty; if (null == message) { return(null); } try { var response = await _restClient.Client.PostAsJsonAsync(endpoint, message); if (response.IsSuccessStatusCode) { result = await response.Content.ReadAsJsonAsync <SynchronizeClientsResponse>(); _results.Add(result); report = SyncReport.GenerateSuccess(clientId, endpoint, result); } else { jsonMessage = JsonConvert.SerializeObject(message, Formatting.Indented); try { result = await response.Content.ReadAsJsonAsync <SynchronizeClientsResponse>(); } catch { Log.Error(new string('+', 40)); Log.Error(new string('+', 40)); Log.Error($"Unkown server Error!"); var error = await response.Content.ReadAsStringAsync(); Log.Error(error); Log.Error(new string('+', 40)); Log.Error(new string('+', 40)); } Log.Debug(new string('_', 50)); Log.Error($"{endpoint}"); Log.Error($"\n{jsonMessage}\n"); Log.Debug(new string('-', 50)); if (null != result) { _errors = result?.Errors; throw new Exception($"Error processing request: {result?.ErrorMessage}"); } else { response.EnsureSuccessStatusCode(); } } } catch (Exception e) { Log.Error(e, $"error posting to endpint [{endpoint}] for {nameof(IndexClientMessage)}"); _errors.Add(new ErrorResponse($"{endpoint} || {e.Message}")); report = SyncReport.GenerateFail(clientId, endpoint, result, jsonMessage, e, e.Message); } return(report); }
private async Task <IEnumerable <SynchronizeClientsResponse> > WriteMessage(string endpoint, params LoadAction[] actions) { _errors = new List <ErrorResponse>(); _results = new List <SynchronizeClientsResponse>(); var htsClients = await _loader.Load(null, actions); foreach (var htsClient in htsClients) { try { // LoadAction.RegistrationOnly SyncReport screeningReport = null; SyncReport tracingReport = null; var demographicsReport = await SendMessage($"{endpoint}/partnerdemographics", htsClient.ClientId, GetMessage <PartnerMessage>(htsClient)); if (null != demographicsReport && demographicsReport.IsSuccess) { // LoadAction.ContactScreenig screeningReport = await SendMessage($"{endpoint}/partnerScreening", htsClient.ClientId, GetMessage <PartnerScreening>(htsClient)); // LoadAction.ContactTracing tracingReport = await SendMessage($"{endpoint}/partnerTracing", htsClient.ClientId, GetMessage <PartnerTracing>(htsClient)); } if (null != demographicsReport) { if (demographicsReport.HasResponse) { _results.Add(demographicsReport.Response); } _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, demographicsReport.Status, demographicsReport.ExceptionInfo); } ///////////////// if (null != screeningReport) { if (screeningReport.HasResponse) { _results.Add(screeningReport.Response); } _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, screeningReport.Status, screeningReport.ExceptionInfo); } if (null != tracingReport) { if (tracingReport.HasResponse) { _results.Add(tracingReport.Response); } _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, tracingReport.Status, tracingReport.ExceptionInfo); } } catch (Exception e) { _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, SyncStatus.SentFail, e.Message); } } return(_results); }
private async Task <IEnumerable <SynchronizeClientsResponse> > WriteMessage(string endpoint, params LoadAction[] actions) { _errors = new List <ErrorResponse>(); _results = new List <SynchronizeClientsResponse>(); var htsClients = await _loader.Load(null, actions); foreach (var htsClient in htsClients) { try { // LoadAction.RegistrationOnly SyncReport pretestReport = null; SyncReport htstestReport = null; SyncReport referrallReport = null; SyncReport tracingReport = null; SyncReport linkageReport = null; var demographicsReport = await SendMessage($"{endpoint}/demographics", htsClient.ClientId, GetMessage <DemographicMessage>(htsClient)); if (null != demographicsReport && demographicsReport.IsSuccess) { // LoadAction.Pretest pretestReport = await SendMessage($"{endpoint}/htsPretest", htsClient.ClientId, GetMessage <PretestMessage>(htsClient)); if (null != pretestReport && pretestReport.IsSuccess) { // LoadAction.Testing htstestReport = await SendMessage($"{endpoint}/htsTests", htsClient.ClientId, GetMessage <TestsMessage>(htsClient)); } // LoadAction.Referral referrallReport = await SendMessage($"{endpoint}/htsReferral", htsClient.ClientId, GetMessage <ReferralMessage>(htsClient)); // LoadAction.Tracing tracingReport = await SendMessage($"{endpoint}/htsTracing", htsClient.ClientId, GetMessage <TracingMessage>(htsClient)); // LoadAction.Linkage linkageReport = await SendMessage($"{endpoint}/htsLinkage", htsClient.ClientId, GetMessage <LinkageMessage>(htsClient)); } if (null != demographicsReport) { if (demographicsReport.HasResponse) { _results.Add(demographicsReport.Response); } _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, demographicsReport.Status, demographicsReport.ExceptionInfo); } ////////// if (null != pretestReport) { if (pretestReport.HasResponse) { _results.Add(pretestReport.Response); } _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, pretestReport.Status, pretestReport.ExceptionInfo); } if (null != htstestReport) { if (htstestReport.HasResponse) { _results.Add(htstestReport.Response); } _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, htstestReport.Status, htstestReport.ExceptionInfo); } if (null != referrallReport) { if (referrallReport.HasResponse) { _results.Add(referrallReport.Response); } _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, referrallReport.Status, referrallReport.ExceptionInfo); } if (null != tracingReport) { if (tracingReport.HasResponse) { _results.Add(tracingReport.Response); } _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, tracingReport.Status, tracingReport.ExceptionInfo); } if (null != linkageReport) { if (linkageReport.HasResponse) { _results.Add(linkageReport.Response); } _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, linkageReport.Status, linkageReport.ExceptionInfo); } } catch (Exception e) { _clientStageRepository.UpdateSyncStatus(htsClient.ClientId, SyncStatus.SentFail, e.Message); } } return(_results); }
public void MyTestInitialize() { this.target = new SyncReport(); }