/// <summary>
        /// Process message once status is received by moving document to the
        /// appropriate folder and writing out a log for the processed document
        /// </summary>
        /// <param name="executionStatus">Execution status</param>
        /// <param name="dataMessage">Name of the file whose status is being processed</param>
        private void PostProcessMessage(string executionStatus, DataMessage dataMessage)
        {
            switch (executionStatus)
            {
            case "Succeeded":
            {
                // Move message file and delete processing status file
                var processingSuccessDestination = Path.Combine(_settings.ProcessingSuccessDir, dataMessage.Name);
                _retryPolicyForIo.Execute(() => FileOperationsHelper.MoveDataToTarget(dataMessage.FullPath, processingSuccessDestination, true, _settings.StatusFileExtension));
                CreateLinkToExecutionSummaryPage(dataMessage.MessageId, processingSuccessDestination);
            }
            break;

            case "Unknown":
            case "PartiallySucceeded":
            case "Failed":
            case "Canceled":
            {
                var processingErrorDestination = Path.Combine(_settings.ProcessingErrorsDir, dataMessage.Name);
                _retryPolicyForIo.Execute(() => FileOperationsHelper.MoveDataToTarget(dataMessage.FullPath, processingErrorDestination, true, _settings.StatusFileExtension));
                CreateLinkToExecutionSummaryPage(dataMessage.MessageId, processingErrorDestination);
            }
            break;

            default:     //"NotRun", "Executing"
                break;
            }
        }
        /// <summary>
        /// Process message once status is received by moving document to the
        /// appropriate folder and writing out a log for the processed document
        /// </summary>
        /// <param name="jobStatusDetail">DataJobStatusDetail object</param>
        /// <param name="dataMessage">Name of the file whose status is being processed</param>
        private void PostProcessMessage(DataJobStatusDetail jobStatusDetail, DataMessage dataMessage)
        {
            if (jobStatusDetail?.DataJobStatus == null)
            {
                return;
            }

            dataMessage.DataJobState = jobStatusDetail.DataJobStatus.DataJobState;

            FileOperationsHelper.WriteStatusFile(dataMessage, _settings.StatusFileExtension);

            switch (dataMessage.DataJobState)
            {
            case DataJobState.Processed:
            {
                // Move message file and delete processing status file
                FileOperationsHelper.MoveDataToTarget(dataMessage.FullPath, Path.Combine(_settings.ProcessingSuccessDir, dataMessage.Name), true);
            }
            break;

            case DataJobState.PostProcessError:
            case DataJobState.PreProcessError:
            case DataJobState.ProcessedWithErrors:
            {
                var targetDataMessage = new DataMessage(dataMessage)
                {
                    FullPath      = Path.Combine(_settings.ProcessingErrorsDir, dataMessage.Name),
                    MessageStatus = MessageStatus.Failed
                };
                FileOperationsHelper.MoveDataToTarget(dataMessage.FullPath, targetDataMessage.FullPath);
                FileOperationsHelper.WriteStatusLogFile(jobStatusDetail, targetDataMessage, null, _settings.StatusFileExtension);
            }
            break;
            }
        }
        private void CreateBackup()
        {
            var relativeFilePaths   = GetRelativeBackupFilePaths();
            var absoluteSourcePaths = relativeFilePaths.Select(fp => Path.Combine(_gamePath, fp)).ToList();

            var backupVersion      = _gtaVersionProvider.GetCurrentGtaVersion().Build;
            var backupName         = $"downgrade_{backupVersion}_{GetGtaGameType(_gamePath)}";
            var backupPath         = Path.Combine(GetBackupPath(), backupName);
            var archivePath        = Path.Combine(GetBackupPath(), backupName + ".zip");
            var totalBackupSize    = FileOperationsHelper.CalculateTotalFileSizes(absoluteSourcePaths);
            var readableBackupSize = FileOperationsHelper.BytesToReadableString(totalBackupSize);

            if (MessageBox.Show($"The backup will take {readableBackupSize} of disk space and might take some minutes. Continue?", "Backup disk usage", MessageBoxButton.YesNoCancel) != MessageBoxResult.Yes)
            {
                return;
            }

            _logger.Write($"Backup has started. ( Type = {GetGtaGameType(_gamePath)}, Gta 5 Version = {_gtaVersionProvider.GetCurrentGtaVersion()} )");
            FileOperationsHelper.CopyFiles(_gamePath, backupPath, relativeFilePaths);
            _logger.Write("Backup has completed.");
            _logger.Write("Archiving Backup.");
            ZipFile.CreateFromDirectory(backupPath, archivePath, CompressionLevel.NoCompression, false);
            Directory.Delete(backupPath, true);
            _logger.Write("Archiving completed.");
            _notificationService.ShowNotification("Successfully created a backup of your GTA 5 files.");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Processes this instance.
        /// </summary>
        /// <returns></returns>
        private async Task Process()
        {
            InputQueue = new ConcurrentQueue <DataMessage>();

            var oneDriveAuthenticationHelper = new OneDriveAuthenticationHelper(
                "", // TODO: Client Id of the OneDrive Azure app
                "", // TODO: Tenant Id of the OneDrive Azure app
                "", // TODO: Username of the user who's OneDrive will be used
                ""  // TODO: Password for the user
                );

            // This action will create a GraphClient which later will be user for other OneDrive actions
            // I will not be writing any more code about that functionality, since it's not important at the time being
            // When creation of GraphClient will be called from here, it will throw an error that Newtonsoft 6.0.0.0 is not being loaded, although it's referenced in the project.
            await oneDriveAuthenticationHelper.GetAuthenticatedClient();

            foreach (
                var dataMessage in FileOperationsHelper.GetFiles(MessageStatus.Input, _settings.InputDir, _settings.SearchPattern, SearchOption.AllDirectories, _settings.OrderBy, _settings.ReverseOrder))
            {
                if (_settings.LogVerbose || Log.IsDebugEnabled)
                {
                    Log.DebugFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_File_1_found_in_input_location, _context.JobDetail.Key, dataMessage.FullPath.Replace(@"{", @"{{").Replace(@"}", @"}}")));
                }
                InputQueue.Enqueue(dataMessage);
            }

            if (!InputQueue.IsEmpty)
            {
                Log.InfoFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_Found_1_file_s_in_input_folder, _context.JobDetail.Key, InputQueue.Count));
                await ProcessInputQueue();
            }
        }
        public frmEthereumAccountDetails(string userFile)
        {
            InitializeComponent();

            UserFile   = userFile;
            fileHelper = new FileOperationsHelper();
        }
        public async Task UpdateSelf()
        {
            var applicationFileName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);

            FileOperationsHelper.EnsureFileDirectory(GetUpdateDownloadPath());

            if (!await TryDownloadNewLauncher(GetUpdateDownloadPath()))
            {
                _notificationService.ShowNotification("Failed to download new launcher.", true);
                return;
            }

            if (!await ExtractUpdate(GetUpdateDownloadPath()))
            {
                _notificationService.ShowNotification("Failed to extract launcher update.", true);
                return;
            }

            var updateBatTargetPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "update.bat");

            if (!await TryExtractUpdateBat(updateBatTargetPath))
            {
                _notificationService.ShowNotification("Failed to perform update.", true);
                return;
            }

            Process.Start(updateBatTargetPath, applicationFileName);
            Process.GetCurrentProcess().Kill();
        }
        /// <summary>
        /// Process message once status is received by moving document to the
        /// appropriate folder and writing out a log for the processed document
        /// </summary>
        /// <param name="jobStatusDetail">DataJobStatusDetail object</param>
        /// <param name="dataMessage">Name of the file whose status is being processed</param>
        /// <param name="cancellationToken">Cancellation token</param>
        private async Task PostProcessMessage(DataJobStatusDetail jobStatusDetail, DataMessage dataMessage, CancellationToken cancellationToken)
        {
            if (jobStatusDetail?.DataJobStatus == null)
            {
                return;
            }
            dataMessage.DataJobState = jobStatusDetail.DataJobStatus.DataJobState;

            await _retryPolicyForAsyncIo.ExecuteAsync(ct => FileOperationsHelper.WriteStatusFileAsync(dataMessage, _settings.StatusFileExtension, ct), cancellationToken);

            switch (dataMessage.DataJobState)
            {
            case DataJobState.Processed:
            {
                // Move message file and delete processing status file
                _retryPolicyForIo.Execute(() => FileOperationsHelper.MoveDataToTarget(dataMessage.FullPath, Path.Combine(_settings.ProcessingSuccessDir, dataMessage.Name), true));
            }
            break;

            case DataJobState.PostProcessError:
            case DataJobState.PreProcessError:
            case DataJobState.ProcessedWithErrors:
            {
                var targetDataMessage = new DataMessage(dataMessage)
                {
                    FullPath      = Path.Combine(_settings.ProcessingErrorsDir, dataMessage.Name),
                    MessageStatus = MessageStatus.Failed
                };
                _retryPolicyForIo.Execute(() => FileOperationsHelper.MoveDataToTarget(dataMessage.FullPath, targetDataMessage.FullPath));
                await _retryPolicyForAsyncIo.ExecuteAsync(ct => FileOperationsHelper.WriteStatusLogFileAsync(jobStatusDetail, targetDataMessage, null, _settings.StatusFileExtension, ct), cancellationToken);

                if (_settings.GetExecutionErrors)
                {
                    if (_settings.LogVerbose || Log.IsDebugEnabled)
                    {
                        Log.DebugFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_Trying_to_download_execution_errors, _context.JobDetail.Key));
                    }
                    var response = await _httpClientHelper.GetExecutionErrors(dataMessage.MessageId, cancellationToken);

                    if (!response.IsSuccessStatusCode)
                    {
                        throw new JobExecutionException(string.Format(Resources.Job_0_download_of_execution_errors_failed_1, _context.JobDetail.Key, string.Format($"Status: {response.StatusCode}. Message: {response.Content}")));
                    }
                    using Stream downloadedStream = await response.Content.ReadAsStreamAsync();

                    var errorsFileName           = $"{Path.GetFileNameWithoutExtension(dataMessage.Name)}-ExecutionErrors-{DateTime.Now:yyyy-MM-dd_HH-mm-ss-ffff}.txt";
                    var errorsFilePath           = Path.Combine(Path.GetDirectoryName(dataMessage.FullPath.Replace(_settings.UploadSuccessDir, _settings.ProcessingErrorsDir)), errorsFileName);
                    var dataMessageForErrorsFile = new DataMessage()
                    {
                        FullPath      = errorsFilePath,
                        Name          = errorsFileName,
                        MessageStatus = MessageStatus.Failed
                    };
                    await _retryPolicyForAsyncIo.ExecuteAsync(ct => FileOperationsHelper.CreateAsync(downloadedStream, dataMessageForErrorsFile.FullPath, ct), cancellationToken);
                }
            }
            break;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Generate file for individual member
        /// </summary>
        /// <param name="viewModel"></param>
        private void GenerateFiles(ViewModel viewModel)
        {
            // Read the Letter text rom the Content Folder
            var letterStream = FileOperationsHelper.ReadFromTemplate();

            //formating the letter for individual Member
            var formatedLetter = GenericHelper.FormattingFile(viewModel, letterStream);

            //Store te file in location
            FileOperationsHelper.CreateFile(viewModel, formatedLetter.ToString());
        }
        private void GetRecipientInfo()
        {
            fileHelper = new FileOperationsHelper();
            EthereumUser userInfo = fileHelper.ReadBinaryFile(fileHelper.FilePathGenerator(Constants.RecipientFile));

            if (userInfo != null)
            {
                tbAddress.Text    = userInfo.PublicAddress;
                tbPrivateKey.Text = userInfo.PrivateKey;
            }
        }
        private void ReadEncryptedEmail_Load(object sender, RibbonUIEventArgs e)
        {
            blockchainHelper = new BlockchainHelper();
            securityHelper   = new SecurityHelper();
            fileHelper       = new FileOperationsHelper();

            ethContract = new EthereumContract();
            ethContract.ContractAddress = Constants.ContractAddress;
            ethContract.ContractABI     = Constants.ContractABI;

            // Get recipient's saved Ethereum account details (If exists)
            GetRecipientInfo();
        }
