public static void CreateWorkerRequestReport(WorkerRequestMicrosoftWordReportStruct reportStruct) { _workerRequestReportStruct = reportStruct; _tempWorkerRequestDocumentPath = Path.Combine(App.TempFolder, "WorkerRequestTemplate.docx"); if (File.Exists(_tempWorkerRequestDocumentPath)) { ReplaceWorkerRequestText(); return; } // Downloading template word file from ftp var ftpFilePath = string.Concat(App.GetFtpUrl, TemplatesDirectory, WorkerRequestTemplate); _ftpClient = new FtpClient(string.Concat(App.GetFtpUrl, TemplatesDirectory), "fa2app", "Franc1961"); if (_ftpClient.IsBusy) { MessageBox.Show("В данный момент невозможно выполнить загрузку файла-шаблона. Попробуйте позже"); return; } if (!Directory.Exists(App.TempFolder)) { Directory.CreateDirectory(App.TempFolder); } if (_ftpClient.FileExist(ftpFilePath)) { var uri = new Uri(ftpFilePath); if (_processWindow == null) { _processWindow = new WaitWindow { Text = "Загрузка файла-шаблона..." }; _processWindow.Show(Application.Current.MainWindow, true); } _fileSize = _ftpClient.GetFileSize(ftpFilePath); _ftpClient.DownloadProgressChanged += OnFtpClientDownloadProgressChanged; _ftpClient.DownloadFileCompleted += OnFtpClientDownloadFileCompleted; _ftpClient.DownloadFileAsync(uri, _tempWorkerRequestDocumentPath); } else { MessageBox.Show("Не удаётся найти файл-шаблон на сервере. \nПопробуйте выполнить операцию позже или обратитесь к администратору."); } }
private static void OnFtpClientDownloadFileCompleted(object sender, AsyncCompletedEventArgs asyncCompletedEventArgs) { _ftpClient.DownloadFileCompleted -= OnFtpClientDownloadFileCompleted; _ftpClient.DownloadProgressChanged -= OnFtpClientDownloadProgressChanged; if (_processWindow != null) { _processWindow.Text = "Формирование заявления..."; } ReplaceWorkerRequestText(); if (_processWindow != null) { _processWindow.Close(true); } _processWindow = null; }