// The Watcher calls this method when a new file shows up in the watched folder. // ReSharper disable once UnusedMethodReturnValue.Local private async Task ProcessNewPrintJob(MhwFile mhwFile) { if (!userSession.IsLoggedIn) { StopMonitoring(); NotificationService.ShowBalloonError("Please log in and try again. Print job deleted."); return; } // Upload the printed PDF file. string fileId = await UploadService.Upload(mhwFile.Content, mhwFile.Name, null); if (fileId == null) { NotificationService.ShowBalloonError("Print to Fax failed: Unable to upload {0}", mhwFile.Name); return; } if (userSession.Settings.PrintToFaxPrompt) { LaunchSendFax(fileId); } else { // Create draft fax. var draftFax = new ApiFax { AccountId = userSession.ActingAsAccount.AccountId, FileId = fileId, To = new List <ApiFaxRecipient>() }; try { Sdk.Fax.Create(draftFax, true, false, null, null); NotificationService.ShowBalloonInfo("Print to Fax Draft succeeded: {0}", mhwFile.Name); } catch (Exception ex) { string details = mhwFile.Name; var httpEx = ex as HttpException; if (httpEx != null && httpEx.GetHttpCode() == (int)HttpStatusCode.Forbidden) { details = "missing fax permission"; } NotificationService.ShowBalloonError("Print to Fax Draft failed: {0}", details); } } }
// The Watcher calls this method when a new file shows up in the watched folder. // ReSharper disable once UnusedMethodReturnValue.Local private async Task ProcessNewPrintJob(MhwFile mhwFile) { if (userSession.IsLoggedIn == false) { StopMonitoring(); NotificationService.ShowBalloonError("Please log in and try again."); return; } string driveItemId = userSession.Settings.PrintToDriveDefaultDestinationId; string fileName = mhwFile.Name ?? ""; string extension = Path.GetExtension(fileName).ToLower(); if (userSession.Settings.PrintToDrivePrompt) { LaunchDrivePicker(mhwFile.Name); if (isDrivePickerSuccess) { driveItemId = drivePickerResult; fileName = drivePickerFileName; } else { return; } } // Make sure the extension didn't get removed fileName = Path.ChangeExtension(fileName, extension); string fileId = await UploadService.Upload(mhwFile.Content, fileName, driveItemId); if (fileId == null) { NotificationService.ShowBalloonError("Print to Drive failed: {0}", fileName ?? mhwFile.Name); } else { NotificationService.ShowBalloonInfo("Print to Drive succeeded: {0}", fileName); } }