public void Test_GettersSetters(string path, string name) { var workflowFile = new WorkflowFile(path); Assert.Equal(path, workflowFile.FilePath); Assert.Equal(name, workflowFile.Name); }
public static string UploadFileDrive(string folderId, double requestNumber, WorkflowFile file) { // Check parameters if (string.IsNullOrEmpty(folderId)) { return("The folder id is required"); } if (string.IsNullOrEmpty(requestNumber.ToString())) { return("The request number is required"); } if (file == null) { return("The file is required"); } try { File body = new File(); body.Name = requestNumber + "_" + file.Name; body.Description = file.Name; body.MimeType = file.ContentType; body.Parents = new List <string> { folderId }; Stream stream = new MemoryStream(file.Content); // Insert preparation string[] scopes = { DriveService.Scope.DriveFile }; var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = GetServiceAccountCredential(scopes), }); FilesResource.CreateMediaUpload request = service.Files.Create(body, stream, file.ContentType); request.SupportsTeamDrives = true; request.UploadAsync().Wait(); return(Success); } catch (Exception e) { Log("[UploadFileDrive] Error - " + e.Message + " - InnerException : " + e.InnerException); return("[UploadFileDrive] Error - " + e.Message); } }
public static string UploadFileOneDrive(string groupId, string folderId, double requestNumber, WorkflowFile file) { // Check parameters if (string.IsNullOrEmpty(groupId)) { return("The group id is required"); } if (string.IsNullOrEmpty(folderId)) { return("The folder id is required"); } if (string.IsNullOrEmpty(requestNumber.ToString())) { return("The request number is required"); } if (file == null) { return("The file is required"); } try { // It's not recommended to use MemoryStream for large file GraphClient.Groups[groupId].Drive.Items[folderId].ItemWithPath(string.Format("{0}_{1}", requestNumber, file.Name)). Content.Request().PutAsync <DriveItem>(new MemoryStream(file.Content)).Wait(); return(Success); } catch (Exception e) { Log("[UploadFileGroup] Error - " + e.Message + " - InnerException : " + e.InnerException); return("[UploadFileGroup] Error - " + e.Message); } }
public static string SendMail(string subject, string content, string toRecipients, string ccRecipients, string bccRecipients, WorkflowFile attachment) { // Check parameters if (string.IsNullOrEmpty(subject)) { return("The subject is required"); } if (string.IsNullOrEmpty(content)) { return("The content is required"); } if (string.IsNullOrEmpty(toRecipients)) { return("Recipients are required"); } try { // Prepare the recipient list string[] splitter = { ";" }; var splitToRecipientsString = toRecipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries); var splitCcRecipientsString = ccRecipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries); var splitBccRecipientsString = bccRecipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries); // Message construction MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(ImpersonateUser); mailMessage.ReplyToList.Add(ImpersonateUser); mailMessage.Subject = subject; mailMessage.Body = content; mailMessage.IsBodyHtml = true; foreach (string recipient in splitToRecipientsString) { mailMessage.To.Add(recipient); } foreach (string recipient in splitCcRecipientsString) { mailMessage.CC.Add(recipient); } foreach (string recipient in splitBccRecipientsString) { mailMessage.Bcc.Add(recipient); } if (attachment != null) { Stream stream = new MemoryStream(attachment.Content); mailMessage.Attachments.Add(new Attachment(stream, attachment.Name)); } var mimeMessage = MimeMessage.CreateFromMailMessage(mailMessage); var gmailMessage = new Message { Raw = Encode(mimeMessage.ToString()) }; // Sending preparation string[] scopes = { GmailService.Scope.GmailSend }; var service = new GmailService(new BaseClientService.Initializer() { HttpClientInitializer = GetServiceAccountCredential(scopes), }); service.Users.Messages.Send(gmailMessage, ImpersonateUser).ExecuteAsync().Wait(); return(Success); } catch (Exception e) { Log("[SendMail] Error - We could not send the message: " + e.Message + " - InnerException : " + e.InnerException); return("We could not send the message: " + e.Message); } }
public XMLSorter(WorkflowFile dataFile, IEnumerable <SortingField> sortingFields) { workflowFile = dataFile; SortingFields.AddRange(sortingFields); }
public static string SendMail(string subject, string content, string toRecipients, string ccRecipients, string bccRecipients, WorkflowFile attachment) { // Check parameters if (string.IsNullOrEmpty(subject)) { return("The subject is required"); } if (string.IsNullOrEmpty(content)) { return("The content is required"); } if (string.IsNullOrEmpty(toRecipients)) { return("Recipients are required"); } try { // Prepare the recipient list string[] splitter = { ";" }; var splitToRecipientsString = toRecipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries); var splitCcRecipientsString = ccRecipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries); var splitBccRecipientsString = bccRecipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries); List <Recipient> toRecipientList = new List <Recipient>(); List <Recipient> ccRecipientList = new List <Recipient>(); List <Recipient> bccRecipientList = new List <Recipient>(); foreach (string recipient in splitToRecipientsString) { toRecipientList.Add(new Recipient { EmailAddress = new EmailAddress { Address = recipient.Trim() } }); } foreach (string recipient in splitCcRecipientsString) { ccRecipientList.Add(new Recipient { EmailAddress = new EmailAddress { Address = recipient.Trim() } }); } foreach (string recipient in splitBccRecipientsString) { bccRecipientList.Add(new Recipient { EmailAddress = new EmailAddress { Address = recipient.Trim() } }); } MessageAttachmentsCollectionPage attachments = new MessageAttachmentsCollectionPage(); if (attachment != null) { attachments.Add(new FileAttachment { ODataType = "#microsoft.graph.fileAttachment", ContentBytes = attachment.Content, ContentType = attachment.ContentType, Name = attachment.Name }); } var email = new Message { Body = new ItemBody { Content = content, ContentType = BodyType.Html, }, Subject = subject, ToRecipients = toRecipientList, CcRecipients = ccRecipientList, BccRecipients = bccRecipientList, Attachments = attachments }; try { GraphClient.Users[ServiceAccountId].SendMail(email, true).Request().PostAsync().Wait(); return(Success); } catch (ServiceException exception) { Log("[SendMail] Error - We could not send the message: " + exception.Error == null ? "No error message returned." : exception.Error.Message); return("We could not send the message: " + exception.Error == null ? "No error message returned." : exception.Error.Message); } } catch (Exception e) { Log("[SendMail] Error - We could not send the message: " + e.Message + " - InnerException : " + e.InnerException); return("We could not send the message: " + e.Message); } }