private static void WebValidationOperations(ISharePointWebValidationService spWebValidationService)
        {
            Task <List <string> > t_missingGroups = Task.Factory.StartNew <List <string> >(() =>
            {
                logger.Log(LogLevel.Info, $"Checking for missing web groups");
                return(spWebValidationService.MissingWebGroups());
            }
                                                                                           );

            Task <List <UserGroupStatus> > t_missingUsersInGroups = Task.Factory.StartNew <List <UserGroupStatus> >(() =>
            {
                logger.Log(LogLevel.Info, $"Checking for missing users in groups");
                return(spWebValidationService.MissingUsersInGroups());
            }
                                                                                                                    );

            Task.WaitAll(new Task[] { t_missingGroups, t_missingUsersInGroups });

            if (t_missingGroups.Result.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(t_missingGroups.Result, Path.Combine(dirInfo.FullName, "missingGroups.csv"));
            }

            if (t_missingUsersInGroups.Result.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(t_missingUsersInGroups.Result, Path.Combine(dirInfo.FullName, "missingUsersInGroups.csv"));
            }
        }
        private static void ListValidationOperations(ISharePointListValidationService spListValidationService)
        {
            Task <List <string> > t_missingLists = Task.Factory.StartNew <List <string> >(() =>
            {
                logger.Log(LogLevel.Info, $"Checking for missing lists");
                return(spListValidationService.MissingLists());
            });

            Task <List <SPListItemCount> > t_listItemsCountMismatch = Task.Factory.StartNew <List <SPListItemCount> >(() =>
            {
                logger.Log(LogLevel.Info, $"Checking for list item count mismatch");
                return(spListValidationService.GetListsItemsCountMismatch());
            });

            Task <List <SPField> > t_missingFields = Task.Factory.StartNew <List <SPField> >(() =>
            {
                logger.Log(LogLevel.Info, $"Checking for missing list fields");
                return(spListValidationService.MissingListColumns());
            });

            Task <List <SPListItem> > t_missingListItems = Task.Factory.StartNew <List <SPListItem> >(() =>
            {
                logger.Log(LogLevel.Info, $"Checking for missing list items");
                return(spListValidationService.MissingListItems());
            });

            Task <List <SPWebPart> > t_missingWebParts = Task.Factory.StartNew <List <SPWebPart> >(() =>
            {
                logger.Log(LogLevel.Info, $"Checking for missing webparts");
                return(spListValidationService.MissingWebParts());
            });

            Task.WaitAll(new Task[] { t_missingLists, t_listItemsCountMismatch, t_missingFields, t_missingListItems, t_missingWebParts });

            if (t_missingLists.Result.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(t_missingLists.Result, Path.Combine(dirInfo.FullName, "missingLists.csv"));
            }

            if (t_listItemsCountMismatch.Result.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(t_listItemsCountMismatch.Result, Path.Combine(dirInfo.FullName, "listItemsCountMismatch.csv"));
            }

            if (t_missingFields.Result.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(t_missingFields.Result, Path.Combine(dirInfo.FullName, "missingFields.csv"));
            }

            if (t_missingListItems.Result.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(t_missingListItems.Result, Path.Combine(dirInfo.FullName, "missingListItems.csv"));
            }

            if (t_missingWebParts.Result.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(t_missingWebParts.Result, Path.Combine(dirInfo.FullName, "missingWebParts.csv"));
            }
        }