Exemplo n.º 11
0
        private void BrowseServerFileClicked()
        {
            var selectedFile = FileOperationsHelper.BrowseForGtMpServerExe();

            if (!File.Exists(selectedFile))
            {
                NotificationService.ShowNotification("Invalid file selected.", true);
                return;
            }

            Settings.ServerHostPath = selectedFile;
            RaisePropertyChanged(nameof(Settings));
        }
Exemplo n.º 12
0
        public IResult Delete(CarImage img)
        {
            IResult result = BusinessRules.Run(CheckIfImagePathIsExists(img.ImagePath));

            if (result != null)
            {
                return(result);
            }

            _carImageDal.Delete(img);
            FileOperationsHelper.Delete(img.ImagePath);
            return(new SuccessResult("Image" + Messages.DeleteSingular));
        }
        private string BrowseForServerExePath()
        {
            var selectedFile = FileOperationsHelper.BrowseForGta5Exe();

            if (!IsValidGtMpServerPath(selectedFile))
            {
                return(null);
            }

            _settings.ServerHostPath = selectedFile;
            _settingsProvider.SaveSettings(_settings);
            return(selectedFile);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Processes download queue by downloading each
        /// file to download success location.
        /// </summary>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>
        /// Task object for continuation
        /// </returns>
        /// <exception cref="System.Exception"></exception>
        private async Task ProcessDownloadQueue(CancellationToken cancellationToken)
        {
            var fileCount = 0;

            while (DownloadQueue.TryDequeue(out DataMessage dataMessage))
            {
                var response = await _httpClientHelper.GetRequestAsync(new UriBuilder(dataMessage.DownloadLocation).Uri, true, cancellationToken);

                cancellationToken.ThrowIfCancellationRequested();

                if (!response.IsSuccessStatusCode)
                {
                    throw new JobExecutionException(string.Format(Resources.Job_0_Download_failure_1, _context.JobDetail.Key, response.StatusCode));
                }
                using (var downloadedStream = await response.Content.ReadAsStreamAsync())
                {
                    if (fileCount > 0 && _settings.DelayBetweenFiles > 0) //Only delay after first file and never after last.
                    {
                        System.Threading.Thread.Sleep(TimeSpan.FromSeconds(_settings.DelayBetweenFiles));
                    }
                    fileCount++;

                    cancellationToken.ThrowIfCancellationRequested();

                    //Downloaded file has no file name. We need to create it.
                    //It will be timestamp followed by number in this download batch.
                    var fileName = $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss-ffff}-{fileCount:D6}";
                    fileName = Path.ChangeExtension(fileName, "zip");

                    dataMessage.FullPath      = Path.Combine(_settings.DownloadSuccessDir, fileName);
                    dataMessage.Name          = fileName;
                    dataMessage.MessageStatus = MessageStatus.Succeeded;

                    await _retryPolicyForAsyncIo.ExecuteAsync(ct => FileOperationsHelper.CreateAsync(downloadedStream, dataMessage.FullPath, ct), cancellationToken);

                    cancellationToken.ThrowIfCancellationRequested();
                }
                if (_settings.LogVerbose || Log.IsDebugEnabled)
                {
                    Log.DebugFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_File_1_was_downloaded, _context.JobDetail.Key, dataMessage.FullPath.Replace(@"{", @"{{").Replace(@"}", @"}}")));
                }
                await AcknowledgeDownload(dataMessage, cancellationToken);

                if (_settings.UnzipPackage)
                {
                    await _retryPolicyForAsyncIo.ExecuteAsync(ct => FileOperationsHelper.UnzipPackageAsync(dataMessage.FullPath, _settings.DeletePackage, _settings.AddTimestamp, ct), cancellationToken);

                    cancellationToken.ThrowIfCancellationRequested();
                }
            }
        }
        /// <summary>
        /// Processes this instance.
        /// </summary>
        /// <returns></returns>
        private async Task Process()
        {
            EnqueuedJobs = new ConcurrentQueue <DataMessage>();
            foreach (var dataMessage in FileOperationsHelper.GetStatusFiles(MessageStatus.InProcess, _settings.UploadSuccessDir, "*" + _settings.StatusFileExtension))
            {
                Log.DebugFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_File_1_found_in_processing_location_and_added_to_queue_for_status_check, _context.JobDetail.Key, dataMessage.FullPath.Replace(@"{", @"{{").Replace(@"}", @"}}")));
                EnqueuedJobs.Enqueue(dataMessage);
            }

            if (!EnqueuedJobs.IsEmpty)
            {
                await ProcessEnqueuedQueue();
            }
        }
        private void GetSenderInfo()
        {
            // Email sender
            emailSender = new EthereumUser();

            fileHelper = new FileOperationsHelper();
            EthereumUser userInfo = fileHelper.ReadBinaryFile(fileHelper.FilePathGenerator(Constants.SenderFile));

            if (userInfo != null)
            {
                emailSender.PublicAddress = userInfo.PublicAddress;
                emailSender.PrivateKey    = userInfo.PrivateKey;
            }
        }
