/// <summary> /// Main method /// </summary> /// <param name="args">Event Arguments</param> public static void Main(string[] args) { string input = String.Empty; string input1 = string.Empty; string input2 = string.Empty; GetCredentials(); //Excception CSV Creation Command ExceptionCsv objException = ExceptionCsv.CurrentInstance; objException.CreateLogFile(Environment.CurrentDirectory); do { ShowUsage(); input = System.Console.ReadLine(); switch (input.ToUpper(System.Globalization.CultureInfo.CurrentCulture)) { case "1": do { System.Console.ForegroundColor = System.ConsoleColor.Green; System.Console.WriteLine(""); System.Console.WriteLine("Your selected Operation [1: \"Transformation\"] supports the following operations."); System.Console.WriteLine("Please type an operation number and press [Enter] to execute the specified operation:"); System.Console.WriteLine("1. Add OOTB Web Part or App Part to a page"); System.Console.WriteLine("2. Replace FTC Web Part with OOTB Web Part or App Part on a page"); System.Console.WriteLine("3. Replace MasterPage"); System.Console.WriteLine("4. Reset Device Channel Mapping Files"); System.Console.WriteLine("5. Manage [Add|Remove] Maintenance Banners"); System.Console.WriteLine("6. Exit"); System.Console.ResetColor(); input1 = System.Console.ReadLine(); switch (input1) { case "1": AddWebPart.DoWork(); break; case "2": ReplaceWebPart.DoWork(); break; case "3": ReplaceMasterPage.DoWork(); break; case "4": ResetDeviceChannelMappingFiles.DoWork(); break; case "5": ManageMaintenanceBanners.DoWork(); break; case "6": break; default: break; } } while (input1.ToUpper(System.Globalization.CultureInfo.CurrentCulture) != "6"); break; case "2": do { System.Console.ForegroundColor = System.ConsoleColor.Magenta; System.Console.WriteLine(""); System.Console.WriteLine("Your selected Operation [2: \"Clean-Up\"] supports the following operations."); System.Console.WriteLine("Please type an operation number and press [Enter] to execute the specified operation:"); System.Console.WriteLine("1. Delete Missing Setup Files"); System.Console.WriteLine("2. Delete Missing Features"); System.Console.WriteLine("3. Delete Missing Event Receivers"); System.Console.WriteLine("4. Delete Workflow Associations"); System.Console.WriteLine("5. Delete List Templates"); System.Console.WriteLine("6. Delete Missing Webparts"); System.Console.WriteLine("7. Exit"); System.Console.ResetColor(); input1 = System.Console.ReadLine(); switch (input1) { case "1": DeleteMissingSetupFiles.DoWork(); break; case "2": DeleteMissingFeatures.DoWork(); break; case "3": DeleteMissingEventReceivers.DoWork(); break; case "4": DeleteMissingWorkflowAssociations.DoWork(); break; case "5": DownloadAndModifyListTemplate.DeleteListTemplate(); break; case "6": DeleteWebparts.DoWork(); break; case "7": break; default: break; } } while (input1.ToUpper(System.Globalization.CultureInfo.CurrentCulture) != "7"); break; case "3": do { System.Console.ForegroundColor = System.ConsoleColor.DarkCyan; System.Console.WriteLine(""); System.Console.WriteLine("Your selected Operation [3: \"Self-Service Reports\"] supports the following operations."); System.Console.WriteLine("Please type an operation number and press [Enter] to execute the specified operation:"); System.Console.WriteLine("1. Generate List Template Report with FTC Analysis"); System.Console.WriteLine("2. Generate Site Template Report with FTC Analysis"); System.Console.WriteLine("3. Generate Site Column/Custom Field & Content Type Usage Report"); System.Console.WriteLine("4. Generate Non-Default Master Page Usage Report"); System.Console.WriteLine("5. Generate Site Collection Report (PPE-Only)"); System.Console.WriteLine("6. Generate Web Part Usage Report"); System.Console.WriteLine("7. Generate Web Part Properties Report"); System.Console.WriteLine("8. Generate Security Group Report"); System.Console.WriteLine("9. Generate Pivot Reports "); System.Console.WriteLine("10. Exit "); System.Console.ResetColor(); input1 = System.Console.ReadLine(); switch (input1) { case "1": DownloadAndModifyListTemplate.DoWork(); break; case "2": DownloadAndModifySiteTemplate.DoWork(); break; case "3": GenerateColumnAndTypeUsageReport.DoWork(); break; case "4": GenerateNonDefaultMasterPageUsageReport.DoWork(); break; case "5": System.Console.ForegroundColor = ConsoleColor.Yellow; System.Console.WriteLine("This operation is intended for use only in PPE; use on PROD at your own risk."); System.Console.WriteLine("For PROD, it is safer to generate the report via the o365 Self-Service Admin Portal."); System.Console.ResetColor(); System.Console.ForegroundColor = System.ConsoleColor.Cyan; System.Console.WriteLine("Press \"y\" only if you wish to continue. Press any other key to abort this operation."); System.Console.ResetColor(); input2 = System.Console.ReadLine(); if (input2.ToUpper(System.Globalization.CultureInfo.CurrentCulture) != "Y") { System.Console.WriteLine("Operation aborted by user."); break; } GenerateSiteCollectionReport.DoWork(); break; case "6": WebPartUsage.DoWork(); break; case "7": WebPartProperties.DoWork(); break; case "8": GenerateSecurityGroupReport.DoWork(); break; case "9": GeneratePivotReport.DoWork(); break; case "10": break; default: break; } } while (input1.ToUpper(System.Globalization.CultureInfo.CurrentCulture) != "10"); break; case "4": break; default: break; } }while (input.ToUpper(System.Globalization.CultureInfo.CurrentCulture) != "4"); }
public static void ReplaceWebPart_UsingCSV(string sourceWebPartType, string targetWebPartXmlFilePath, string targetWebPartFileName, string targetWebPartXmlDir, string usageFileName, string outPutFolder) { string exceptionCommentsInfo1 = string.Empty; try { //Reading Input File IEnumerable <WebPartDiscoveryInput> objWPDInput; ReadWebPartUsageCSV(sourceWebPartType, usageFileName, outPutFolder, out objWPDInput); bool headerTransformWebPart = false; if (objWPDInput.Any()) { //bool headerPageLayout = false; for (int i = 0; i < objWPDInput.Count(); i++) { try { WebPartDiscoveryInput objInput = objWPDInput.ElementAt(i); SetExceptionCSVWebAppSiteColWebUrls(objInput.WebUrl.ToString()); //This is for Exception Comments: exceptionCommentsInfo1 = "WebUrl: " + objInput.WebUrl + ", ZoneID: " + objInput.ZoneID + ", Web PartID:" + objInput.WebPartId.ToString() + " ,PageUrl: " + objInput.PageUrl.ToString(); //This is for Exception Comments: //This function is Get Relative URL of the page string _relativePageUrl = string.Empty; _relativePageUrl = GetPageRelativeURL(objInput.WebUrl.ToString(), objInput.PageUrl.ToString()); string _storageKey = string.Empty; _storageKey = GetWebPartID(objInput.StorageKey); //sourceWebPartId - Used to update the content of the wikipage with new web part id [Fix for BugId - 95007] string _webPartId = string.Empty; _webPartId = GetWebPartID(objInput.WebPartId); //End bool status = false; string sourceWebPartXmlFilePath = WebPartProperties.GetWebPartProperties(_relativePageUrl, _storageKey, objInput.WebUrl, outPutFolder); if (!string.IsNullOrEmpty(sourceWebPartXmlFilePath)) { ConfigureNewWebPartXmlFile(targetWebPartXmlFilePath, sourceWebPartXmlFilePath, outPutFolder); string _targetWebPartXml = string.Empty; _targetWebPartXml = GetTargetWebPartXmlFilePath(_storageKey, targetWebPartXmlDir); if (_targetWebPartXml != "") { status = ReplaceWebPartInPage(objInput.WebUrl, targetWebPartFileName, _targetWebPartXml, _storageKey, objInput.ZoneIndex, objInput.ZoneID, _relativePageUrl, outPutFolder, _webPartId); } else { System.Console.ForegroundColor = System.ConsoleColor.Red; Logger.LogErrorMessage("[ReplaceWebPart_UsingCSV] Target WebPartXml File: " + targetWebPartFileName + " does not exists for StorageKey" + _storageKey + "in Path(TargetWebPartXmlDir): " + targetWebPartXmlDir + " for page " + _relativePageUrl); System.Console.ResetColor(); } } else { System.Console.ForegroundColor = ConsoleColor.Red; Logger.LogErrorMessage("[ReplaceWebPart_UsingCSV] Failed to get Source WebPart Properties: on Web: " + objInput.WebUrl + " for StorageKey " + _storageKey + "for page " + _relativePageUrl); System.Console.ResetColor(); } TranformWebPartStatusBase objWPOutputBase = new TranformWebPartStatusBase(); objWPOutputBase.WebApplication = ExceptionCsv.WebApplication; objWPOutputBase.SiteCollection = ExceptionCsv.SiteCollection; objWPOutputBase.WebUrl = objInput.WebUrl; objWPOutputBase.WebPartType = objInput.WebPartType; objWPOutputBase.ZoneID = objInput.ZoneID; objWPOutputBase.ZoneIndex = objInput.ZoneIndex; objWPOutputBase.WebPartId = objInput.WebPartId; objWPOutputBase.PageUrl = objInput.PageUrl; objWPOutputBase.ExecutionDateTime = DateTime.Now.ToString(); if (status) { objWPOutputBase.Status = Constants.Success; } else { objWPOutputBase.Status = Constants.Failure; } if (!System.IO.File.Exists(outputPath + @"\" + Constants.ReplaceWebPartStatusFileName + timeStamp + Constants.CSVExtension)) { headerTransformWebPart = false; } else { headerTransformWebPart = true; } FileUtility.WriteCsVintoFile(outPutFolder + @"\" + Constants.ReplaceWebPartStatusFileName + timeStamp + Constants.CSVExtension, objWPOutputBase, ref headerTransformWebPart); } catch (Exception ex) { System.Console.ForegroundColor = ConsoleColor.Red; Logger.LogErrorMessage("Error in Processing Web:" + ExceptionCsv.WebUrl + " `\r\nError Details:" + ex.Message + " `\r\nExceptionComments:" + exceptionCommentsInfo1); System.Console.ResetColor(); ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, Constants.NotApplicable, "ReplaceWebPart", ex.Message, ex.ToString(), "ReplaceWebPart_UsingCSV()", ex.GetType().ToString(), exceptionCommentsInfo1); } } } else { Logger.LogInfoMessage("Source WebPart Type: " + sourceWebPartType + " does not exist in the Input file: " + usageFileName, true); } } catch (Exception ex) { Logger.LogErrorMessage("[ReplaceWebPart_UsingCSV] Exception Message: " + ex.Message); ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, Constants.NotApplicable, "ReplaceWebPart", ex.Message, ex.ToString(), "ReplaceWebPart_UsingCSV()", ex.GetType().ToString(), exceptionCommentsInfo1); } }