public void Test_MessageRuleActionsDeserialization() { string messageRuleActionsDefinition = @"{ ""stopProcessingRules"": true, ""forwardTo"": [ { ""emailAddress"": { ""name"": ""*****@*****.**"", ""address"": ""*****@*****.**"" } } ] }"; MessageRuleActions actions = this.Convert <MessageRuleActions>(messageRuleActionsDefinition); }
public ICustomActivityResult Execute() { DataTable dt = new DataTable("resultSet"); dt.Columns.Add("Result"); MessageRulePredicates condition = new MessageRulePredicates(); MessageRuleActions actions = new MessageRuleActions(); GraphServiceClient client = new GraphServiceClient("https://graph.microsoft.com/v1.0", GetProvider()); var user = client.Users[userEmail]; var rules = user.MailFolders["Inbox"].MessageRules.Request().GetAsync().Result; if (rules.Where(r => r.DisplayName.ToLower() == ruleDisplayName.ToLower()).FirstOrDefault() != null) { throw new Exception(string.Format("Rule with name '{0}' already exist", ruleDisplayName)); } var messageRule = new MessageRule { DisplayName = ruleDisplayName, IsEnabled = true }; if (!string.IsNullOrEmpty(senderContains)) { condition.SenderContains = new List <string>() { senderContains }; } if (!string.IsNullOrEmpty(bodyContains)) { condition.BodyContains = new List <string>() { bodyContains }; } if (forwardAction) { if (string.IsNullOrEmpty(forwardEmail)) { throw new Exception("forwardEmail field must be populated when forwardAction is set to True"); } actions.ForwardTo = new List <Recipient>() { new Recipient { EmailAddress = new EmailAddress { Address = forwardEmail } } }; } else if (deleteAction) { actions.Delete = true; } if (string.IsNullOrEmpty(user.Request().GetAsync().Result.UsageLocation)) { this.UpdateUser(user); } messageRule.Conditions = condition; messageRule.Actions = actions; messageRule.Actions.StopProcessingRules = messageRule.IsEnabled = true; messageRule.Sequence = rules.Count + 1; user.MailFolders["Inbox"].MessageRules.Request().AddAsync(messageRule).Wait(); dt.Rows.Add(messageRule.Id); return(this.GenerateActivityResult(dt)); }