Exemplo n.º 17
0
        private void CopyFixedSaveGame(string saveGameFolderPath)
        {
            var currentSaveGameBackupFilePath = Path.Combine(saveGameFolderPath, "SGTA50000.bak");
            var currentSaveGameFilePath       = Path.Combine(saveGameFolderPath, "SGTA50000");
            var fixedSaveGameFilePath         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"savegame\SGTA50000");

            if (File.Exists(currentSaveGameFilePath))
            {
                _logger.Write($"Backing up save game file: {currentSaveGameFilePath} to {currentSaveGameBackupFilePath}");
                FileOperationsHelper.MoveFileIgnoreReadonly(currentSaveGameFilePath, currentSaveGameBackupFilePath);
            }

            _logger.Write($"Copying custom save game: {fixedSaveGameFilePath} to {currentSaveGameFilePath}");
            File.Copy(fixedSaveGameFilePath, currentSaveGameFilePath);
        }
Exemplo n.º 18
0
        public IResult Add(IFormFile image, CarImage img)
        {
            IResult result = BusinessRules.Run(CheckIfCarIsExists(img.CarId),
                                               CheckIfFileExtensionValid(image.FileName),
                                               CheckIfImageNumberLimitForCar(img.CarId));

            if (result != null)
            {
                return(result);
            }
            img.ImagePath = FileOperationsHelper.Add(image);
            img.CreatedAt = DateTime.Now;
            _carImageDal.Add(img);
            return(new SuccessResult("Image" + Messages.AddSingular));
        }
        /// <summary>
        /// Processes this instance.
        /// </summary>
        /// <returns></returns>
        private async Task Process()
        {
            InputQueue = new ConcurrentQueue <DataMessage>();

            foreach (var dataMessage in FileOperationsHelper.GetFiles(MessageStatus.Input, _settings.InputDir, _settings.SearchPattern, SearchOption.AllDirectories, _settings.OrderBy, _settings.ReverseOrder))
            {
                Log.DebugFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_File_1_found_in_input_location, _context.JobDetail.Key, dataMessage.FullPath.Replace(@"{", @"{{").Replace(@"}", @"}}")));
                InputQueue.Enqueue(dataMessage);
            }

            if (!InputQueue.IsEmpty)
            {
                Log.InfoFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_Found_1_file_s_in_input_folder, _context.JobDetail.Key, InputQueue.Count));
                await ProcessInputQueue();
            }
        }
