Inheritance: SiteCustomizationHeader
        private static bool ProcessWspFile(string filePath, string solFileName, ref SiteTemplateFTCAnalysisOutputBase objSiteCustOutput)
        {
            string receiversXml = string.Empty;
            string contentTypesXml = string.Empty;
            string customFieldsTypesXml = string.Empty;
            bool isCustomizationPresent = false;
            bool isCustomContentType = false;
            bool isCustomEventReceiver = false;
            bool isCustomSiteColumn = false;
            bool isCustomFeature = false;
            StringBuilder cTHavingCustomER = new StringBuilder();

            string fileName = objSiteCustOutput.SiteTemplateName;
            string downloadPath = filePath + @"\" + Constants.DownloadPathSiteTemplates;

            Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Processing the Site Template: " + objSiteCustOutput.SiteTemplateName, true);
            try
            {
                string newFilePath = solFileName.ToLower().Replace(".wsp", ".cab");
                if (System.IO.File.Exists(newFilePath))
                    System.IO.File.Delete(newFilePath);
                System.IO.File.Move(solFileName, newFilePath);

                var destDir = newFilePath.Substring(0, newFilePath.LastIndexOf(@"\"));
                Directory.SetCurrentDirectory(destDir);
                string newFileName = newFilePath.Substring(newFilePath.LastIndexOf(@"\") + 1);

                FileInfo solFileObj = new FileInfo(newFileName);
                Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Extracting the Site Template: " + objSiteCustOutput.SiteTemplateName, true);
                //string cmd = "/e /a /y /L \"" + newFileName.Replace(".", "_") + "\" \"" + newFileName + "\"";
                //ProcessStartInfo pI = new ProcessStartInfo("extrac32.exe", cmd);
                //pI.WindowStyle = ProcessWindowStyle.Hidden;
                //Process p = Process.Start(pI);
                //p.WaitForExit();
                //string cabDir = newFilePath.Replace(".", "_");
                //Directory.SetCurrentDirectory(newFileName.Replace(".", "_"));
                FileUtility.UnCab(solFileName.ToLower().Replace(".wsp", ".cab"), destDir);
                //string cabDir = newFilePath.Replace(".", "_");
                Directory.SetCurrentDirectory(destDir);
                //string extractedPath = solFileName.Replace(".wsp", "_cab");
                string extractedPath = destDir;
                Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Extracted the Site Template: " + objSiteCustOutput.SiteTemplateName + "to path: " + extractedPath, true);

                string[] webTempFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "Onet.xml", SearchOption.AllDirectories);

                if (webTempFiles.Length > 0)
                {
                    string fileNameWithoutExtension = fileName.Substring(0, fileName.LastIndexOf("."));

                    string listInstanceFolderName = extractedPath + @"\" + fileNameWithoutExtension + "ListInstances";

                    string[] featureFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "Feature.xml", SearchOption.AllDirectories);

                    #region Custom Features

                    Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Searching for Onet.xml file for finding customized features in path: " + webTempFiles.ElementAt(0), true);

                    if (lstCustomFeatureIDs != null && lstCustomFeatureIDs.Count > 0)
                    {
                        if (webTempFiles.Count() > 0)
                        {
                            #region Custom SiteFeatures
                            try
                            {
                                CheckCustomFeature(webTempFiles.ElementAt(0), "/Project/Configurations/Configuration/SiteFeatures/Feature", ref isCustomFeature, solFileName);
                            }
                            catch (Exception ex)
                            {
                                Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Custom Site Features tag", true);
                                ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                    "ProcessWspFile", ex.GetType().ToString(), "Exception while reading Custom Site Features tag. SolutionName: " + solFileName + ", FileName: " + webTempFiles.ElementAt(0));
                            }
                            #endregion

                            #region Custom WebFeatures
                            if (!isCustomFeature)
                            {
                                try
                                {
                                    CheckCustomFeature(webTempFiles.ElementAt(0), "/Project/Configurations/Configuration/WebFeatures/Feature", ref isCustomFeature, solFileName);
                                }
                                catch (Exception ex)
                                {
                                    Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Custom Web Features tag", true);
                                    ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                        "ProcessWspFile", ex.GetType().ToString(), "Exception while reading Custom Web Features tag. SolutionName: " + solFileName + ", FileName: " + webTempFiles.ElementAt(0));
                                }
                            }
                            #endregion
                        }

                        if (featureFiles.Count() > 0 && !isCustomFeature)
                        {
                            for (int i = 0; i < featureFiles.Count(); i++)
                            {
                                try
                                {
                                    Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Searching for Feature.xml file for finding customized features in path: " + featureFiles.ElementAt(i), true);

                                    CheckCustomFeature(featureFiles.ElementAt(i), "/Feature", ref isCustomFeature, solFileName);
                                }
                                catch (Exception ex)
                                {
                                    Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Features tag", true);
                                    ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                        "ProcessWspFile", ex.GetType().ToString(), "Exception while reading Features tag. SolutionName: " + solFileName + ", FileName: " + featureFiles.ElementAt(i));
                                }
                            }
                        }
                    }
                    #endregion

                    #region Web EventReceivers
                    Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Searching for WebEventReceivers Folder for finding customized Event Receivers in path: " + extractedPath, true);
                    IEnumerable<string> ERlist = Directory.GetDirectories(extractedPath).Where(s => s.EndsWith("WebEventReceivers"));

                    if (lstCustomErs != null && lstCustomErs.Count > 0)
                    {
                        if (ERlist.Count() > 0)
                        {
                            if (ERlist.ElementAt(0).EndsWith(@"\"))
                                receiversXml = ERlist.ElementAt(0) + "Elements.xml";
                            else
                                receiversXml = ERlist.ElementAt(0) + @"\" + "Elements.xml";

                            CheckCustomEventReceiver(receiversXml, "/Elements/Receivers", ref isCustomEventReceiver, solFileName);
                        }
                    }
                    #endregion

                    Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Searching for ListInstances Folder for finding customized elements in path: " + extractedPath, true);
                    IEnumerable<string> list = Directory.GetDirectories(extractedPath).Where(s => s.EndsWith("ListInstances"));

                    if (list.Count() > 0 & !isCustomEventReceiver)
                    {
                        #region Custom List EventReceivers

                        if (list.ElementAt(0).EndsWith(@"\"))
                            receiversXml = list.ElementAt(0) + "Elements.xml";
                        else
                            receiversXml = list.ElementAt(0) + @"\" + "Elements.xml";

                        CheckCustomEventReceiver(receiversXml, "/Elements/Receivers", ref isCustomEventReceiver, solFileName);

                        #endregion

                        //Reading ElementContentTypes.xml for Searching Content Types
                        if (list.ElementAt(0).EndsWith(@"\"))
                            contentTypesXml = list.ElementAt(0) + "ElementsContentType.xml";
                        else
                            contentTypesXml = list.ElementAt(0) + @"\" + "ElementsContentType.xml";

                        if (System.IO.File.Exists(contentTypesXml))
                        {
                            Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Searching for customized Content Types and Customized Event Receivers or Site Columns associated in Content Types in: " + contentTypesXml, true);
                            var reader = new XmlTextReader(contentTypesXml);

                            reader.Namespaces = false;
                            reader.Read();
                            XmlDocument doc2 = new XmlDocument();
                            doc2.Load(reader);

                            //Initiallizing all the nodes required to check
                            XmlNodeList xmlDocReceivers = doc2.SelectNodes("/Elements/ContentType");

                            #region Custom ContentType Event Receviers
                            if (lstCustomErs != null && lstCustomErs.Count > 0)
                            {
                                for (int i = 0; i < xmlDocReceivers.Count; i++)
                                {
                                    try
                                    {
                                        if (xmlDocReceivers[i].HasChildNodes)
                                        {
                                            var docList = xmlDocReceivers[i]["XmlDocuments"];
                                            if (docList != null)
                                            {
                                                XmlNodeList xmlDocList = docList.ChildNodes;

                                                for (int j = 0; j < xmlDocList.Count; j++)
                                                {
                                                    try
                                                    {
                                                        if (xmlDocList[j].Attributes["NamespaceURI"] != null)
                                                        {
                                                            var namespaceURl = xmlDocList[j].Attributes["NamespaceURI"].Value;
                                                            if (namespaceURl.Contains("http://schemas.microsoft.com/sharepoint/events"))
                                                            {
                                                                XmlNodeList child = xmlDocList[j].ChildNodes;

                                                                if (child != null && child.Count > 0)
                                                                {
                                                                    for (int x = 0; x < child.Count; x++)
                                                                    {
                                                                        XmlNodeList receiverChilds = child[x].ChildNodes;
                                                                        for (int y = 0; y < receiverChilds.Count; y++)
                                                                        {
                                                                            try
                                                                            {
                                                                                if (receiverChilds[y].HasChildNodes)
                                                                                {
                                                                                    string ctAssemblyValue = receiverChilds[y]["Assembly"].InnerText;
                                                                                    if (lstCustomErs.Where(c => ctAssemblyValue.Equals(c, StringComparison.CurrentCultureIgnoreCase)).Any())
                                                                                    {
                                                                                        //isCustomEventReceiver = true;
                                                                                        cTHavingCustomER.Append(xmlDocReceivers[i].Attributes["Name"].Value + ";");
                                                                                        Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Customized Event Receiver in Content Type Found for: " + objSiteCustOutput.SiteTemplateName, true);
                                                                                        break;
                                                                                    }
                                                                                }
                                                                            }
                                                                            catch (Exception ex)
                                                                            {
                                                                                Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Receivers tag in content types", true);
                                                                                ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                                                                    "ProcessWspFile", ex.GetType().ToString(), "Exception while reading Receivers tag in content types. SolutionName: " + solFileName + ", FileName: " + contentTypesXml);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Receivers tag in content types", true);
                                                        ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                                                                    "ProcessWspFile", ex.GetType().ToString(), "Exception while reading Receivers tag in content types. SolutionName: " + solFileName + ", FileName: " + contentTypesXml);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.ToString() + ", " + ex.Message, true);
                                        ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                            "ProcessWspFile", ex.GetType().ToString(), "SolutionName: " + solFileName + ", FileName: " + contentTypesXml);
                                    }
                                }
                            }
                            #endregion

                            #region Custom ContentTypes
                            if (lstContentTypeIDs != null && lstContentTypeIDs.Count > 0)
                            {

                                //Iterate all ContentTypes in manifest.xml
                                for (int i = 0; i < xmlDocReceivers.Count; i++)
                                {
                                    try
                                    {
                                        var docList = xmlDocReceivers[i].Attributes["ID"].Value;

                                        //Remove contenttype tag if ContentTypeId present in custom ContentTypes file ContentTypes.csv
                                        if (lstContentTypeIDs.Where(c => docList.StartsWith(c)).Any())
                                        {
                                            isCustomContentType = true;
                                            Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Customized Content Type Found for: " + objSiteCustOutput.SiteTemplateName, true);
                                            break;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading content types", true);
                                        ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                            "ProcessWspFile", ex.GetType().ToString(), "Exception while reading content types. SolutionName: " + solFileName + ", FileName: " + contentTypesXml);
                                    }
                                }
                            }
                            #endregion

                            #region CustomFields in ContentTypes
                            if (lstCustomFieldIDs != null && lstCustomFieldIDs.Count > 0)
                            {
                                //Checking Site Columns presence in Content Types
                                for (int i = 0; i < xmlDocReceivers.Count; i++)
                                {
                                    try
                                    {
                                        var fieldRefs = xmlDocReceivers[i]["FieldRefs"];
                                        if (fieldRefs != null)
                                        {
                                            XmlNodeList xmlFieldRefList = fieldRefs.ChildNodes;

                                            for (int j = 0; j < xmlFieldRefList.Count; j++)
                                            {
                                                try
                                                {
                                                    string fieldRefId = xmlFieldRefList[j].Attributes["ID"].Value;
                                                    if (lstCustomFieldIDs.Where(c => fieldRefId.Equals(c)).Any())
                                                    {
                                                        isCustomSiteColumn = true;
                                                        Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Customized Site Column associated with Content Type Found for: " + objSiteCustOutput.SiteTemplateName, true);
                                                        break;
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Site Columns tag in content types", true);
                                                    ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                                        "ProcessWspFile", ex.GetType().ToString(), "Exception while reading Site Columns tag in content types. SolutionName: " + solFileName + ", FileName: " + contentTypesXml);
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Site Columns tag in content types", true);
                                        ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                            "ProcessWspFile", ex.GetType().ToString(), "Exception while reading Site Columns tag in content types. SolutionName: " + solFileName + ", FileName: " + contentTypesXml);
                                    }
                                }
                            }
                            #endregion

                            reader.Dispose();
                        }
                        //Reading ElementContentTypes.xml for Searching Custom Fields
                        if (list.ElementAt(0).EndsWith(@"\"))
                            customFieldsTypesXml = list.ElementAt(0) + "ElementsFields.xml";
                        else
                            customFieldsTypesXml = list.ElementAt(0) + @"\" + "ElementsFields.xml";

                        if (!isCustomSiteColumn && System.IO.File.Exists(customFieldsTypesXml) && !isCustomSiteColumn)
                        {
                            Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Searching for customized Site Columns in List in: " + customFieldsTypesXml, true);
                            var reader = new XmlTextReader(customFieldsTypesXml);

                            reader.Namespaces = false;
                            reader.Read();
                            XmlDocument doc3 = new XmlDocument();
                            doc3.Load(reader);
                            XmlNodeList xmlFields = doc3.SelectNodes("/Elements/Field");

                            #region Custom Fields
                            if (lstCustomFieldIDs != null && lstCustomFieldIDs.Count > 0)
                            {
                                for (int i = 0; i < xmlFields.Count; i++)
                                {
                                    try
                                    {
                                        var fieldList = xmlFields[i].Attributes["ID"].Value;

                                        //Remove contenttype tag if ContentTypeId present in custom ContentTypes file ContentTypes.csv
                                        if (lstCustomFieldIDs.Where(c => fieldList.Equals(c)).Any())
                                        {
                                            isCustomSiteColumn = true;
                                            Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Customized Site Column Found for: " + objSiteCustOutput.SiteTemplateName, true);
                                            break;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Site Columns", true);
                                        ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                            "ProcessWspFile", ex.GetType().ToString(), "Exception while reading Site Columns. SolutionName: " + solFileName + ", FileName: " + customFieldsTypesXml);
                                    }
                                }
                            }
                            #endregion
                            reader.Dispose();
                        }
                    }
                    if (isCustomContentType || isCustomEventReceiver || isCustomSiteColumn || isCustomFeature)
                    {
                        if (cTHavingCustomER != null && cTHavingCustomER.Length > 0)
                        {
                            cTHavingCustomER.Length -= 1;
                            objSiteCustOutput.CTHavingCustomEventReceiver = cTHavingCustomER.ToString();
                        }
                        else
                        {
                            objSiteCustOutput.CTHavingCustomEventReceiver = Constants.NotApplicable;
                        }

                        objSiteCustOutput.IsCustomizationPresent = "YES";
                        isCustomizationPresent = true;

                        if (lstCustomErs != null && lstCustomErs.Count > 0)
                            objSiteCustOutput.IsCustomizedEventReceiver = isCustomEventReceiver ? "YES" : "NO";
                        else
                            objSiteCustOutput.IsCustomizedEventReceiver = Constants.NoInputFile;

                        if (lstContentTypeIDs != null && lstContentTypeIDs.Count > 0)
                            objSiteCustOutput.IsCustomizedContentType = isCustomContentType ? "YES" : "NO";
                        else
                            objSiteCustOutput.IsCustomizedContentType = Constants.NoInputFile;

                        if (lstCustomFieldIDs != null && lstCustomFieldIDs.Count > 0)
                            objSiteCustOutput.IsCustomizedSiteColumn = isCustomSiteColumn ? "YES" : "NO";
                        else
                            objSiteCustOutput.IsCustomizedSiteColumn = Constants.NoInputFile;

                        if (lstCustomFeatureIDs != null && lstCustomFeatureIDs.Count > 0)
                            objSiteCustOutput.IsCustomizedFeature = isCustomFeature ? "YES" : "NO";
                        else
                            objSiteCustOutput.IsCustomizedFeature = Constants.NoInputFile;

                        cTHavingCustomER.Clear();
                    }
                    else
                    {
                        if (cTHavingCustomER != null && cTHavingCustomER.Length > 0)
                        {
                            cTHavingCustomER.Length -= 1;
                            objSiteCustOutput.CTHavingCustomEventReceiver = cTHavingCustomER.ToString();
                            objSiteCustOutput.IsCustomizationPresent = "YES";
                            isCustomizationPresent = true;
                            objSiteCustOutput.IsCustomizedEventReceiver = "NO";
                            objSiteCustOutput.IsCustomizedContentType = "NO";
                            objSiteCustOutput.IsCustomizedFeature = "NO";
                            objSiteCustOutput.IsCustomizedSiteColumn = "NO";
                        }
                        else
                        {
                            objSiteCustOutput.CTHavingCustomEventReceiver = Constants.NotApplicable;
                            isCustomizationPresent = false;
                        }

                    }
                }
                else
                {
                    isCustomizationPresent = false;
                }

            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessWspFile]. Exception Message: " + ex.Message + " SolFileName: " + solFileName, true);
                ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                    "ProcessWspFile", ex.GetType().ToString(), " SolFileName: " + solFileName);
            }

            Directory.SetCurrentDirectory(downloadPath);
            System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(downloadPath);
            foreach (System.IO.FileInfo file in directory.GetFiles())
            {
                try { file.Delete(); }
                catch (Exception ex)
                {
                    //As we are extracting .wsp file to local folder, no need to display any
                    //exception while deleting these files.
                }
            }
            foreach (System.IO.DirectoryInfo subDirectory in directory.GetDirectories())
            {
                try { subDirectory.Delete(true); }
                catch (Exception ex)
                {
                    //As we are extracting .wsp file to local folder, no need to display any
                    //exception while deleting these files.
                }
            }
            return isCustomizationPresent;
        }
        public static void ProcessSiteCollectionUrl(string siteCollectionUrl,
            ref List<SiteTemplateFTCAnalysisOutputBase> lstMissingSiteTempaltesInGalleryBase, string webApplicationUrl)
        {
            try
            {
                using (ClientContext userContext = Helper.CreateAuthenticatedUserContext(Program.AdminDomain, Program.AdminUsername, Program.AdminPassword, siteCollectionUrl))
                {
                    //userContext.AuthenticationMode = ClientAuthenticationMode.Default;
                    //userContext.ExecuteQuery();
                    Web web = userContext.Web;
                    Folder folder = userContext.Web.GetFolderByServerRelativeUrl("_catalogs/solutions");
                    userContext.Load(web.Folders);
                    userContext.Load(folder);
                    userContext.Load(folder.Files);
                    userContext.Load(web);
                    userContext.ExecuteQuery();

                    // Loop through all the site templates
                    foreach (Microsoft.SharePoint.Client.File stFile in folder.Files)
                    {
                        try
                        {
                            System.Console.WriteLine("File Name: " + stFile.Name);
                            SiteTemplateFTCAnalysisOutputBase objSiteCustOutput = new SiteTemplateFTCAnalysisOutputBase();
                            string siteTemplatePath = string.Empty;
                            string siteTemplateGalleryPath = stFile.ServerRelativeUrl.Substring(0, stFile.ServerRelativeUrl.LastIndexOf('/'));

                            bool isCustomizationPresent = false;

                            isCustomizationPresent = GetCustomizedSiteTemplate(ref objSiteCustOutput, null, stFile, siteCollectionUrl, webApplicationUrl);

                            if (isCustomizationPresent)
                            {
                                userContext.Load(stFile.Author);
                                userContext.Load(stFile.ModifiedBy);
                                userContext.ExecuteQuery();

                                try
                                {
                                    if (stFile.Author != null)
                                        objSiteCustOutput.CreatedBy = stFile.Author.LoginName;
                                    else
                                        objSiteCustOutput.CreatedBy = Constants.NotApplicable;
                                }
                                catch (Exception ex)
                                {
                                    objSiteCustOutput.CreatedBy = Constants.NotApplicable;
                                    Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessSiteCollectionUrl]. Error recorded for Site Collection: " + siteCollectionUrl + " and for file: " + stFile.Name + " Exception Message: " + ex.Message + ". Author is NULL.", true);
                                    ExceptionCsv.WriteException(webApplicationUrl, siteCollectionUrl, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                        "ProcessSiteCollectionUrl", ex.GetType().ToString(), "Error recorded for Site Collection: " + siteCollectionUrl + " and for file: " + stFile.Name + " Exception Message: " + ex.Message + ". Author is NULL.");
                                }

                                try
                                {
                                    if (stFile.TimeCreated != null)
                                        objSiteCustOutput.CreatedDate = stFile.TimeCreated.ToString();
                                    else
                                        objSiteCustOutput.CreatedDate = Constants.NotApplicable;
                                }
                                catch (Exception ex)
                                {
                                    objSiteCustOutput.CreatedDate = Constants.NotApplicable;
                                    Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessSiteCollectionUrl]. Error recorded for Site Collection: " + siteCollectionUrl + " and for file: " + stFile.Name + " Exception Message: " + ex.Message + ". TimeCreated is NULL.", true);
                                    ExceptionCsv.WriteException(webApplicationUrl, siteCollectionUrl, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                        "ProcessSiteCollectionUrl", ex.GetType().ToString(), "Error recorded for Site Collection: " + siteCollectionUrl + " and for file: " + stFile.Name + " Exception Message: " + ex.Message + ". TimeCreated is NULL.");
                                }

                                try
                                {
                                    if (stFile.ModifiedBy != null)
                                        objSiteCustOutput.ModifiedBy = stFile.ModifiedBy.LoginName;
                                    else
                                        objSiteCustOutput.ModifiedBy = Constants.NotApplicable;
                                }
                                catch (Exception ex)
                                {
                                    objSiteCustOutput.ModifiedBy = Constants.NotApplicable;
                                    Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessSiteCollectionUrl]. Error recorded for Site Collection: " + siteCollectionUrl + " and for file: " + stFile.Name + " Exception Message: " + ex.Message + ". ModifiedBy is NULL.", true);
                                    ExceptionCsv.WriteException(webApplicationUrl, siteCollectionUrl, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                        "ProcessSiteCollectionUrl", ex.GetType().ToString(), "Error recorded for Site Collection: " + siteCollectionUrl + " and for file: " + stFile.Name + " Exception Message: " + ex.Message + ". ModifiedBy is NULL.");
                                }

                                try
                                {
                                    if (stFile.TimeLastModified != null)
                                        objSiteCustOutput.ModifiedDate = stFile.TimeLastModified.ToString();
                                    else
                                        objSiteCustOutput.ModifiedDate = Constants.NotApplicable;
                                }
                                catch (Exception ex)
                                {
                                    objSiteCustOutput.ModifiedDate = Constants.NotApplicable;
                                    Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessSiteCollectionUrl]. Error recorded for Site Collection: " + siteCollectionUrl + " and for file: " + stFile.Name + " Exception Message: " + ex.Message + ". TimeLastModified is NULL.", true);
                                    ExceptionCsv.WriteException(webApplicationUrl, siteCollectionUrl, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                        "ProcessSiteCollectionUrl", ex.GetType().ToString(), "Error recorded for Site Collection: " + siteCollectionUrl + " and for file: " + stFile.Name + " Exception Message: " + ex.Message + ". TimeLastModified is NULL.");
                                }

                                lstMissingSiteTempaltesInGalleryBase.Add(objSiteCustOutput);
                            }
                            objSiteCustOutput = null;
                        }
                        catch (Exception ex)
                        {
                            if ((ex.Message.ToLower()).Contains("access denied") || (ex.Message.ToLower()).Contains("unauthorized"))
                            {
                                System.Console.ForegroundColor = ConsoleColor.Yellow;
                                Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessSiteCollectionUrl]. Error recorded for Site Collection: " + siteCollectionUrl + " And For file: " + stFile.Name + " Exception Message: " + ex.Message, true);
                                System.Console.ResetColor();
                                ExceptionCsv.WriteException(webApplicationUrl, siteCollectionUrl, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                    "ProcessSiteCollectionUrl", ex.GetType().ToString(), "Error recorded for Site Collection: " + siteCollectionUrl + " And For file: " + stFile.Name);
                            }
                            else
                            {
                                Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessSiteCollectionUrl]. Error recorded for Site Collection: " + siteCollectionUrl + " And For file: " + stFile.Name + " Exception Message: " + ex.Message, true);
                                ExceptionCsv.WriteException(webApplicationUrl, siteCollectionUrl, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                                    "ProcessSiteCollectionUrl", ex.GetType().ToString(), "Error recorded for Site Collection: " + siteCollectionUrl + " And For file: " + stFile.Name);
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if ((ex.Message.ToLower()).Contains("access denied") || (ex.Message.ToLower()).Contains("unauthorized"))
                {
                    System.Console.ForegroundColor = ConsoleColor.Yellow;
                    Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessSiteCollectionUrl]. Error recorded for Site Collection: " + siteCollectionUrl + " Exception Message: " + ex.Message);
                    System.Console.ResetColor();
                    ExceptionCsv.WriteException(webApplicationUrl, siteCollectionUrl, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                       "ProcessSiteCollectionUrl", ex.GetType().ToString(), "Error recorded for Site Collection: " + siteCollectionUrl);
                }
                else
                {
                    Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: ProcessSiteCollectionUrl]. Error recorded for Site Collection: " + siteCollectionUrl + " Exception Message: " + ex.Message, true);
                    ExceptionCsv.WriteException(webApplicationUrl, siteCollectionUrl, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                        "ProcessSiteCollectionUrl", ex.GetType().ToString(), "Error recorded for Site Collection: " + siteCollectionUrl);
                }
            }
        }
 public static void WriteOutputReport(List<SiteTemplateFTCAnalysisOutputBase> ltSiteTemplateOutputBase, string csvFileName, ref bool headerOfCsv)
 {
     try
     {
         Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: WriteOutputReport] Writing the Output file " + csvFileName, true);
         if (System.IO.File.Exists(csvFileName))
             System.IO.File.Delete(csvFileName);
         if (ltSiteTemplateOutputBase != null && ltSiteTemplateOutputBase.Any())
         {
             //Export the result(Missing Workflow Details) in CSV file
             FileUtility.WriteCsVintoFile(csvFileName, ref ltSiteTemplateOutputBase, ref headerOfCsv);
         }
         else
         {
             headerOfCsv = false;
             SiteTemplateFTCAnalysisOutputBase objSiteTemplatesNoInstancesFound = new SiteTemplateFTCAnalysisOutputBase();
             FileUtility.WriteCsVintoFile(csvFileName, objSiteTemplatesNoInstancesFound, ref headerOfCsv);
             objSiteTemplatesNoInstancesFound = null;
         }
     }
     catch (Exception ex)
     {
         Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: WriteOutputReport] Exception Message: " + ex.Message, true);
         ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
             "WriteOutputReport", ex.GetType().ToString(), Constants.NotApplicable);
     }
 }
        public static bool GetCustomizedSiteTemplate(ref SiteTemplateFTCAnalysisOutputBase objSiteCustOutput, DataRow siteTemplateRow,
            Microsoft.SharePoint.Client.File ltFile, string siteCollection, string webAppUrl)
        {
            bool isCustomizationPresent = false;
            string fileName = string.Empty;
            string siteGalleryPath = string.Empty;

            try
            {
                fileName = ltFile.Name;
                siteGalleryPath = ltFile.ServerRelativeUrl.Substring(0, ltFile.ServerRelativeUrl.LastIndexOf('/'));
                objSiteCustOutput.SiteCollection = siteCollection;
                objSiteCustOutput.WebApplication = GetWebapplicationUrlFromSiteCollectionUrl(siteCollection);
                objSiteCustOutput.WebUrl = siteCollection;
                objSiteCustOutput.SiteTemplateName = fileName;
                objSiteCustOutput.SiteTemplateGalleryPath = siteGalleryPath;
                TempFolderName += 1;

                bool isDownloaded = DownloadSiteTemplate(outputPath + @"\" + Constants.DownloadPathSiteTemplates + @"\" + TempFolderName,
                    siteGalleryPath, ref fileName, objSiteCustOutput.WebUrl, objSiteCustOutput.WebUrl, TempFolderName.ToString());
                if (isDownloaded)
                {
                    isCustomizationPresent = ProcessWspFile(outputPath, outputPath + @"\" + Constants.DownloadPathSiteTemplates + @"\" + TempFolderName + @"\" + fileName.ToLower(),
                        ref objSiteCustOutput);
                }

            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: GetCustomizedSiteTemplate]. Exception Message: " + ex.Message, true);
                ExceptionCsv.WriteException(objSiteCustOutput.WebApplication, objSiteCustOutput.SiteCollection, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(),
                    "GetCustomizedSiteTemplate", ex.GetType().ToString(), Constants.NotApplicable);
            }
            return isCustomizationPresent;
        }