private async Task <bool> RunCollectionFlow() { List <Task> taskList; _logger.Add($"Setting up connection to Sense Server on {ServiceVariables.DnsHostName}"); var dto = new SenseConnectDto { SenseHostName = ServiceVariables.DnsHostName, ConnectToSenseApiManuallyDlg = ConnectToSenseApiManuallyDlg }; await Task.Run(() => { var a = new ConnectToSenseHelper(_logger).ConnectToSenseApi(dto); dto = a; _notify("Connected to Qlik Sense Installation", MessageLevels.Ok, "Connecting"); }).ConfigureAwait(false); if (dto == null || dto.AbortAndExit) { AbortAndExit = true; _logger.Add("Aborting connection requested."); _notify("Aborting.", MessageLevels.Error, null); _onFinished(null, null, this); return(false); } if (dto.RunWithDeadInstallation) { _logger.Add("Running with local folders only"); taskList = GetTasksForDeadInstallation(dto); if (taskList == null) { return(false); } taskList.AddRange(GetTasksForWindows()); } else { taskList = await GetTasksForFullRun(dto).ConfigureAwait(false); taskList.AddRange(GetTasksForWindows()); } await Task.WhenAll(taskList).ContinueWith(p => { _logger.Add("Finished collection part"); _logger.Add(JsonConvert.SerializeObject(ServiceVariables)); Log.Shutdown(); Task.Delay(TimeSpan.FromSeconds(2)).ConfigureAwait(false); var pathToZip = _collectorHelper.CreateZipFile(ServiceVariables); ServiceVariables.CollectorOutput.ZipFile = pathToZip; _notify(pathToZip, MessageLevels.Ok, null); try { Task.Delay(TimeSpan.FromSeconds(2)).ContinueWith(task => { // give the system time to flush the filesystem. FileSystem.Singleton.DeleteDirectory(ServiceVariables.OutputFolderPath); }); } catch (Exception e) { Trace.WriteLine(e); //nothing to log home about :( the log is already zipped. } //if (Settings.UseOnlineDelivery) // var transport = new Sender(Settings.Key, Settings.SendId); // transport.Transport(Settings.OnlineReccever, Settings.CollectorOutput.ZipFile); AbortAndExit = false; _onFinished(null, null, this); } ).ConfigureAwait(false); return(true); }
private async Task <bool> RunCollectionFlow() { _logger.Add($"Setting up connection to QlikView Server on {ServiceVariables.QvSettings.QmsAddress}"); var dto = new QlikViewConnectDto { ConnectToQmsApiManuallyDlg = ConnectToApiManuallyDlg, QmsAddress = ServiceVariables.QvSettings.QmsAddress }; await Task.Run(() => { var helper = new ConnectToQlikViewHelper(_logger); dto = helper.ConnectToQmsApi(dto); }).ConfigureAwait(false); if (dto == null || dto.AbortAndExit) { AbortAndExit = true; _logger.Add("Aborting connection requested."); _notify("Failed Connecting to QlikView Installation", MessageLevels.Error, "Connecting"); _notify("Aborting.", MessageLevels.Error, null); _onFinished(null, null, this); return(false); } try { var taskList = new List <Task>(); ServiceVariables.QvSettings.QmsAddress = dto.QmsAddress; //_apiCollector = new ApiCollector(_logger, _notify, ServiceVariables,dto); if (dto.RunWithDeadInstallation) { _notify("Not connected to QlikView", MessageLevels.Warning, "Connecting"); dto = PathToLogFolderDlg.Invoke(dto); if (dto.AbortAndExit) { _notify("Failed Connecting to QlikView Installation", MessageLevels.Error, "Connecting"); _notify("Aborting.", MessageLevels.Error, null); _onFinished(null, null, this); return(false); } ServiceVariables.QvSettings.QvLogLocations.Add(new QvLogLocation { LogCollectionType = QvLogCollectionType.All, Name = "BasicLogs", Path = dto.PathToLocalLogFolder }); taskList.AddRange(GetTasksForWindows()); taskList.AddRange(GetDeadLogTasks()); } else { _notify("Connected to QlikView Installation", MessageLevels.Ok, "Connecting"); taskList.AddRange(GetApiTasks()); taskList.AddRange(GetTasksForWindows()); } await Task.WhenAll(taskList).ContinueWith(p => { _logger.Add("Finished collection part"); _logger.Add(JsonConvert.SerializeObject(ServiceVariables)); Log.Shutdown(); Task.Delay(TimeSpan.FromSeconds(2)).ConfigureAwait(false); var pathToZip = _collectorHelper.CreateZipFile(ServiceVariables); ServiceVariables.CollectorOutput.ZipFile = pathToZip; _notify(pathToZip, MessageLevels.Ok, null); try { Task.Delay(TimeSpan.FromSeconds(2)).ContinueWith(task => { // give the system time to flush the filesystem. FileSystem.Singleton.DeleteDirectory(ServiceVariables.OutputFolderPath); }); } catch (Exception e) { Trace.WriteLine(e); //nothing to log home about :( the log is already zipped. } AbortAndExit = false; _onFinished(null, null, this); } ).ConfigureAwait(false); return(true); } catch (Exception e) { Console.WriteLine(e); } return(true); }