Exemplo n.º 20
0
        private void MoveGrandTheftMultiplayerLibsToDisabledFolder(string gamePath, string disabledModsFolderPath)
        {
            foreach (var modFileName in _modFiles)
            {
                var modFileTargetPath   = Path.Combine(gamePath, modFileName);
                var modFileDisabledPath = Path.Combine(disabledModsFolderPath, modFileName);

                if (!File.Exists(modFileTargetPath))
                {
                    continue;
                }

                _logger.Write($"Moving game mod from {modFileTargetPath} to {modFileDisabledPath}");
                FileOperationsHelper.MoveFileIgnoreReadonly(modFileTargetPath, modFileDisabledPath);
            }
        }
Exemplo n.º 21
0
        private string BrowseForGta5ExePath()
        {
            var selectedFile = FileOperationsHelper.BrowseForGta5Exe();

            _logger.Write($"User manually selected {selectedFile} as GTA5.exe path.");

            var selectedFolder = string.IsNullOrEmpty(selectedFile) ? null : Path.GetDirectoryName(selectedFile);

            if (!IsValidGtaPath(selectedFolder))
            {
                return(null);
            }

            _settings.GamePath = selectedFolder;
            _settingsProvider.SaveSettings(_settings);
            return(selectedFile);
        }
Exemplo n.º 22
0
        private void MoveActiveModsToDisabledFolder(string gamePath)
        {
            var disabledModsFolderPath = Path.Combine(gamePath, DisabledModsFolderName);

            FileOperationsHelper.EnsureDirectory(disabledModsFolderPath);

            _logger.Write("Moving active game mods to disabled folder");
            try
            {
                MoveAsiFilesToDisabledFolder(gamePath, disabledModsFolderPath);
                MoveGrandTheftMultiplayerLibsToDisabledFolder(gamePath, disabledModsFolderPath);
            }
            catch (Exception e)
            {
                _logger.Write(e);
            }
        }
