Esempio n. 1
0
        /// <summary>
        /// Executes the business logic
        /// </summary>
        /// <param name="logger">The logger.</param>
        public virtual void Run(BaseAction parentAction, DateTime CurrentTime, LogHelper logger = null)
        {
            CsvProcessor csvProcessor = new CsvProcessor();

            string[] csvFiles = Directory.GetFiles(this.CSVDirectoryLocation, "*.csv", SearchOption.TopDirectoryOnly);

            foreach (string csvFile in csvFiles)
            {
                using (StreamReader reader = new StreamReader(csvFile))
                {
                    using (ClientContext context = new ClientContext(this.TenantSiteUrl))
                    {
                        using (SecureString password = new SecureString())
                        {
                            foreach (char c in this.TenantAdminPassword.ToCharArray())
                            {
                                password.AppendChar(c);
                            }

                            context.Credentials = new SharePointOnlineCredentials(this.TenantAdminUserName, password);
                        }

                        csvProcessor.Execute(reader, (entries, y) => { IterateCollection(context, entries, logger); }, logger);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Executes the business logic
        /// </summary>
        /// <param name="logger">The logger.</param>
        public override void Run(BaseAction parentAction, DateTime CurrentTime, LogHelper logger)
        {
            CsvProcessor csvProcessor = new CsvProcessor();

            logger.LogVerbose(string.Format("Attempting to read mapping CSV file '{0}'", this.UserMappingCSVFile));

            using (StreamReader reader = new StreamReader(this.UserMappingCSVFile))
            {
                csvProcessor.Execute(reader, (entries, y) => { IterateCollection(entries, logger); }, logger);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the business logic
        /// </summary>
        /// <param name="logger">The logger.</param>
        public override void Run(BaseAction parentAction, DateTime CurrentTime, LogHelper logger)
        {
            if (parentAction != null)
            {
                this.Properties = parentAction.Properties;
            }

            CsvProcessor csvProcessor = new CsvProcessor();

            string[] csvFiles = Directory.GetFiles(this.CSVDirectoryLocation, "*.csv", SearchOption.TopDirectoryOnly);

            logger.LogVerbose(string.Format("Attempting to get files from directory 'location' {0}. Number of files found {1}", this.CSVDirectoryLocation, csvFiles.Length));

            foreach (string csvFile in csvFiles)
            {
                logger.LogVerbose(string.Format("Attempting to read CSV file '{0}' from location {1}", csvFile, this.CSVDirectoryLocation));

                logger.LogVerbose(string.Format("Pausing the utility for '{0}' seconds so ASMX service is not overloaded", this.SleepPeriod));

                Thread.Sleep(this.SleepPeriod * 1000);

                using (StreamReader reader = new StreamReader(csvFile))
                {
                    logger.LogVerbose(string.Format("Establishing connection with tenant at '{0}'", this.TenantSiteUrl));

                    using (ClientContext context = new ClientContext(this.TenantSiteUrl))
                    {
                        Uri site = new Uri(this.TenantSiteUrl);

                        try
                        {
                            UserProfileService.UserProfileService profileService = new UserProfileService.UserProfileService(site.ToString() + ProfileService);
                            this.profileService = profileService;
                            profileService.UseDefaultCredentials = false;

                            using (SecureString password = new SecureString())
                            {
                                foreach (char c in this.TenantAdminPassword.ToCharArray())
                                {
                                    password.AppendChar(c);
                                }

                                logger.LogVerbose(string.Format("Attempting to authenticate against tenant with user name '{1}'", this.TenantSiteUrl, this.TenantAdminUserName));

                                var crudentials = new SharePointOnlineCredentials(this.TenantAdminUserName, password);

                                string cookie = crudentials.GetAuthenticationCookie(site);

                                profileService.CookieContainer = new CookieContainer();
                                profileService.CookieContainer.Add(new Cookie(FedAuthCookieName, cookie.TrimStart(SPOIDCookieValue.ToCharArray()), string.Empty, site.Authority));
                                csvProcessor.Execute(reader, (entries, y) => { IterateCollection(context, entries, logger); }, logger);
                            }
                        }
                        finally
                        {
                            if (this.profileService != null)
                            {
                                this.profileService.Dispose();
                            }
                        }
                    }
                }

                // Clean up current CSV file
                System.IO.File.Delete(csvFile);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Executes the business logic
        /// </summary>
        /// <param name="logger">The logger.</param>
        public override void Run(BaseAction parentAction, DateTime CurrentTime, LogHelper logger)
        {
            CsvProcessor csvProcessor = new CsvProcessor();

            logger.LogVerbose(string.Format("Attempting to read mapping CSV file '{0}'", this.UserMappingCSVFile));

            using (StreamReader reader = new StreamReader(this.UserMappingCSVFile))
            {
                csvProcessor.Execute(reader, (entries, y) => { IterateCollection(entries, logger); }, logger);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Executes the business logic
        /// </summary>
        /// <param name="logger">The logger.</param>
        public override void Run(BaseAction parentAction, DateTime CurrentTime, LogHelper logger)
        {
            if (parentAction != null)
            {
                this.Properties = parentAction.Properties;
            }

            CsvProcessor csvProcessor = new CsvProcessor();

            string[] csvFiles = Directory.GetFiles(this.CSVDirectoryLocation, "*.csv", SearchOption.TopDirectoryOnly);

            logger.LogVerbose(string.Format("Attempting to get files from directory 'location' {0}. Number of files found {1}", this.CSVDirectoryLocation, csvFiles.Length));

            foreach (string csvFile in csvFiles)
            {
                logger.LogVerbose(string.Format("Attempting to read CSV file '{0}' from location {1}", csvFile, this.CSVDirectoryLocation));

                logger.LogVerbose(string.Format("Pausing the utility for '{0}' seconds so ASMX service is not overloaded", this.SleepPeriod));

                Thread.Sleep(this.SleepPeriod * 1000);

                using (StreamReader reader = new StreamReader(csvFile))
                {
                    logger.LogVerbose(string.Format("Establishing connection with tenant at '{0}'", this.TenantSiteUrl));

                    using (ClientContext context = new ClientContext(this.TenantSiteUrl))
                    {
                        Uri site = new Uri(this.TenantSiteUrl);

                        try
                        {
                            UserProfileService.UserProfileService profileService = new UserProfileService.UserProfileService(site.ToString() + ProfileService);
                            this.profileService = profileService;
                            profileService.UseDefaultCredentials = false;

                            using (SecureString password = new SecureString())
                            {
                                foreach (char c in this.TenantAdminPassword.ToCharArray())
                                {
                                    password.AppendChar(c);
                                }

                                logger.LogVerbose(string.Format("Attempting to authenticate against tenant with user name '{1}'", this.TenantSiteUrl, this.TenantAdminUserName));

                                var crudentials = new SharePointOnlineCredentials(this.TenantAdminUserName, password);

                                string cookie = crudentials.GetAuthenticationCookie(site);

                                profileService.CookieContainer = new CookieContainer();
                                profileService.CookieContainer.Add(new Cookie(FedAuthCookieName, cookie.TrimStart(SPOIDCookieValue.ToCharArray()), string.Empty, site.Authority));
                                csvProcessor.Execute(reader, (entries, y) => { IterateCollection(context, entries, logger); }, logger);
                            }
                        }
                        finally
                        {
                            if (this.profileService != null)
                            {
                                this.profileService.Dispose();
                            }
                        }
                    }
                }

                // Clean up current CSV file
                System.IO.File.Delete(csvFile);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Executes the business logic
        /// </summary>
        /// <param name="logger">The logger.</param>
        public virtual void Run(BaseAction parentAction, DateTime CurrentTime, LogHelper logger = null)
        {
            CsvProcessor csvProcessor = new CsvProcessor();

            string[] csvFiles = Directory.GetFiles(this.CSVDirectoryLocation, "*.csv", SearchOption.TopDirectoryOnly);

            foreach (string csvFile in csvFiles)
            {
                using (StreamReader reader = new StreamReader(csvFile))
                {
                    using (ClientContext context = new ClientContext(this.TenantSiteUrl))
                    {
                        using (SecureString password = new SecureString())
                        {
                            foreach (char c in this.TenantAdminPassword.ToCharArray())
                            {
                                password.AppendChar(c);
                            }

                            context.Credentials = new SharePointOnlineCredentials(this.TenantAdminUserName, password);
                        }

                        csvProcessor.Execute(reader, (entries, y) => { IterateCollection(context, entries, logger); }, logger);
                    }
                }
            }
        }