Exemple #3
0
        private void GetListItemsInventory(string list)
        {
            List <SPListItem> listItems = this.SharePointRepository2007.GetListItems(list);

            CsvWriterHelper.WriteCsvRecords(listItems, System.IO.Path.Combine(@"D:\Logs", "2007ListItems.csv"));

            List <SPListItem> listItems2 = this.SharePointRepository.GetListItems(TargetClientContext, list);

            CsvWriterHelper.WriteCsvRecords(listItems2, System.IO.Path.Combine(@"D:\Logs", "2013ListItems.csv"));
        }
        private static void SiteCollectionValidationOperations(ISharePointWebValidationService spWebValidationService)
        {
            watch.Restart();
            logger.Log(LogLevel.Info, $"Checking for missing site content types");
            var missingContentTypes = spWebValidationService.MissingContentTypes();

            if (missingContentTypes.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(missingContentTypes, Path.Combine(dirInfo.FullName, "missingContentTypes.csv"));
            }
            watch.Stop();
            logger.Log(LogLevel.Info, $"Missing site content types Elapsed Time: {watch.Elapsed.Seconds}");

            watch.Restart();
            logger.Log(LogLevel.Info, $"Checking for missing site columns");
            var missingSiteColumns = spWebValidationService.MissingSiteColumns();

            if (missingSiteColumns.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(missingSiteColumns, Path.Combine(dirInfo.FullName, "missingSiteColumns.csv"));
            }
            watch.Stop();
            logger.Log(LogLevel.Info, $"Missing site columns elapsed time: {watch.Elapsed.Seconds}");

            logger.Log(LogLevel.Info, $"Checking for missing site groups");
            var missingGroups = spWebValidationService.MissingSiteGroupsV1();

            if (missingGroups.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(missingGroups, Path.Combine(dirInfo.FullName, "missingSiteGroups.csv"));
            }
            watch.Stop();
            logger.Log(LogLevel.Info, $"Missing Site Groups Elapsed Time: {watch.Elapsed.Seconds}");

            //TODO: custom permission levels

            /*
             * logger.Log(LogLevel.Info, $"Checking for missing users in groups");
             * var missingUsersInGroups = spWebValidationService.MissingUsersInGroups();
             * if (missingUsersInGroups.Count > 0)
             *  CsvWriterHelper.WriteCsvRecords(missingUsersInGroups, Path.Combine(dirInfo.FullName, "missingUsersInGroups.csv"));
             *
             *
             * logger.Log(LogLevel.Info, $"Checking for site user permissions");
             * var mismatchUserPerms = spWebValidationService.CheckUserPermissions();
             * if (mismatchUserPerms.Count > 0)
             *  CsvWriterHelper.WriteCsvRecords(mismatchUserPerms, Path.Combine(dirInfo.FullName, "mismatchUserPerms.csv"));
             */
        }
        private static void WebValidationOperations(ISharePointWebValidationService spWebValidationService)
        {
            logger.Log(LogLevel.Info, $"Checking for mismatches in web permissions inheritance");
            var mismatchWebPermsInheritance = spWebValidationService.CheckWebPermissionsInheritance();

            if (mismatchWebPermsInheritance.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(mismatchWebPermsInheritance, Path.Combine(dirInfo.FullName, "mismatchWebPermsInheritance.csv"));
            }

            logger.Log(LogLevel.Info, $"Checking for missing web groups");
            var missingGroups = spWebValidationService.MissingWebGroups();

            if (missingGroups.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(missingGroups, Path.Combine(dirInfo.FullName, "missingWebGroups.csv"));
            }
        }
        private static void SiteCollectionValidationOperations(ISharePointWebValidationService spWebValidationService)
        {
            Task <List <UserPermStatus> > t_mismatchUserPerms = Task.Factory.StartNew <List <UserPermStatus> >(() =>
            {
                logger.Log(LogLevel.Info, $"Checking for site user permissions");
                return(spWebValidationService.CheckUserPermissions());
            });

            Task <List <string> > t_missingContentTypes = Task.Factory.StartNew <List <string> >(() =>
            {
                logger.Log(LogLevel.Info, $"Checking for missing site content types");
                return(spWebValidationService.MissingContentTypes());
            });

            Task <List <SPField> > t_missingSiteColumns = Task.Factory.StartNew <List <SPField> >(() =>
            {
                logger.Log(LogLevel.Info, $"Checking for missing site columns");
                return(spWebValidationService.MissingSiteColumns());
            });

            Task.WaitAll(new Task[] { t_mismatchUserPerms, t_missingContentTypes, t_missingSiteColumns });

            if (t_mismatchUserPerms.Result.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(t_mismatchUserPerms.Result, Path.Combine(dirInfo.FullName, "mismatchUserPerms.csv"));
            }

            if (t_missingContentTypes.Result.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(t_missingContentTypes.Result, Path.Combine(dirInfo.FullName, "missingContentTypes.csv"));
            }

            if (t_missingSiteColumns.Result.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(t_missingSiteColumns.Result, Path.Combine(dirInfo.FullName, "missingSiteColumns.csv"));
            }
        }
        static void Main(string[] args)
        {
            try
            {
                //Register and initialize containers
                var container = new UnityContainer();
                container.RegisterType <ISharePointWebValidationService, WebValidationServiceController>();
                container.RegisterType <ISharePointListValidationService, ListValidationServiceController>();
                container.RegisterType <IUserMapping, UserMappingController>();

                IUserMapping userMapping = null;
                if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["UserMappingFilePath"]))
                {
                    container.RegisterType <IUserMapping, UserMappingController>();
                    userMapping = container.Resolve <IUserMapping>(
                        new ParameterOverrides
                    {
                        { "filePath", ConfigurationManager.AppSettings["UserMappingFilePath"] }
                    });
                }
                var siteRelativeUrls = ConfigurationManager.AppSettings["SiteRelativeUrls"].Split(new char[] { ';' });
                var userMappingFile  = ConfigurationManager.AppSettings["UserMappingFilePath"];

                foreach (var siteRelativeUrl in siteRelativeUrls)
                {
                    var sRelativeUrl  = siteRelativeUrl;
                    var sourceSiteUrl = ConfigurationManager.AppSettings["SourceSiteHost"] + sRelativeUrl;
                    var targetSiteUrl = ConfigurationManager.AppSettings["TargetSiteHost"] + sRelativeUrl;

                    //initialize source connection object
                    var srcSPCredObject = new SPConnection(ConfigurationManager.AppSettings["SourceSiteType"], sourceSiteUrl, sRelativeUrl, ConfigurationManager.AppSettings["SourceUserName"], ConfigurationManager.AppSettings["SourcePassword"]);
                    var tgtSPCredObject = new SPConnection(ConfigurationManager.AppSettings["TargetSiteType"], targetSiteUrl, sRelativeUrl, ConfigurationManager.AppSettings["TargetUserName"], ConfigurationManager.AppSettings["TargetPassword"]);

                    var spWebValidationService = container.Resolve <ISharePointWebValidationService>(
                        new ParameterOverrides
                    {
                        { "sourceCreds", srcSPCredObject },
                        { "targetCreds", tgtSPCredObject },
                        { "userMapping", userMapping },
                        { "logger", logger }
                    });

                    var spListValidationService = container.Resolve <ISharePointListValidationService>(
                        new ParameterOverrides
                    {
                        { "sourceCreds", srcSPCredObject },
                        { "targetCreds", tgtSPCredObject },
                        { "userMapping", userMapping },
                        { "logger", logger }
                    });

                    //Create base directory first based on the sRelativeUrl
                    dirInfo = Directory.CreateDirectory(ConfigurationManager.AppSettings["LogDirectory"] + sRelativeUrl);

                    //Get missing Sites from the site collection
                    logger.Log(LogLevel.Info, $"Validating Sites and Lists for {targetSiteUrl}");

                    Task <List <string> > t_missingSites = Task.Factory.StartNew <List <string> >(() =>
                    {
                        logger.Log(LogLevel.Info, $"Checking for missing sites");
                        return(spWebValidationService.MissingSites());
                    });

                    t_missingSites.Wait();
                    var missingSites = t_missingSites.Result;

                    if (missingSites.Count > 0)
                    {
                        CsvWriterHelper.WriteCsvRecords(missingSites, Path.Combine(dirInfo.FullName, "missingSites.csv"));
                    }

                    //Perform site collection operations
                    SiteCollectionValidationOperations(spWebValidationService);

                    //Perform web & list operations
                    var webUrls = spWebValidationService.GetAllSourceWebUrls();

                    foreach (var webUrl in webUrls)
                    {
                        var webUri      = new Uri(webUrl, true);
                        var relativeUri = webUri.MakeRelativeUri(webUri);
                        dirInfo = Directory.CreateDirectory(dirInfo.FullName + relativeUri.ToString());

                        if (webUrl == sourceSiteUrl)
                        {
                            WebValidationOperations(spWebValidationService);
                            ListValidationOperations(spListValidationService);
                            continue;
                        }

                        if (missingSites.Count > 0)
                        {
                            var match = missingSites.Exists(s => s == webUrl);
                            if (match)
                            {
                                continue;
                            }
                        }

                        targetSiteUrl = ConfigurationManager.AppSettings["TargetSiteHost"] + "/" + relativeUri.ToString();

                        //initialize source connection object
                        srcSPCredObject = new SPConnection(ConfigurationManager.AppSettings["SourceSiteType"], webUrl, relativeUri.ToString(), ConfigurationManager.AppSettings["SourceUserName"], ConfigurationManager.AppSettings["SourcePassword"]);
                        tgtSPCredObject = new SPConnection(ConfigurationManager.AppSettings["TargetSiteType"], targetSiteUrl, relativeUri.ToString(), ConfigurationManager.AppSettings["TargetUserName"], ConfigurationManager.AppSettings["TargetPassword"]);

                        spWebValidationService = container.Resolve <ISharePointWebValidationService>(
                            new ParameterOverrides
                        {
                            { "sourceCreds", srcSPCredObject },
                            { "targetCreds", tgtSPCredObject },
                            { "userMapping", userMapping },
                            { "logger", logger }
                        });
                        WebValidationOperations(spWebValidationService);

                        spListValidationService = container.Resolve <ISharePointListValidationService>(
                            new ParameterOverrides
                        {
                            { "sourceCreds", srcSPCredObject },
                            { "targetCreds", tgtSPCredObject },
                            { "userMapping", userMapping },
                            { "logger", logger }
                        });
                        ListValidationOperations(spListValidationService);
                    }
                }


                /*
                 * List<Task> tasks = new List<Task>();
                 * foreach (var siteRelativeUrl in siteRelativeUrls)
                 * {
                 *  //Passing the task with parameters -- arg = siteRelativeUrl.
                 *  Task t = Task.Factory.StartNew((arg) =>
                 *  {
                 *      var sRelativeUrl = (string)arg;
                 *      var sourceSiteUrl = ConfigurationManager.AppSettings["SourceSiteHost"] + sRelativeUrl;
                 *      var targetSiteUrl = ConfigurationManager.AppSettings["TargetSiteHost"] + sRelativeUrl;
                 *
                 *      //initialize source connection object
                 *      var srcSPCredObject = new SPConnection(sourceSiteUrl, ConfigurationManager.AppSettings["SourceUserName"], ConfigurationManager.AppSettings["SourcePassword"]);
                 *      var tgtSPCredObject = new SPConnection(targetSiteUrl, ConfigurationManager.AppSettings["TargetUserName"], ConfigurationManager.AppSettings["TargetPassword"]);
                 *
                 *      var spWebValidationService = container.Resolve<ISharePointWebValidationService>(
                 *          new ParameterOverrides
                 *          {
                 *              {"sourceCreds", srcSPCredObject },
                 *              {"targetCreds", tgtSPCredObject},
                 *              {"userMapping", userMapping},
                 *              {"logger", logger }
                 *          });
                 *
                 *      var spListValidationService = container.Resolve<ISharePointListValidationService>(
                 *          new ParameterOverrides
                 *          {
                 *              {"sourceCreds", srcSPCredObject },
                 *              {"targetCreds", tgtSPCredObject},
                 *              {"userMapping", userMapping},
                 *              {"logger", logger }
                 *          });
                 *
                 *      //Create base directory first based on the sRelativeUrl
                 *      dirInfo = Directory.CreateDirectory(ConfigurationManager.AppSettings["LogDirectory"] + sRelativeUrl);
                 *
                 *      //Get missing Sites from the site collection
                 *      logger.Log(LogLevel.Info, $"Validating Sites and Lists for {targetSiteUrl}");
                 *
                 *      Task<List<string>> t_missingSites = Task.Factory.StartNew<List<string>>(() =>
                 *      {
                 *          logger.Log(LogLevel.Info, $"Checking for missing sites");
                 *          return spWebValidationService.MissingSites();
                 *      });
                 *
                 *      t_missingSites.Wait();
                 *      var missingSites = t_missingSites.Result;
                 *
                 *      if (missingSites.Count > 0)
                 *          CsvWriterHelper.WriteCsvRecords(missingSites, Path.Combine(dirInfo.FullName, "missingSites.csv"));
                 *
                 *      //Perform site collection operations
                 *      SiteCollectionValidationOperations(spWebValidationService);
                 *
                 *      //Perform web & list operations
                 *      var webUrls = spWebValidationService.GetAllSourceWebUrls();
                 *
                 *      foreach (var webUrl in webUrls)
                 *      {
                 *          var webUri = new Uri(webUrl, true);
                 *          var relativeUri = webUri.MakeRelativeUri(webUri);
                 *          dirInfo = Directory.CreateDirectory(dirInfo.FullName + relativeUri.ToString());
                 *
                 *          if (webUrl == sourceSiteUrl)
                 *          {
                 *              WebValidationOperations(spWebValidationService);
                 *              ListValidationOperations(spListValidationService);
                 *              continue;
                 *          }
                 *
                 *          if (missingSites.Count > 0)
                 *          {
                 *              var match = missingSites.Exists(s => s == webUrl);
                 *              if (match)
                 *                  continue;
                 *          }
                 *
                 *          targetSiteUrl = ConfigurationManager.AppSettings["TargetSiteHost"] + "/" + relativeUri.ToString();
                 *
                 *          //initialize source connection object
                 *          srcSPCredObject = new SPConnection(webUrl, ConfigurationManager.AppSettings["SourceUserName"], ConfigurationManager.AppSettings["SourcePassword"]);
                 *          tgtSPCredObject = new SPConnection(targetSiteUrl, ConfigurationManager.AppSettings["TargetUserName"], ConfigurationManager.AppSettings["TargetPassword"]);
                 *
                 *          spWebValidationService = container.Resolve<ISharePointWebValidationService>(
                 *          new ParameterOverrides
                 *          {
                 *              {"sourceCreds", srcSPCredObject },
                 *              {"targetCreds", tgtSPCredObject},
                 *              {"userMapping", userMapping},
                 *              {"logger", logger }
                 *          });
                 *          WebValidationOperations(spWebValidationService);
                 *
                 *          spListValidationService = container.Resolve<ISharePointListValidationService>(
                 *          new ParameterOverrides
                 *          {
                 *              {"sourceCreds", srcSPCredObject },
                 *              {"targetCreds", tgtSPCredObject},
                 *              {"userMapping", userMapping},
                 *              {"logger", logger }
                 *          });
                 *          ListValidationOperations(spListValidationService);
                 *      }
                 *  },
                 *      siteRelativeUrl // pass symbol as an arg so task receives proper value to process:
                 *  );
                 *
                 *  tasks.Add(t);
                 * }
                 * //wait for all the tasks to complete.
                 * Task.WaitAll(tasks.ToArray());
                 * }
                 */

                logger.Log(LogLevel.Info, $"Validation Complete");
                Console.ReadKey();
            }
            catch (AggregateException ae)
            {
                ae = ae.Flatten();  // could have a tree of exceptions, so flatten first:
                foreach (Exception ex in ae.InnerExceptions)
                {
                    logger.Log(LogLevel.Error, ex);
                }
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                //Register and initialize containers
                var container = new UnityContainer();
                container.RegisterType <ISharePointWebValidationService, WebValidationServiceController>();
                container.RegisterType <ISharePointListValidationService, ListValidationServiceController>();
                container.RegisterType <IUserMapping, UserMappingController>();

                //TODO: What id userMapping is empty.. currently its set to an empty constructor.
                IUserMapping userMapping = new UserMappingController();
                if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["UserMappingFilePath"]))
                {
                    userMapping = container.Resolve <IUserMapping>(
                        new ParameterOverrides
                    {
                        { "filePath", ConfigurationManager.AppSettings["UserMappingFilePath"] }
                    });
                }

                var siteRelativeUrls = ConfigurationManager.AppSettings["SiteRelativeUrls"].Split(new char[] { ';' });
                var userMappingFile  = ConfigurationManager.AppSettings["UserMappingFilePath"];
                foreach (var siteRelativeUrl in siteRelativeUrls)
                {
                    var sRelativeUrl = siteRelativeUrl.Equals("/") ? "" : siteRelativeUrl;

                    var sourceSiteUrl = ConfigurationManager.AppSettings["SourceSiteHost"] + sRelativeUrl;
                    var targetSiteUrl = ConfigurationManager.AppSettings["TargetSiteHost"] + sRelativeUrl;

                    //initialize source connection object
                    var srcSPCredObject = new SPConnection(ConfigurationManager.AppSettings["SourceSiteType"], sourceSiteUrl, sRelativeUrl, ConfigurationManager.AppSettings["SourceUserName"], ConfigurationManager.AppSettings["SourcePassword"]);
                    var tgtSPCredObject = new SPConnection(ConfigurationManager.AppSettings["TargetSiteType"], targetSiteUrl, sRelativeUrl, ConfigurationManager.AppSettings["TargetUserName"], ConfigurationManager.AppSettings["TargetPassword"]);

                    var spWebValidationService = container.Resolve <ISharePointWebValidationService>(
                        new ParameterOverrides
                    {
                        { "sourceCreds", srcSPCredObject },
                        { "targetCreds", tgtSPCredObject },
                        { "userMapping", userMapping },
                        { "logger", logger }
                    });

                    var spListValidationService = container.Resolve <ISharePointListValidationService>(
                        new ParameterOverrides
                    {
                        { "sourceCreds", srcSPCredObject },
                        { "targetCreds", tgtSPCredObject },
                        { "userMapping", userMapping },
                        { "logger", logger }
                    });

                    //Create base directory first based on the siteRelativeUrl
                    var targetFilePath = Path.Combine(ConfigurationManager.AppSettings["LogDirectory"], (targetSiteUrl.Contains("https://") ? targetSiteUrl.Replace("https://", "") : targetSiteUrl.Replace("http://", "")));
                    dirInfo = Directory.CreateDirectory(targetFilePath);

                    //Get missing Sites from the site collection
                    logger.Log(LogLevel.Info, $"Validating Sites and Lists for {targetSiteUrl}");

                    logger.Log(LogLevel.Info, $"Checking for missing sites");

                    watch.Restart();
                    var missingSites = spWebValidationService.MissingSitesV1();
                    watch.Stop();
                    logger.Log(LogLevel.Info, $"Missing Sites Elapsed Time: {watch.Elapsed.Seconds}");

                    if (missingSites.Count > 0)
                    {
                        CsvWriterHelper.WriteCsvRecords(missingSites, Path.Combine(dirInfo.FullName, "missingSites.csv"));
                    }

                    //Perform site collection operations
                    SiteCollectionValidationOperations(spWebValidationService);

                    //Perform web & list operations
                    var webUrls = spWebValidationService.GetAllSourceWebUrls();

                    //TODO: Revisit this again

                    /*
                     * if (webUrls.Count() == 1)
                     * {
                     *  if (webUrls.First().ToLower() == sourceSiteUrl.ToLower())
                     *  {
                     *      WebValidationOperations(spWebValidationService);
                     *      ListValidationOperations(spListValidationService);
                     *  }
                     *  continue;
                     * }
                     */

                    foreach (var webUrl in webUrls)
                    {
                        if (missingSites.Count > 0)
                        {
                            var match = missingSites.Exists(s => s.ToLower() == webUrl.ToLower());
                            if (match)
                            {
                                continue;
                            }
                        }

                        if (webUrl.ToLower() == sourceSiteUrl.ToLower())
                        {
                            WebValidationOperations(spWebValidationService);
                            ListValidationOperations(spListValidationService);
                            continue;
                        }

                        // relative URL --> the very last part
                        var relativeUrl = webUrl.ToLower().Replace(sourceSiteUrl.ToLower(), "");

                        targetSiteUrl = ConfigurationManager.AppSettings["TargetSiteHost"] + sRelativeUrl + relativeUrl;

                        targetFilePath = Path.Combine(ConfigurationManager.AppSettings["LogDirectory"], (targetSiteUrl.Contains("https://") ? targetSiteUrl.Replace("https://", "") : targetSiteUrl.Replace("http://", "")));
                        dirInfo        = Directory.CreateDirectory(targetFilePath);

                        //initialize source connection object
                        srcSPCredObject = new SPConnection(ConfigurationManager.AppSettings["SourceSiteType"], webUrl, relativeUrl, ConfigurationManager.AppSettings["SourceUserName"], ConfigurationManager.AppSettings["SourcePassword"]);
                        tgtSPCredObject = new SPConnection(ConfigurationManager.AppSettings["TargetSiteType"], targetSiteUrl, relativeUrl, ConfigurationManager.AppSettings["TargetUserName"], ConfigurationManager.AppSettings["TargetPassword"]);


                        logger.Log(LogLevel.Info, $"Validating Sites and Lists for {targetSiteUrl}");

                        spWebValidationService = container.Resolve <ISharePointWebValidationService>(
                            new ParameterOverrides
                        {
                            { "sourceCreds", srcSPCredObject },
                            { "targetCreds", tgtSPCredObject },
                            { "userMapping", userMapping },
                            { "logger", logger }
                        });
                        WebValidationOperations(spWebValidationService);

                        spListValidationService = container.Resolve <ISharePointListValidationService>(
                            new ParameterOverrides
                        {
                            { "sourceCreds", srcSPCredObject },
                            { "targetCreds", tgtSPCredObject },
                            { "userMapping", userMapping },
                            { "logger", logger }
                        });
                        ListValidationOperations(spListValidationService);
                    }
                }
                logger.Log(LogLevel.Info, $"Validation Complete");
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex);
            }
        }
        private static void ListValidationOperations(ISharePointListValidationService spListValidationService)
        {
            logger.Log(LogLevel.Info, $"Checking for missing lists");
            var missingLists = spListValidationService.MissingLists();

            if (missingLists.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(missingLists, Path.Combine(dirInfo.FullName, "missingLists.csv"));
            }

            logger.Log(LogLevel.Info, $"Checking for list item count mismatch");
            var listItemsCountMismatch = spListValidationService.GetListsItemsCountMismatch();

            if (listItemsCountMismatch.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(listItemsCountMismatch, Path.Combine(dirInfo.FullName, "listItemsCountMismatch.csv"));
            }

            logger.Log(LogLevel.Info, $"Checking for missing list fields");
            var missingFields = spListValidationService.MissingListColumnsV1();

            if (missingFields.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(missingFields, Path.Combine(dirInfo.FullName, "missingFields.csv"));
            }

            logger.Log(LogLevel.Info, $"Checking for missing list views");
            var missingListViews = spListValidationService.MissingListViews();

            if (missingListViews.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(missingListViews, Path.Combine(dirInfo.FullName, "missingListViews.csv"));
            }

            logger.Log(LogLevel.Info, $"Checking for missing list items");
            var missingListItems = spListValidationService.MissingListItemsV1();

            if (missingListItems.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(missingListItems, Path.Combine(dirInfo.FullName, "missingListItems.csv"));
            }


            /*
             * logger.Log(LogLevel.Info, $"Checking for missing list items by modified date");
             * var missingListItemsByModifiedDate = spListValidationService.MissingListItems();
             * if (missingListItemsByModifiedDate.Count > 0)
             *  CsvWriterHelper.WriteCsvRecords(missingListItemsByModifiedDate, Path.Combine(dirInfo.FullName, "missingListItemsByModifiedDate.csv"));
             */

            logger.Log(LogLevel.Info, $"Checking for missing webparts");
            var missingWebParts = spListValidationService.MissingWebParts();

            if (missingWebParts.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(missingWebParts, Path.Combine(dirInfo.FullName, "missingWebParts.csv"));
            }

            logger.Log(LogLevel.Info, $"Checking for missing worflows");
            var missingWorkflows = spListValidationService.MissingWorkflows();

            if (missingWorkflows.Count > 0)
            {
                CsvWriterHelper.WriteCsvRecords(missingWorkflows, Path.Combine(dirInfo.FullName, "missingWorkflows.csv"));
            }
        }