protected override void ProcessRecord() { WebPartTransformationHelper webPartTransformationHelper = new WebPartTransformationHelper(); string csvFile = OutPutDirectory + @"\" + System.IO.Path.GetFileNameWithoutExtension(WebPartUsageFilePath) + "_DeleteOperationStatus" + "_" + DateTime.Now.ToString("dd_MM_yyyy_hh_ss") + ".csv"; if (String.Equals(Transformation.PowerShell.Common.Constants.ActionType_All, SourceWebPartType, StringComparison.CurrentCultureIgnoreCase)) { //Reading Input File IEnumerable <WebPartDiscoveryInput> objWPDInput; objWPDInput = ImportCsv.ReadMatchingColumns <WebPartDiscoveryInput>(WebPartUsageFilePath, Transformation.PowerShell.Common.Constants.CsvDelimeter); if (objWPDInput.Any()) { IEnumerable <string> webPartTypes = objWPDInput.Select(x => x.WebPartType); webPartTypes = webPartTypes.Distinct(); foreach (string webPartType in webPartTypes) { webPartTransformationHelper.DeleteWebPart_UsingCSV(webPartType, WebPartUsageFilePath, OutPutDirectory, csvFile, SharePointOnline_OR_OnPremise, UserName, Password, Domain); } } } else { webPartTransformationHelper.DeleteWebPart_UsingCSV(SourceWebPartType, WebPartUsageFilePath, OutPutDirectory, csvFile, SharePointOnline_OR_OnPremise, UserName, Password, Domain); } }
public void ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV(string outPutFolder, string MasterPageUsagePath, out IEnumerable <MasterPageInput> objMPInput, string New_MasterPageDetails = "N/A", string Old_MasterPageDetails = "N/A", string SharePointOnline_OR_OnPremise = Constants.OnPremise, string UserName = "******", string Password = "******", string Domain = "N/A") { string exceptionCommentsInfo1 = string.Empty; List <MasterPageBase> _WriteMasterList = new List <MasterPageBase>(); Logger.AddMessageToTraceLogFile(Constants.Logging, "[START] ::: ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV"); Logger.AddMessageToTraceLogFile(Constants.Logging, "[ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV] [START] Calling function ImportCsv.ReadMatchingColumns<MasterPageInput>. Master Page Input CSV file is available at " + MasterPageUsagePath); Console.WriteLine("[ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV] [START] Calling function ImportCsv.ReadMatchingColumns<MasterPageInput>. Master Page Input CSV file is available at " + MasterPageUsagePath); objMPInput = null; //objMPInput = ImportCsv.Read<MasterPageInput>(outPutFolder + @"\" + Transformation.PowerShell.Common.Constants.MasterPageInput, Transformation.PowerShell.Common.Constants.CsvDelimeter); objMPInput = ImportCsv.ReadMatchingColumns <MasterPageInput>(MasterPageUsagePath, Transformation.PowerShell.Common.Constants.CsvDelimeter); Logger.AddMessageToTraceLogFile(Constants.Logging, "[ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV] [END] Read all the INPUT from Master Page and saved in List - out IEnumerable<MasterPageInput> objMpInput, for processing."); Console.WriteLine("[ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV] [END] Read all the INPUT from Master Page and saved in List - out IEnumerable<MasterPageInput> objMpInput, for processing."); try { if (objMPInput.Any()) { Logger.AddMessageToTraceLogFile(Constants.Logging, "[START] ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV - After Loading InputCSV "); Console.WriteLine("[START] ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV - After Loading InputCSV"); bool headerMasterPage = false; foreach (MasterPageInput objInput in objMPInput) { //This is for Exception Comments: ExceptionCsv.WebUrl = objInput.WebUrl; ExceptionCsv.SiteCollection = objInput.SiteCollectionUrl; ExceptionCsv.WebApplication = objInput.WebApplicationUrl; exceptionCommentsInfo1 = "<Input>New MasterPage Url = " + New_MasterPageDetails + ", <Input> OLD MasterUrl: " + Old_MasterPageDetails + ", WebUrl: " + objInput.WebUrl + ", CustomMasterUrlStatus" + objInput.CustomMasterUrlStatus + "MasterUrlStatus" + objInput.MasterUrlStatus; //This is for Exception Comments: MasterPageBase objMPBase = new MasterPageBase(); //if (Old_MasterPageDetails.Trim().ToLower() != Constants.Input_Blank && Old_MasterPageDetails.Trim().ToLower() != Constants.Input_All) if (Old_MasterPageDetails.Trim().ToLower() != Constants.Input_All) { objMPBase = ChangeMasterPageForWeb(outPutFolder, objInput.WebUrl, New_MasterPageDetails, Old_MasterPageDetails, Convert.ToBoolean(objInput.CustomMasterUrlStatus), Convert.ToBoolean(objInput.MasterUrlStatus), Constants.ActionType_CSV, SharePointOnline_OR_OnPremise, UserName, Password, Domain); } else { objMPBase = ChangeMasterPageForWeb(outPutFolder, objInput.WebUrl, New_MasterPageDetails, Old_MasterPageDetails, true, Convert.ToBoolean(objInput.MasterUrlStatus), Constants.ActionType_CSV, SharePointOnline_OR_OnPremise, UserName, Password, Domain); } if (objMPBase != null) { _WriteMasterList.Add(objMPBase); } } if (_WriteMasterList != null) { if (_WriteMasterList.Count > 0) { FileUtility.WriteCsVintoFile(outPutFolder + @"\" + Constants.MasterPageUsage, ref _WriteMasterList, ref headerMasterPage); } } Logger.AddMessageToTraceLogFile(Constants.Logging, "[END] ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV - After Loading InputCSV. Updated the Master Pages."); Console.WriteLine("[END] ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV - After Loading InputCSV. Updated the Master Pages."); } } catch (Exception ex) { ExceptionCsv.WriteException(ExceptionCsv.WebApplication, ExceptionCsv.SiteCollection, ExceptionCsv.WebUrl, "MasterPage", ex.Message, ex.ToString(), "ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV", ex.GetType().ToString(), exceptionCommentsInfo1); Logger.AddMessageToTraceLogFile(Constants.Logging, "[Exception] ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV. Exception Message:" + ex.Message); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("[Exception] ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV. Exception Message:" + ex.Message + ", Exception Comment: " + exceptionCommentsInfo1); Console.ForegroundColor = ConsoleColor.Gray; } Logger.AddMessageToTraceLogFile(Constants.Logging, "[END] ::: ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV"); Console.WriteLine("[END] ::: ChangeMasterPageForDiscoveryOutPut_ReadMasterPagesCSV"); }