/// <summary> /// Removes all references to the list of fields. /// this deletes field links from content types. /// Only field links that refer to fields that have a different GUID /// to the equivalent one in the CTH are removed /// </summary> /// <param name="ResetValues"></param> /// <returns></returns> public string RemoveSCFields(SyndicationResetValues ResetValues) { string outputReport = String.Format("Report generated on: {0}{1}", DateTime.Now, Environment.NewLine); string stage = "Start"; _resetValues = ResetValues; try { using (_ctx = GetClientContext(_resetValues.ContentTypeHubURL)) { stage = "Set CTH context"; GetContentHubColumnGUIDs(); stage = "Retrieved CTH values"; outputReport += "GUIDs read from the Hub" + Environment.NewLine; } stage = "Processing site collections"; ProcessSiteCollections(ResetValues, ref outputReport); outputReport += "*************** Finished ***************"; stage = "Site collections processed"; } catch (Exception ex) { outputReport += String.Format("{3}{3}ERROR: {0} {3}{1}{3}{3}At stage: {2}", ex.Message, ex.InnerException, stage, Environment.NewLine); } return outputReport; }
/// <summary> /// Reads app.config and loads variables into a configuration object /// that will be sent to the column removal object /// </summary> /// <returns></returns> private static SyndicationResetValues SetupResetValue() { SyndicationResetValues srv = new SyndicationResetValues(); srv.UsePassword = Boolean.Parse(ConfigurationManager.AppSettings["requestPassword"]); if (srv.UsePassword) { Console.WriteLine("Please enter the user name:"); srv.UserName = Console.ReadLine(); Console.WriteLine("Please provide the password:"******"processFields"]); srv.ProcessCTHide = Boolean.Parse(ConfigurationManager.AppSettings["processCTHide"]); srv.ProcessCTRemove = Boolean.Parse(ConfigurationManager.AppSettings["processCTRemove"]); srv.ProcessRefreshCTFlag = Boolean.Parse(ConfigurationManager.AppSettings["processRefreshCTFlag"]); srv.ProcessRemoveFieldsFromLists = Boolean.Parse(ConfigurationManager.AppSettings["processFieldRemovalFromLists"]); srv.FieldNamesToRemove = GetFileContents(ConfigurationManager.AppSettings["fieldListFile"]); srv.ContentTypesToRemove = GetFileContents(ConfigurationManager.AppSettings["contentTypeRemoveFile"]); srv.ContentTypesToRenameAndHide = GetFileContents(ConfigurationManager.AppSettings["contentTypeHideFile"]); srv.SiteCollections = GetFileContents(ConfigurationManager.AppSettings["siteCollectionURLFile"]); srv.ContentTypeHubURL = ConfigurationManager.AppSettings["configHubURL"]; if (!srv.ValidSettings()) { throw new Exception(srv.FailReason); } else { return srv; } }
/// <summary> /// Wrapper function to cover several activities (looping around all site collections) /// 1. Getting content types for the SC /// 2. removing field links to the fields /// 3. removing the fields /// 4. Hide and rename of content types /// 5. removal of content types /// 6. Reset the 'refresh CT publishing' flag /// </summary> /// <param name="ResetValues"></param> /// <param name="outputReport"></param> private void ProcessSiteCollections(SyndicationResetValues ResetValues, ref string outputReport) { Dictionary<string, string> jobOutput = new Dictionary<string, string>(); foreach (string siteCollectionURL in _resetValues.SiteCollections) { ProgressReport scReport = new ProgressReport(siteCollectionURL); using (_ctx = GetClientContext(siteCollectionURL)) { RetreiveContentTypes(); scReport.AddEntry("Content types read from target site collection"); if (_resetValues.ProcessFields) { scReport.AddEntry("*** Removing field links"); jobOutput = RemoveFieldLinks(); AddJobOutputToReport(jobOutput, ref scReport); scReport.AddEntry(String.Format("*** Removing Site Columns: {0} columns to process", _cthCols.Keys.Count)); jobOutput = RemoveSiteColumns(); AddJobOutputToReport(jobOutput, ref scReport); } if (_resetValues.ProcessCTHide) { scReport.AddEntry(String.Format("*** Rename and hiding {0} content types", ResetValues.ContentTypesToRenameAndHide.Count)); jobOutput = RenameAndHideContentTypes(ResetValues.ContentTypesToRenameAndHide); AddJobOutputToReport(jobOutput, ref scReport); } if (_resetValues.ProcessCTRemove) { scReport.AddEntry(String.Format("*** Removing {0} content types", ResetValues.ContentTypesToRemove.Count)); jobOutput = RemoveContentTypes(ResetValues.ContentTypesToRemove); AddJobOutputToReport(jobOutput, ref scReport); } if (_resetValues.ProcessRemoveFieldsFromLists) { scReport.AddEntry(String.Format("*** Removing {0} content types", ResetValues.ContentTypesToRemove.Count)); jobOutput = RemoveFieldsFromLists(); AddJobOutputToReport(jobOutput, ref scReport); } if (_resetValues.ProcessRefreshCTFlag) { scReport.AddEntry("*** Setting the 'Refresh Content Types' Flag"); SetRefreshContentTypesFlag(); } } outputReport += scReport.Output() + Environment.NewLine; outputReport += "-----------------------------------------------------------" + Environment.NewLine + Environment.NewLine; } }