Exemplo n.º 23
0
        public IResult Update(IFormFile image, CarImage img)
        {
            IResult result = BusinessRules.Run(CheckIfImageIsExists(img.Id),
                                               CheckIfFileExtensionValid(image.FileName));

            if (result != null)
            {
                return(result);
            }
            var carImg = _carImageDal.Get(x => x.Id == img.Id);

            carImg.CreatedAt = DateTime.Now;
            carImg.ImagePath = FileOperationsHelper.Add(image);
            FileOperationsHelper.Delete(img.ImagePath);
            _carImageDal.Update(carImg);
            return(new SuccessResult("Image" + Messages.UpdateSingular));
        }
Exemplo n.º 24
0
        private static void EnsureLogFile(string logFilePath)
        {
            FileOperationsHelper.EnsureFileDirectory(logFilePath);

            if (File.Exists(logFilePath))
            {
                return;
            }

            try
            {
                File.Create(logFilePath).Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create log file! Exception:\n\n" + ex);
            }
        }
Exemplo n.º 25
0
        private void MoveAsiFilesToDisabledFolder(string gamePath, string disabledModsFolderPath)
        {
            var asiModFiles = Directory.GetFiles(gamePath, "*.asi", SearchOption.TopDirectoryOnly);

            foreach (var asiModFilePath in asiModFiles)
            {
                var modFileName = Path.GetFileName(asiModFilePath);
                if (modFileName == null)
                {
                    continue;
                }

                var targetDisabledPath = Path.Combine(disabledModsFolderPath, modFileName);

                _logger.Write($"Moving game mod from {asiModFilePath} to {targetDisabledPath}");
                FileOperationsHelper.MoveFileIgnoreReadonly(asiModFilePath, targetDisabledPath);
            }
        }
