/// <summary>
/// This web job function will process matter that is there in azure table storage called MatterRequests.
/// If there are any new matter is created, this web job function will get invoked for the time duration that has
/// been specified and will preocess all new matters and will send notification for those respective users
/// Once the matter has been processed, it will change the status of that matter to "Send" so that it will not
/// be processed again
/// </summary>
/// <param name="timerInfo"></param>
/// <param name="matterInformationVM"></param>
public static void ProcessMatter([TimerTrigger("00:00:05", RunOnStartup = true)] TimerInfo timerInfo,
[Table("MatterRequests")] IQueryable <MatterInformationVM> matterInformationVM, TextWriter log)
{
var query = from p in matterInformationVM select p;
if (query.ToList().Count() > 0)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appSettings.json")
.AddInMemoryCollection()
.AddEnvironmentVariables();//appsettings.json will be overridden with azure web appsettings
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
var configuration = builder.Build();
KeyVaultHelper kv = new KeyVaultHelper(configuration);
KeyVaultHelper.GetCert(configuration);
kv.GetKeyVaultSecretsCerticate();
//// can use on premise exchange server credentials with service.UseDefaultCredentials = true, or
//explicitly specify the admin account (set default to false)
string adminUserName = configuration.GetSection("General").GetSection("AdminUserName").Value;
string adminPassword = configuration.GetSection("General").GetSection("AdminPassword").Value;
service.Credentials = new WebCredentials(adminUserName, adminPassword);
service.Url = new Uri(configuration.GetSection("Settings").GetSection("ExchangeServiceURL").Value);
string mailSubject = configuration.GetSection("Mail").GetSection("MatterMailSubject").Value;
string defaultHtmlChunk = configuration.GetSection("Mail").GetSection("MatterMailDefaultContentTypeHtmlChunk").Value;
string oneNoteLibrarySuffix = configuration.GetSection("Matter").GetSection("OneNoteLibrarySuffix").Value;
string matterMailBodyMatterInformation = configuration.GetSection("Mail").GetSection("MatterMailBodyMatterInformation").Value;
string matterMailBodyConflictCheck = configuration.GetSection("Mail").GetSection("MatterMailBodyConflictCheck").Value;
string matterCenterDateFormat = configuration.GetSection("Mail").GetSection("MatterCenterDateFormat").Value;
string matterMailBodyTeamMembers = configuration.GetSection("Mail").GetSection("MatterMailBodyTeamMembers").Value;
foreach (MatterInformationVM matterInformation1 in query)
{
if (matterInformation1 != null)
{
if (matterInformation1.Status.ToLower() == "pending")
{
if (configuration["General:IsBackwardCompatible"].ToString().ToLower() == "false")
{
SentEmailNotificationForCreatedMatters(matterInformation1, service, log, configuration);
}
else
{
SentEmailNotificationForCreatedIsBackwardCompatibleMatters(matterInformation1, service, log, configuration);
}
}
}
}
}
}