Exemple #1
0
        /// <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);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <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);
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appSettings.json")
                .AddInMemoryCollection()
                .AddEnvironmentVariables();//appsettings.json will be overridden with azure web appsettings

            var configuration = builder.Build();
            KeyVaultHelper kv = new KeyVaultHelper(configuration);
            KeyVaultHelper.GetCert(configuration);
            kv.GetKeyVaultSecretsCerticate();
            var azureStorageConnectionString = configuration["General:CloudStorageConnectionString"];
            JobHostConfiguration config = new JobHostConfiguration(azureStorageConnectionString);
            config.UseTimers();
            
            var host = new JobHost(config);            
            host.RunAndBlock();
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appSettings.json")
                          .AddInMemoryCollection()
                          .AddEnvironmentVariables();//appsettings.json will be overridden with azure web appsettings

            var            configuration = builder.Build();
            KeyVaultHelper kv            = new KeyVaultHelper(configuration);

            KeyVaultHelper.GetCert(configuration);
            kv.GetKeyVaultSecretsCerticate();
            var azureStorageConnectionString = configuration["General:CloudStorageConnectionString"];
            JobHostConfiguration config      = new JobHostConfiguration(azureStorageConnectionString);

            config.UseTimers();

            var host = new JobHost(config);

            host.RunAndBlock();
        }