Exemplo n.º 26
0
        private void RestoreBackedUpSaveGame(string saveGameFolderPath)
        {
            var saveGameBackupFilePath = Path.Combine(saveGameFolderPath, "SGTA50000.bak");
            var saveGameFilePath       = Path.Combine(saveGameFolderPath, "SGTA50000");

            if (!File.Exists(saveGameBackupFilePath))
            {
                return;
            }
            if (File.Exists(saveGameFilePath))
            {
                _logger.Write($"Deleting save game file: {saveGameFilePath}");
                File.Delete(saveGameFilePath);
            }

            _logger.Write($"Moving backed up save game file: {saveGameBackupFilePath} to {saveGameFilePath}");
            FileOperationsHelper.MoveFileIgnoreReadonly(saveGameBackupFilePath, saveGameFilePath);
        }
Exemplo n.º 27
0
        private static void LoadConfigurationFiles()
        {
            var file = FileOperationsHelper.GetFilesFromPath("appsettings.json")?.FirstOrDefault();

            if (file == null)
            {
                throw new ArgumentException("No appsettings.json was provided");
            }

            Configuration = new ConfigurationBuilder().AddJsonFile(file, true, true).Build();

            var environmentFileName = Configuration.GetSection("Environment").Value;

            var environmentFile = FileOperationsHelper.GetFilesFromPath($"appsettings.{environmentFileName}.json")?.FirstOrDefault();

            Configuration = new ConfigurationBuilder().AddConfiguration(Configuration).AddJsonFile(environmentFile, true, true).Build();

            CdkOptions = Configuration.GetSection("CdkOptions").Get <List <CdkOptions> >();
        }
