protected override async void OnLoad(EventArgs e) { base.OnLoad(e); _asyncTaskStarted = true; try { foreach (var scannedImage in _scannedImages) { if (string.IsNullOrWhiteSpace(scannedImage.Path)) { var uploadDir = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory); scannedImage.Path = String.Format("{0}\\{1}", uploadDir, scannedImage.Name + scannedImage.FileType); if (!Directory.Exists(uploadDir)) { Directory.CreateDirectory(uploadDir); } try { scannedImage.Image.Save(scannedImage.Path, scannedImage.FileType.ToImageFormat()); } catch (Exception ex) { MessageBox.Show(string.Format("{0}\n\n{1}", ErrorMessages.AsyncTaskError, ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.Cancel; break; } } var result = await DokuFlexService.UploadAsync(_ticket, scannedImage.Routing.Community, string.Empty, scannedImage.Routing.Folder, string.Empty, string.Empty, true, scannedImage.Routing.Certificate, "scan", scannedImage.Routing.ConvertToPdf, new FileInfo(scannedImage.Path)); scannedImage.Routing.FileId = result.nodeId; } if (DialogResult == DialogResult.None) { this.DialogResult = DialogResult.OK; } } finally { _asyncTaskStarted = false; this.Close(); } }
public void UploadEmailAsEmlFile() { var ticket = Session.GetTikect(); var groupId = string.Empty; var folderId = string.Empty; using (var folderBrowse = new BrowseFolderForm(ticket)) { if (folderBrowse.ShowFolderBrowserDialog()) { groupId = folderBrowse.Group.id; folderId = folderBrowse.Folder.id; } else { return; } } var fileName = string.Format("{0}.msg", GetMailItem().Subject); var uploadDirectory = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory); var uploadPath = string.Format("{0}\\{1}", uploadDirectory, fileName); try { if (!Directory.Exists(uploadDirectory)) { Directory.CreateDirectory(uploadDirectory); } //Delete any file withing directory with the same name and extension. if (File.Exists(uploadPath)) { File.Delete(uploadPath); } } catch (Exception e) { LogFactory.CreateLog().LogError(e); throw; } //Save attach to the uploadDirectory GetMailItem().SaveAs(uploadPath); var fileInfo = new FileInfo(uploadPath); using (var form = new TransferProgressForm()) { if (form.UploadFile(ticket, groupId, folderId, String.Empty, uploadPath, false)) { File.Delete(uploadPath); } } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (_currentListViewItem == null) { return; } var scannedImage = _currentListViewItem.Tag as ScannedImage; if (String.IsNullOrWhiteSpace(scannedImage.Path)) { scannedImage.Path = String.Format("{0}\\{1}", DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory), scannedImage.Name + scannedImage.FileType); scannedImage.Image.Save(scannedImage.Path, scannedImage.FileType.ToImageFormat()); } System.Diagnostics.Process.Start(scannedImage.Path); }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { this.Cursor = Cursors.WaitCursor; try { var directory = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory); if (Directory.Exists(directory)) { try { Directory.Delete(directory, true); } catch (Exception) { //Silent exception } } directory = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.DownloadDirectory); if (Directory.Exists(directory)) { try { Directory.Delete(directory, true); } catch (Exception) { //Silent exception } } } finally { this.Cursor = Cursors.Default; } }
public string UploadAttach(string displayName, string ticket, string communityId) { var attach = GetAttachments().FirstOrDefault(a => a.DisplayName.Equals(displayName)); var uploadDir = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory); if (!Directory.Exists(uploadDir)) { Directory.CreateDirectory(uploadDir); } var filePath = String.Format("{0}\\{1}", uploadDir, _mailItem.Attachments[attach.Index].FileName); //Save attach to the uploadDirectory _mailItem.Attachments[attach.Index].SaveAsFile(filePath); var result = DokuFlexService.Upload(ticket, communityId, String.Empty, _folder.id, String.Empty, String.Empty, false, String.Empty, "plugin", false, new FileInfo(filePath)); return(result.nodeId); }
public async Task <string> UploadAttachAsync(string displayName, string linkedFileId, bool messageAsComments) { var attach = GetAttachments().FirstOrDefault(a => a.DisplayName.Equals(displayName)); var uploadDirectory = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory); var uploadPath = string.Format("{0}\\{1}", uploadDirectory, _mailItem.Attachments[attach.Index].FileName); try { if (!Directory.Exists(uploadDirectory)) { Directory.CreateDirectory(uploadDirectory); } //Delete any file withing directory with the same name and extension. if (File.Exists(uploadPath)) { File.Delete(uploadPath); } } catch (Exception e) { LogFactory.CreateLog().LogError(e); throw; } //Save attach to the uploadDirectory _mailItem.Attachments[attach.Index].SaveAsFile(uploadPath); var fileInfo = new FileInfo(uploadPath); var result = (UploadResult)null; if (string.IsNullOrWhiteSpace(ProcessId)) { if (messageAsComments) { result = await DokuFlexService.UploadAsync(_ticket, _groupId, String.Empty, _folderId, _mailItem.Body, String.Empty, false, String.Empty, "plugin", false, fileInfo); } else { result = await DokuFlexService.UploadAsync(_ticket, _groupId, String.Empty, _folderId, String.Empty, String.Empty, false, String.Empty, "plugin", false, fileInfo); } } else { result = await DokuFlexService.UploadAsync(_ticket, _groupId, String.Empty, _folderId, _mailItem.Body, String.Empty, false, String.Empty, "plugin", false, fileInfo); } if (!String.IsNullOrWhiteSpace(result.nodeId)) { //Delete the file from temp folder :) try { File.Delete(uploadPath); } catch (Exception e) { LogFactory.CreateLog().LogError(e); } return(result.nodeId); } else { return(String.Empty); } }
public void OpenDocument() { //Step 1: Login to DokuFlex to get the ticket; var ticket = Session.GetTikect(); //Step 2: get addional info var community = (UserGroup)null; var folder = (FileFolder)null; var file = (FileFolder)null; using (var form = new OpenFileForm(ticket, _fileExtensions)) { if (form.ShowOpenFileDialog()) { community = form.Group; folder = form.Folder; file = form.File; } else { return; } } TrackingListManager.Reload(); var trackingItem = TrackingListManager.GetByFileId(file.id); if (trackingItem != null && File.Exists(trackingItem.Path)) { if (trackingItem.ModifiedTime < file.modifiedTime) { using (var form = new TransferProgressForm()) { if (form.DownloadFile(ticket, trackingItem.FileId, trackingItem.Path)) { TrackOff(); Globals.ThisAddIn.Application.Documents.Open(trackingItem.Path); TrackOn(); trackingItem.ModifiedTime = file.modifiedTime; TrackingListManager.Save(); } } } else { //Open the document. TrackOff(); this.Application.Documents.Open(trackingItem.Path); TrackOn(); } } else { //Step 3: Create directory and file paths var currentDir = String.Format("{0}\\{1}", DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.Documents), community.name); var currentPath = string.Format("{0}\\{1}", currentDir, file.name); try { if (!Directory.Exists(currentDir)) { try { Directory.CreateDirectory(currentDir); } catch (Exception) { //Silent exception } } } catch (Exception e) { LogFactory.CreateLog().LogError(e); MessageBox.Show(e.Message, this.Application.Name, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Step 4: download the file using (var form = new TransferProgressForm()) { if (form.DownloadFile(ticket, file.id, currentPath)) { TrackOff(); Globals.ThisAddIn.Application.Documents.Open(currentPath); TrackOn(); trackingItem = new TrackingItem() { Name = file.name, LastWriteTime = DateTime.Now.ToFileTimeUtc(), Path = currentPath, Type = "F", GroupId = community.id, FolderId = folder.id, FileId = file.id, ModifiedTime = file.modifiedTime }; TrackingListManager.Add(trackingItem); TrackingListManager.Save(); } } } }
public void OpenRecentDocument(string ticket, IDocument document) { TrackingListManager.Reload(); var trackingItem = TrackingListManager.GetByFileId(document.id); if (trackingItem != null) { if (trackingItem.ModifiedTime < document.modifiedTime) { using (var form = new TransferProgressForm()) { if (form.DownloadFile(ticket, trackingItem.FileId, trackingItem.Path)) { TrackOff(); Globals.ThisAddIn.Application.Documents.Open(trackingItem.Path); TrackOn(); trackingItem.ModifiedTime = document.modifiedTime; TrackingListManager.Save(); } } } else { //Open the document. TrackOff(); this.Application.Documents.Open(trackingItem.Path); TrackOn(); } } else { //Step 3: Create directory and file paths var currentDir = String.Format("{0}\\{1}", DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.Documents), "Huerfanos"); var currentPath = string.Format("{0}\\{1}", currentDir, document.name); try { if (!Directory.Exists(currentDir)) { try { Directory.CreateDirectory(currentDir); } catch (Exception) { //Silent exception } } } catch (Exception e) { LogFactory.CreateLog().LogError(e); MessageBox.Show(e.Message, this.Application.Name, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Step 4: download the file using (var form = new TransferProgressForm()) { if (form.DownloadFile(ticket, document.id, currentPath)) { TrackOff(); Globals.ThisAddIn.Application.Documents.Open(currentPath); TrackOn(); trackingItem = new TrackingItem() { Name = document.name, LastWriteTime = DateTime.Now.ToFileTimeUtc(), Path = currentPath, Type = "F", FileId = document.id, ModifiedTime = document.modifiedTime }; TrackingListManager.Add(trackingItem); TrackingListManager.Save(); } } } }
private string UploadFile(string ticket, string fullName) { //Step 1: Create a copy of the file and build the path to there. var uploadPath = string.Empty; var uploadDir = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory); var fileName = string.Empty; try { if (!Directory.Exists(uploadDir)) { Directory.CreateDirectory(uploadDir); } var fileInfo = new FileInfo(fullName); uploadPath = string.Format("{0}\\{1}", uploadDir, fileInfo.Name); fileName = fileInfo.Name; fileInfo.CopyTo(uploadPath, true); } catch (Exception ex) { LogFactory.CreateLog().LogError(ex); MessageBox.Show(ex.Message, this.Application.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Error); return(String.Empty); } //Step 3: Upload the file TrackingListManager.Reload(); var trackingItem = TrackingListManager.GetByPath(fullName); if (trackingItem != null) { using (var form = new TransferProgressForm()) { if (form.UploadFile(ticket, trackingItem.GroupId, trackingItem.FolderId, trackingItem.FileId, uploadPath, true)) { trackingItem.FileId = form.FileId; trackingItem.ModifiedTime = form.ModifiedTime; TrackingListManager.Save(); } } } else { var community = (UserGroup)null; var folder = (FileFolder)null; var saveAsNewVersion = false; using (var saveFileView = new SaveFileForm(ticket)) { if (saveFileView.ShowSaveFileDialog()) { community = saveFileView.Group; folder = saveFileView.Folder; saveAsNewVersion = saveFileView.SaveAsNewVersion; } else { return(String.Empty); } } //Upload file to the server. using (var form = new TransferProgressForm()) { if (form.UploadFile(ticket, community.id, folder.id, string.Empty, uploadPath, saveAsNewVersion)) { trackingItem = new TrackingItem() { Name = Path.GetFileName(fullName), LastWriteTime = DateTime.Now.ToFileTimeUtc(), Path = fullName, Type = "F", GroupId = community.id, FolderId = folder.id, FileId = form.FileId, ModifiedTime = form.ModifiedTime }; TrackingListManager.Add(trackingItem); TrackingListManager.Save(); } } } try { File.Delete(uploadPath); } catch (Exception e) { LogFactory.CreateLog().LogError(e); } return(trackingItem.FileId); }
public ScanHistoryForm() { InitializeComponent(); _downloadDir = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.DownloadDirectory); }
private void CreateScannedImagesList() { _scannedItems.Clear(); var nameIndex = 0; if (rbtnTIFF.Checked) { var pageIndex = 0; var pageCount = int.Parse(upDownPageBreak.Value.ToString()); var imageList = (List <Image>)null; switch (chkBarCode.Checked) { case true: var dataMatrix = new DmtxImageDecoder(); for (int i = 0; i < _images.Count; i++) { if (pageIndex == 0) { imageList = new List <Image>(); } using (var bmp = new Bitmap(_images[i])) { var decodeInfo = dataMatrix.DecodeImage(bmp); if (decodeInfo.Count > 0 && String.Compare(decodeInfo[0], "DOKUFLEX") == 0) { var uploadDir = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory); if (!Directory.Exists(uploadDir)) { Directory.CreateDirectory(uploadDir); } var scannedItem = new ScannedImage(); scannedItem.Name = String.Format("{0}_{1}", scannedItem.Name, ++nameIndex); scannedItem.FileType = ".tiff"; scannedItem.Pages = pageIndex; scannedItem.Path = String.Format("{0}\\{1}", uploadDir, scannedItem.Name + ".tiff"); scannedItem.Image = CreateMultipageTiff(imageList.ToArray(), scannedItem.Path); if (_scanSetting != null) { scannedItem.Routing.Assign(_scanSetting.Routing); } _scannedItems.Add(scannedItem); pageIndex = 0; } else { imageList.Add(_images[i]); pageIndex++; } } } break; default: for (int i = 0; i < _images.Count; i++) { if (pageIndex == 0) { imageList = new List <Image>(); } if (pageCount == 0) { imageList.Add(_images[i]); pageIndex++; continue; } if (pageIndex >= pageCount) { var uploadDir = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory); if (!Directory.Exists(uploadDir)) { Directory.CreateDirectory(uploadDir); } var scannedItem = new ScannedImage(); scannedItem.Name = String.Format("{0}_{1}", scannedItem.Name, ++nameIndex); scannedItem.FileType = ".tiff"; scannedItem.Pages = imageList.Count; scannedItem.Path = String.Format("{0}\\{1}", uploadDir, scannedItem.Name + ".tiff"); scannedItem.Image = CreateMultipageTiff(imageList.ToArray(), scannedItem.Path); if (_scanSetting != null) { scannedItem.Routing.Assign(_scanSetting.Routing); } _scannedItems.Add(scannedItem); pageIndex = 0; } else { imageList.Add(_images[i]); pageIndex++; } } break; } if (pageIndex > 0) { var uploadDir = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory); if (!Directory.Exists(uploadDir)) { Directory.CreateDirectory(uploadDir); } var scannedItem = new ScannedImage(); scannedItem.Name = String.Format("{0}_{1}", scannedItem.Name, ++nameIndex); scannedItem.FileType = ".tiff"; scannedItem.Pages = imageList.Count; scannedItem.Path = String.Format("{0}\\{1}", uploadDir, scannedItem.Name + ".tiff"); scannedItem.Image = CreateMultipageTiff(imageList.ToArray(), scannedItem.Path); if (_scanSetting != null) { scannedItem.Routing.Assign(_scanSetting.Routing); } _scannedItems.Add(scannedItem); } } else { var fileType = String.Empty; if (rbtnBMP.Checked) { fileType = ".bmp"; } if (rbtnJPG.Checked) { fileType = ".jpeg"; } if (rbtnPNG.Checked) { fileType = ".png"; } for (int i = 0; i < _images.Count; i++) { var scannedItem = new ScannedImage(); scannedItem.Name = String.Format("{0}_{1}", scannedItem.Name, ++nameIndex); scannedItem.Image = _images[i]; scannedItem.FileType = fileType; if (_scanSetting != null) { scannedItem.Routing.Assign(_scanSetting.Routing); } _scannedItems.Add(scannedItem); } } }