Exemple #5
0
 /// <summary>
 /// This method will read external access requests azure table storage for all
 /// pending requests and update the matter related lists and libraries permissions for external users
 /// </summary>
 /// <param name="timerInfo"></param>
 /// <param name="matterInformationVM"></param>
 /// <param name="log"></param>
 public static void ReadExternalAccessRequests([TimerTrigger("00:00:05", RunOnStartup = true)] TimerInfo timerInfo,
                                               [Table("ExternalAccessRequests")] IQueryable <MatterInformationVM> matterInformationVM,
                                               TextWriter log)
 {
     try
     {
         var builder = new ConfigurationBuilder()
                       .SetBasePath(Directory.GetCurrentDirectory())
                       .AddJsonFile("appSettings.json")
                       .AddEnvironmentVariables();//appsettings.json will be overridden with azure web appsettings
         var            configuration = builder.Build();
         KeyVaultHelper kv            = new KeyVaultHelper(configuration);
         KeyVaultHelper.GetCert(configuration);
         kv.GetKeyVaultSecretsCerticate();
         //Read all rows from table storage which
         //Read all rows from table storage which are in pending state
         var query = from p in matterInformationVM select p;
         foreach (MatterInformationVM matterInformation in query)
         {
             if (matterInformation != null)
             {
                 if (matterInformation.Status.ToLower() == "pending")
                 {
                     string serializedMatter = matterInformation.SerializeMatter;
                     //De Serialize the matter information
                     MatterInformationVM originalMatter = Newtonsoft.Json.JsonConvert.DeserializeObject <MatterInformationVM>(serializedMatter);
                     log.WriteLine($"Checking the matter name {originalMatter.Matter.Name} has been acceped by the user or not");
                     //Read all external access requests records from azure table storge
                     GetExternalAccessRequestsFromSPO(originalMatter, log, configuration);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         log.WriteLine($"Exception occured in the method ReadExternalAccessRequests. {ex}");
     }
 }
        /// <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")
                        {
                            //De Serialize the matter information
                            MatterInformationVM originalMatter = JsonConvert.DeserializeObject <MatterInformationVM>(matterInformation1.SerializeMatter);
                            Matter        matter        = originalMatter.Matter;
                            MatterDetails matterDetails = originalMatter.MatterDetails;
                            Client        client        = originalMatter.Client;

                            string matterMailBody, blockUserNames;
                            // Generate Mail Subject
                            string matterMailSubject = string.Format(CultureInfo.InvariantCulture, mailSubject,
                                                                     matter.Id, matter.Name, originalMatter.MatterCreator);

                            // Step 1: Create Matter Information
                            string defaultContentType = string.Format(CultureInfo.InvariantCulture,
                                                                      defaultHtmlChunk, matter.DefaultContentType);
                            string matterType = string.Join(";", matter.ContentTypes.ToArray()).TrimEnd(';').Replace(matter.DefaultContentType, defaultContentType);
                            if (matterType == string.Empty)
                            {
                                matterType = defaultContentType;
                            }
                            // Step 2: Create Team Information
                            string secureMatter = ServiceConstants.FALSE.ToUpperInvariant() == matter.Conflict.SecureMatter.ToUpperInvariant() ?
                                                  ServiceConstants.NO : ServiceConstants.YES;
                            string mailBodyTeamInformation = string.Empty;
                            mailBodyTeamInformation = TeamMembersPermissionInformation(matterDetails, mailBodyTeamInformation);

                            string oneNotePath = string.Concat(client.Url, ServiceConstants.FORWARD_SLASH,
                                                               matter.MatterGuid, oneNoteLibrarySuffix,
                                                               ServiceConstants.FORWARD_SLASH, matter.MatterGuid, ServiceConstants.FORWARD_SLASH, matter.MatterGuid);

                            if (originalMatter.IsConflictCheck)
                            {
                                string conflictIdentified = ServiceConstants.FALSE.ToUpperInvariant() == matter.Conflict.Identified.ToUpperInvariant() ?
                                                            ServiceConstants.NO : ServiceConstants.YES;
                                blockUserNames = string.Join(";", matter.BlockUserNames.ToArray()).Trim().TrimEnd(';');

                                blockUserNames = !String.IsNullOrEmpty(blockUserNames) ? string.Format(CultureInfo.InvariantCulture,
                                                                                                       "<div>{0}: {1}</div>", "Conflicted User", blockUserNames) : string.Empty;
                                matterMailBody = string.Format(CultureInfo.InvariantCulture,
                                                               matterMailBodyMatterInformation, client.Name, client.Id,
                                                               matter.Name, matter.Id, matter.Description, matterType) + string.Format(CultureInfo.InvariantCulture,
                                                                                                                                       matterMailBodyConflictCheck, ServiceConstants.YES, matter.Conflict.CheckBy,
                                                                                                                                       Convert.ToDateTime(matter.Conflict.CheckOn, CultureInfo.InvariantCulture).ToString(matterCenterDateFormat, CultureInfo.InvariantCulture),
                                                                                                                                       conflictIdentified) + string.Format(CultureInfo.InvariantCulture,
                                                                                                                                                                           matterMailBodyTeamMembers, secureMatter, mailBodyTeamInformation,
                                                                                                                                                                           blockUserNames, client.Url, oneNotePath, matter.Name, originalMatter.MatterLocation, matter.Name);
                            }
                            else
                            {
                                blockUserNames = string.Empty;
                                matterMailBody = string.Format(CultureInfo.InvariantCulture, matterMailBodyMatterInformation,
                                                               client.Name, client.Id, matter.Name, matter.Id,
                                                               matter.Description, matterType) + string.Format(CultureInfo.InvariantCulture, matterMailBodyTeamMembers, secureMatter,
                                                                                                               mailBodyTeamInformation, blockUserNames, client.Url, oneNotePath, matter.Name, originalMatter.MatterLocation, matter.Name);
                            }

                            EmailMessage email = new EmailMessage(service);
                            foreach (IList <string> userNames  in matter.AssignUserEmails)
                            {
                                foreach (string userName in userNames)
                                {
                                    if (!string.IsNullOrWhiteSpace(userName))
                                    {
                                        using (var ctx = new ClientContext(originalMatter.Client.Url))
                                        {
                                            SecureString password = Utility.GetEncryptedPassword(configuration["General:AdminPassword"]);
                                            ctx.Credentials = new SharePointOnlineCredentials(configuration["General:AdminUserName"], password);
                                            if (CheckUserPresentInMatterCenter(ctx, originalMatter.Client.Url, userName, null, log))
                                            {
                                                email.ToRecipients.Add(userName);
                                            }
                                        }
                                    }
                                }
                            }
                            email.From    = new EmailAddress(adminUserName);
                            email.Subject = matterMailSubject;
                            email.Body    = matterMailBody;
                            email.Send();
                            Utility.UpdateTableStorageEntity(originalMatter, log, configuration["Data:DefaultConnection:AzureStorageConnectionString"],
                                                             configuration["Settings:MatterRequests"], "Accepted");
                        }
                    }
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// This method will read external access requests azure table storage for all
 /// pending requests and update the matter related lists and libraries permissions for external users
 /// </summary>
 /// <param name="timerInfo"></param>
 /// <param name="matterInformationVM"></param>
 /// <param name="log"></param>
 public static void ReadExternalAccessRequests([TimerTrigger("00:00:05", RunOnStartup = true)]TimerInfo timerInfo,
     [Table("ExternalAccessRequests")] IQueryable<MatterInformationVM> matterInformationVM,
     TextWriter log)
 {
     try
     {
         var builder = new ConfigurationBuilder()
             .SetBasePath(Directory.GetCurrentDirectory())
             .AddJsonFile("appSettings.json")
             .AddEnvironmentVariables();//appsettings.json will be overridden with azure web appsettings
         var configuration = builder.Build();
         KeyVaultHelper kv = new KeyVaultHelper(configuration);
         KeyVaultHelper.GetCert(configuration);
         kv.GetKeyVaultSecretsCerticate();
         //Read all rows from table storage which
         //Read all rows from table storage which are in pending state
         var query = from p in matterInformationVM select p;
         foreach (MatterInformationVM matterInformation in query)
         {
             if (matterInformation != null)
             {
                 if (matterInformation.Status.ToLower() == "pending")
                 {
                     string serializedMatter = matterInformation.SerializeMatter;
                     //De Serialize the matter information
                     MatterInformationVM originalMatter = Newtonsoft.Json.JsonConvert.DeserializeObject<MatterInformationVM>(serializedMatter);
                     log.WriteLine($"Checking the matter name {originalMatter.Matter.Name} has been acceped by the user or not");
                     //Read all external access requests records from azure table storge
                     GetExternalAccessRequestsFromSPO(matterInformation, originalMatter, log, configuration);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         log.WriteLine($"Exception occured in the method ReadExternalAccessRequests. {ex}");
     }
 }