Exemplo n.º 28
0
        /// <summary>
        /// Acknowledges the download.
        /// </summary>
        /// <param name="dataMessage">The data message.</param>
        /// <returns></returns>
        private async Task AcknowledgeDownload(DataMessage dataMessage)
        {
            var content = JsonConvert.SerializeObject((DequeueResponse)dataMessage);

            var response = await _httpClientHelper.PostStringRequestAsync(_acknowledgeDownloadUri, content);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                Log.DebugFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_File_1_was_acknowledged_successfully, _context.JobDetail.Key, dataMessage.FullPath.Replace(@"{", @"{{").Replace(@"}", @"}}")));
            }
            else
            {
                // Acknowledgment failed. Log error.
                Log.ErrorFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_Acknowledgment_failure_response, _context.JobDetail.Key, response.StatusCode, response.StatusCode, response.ReasonPhrase));

                // Move message file
                FileOperationsHelper.Move(dataMessage.FullPath, Path.Combine(_settings.DownloadErrorsDir, dataMessage.Name));
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Processes download queue by downloading each
        /// file to download success location.
        /// </summary>
        /// <returns>
        /// Task object for continuation
        /// </returns>
        /// <exception cref="System.Exception"></exception>
        private async Task ProcessDownloadQueue()
        {
            //Stream downloadedStream = null;
            var fileCount = 0;

            while (DownloadQueue.TryDequeue(out DataMessage dataMessage))
            {
                var response = await _httpClientHelper.GetRequestAsync(new UriBuilder(dataMessage.DownloadLocation).Uri);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(string.Format(Resources.Job_0_Download_failure_1, _context.JobDetail.Key, response.StatusCode));
                }

                using (var downloadedStream = await response.Content.ReadAsStreamAsync())
                {
                    fileCount++;
                    //Downloaded file has no file name. We need to create it.
                    //It will be timestamp followed by number in this download batch.
                    var fileName = $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss-ffff}-{fileCount:D6}";
                    fileName = Path.ChangeExtension(fileName, "zip");

                    dataMessage.FullPath      = Path.Combine(_settings.DownloadSuccessDir, fileName);
                    dataMessage.Name          = fileName;
                    dataMessage.MessageStatus = MessageStatus.Succeeded;

                    _retryPolicyForIo.Execute(() => FileOperationsHelper.Create(downloadedStream, dataMessage.FullPath));
                }
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_File_1_was_downloaded, _context.JobDetail.Key, dataMessage.FullPath.Replace(@"{", @"{{").Replace(@"}", @"}}")));
                }

                await AcknowledgeDownload(dataMessage);

                if (_settings.UnzipPackage)
                {
                    _retryPolicyForIo.Execute(() => FileOperationsHelper.UnzipPackage(dataMessage.FullPath, _settings.DeletePackage, _settings.AddTimestamp));
                }

                System.Threading.Thread.Sleep(_settings.Interval);
            }
        }
        /// <summary>
        /// Processes this instance.
        /// </summary>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns></returns>
        private async Task Process(CancellationToken cancellationToken)
        {
            PowerShellHelper.ExecutePowerShellScript(_settings.PreTaskScript, new Dictionary <string, string> {
                ["taskFolderName"] = _settings.InputDir
            });

            InputQueue = new ConcurrentQueue <DataMessage>();

            foreach (
                var dataMessage in FileOperationsHelper.GetFiles(MessageStatus.Input, _settings.InputDir, _settings.SearchPattern, SearchOption.AllDirectories, _settings.OrderBy, _settings.ReverseOrder))
            {
                if (_settings.LogVerbose || Log.IsDebugEnabled)
                {
                    Log.DebugFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_File_1_found_in_input_location, _context.JobDetail.Key, dataMessage.FullPath.Replace(@"{", @"{{").Replace(@"}", @"}}")));
                }
                InputQueue.Enqueue(dataMessage);
            }

            if (!InputQueue.IsEmpty)
            {
                Log.InfoFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_Found_1_file_s_in_input_folder, _context.JobDetail.Key, InputQueue.Count));
                await ProcessInputQueue(cancellationToken);
            }
        }