public List<object> Table_GetAll() { var returnValue = new List<object>(); try { var allTables = base.GetAllFiles(this._tableDirectoryPath); foreach (var table in allTables) { var fileStream = base.GetFileReadStream(table.Value); var xmlTextReader = new XmlTextReader(fileStream); returnValue.Add(Serializer.Deserialize(xmlTextReader)); fileStream.Close(); fileStream.Dispose(); xmlTextReader.Close(); xmlTextReader.Dispose(); } } catch (Exception ex) { if (this._logger != null) { this._logger.Log(ex.Message, Category.Exception, Priority.High); } } return returnValue; }
public static void VerifyTest(string actResult, string expResult) { XmlDiff.XmlDiff diff = new XmlDiff.XmlDiff(); diff.Option = XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder; XmlTextReader xrActual = new XmlTextReader(new StringReader(actResult)); XmlTextReader xrExpected = new XmlTextReader(new StringReader(expResult)); bool bResult = false; try { bResult = diff.Compare(xrActual, xrExpected); } catch (Exception e) { bResult = false; s_output.WriteLine("Exception thrown in XmlDiff compare!"); s_output.WriteLine(e.ToString()); } finally { if (xrActual != null) xrActual.Dispose(); if (xrExpected != null) xrExpected.Dispose(); } s_output.WriteLine("Expected : " + expResult); s_output.WriteLine("Actual : " + actResult); if (bResult) return; else Assert.True(false); }
public object Table_GetByID(Guid tableId) { object returnValue = null; try { var fileStream = base.GetFileReadStream(Path.Combine(this._tableDirectoryPath, tableId.ToString() + ".xml")); var xmlTextReader = new XmlTextReader(fileStream); returnValue = Serializer.Deserialize(xmlTextReader); fileStream.Close(); fileStream.Dispose(); xmlTextReader.Close(); xmlTextReader.Dispose(); } catch (Exception ex) { if (this._logger != null) { this._logger.Log(ex.Message, Category.Exception, Priority.High); } } return returnValue; }
public void import(String filename) { WindowTitle = "Importing Tags"; XmlTextReader inFile = null; try { inFile = new XmlTextReader(filename); Type[] knownTypes = new Type[] { typeof(TagDTO), typeof(TagCategoryDTO) }; DataContractSerializer tagSerializer = new DataContractSerializer(typeof(List<TagDTO>), knownTypes); List<Tag> tags = new List<Tag>(); List<TagDTO> tagDTOs = (List<TagDTO>)tagSerializer.ReadObject(inFile); foreach (TagDTO tagDTO in tagDTOs) { var tag = Mapper.Map<TagDTO, Tag>(tagDTO, new Tag()); tags.Add(tag); } TotalProgressMax = tags.Count; TotalProgress = 0; using (TagDbCommands tagCommands = new TagDbCommands()) { foreach (Tag tag in tags) { if (CancellationToken.IsCancellationRequested == true) return; ItemInfo = "Merging: " + tag.Name; ItemProgress = 0; tagCommands.merge(tag); ItemProgress = 100; TotalProgress++; InfoMessages.Add("Merged: " + tag.Name); } } } catch (Exception e) { InfoMessages.Add("Error importing tags " + e.Message); } finally { operationFinished(); if (inFile != null) { inFile.Dispose(); } } }
// -------------------------------------------------------------------------------------------------------------- // LoadXSL_Resolver_Evidence // ------------------------------------------------------------------------------------------------------------- /*public int LoadXSL_Resolver_Evidence(String _strXslFile, XmlResolver xr, Evidence e) { _strXslFile = FullFilePath(_strXslFile); xslt = new XslCompiledTransform(); switch (_nInputXsl) { case XslInputType.Reader: switch (_readerType) { case ReaderType.XmlTextReader: XmlReader trTemp = XmlReader.Create(_strXslFile); try { _output.WriteLine("Loading style sheet as XmlTextReader " + _strXslFile); //xslt.Load(trTemp, xr, e); //Evidence is not supported on V2 XSLT Load xslt.Load(trTemp, XsltSettings.TrustedXslt, xr); } catch (Exception ex) { throw (ex); } finally { if (trTemp != null) trTemp.Dispose(); } break; case ReaderType.XmlNodeReader: XmlDocument docTemp = new XmlDocument(); docTemp.Load(_strXslFile); XmlNodeReader nrTemp = new XmlNodeReader(docTemp); try { _output.WriteLine("Loading style sheet as XmlNodeReader " + _strXslFile); //xslt.Load(nrTemp, xr, e); Evidence is not supported in V2 XSLT Load xslt.Load(nrTemp, XsltSettings.TrustedXslt, xr); } catch (Exception ex) { throw (ex); } finally { if (nrTemp != null) nrTemp.Dispose(); } break; case ReaderType.XmlValidatingReader: default: XmlReaderSettings xrs = new XmlReaderSettings(); #pragma warning disable 0618 xrs.ProhibitDtd = false; #pragma warning restore 0618 XmlReader vrTemp = null; try { vrTemp = XmlReader.Create(_strXslFile, xrs); _output.WriteLine("Loading style sheet as XmlValidatingReader " + _strXslFile); //xslt.Load(vrTemp, xr, e); Evidence is not supported in V2 XSLT Load xslt.Load(vrTemp, XsltSettings.TrustedXslt, xr); } catch (Exception ex) { throw (ex); } finally { if (vrTemp != null) vrTemp.Dispose(); } break; } break; case XslInputType.Navigator: XmlReader xrLoad = XmlReader.Create(_strXslFile); XPathDocument xdTemp = new XPathDocument(xrLoad, XmlSpace.Preserve); xrLoad.Dispose(); _output.WriteLine("Loading style sheet as Navigator " + _strXslFile); xslt.Load(xdTemp.CreateNavigator(), XsltSettings.TrustedXslt, xr); break; } return 1; }*/ //VerifyResult public void VerifyResult(string expectedValue) { XmlDiff.XmlDiff xmldiff = new XmlDiff.XmlDiff(); xmldiff.Option = XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement; StreamReader sr = new StreamReader(new FileStream("out.xml", FileMode.Open, FileAccess.Read)); string actualValue = sr.ReadToEnd(); sr.Dispose(); //Output the expected and actual values _output.WriteLine("Expected : " + expectedValue); _output.WriteLine("Actual : " + actualValue); //Load into XmlTextReaders XmlTextReader tr1 = new XmlTextReader("out.xml"); XmlTextReader tr2 = new XmlTextReader(new StringReader(expectedValue)); bool bResult = xmldiff.Compare(tr1, tr2); //Close the readers tr1.Dispose(); tr2.Dispose(); if (bResult) return; else Assert.True(false); }
// -------------------------------------------------------------------------------------------------------------- // LoadXSL_Resolver // ------------------------------------------------------------------------------------------------------------- public int LoadXSL_Resolver(String _strXslFile, XmlResolver xr) { _strXslFile = FullFilePath(_strXslFile); xslt = new XslCompiledTransform(); XmlReaderSettings xrs = null; switch (_nInputXsl) { case XslInputType.URI: _output.WriteLine("Loading style sheet as URI " + _strXslFile); xslt.Load(_strXslFile, XsltSettings.TrustedXslt, xr); break; case XslInputType.Reader: switch (_readerType) { case ReaderType.XmlTextReader: XmlTextReader trTemp = new XmlTextReader(_strXslFile); try { _output.WriteLine("Loading style sheet as XmlTextReader " + _strXslFile); xslt.Load(trTemp, XsltSettings.TrustedXslt, xr); } catch (Exception ex) { throw (ex); } finally { if (trTemp != null) trTemp.Dispose(); } break; case ReaderType.XmlNodeReader: XmlDocument docTemp = new XmlDocument(); docTemp.Load(_strXslFile); XmlNodeReader nrTemp = new XmlNodeReader(docTemp); try { _output.WriteLine("Loading style sheet as XmlNodeReader " + _strXslFile); xslt.Load(nrTemp, XsltSettings.TrustedXslt, xr); } catch (Exception ex) { throw (ex); } finally { if (nrTemp != null) nrTemp.Dispose(); } break; case ReaderType.XmlValidatingReader: default: xrs = new XmlReaderSettings(); #pragma warning disable 0618 xrs.ProhibitDtd = false; #pragma warning restore 0618 XmlReader vrTemp = XmlReader.Create(_strXslFile, xrs); try { _output.WriteLine("Loading style sheet as XmlValidatingReader " + _strXslFile); xslt.Load(vrTemp, XsltSettings.TrustedXslt, xr); } catch (Exception ex) { throw (ex); } finally { if (vrTemp != null) vrTemp.Dispose(); } break; } break; case XslInputType.Navigator: xrs = new XmlReaderSettings(); #pragma warning disable 0618 xrs.ProhibitDtd = false; #pragma warning restore 0618 XmlReader xrLoad = XmlReader.Create(_strXslFile, xrs); XPathDocument xdTemp = new XPathDocument(xrLoad, XmlSpace.Preserve); xrLoad.Dispose(); _output.WriteLine("Loading style sheet as Navigator " + _strXslFile); xslt.Load(xdTemp, XsltSettings.TrustedXslt, xr); break; } return 1; }
// TODO : ADDED FOR PS5 /// <summary> /// Returns the version information of the spreadsheet saved in the named file. /// If there are any problems opening, reading, or closing the file, the method /// should throw a SpreadsheetReadWriteException with an explanatory message. /// </summary> public override string GetSavedVersion(string filename) { string vers = ""; XmlTextReader xmlReader = null; try { xmlReader = new XmlTextReader(filename); } catch (Exception) { xmlReader.Dispose(); throw new SpreadsheetReadWriteException("File could not be opened using XmlTextReader"); } // Attempts to read the spreadsheet version from the XML file. if (!xmlReader.ReadToFollowing("spreadsheet") || !xmlReader.MoveToFirstAttribute()) throw new SpreadsheetReadWriteException("Spreadsheet version could not be found"); vers = xmlReader.Value; // Attemtps to close the XML reader. try { xmlReader.Close(); } catch (Exception) { xmlReader.Dispose(); throw new SpreadsheetReadWriteException("File could not be closed."); } return vers; }
/// <summary> /// Provides a four argument constructor for a spreadsheet. /// This constructor will use the provided Validator and Normalizer, and will set the version to be the provided version string. /// This constructor will also construct cells based on an XMl spreadsheet representation of a spreadsheet. /// If the version passed into the constructor does not match the version in the XML file, an exception is thrown. /// </summary> public Spreadsheet(string filePath, Func<string, bool> isValid, Func<string, string> normalize, string version) : base(isValid, normalize, version) { cells = new Dictionary<string, Cell>(); dependencies = new DependencyGraph(); if (GetSavedVersion(filePath) != version) throw new SpreadsheetReadWriteException("The saved version of the XML file does not match the version provided to the constructor."); // Constructs an XML reader object. XmlTextReader xmlReader = null; try { xmlReader = new XmlTextReader(filePath); } catch (Exception) { xmlReader.Dispose(); throw new SpreadsheetReadWriteException("File could not be opened using XmlTextReader"); } // Reads cells from XML spreadsheet. while (xmlReader.Read()) { string name = ""; string contents = ""; if (xmlReader.ReadToFollowing("name")) { name = xmlReader.ReadElementContentAsString(); if (!xmlReader.ReadToFollowing("contents")) throw new SpreadsheetReadWriteException("No contents found associated with name: " + name); contents = xmlReader.ReadElementContentAsString(); this.SetContentsOfCell(name, contents); } } IsValid = isValid; Normalize = normalize; hasChanged = false; }
// -------------------------------------------------------------------------------------------------------------- // LoadXSL_Resolver // ------------------------------------------------------------------------------------------------------------- public int LoadXSL_Resolver(String _strXslFile, XmlResolver xr) { _strXslFile = FullFilePath(_strXslFile); #pragma warning disable 0618 xslt = new XslTransform(); #pragma warning restore 0618 switch (_nInput) { case InputType.URI: _output.WriteLine("Loading style sheet as URI {0}", _strXslFile); xslt.Load(_strXslFile, xr); break; case InputType.Reader: switch (_readerType) { case ReaderType.XmlTextReader: XmlTextReader trTemp = new XmlTextReader(_strXslFile); try { _output.WriteLine("Loading style sheet as XmlTextReader {0}", _strXslFile); xslt.Load(trTemp, xr); } catch (Exception ex) { throw (ex); } finally { if (trTemp != null) trTemp.Dispose(); } break; case ReaderType.XmlNodeReader: XmlDocument docTemp = new XmlDocument(); docTemp.Load(_strXslFile); XmlNodeReader nrTemp = new XmlNodeReader(docTemp); try { _output.WriteLine("Loading style sheet as XmlNodeReader {0}", _strXslFile); xslt.Load(nrTemp, xr); } catch (Exception ex) { throw (ex); } finally { if (nrTemp != null) nrTemp.Dispose(); } break; case ReaderType.XmlValidatingReader: default: #pragma warning disable 0618 XmlValidatingReader vrTemp = new XmlValidatingReader(new XmlTextReader(_strXslFile)); #pragma warning restore 0618 vrTemp.ValidationType = ValidationType.None; vrTemp.EntityHandling = EntityHandling.ExpandEntities; try { _output.WriteLine("Loading style sheet as XmlValidatingReader {0}", _strXslFile); xslt.Load(vrTemp, xr); } catch (Exception ex) { throw (ex); } finally { if (vrTemp != null) vrTemp.Dispose(); } break; } break; case InputType.Navigator: #pragma warning disable 0618 XmlValidatingReader xrLoad = new XmlValidatingReader(new XmlTextReader(_strXslFile)); #pragma warning restore 0618 XPathDocument xdTemp = new XPathDocument(xrLoad, XmlSpace.Preserve); xrLoad.Dispose(); _output.WriteLine("Loading style sheet as Navigator {0}", _strXslFile); xslt.Load(xdTemp, xr); break; } return 1; }
public void TransformStrStrResolver1() { String szFullFilename = FullFilePath("fruits.xml"); try { if (LoadXSL("xmlResolver_main.xsl", new XmlUrlResolver()) == 1) { XmlTextReader xr = new XmlTextReader(szFullFilename); XmlTextWriter xw = new XmlTextWriter("out.xml", Encoding.Unicode); xslt.Transform(xr, null, xw, null); xr.Dispose(); xw.Dispose(); if (CheckResult(403.7784431795) == 1) return; else Assert.True(false); } } catch (Exception e) { _output.WriteLine(e.ToString()); Assert.True(false); } Assert.True(false); }
public void TransformStrStrResolver1() { String szFullFilename = FullFilePath("fruits.xml"); string expected = @"<result> <fruit>Apple</fruit> <fruit>orange</fruit> </result>"; if (LoadXSL("XmlResolver_Main.xsl", new XmlUrlResolver()) == 1) { XmlTextReader xr = new XmlTextReader(szFullFilename); XmlTextWriter xw = new XmlTextWriter("out.xml", Encoding.Unicode); xslt.Transform(xr, null, xw, null); xr.Dispose(); xw.Dispose(); VerifyResult(expected); return; } Assert.True(false); }
public static void ProcessClientBigRequest(string ConnString, Stream requestStream, Stream responseStream, bool dispose, FlushDelegate flushDelegate, TaskLoggingHelper log) { XmlTextReader xr = new XmlTextReader(requestStream); XmlTextWriter xw = new XmlTextWriter(responseStream, Encoding.UTF8); xw.WriteStartDocument(); xw.WriteStartElement("table"); bool first = true; //using (xr) //{ xr.Read(); xr.Read(); xr.ReadStartElement("request"); while (xr.Name == "id") { int serviceTableID = Convert.ToInt32(xr.ReadElementString("id")); ServiceTable st = DAO.GetServiceTable(ConnString, serviceTableID); if (first) { if (log != null) log.LogMessage("Processing ID " + serviceTableID.ToString() + " response " + st.ServiceTableID.ToString()); first = false; } xw.WriteStartElement("record"); xw.WriteElementString("ServiceTableID", st.ServiceTableID.ToString()); xw.WriteElementString("DescServiceTable", st.DescServiceTable); xw.WriteElementString("Value", st.Value.ToString("0.00")); xw.WriteElementString("CreationDate", st.CreationDate.ToString("dd/MM/yyyy hh:mm:ss")); xw.WriteElementString("StringField1", st.StringField1); xw.WriteElementString("StringField2", st.StringField2); xw.WriteEndElement(); if (flushDelegate != null) flushDelegate(); } xr.ReadEndElement(); //} xr.Dispose(); xw.WriteEndElement(); xw.Flush(); if (dispose) xw.Close(); }
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 CheckCustomEventReceiver(string xmlFilePath, string erNodePath, ref bool isCustomEventReceiver, string siteTemplateName) { string xml; if (System.IO.File.Exists(xmlFilePath)) { Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: ProcessWspFile] Searching for customized Web/Site Event Receivers in: " + xmlFilePath, true); var reader = new XmlTextReader(xmlFilePath); try { using (TextReader txtreader = new StreamReader(xmlFilePath)) { xml = txtreader.ReadToEnd(); } xml = CommonUtility.SanitizeXmlString(xml); reader.Namespaces = false; reader.Read(); XmlDocument doc = new XmlDocument(); try { doc = CommonUtility.GetXmlDocumentFromString(xml); } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: CheckCustomEventReceiver]. Exception Message: " + ex.Message + ", Exception Comments: Exception while loading the XML File. XML File Path: " + xmlFilePath + ". SiteTemplateName: " + siteTemplateName, true); ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(), "CheckCustomEventReceiver", ex.GetType().ToString(), "Exception while loading the XML File. XML File Path: " + xmlFilePath + ". SiteTemplateName: " + siteTemplateName); } //reader.Namespaces = false; //reader.Read(); //XmlDocument doc = new XmlDocument(); //doc.Load(reader); //Initiallizing all the nodes required to check XmlNodeList receiverNodes = doc.SelectNodes(erNodePath); //Chcecking for Custom Event Receivers if (receiverNodes != null && receiverNodes.Count > 0) { for (int i = 0; i < receiverNodes.Count; i++) { XmlNodeList receiverChilds = receiverNodes[i].ChildNodes; for (int j = 0; j < receiverChilds.Count; j++) { try { if (receiverChilds[j].HasChildNodes) { string assemblyValue = receiverChilds[j]["Assembly"].InnerText; if (lstCustomErs.Where(c => assemblyValue.Equals(c, StringComparison.CurrentCultureIgnoreCase)).Any()) { isCustomEventReceiver = true; Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: CheckCustomEventReceiver] Customized Web/Site/List Event Receiver Found for: " + siteTemplateName, true); break; } } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: CheckCustomEventReceiver]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Web/Site Receivers tag", true); ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(), "CheckCustomEventReceiver", ex.GetType().ToString(), "Exception while reading Web/Site Receivers tag"); } } } } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: CheckCustomEventReceiver]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Features tag", true); ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(), "CheckCustomEventReceiver", ex.GetType().ToString(), "Exception while reading Web/Site Receivers tag"); } finally { reader.Dispose(); } } }
public static void CheckCustomFeature(string xmlFilePath, string featureNodePath, ref bool isCustomFeature, string siteTemplateName) { string featureID = string.Empty; string xml; if (System.IO.File.Exists(xmlFilePath)) { var reader = new XmlTextReader(xmlFilePath); try { using (TextReader txtreader = new StreamReader(xmlFilePath)) { xml = txtreader.ReadToEnd(); } xml = CommonUtility.SanitizeXmlString(xml); reader.Namespaces = false; reader.Read(); XmlDocument doc = new XmlDocument(); try { doc = CommonUtility.GetXmlDocumentFromString(xml); } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: CheckCustomFeature]. Exception Message: " + ex.Message + ", Exception Comments: Exception while loading the XML File. XML File Path: " + xmlFilePath + ". SiteTemplateName: " + siteTemplateName, true); ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(), "CheckCustomFeature", ex.GetType().ToString(), "Exception while loading the XML File. XML File Path: " + xmlFilePath + ". SiteTemplateName: " + siteTemplateName); } //reader.Namespaces = false; //reader.Read(); //XmlDocument doc = new XmlDocument(); ////doc.Load(reader); //Initiallizing all the nodes required to check XmlNodeList siteFeatureNodes = doc.SelectNodes(featureNodePath); for (int j = 0; j < siteFeatureNodes.Count; j++) { try { try { featureID = siteFeatureNodes[j].Attributes["ID"].Value; } catch { } if (string.IsNullOrEmpty(featureID)) { featureID = siteFeatureNodes[j].Attributes["Id"].Value; } if (featureID.StartsWith("{")) { featureID = featureID.TrimStart('{'); featureID = featureID.TrimEnd('}'); } if (lstCustomFeatureIDs.Where(c => c.Contains(featureID.ToLower())).Any()) { isCustomFeature = true; Logger.LogInfoMessage("[DownloadAndModifySiteTemplate: CheckCustomFeature] Customized Feature Found for: " + siteTemplateName, true); break; } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: CheckCustomFeature]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Features tag", true); ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(), "CheckCustomFeature", ex.GetType().ToString(), "Exception while reading Features tag"); } } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifySiteTemplate: CheckCustomFeature]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Features tag", true); ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, Constants.NotApplicable, "SiteTemplate", ex.Message, ex.ToString(), "CheckCustomFeature", ex.GetType().ToString(), "Exception while reading Features tag"); } finally { reader.Dispose(); } } }
public static bool ProcessStpFile(string filePath, string solFileName, ref ListTemplateFTCAnalysisOutputBase objListCustOutput) { bool isCustomizationPresent = false; bool isCustomContentType = false; bool isCustomEventReceiver = false; bool isCustomSiteColumn = false; StringBuilder cTHavingCustomER = new StringBuilder(); string fileName = objListCustOutput.ListTemplateName; string downloadFolder = filePath + @"\" + Constants.DownloadPathListTemplates; Logger.LogInfoMessage("[DownloadAndModifyListTemplate: ProcessStpFile] Processing the List Template: " + objListCustOutput.ListTemplateName, true); try { string cabDir = string.Empty; string newFilePath = solFileName.ToLower().Replace(".stp", ".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("[DownloadAndModifyListTemplate: ProcessStpFile] Extracting the List Template: " + objListCustOutput.ListTemplateName, 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(); //if (!destDir.EndsWith(@"\")) // cabDir = destDir + @"\" + newFileName.Replace(".", "_"); //else // cabDir = destDir + newFileName.Replace(".", "_"); //Directory.SetCurrentDirectory(newFileName.Replace(".", "_")); //if (!destDir.EndsWith(@"\")) // cabDir = destDir + @"\" + newFileName.Replace(".", "_"); //else // cabDir = destDir + newFileName.Replace(".", "_"); FileUtility.UnCab(solFileName.ToLower().Replace(".stp", ".cab"), destDir); Directory.SetCurrentDirectory(destDir); Logger.LogInfoMessage("[DownloadAndModifyListTemplate: ProcessStpFile] Extracted the List Template: " + objListCustOutput.ListTemplateName + " in path: " + cabDir, true); string[] webTempFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "Manifest.xml", SearchOption.AllDirectories); XmlDocument xmlReceiver = new XmlDocument(); string xmlString = webTempFiles[0]; Logger.LogInfoMessage("[DownloadAndModifyListTemplate: ProcessStpFile] Searching for customized elements in: " + xmlString, true); var reader = new XmlTextReader(xmlString); string xml; using (TextReader txtreader = new StreamReader(xmlString)) { xml = txtreader.ReadToEnd(); } xml = CommonUtility.SanitizeXmlString(xml); reader.Namespaces = false; reader.Read(); XmlDocument doc = new XmlDocument(); //doc.Load(reader); //doc.LoadXml(xml); try { doc = CommonUtility.GetXmlDocumentFromString(xml); } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifyListTemplate: ProcessStpFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while loading the XML File. XML File Path: " + xmlString + ". SolFileName: " + solFileName, true); ExceptionCsv.WriteException(objListCustOutput.WebApplication, objListCustOutput.SiteCollection, objListCustOutput.WebUrl, "ListTemplate", ex.Message, ex.ToString(), "ProcessStpFile", ex.GetType().ToString(), "Exception while loading the XML File. XML File Path: " + xmlString + ". SolFileName: " + solFileName); } //Initiallizing all the nodes required to check XmlNodeList receiverNodes = doc.SelectNodes("/ListTemplate/UserLists/List/MetaData/Receivers/Receiver"); XmlNodeList xmlCTReceivers = doc.SelectNodes("/ListTemplate/UserLists/List/MetaData/ContentTypes/ContentType"); XmlNodeList xmlFields = doc.SelectNodes("/ListTemplate/UserLists/List/MetaData/Fields/Field"); #region Custom_EventReceivers //Checking for Customization Logger.LogInfoMessage("[DownloadAndModifyListTemplate: ProcessStpFile] Searching for customized List Event Receivers", true); if (receiverNodes != null && receiverNodes.Count > 0) { if (lstCustomErs != null && lstCustomErs.Count > 0) { foreach (XmlNode node in receiverNodes) { try { string assemblyValue = node["Assembly"].InnerText; if (lstCustomErs.Where(c => assemblyValue.Equals(c, StringComparison.CurrentCultureIgnoreCase)).Any()) { isCustomEventReceiver = true; Logger.LogInfoMessage("[DownloadAndModifyListTemplate: ProcessStpFile] Customized List Event Receiver Found for " + objListCustOutput.ListTemplateName, true); break; } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifyListTemplate: ProcessStpFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading List Receivers tag" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString, true); ExceptionCsv.WriteException(objListCustOutput.WebApplication, objListCustOutput.SiteCollection, objListCustOutput.WebUrl, "ListTemplate", ex.Message, ex.ToString(), "ProcessStpFile", ex.GetType().ToString(), "Exception while reading List Receivers tag" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString); } } } } #endregion Logger.LogInfoMessage("[DownloadAndModifyListTemplate: ProcessStpFile] Searching for customized Event Receivers associated with Content Types", true); if (xmlCTReceivers != null && xmlCTReceivers.Count > 0) { #region Custom ContentTypeEventReceivers //checking Event Receivers in Content Types if (lstCustomErs != null && lstCustomErs.Count > 0) { for (int i = 0; i < xmlCTReceivers.Count; i++) { try { //cTHavingCustomER.Append(xmlCTReceivers[i].Attributes["Name"].Value + ";"); var docList = xmlCTReceivers[i]["XmlDocuments"]; if (docList != null) { XmlNodeList xmlDocList = docList.ChildNodes; for (int j = 0; j < xmlDocList.Count; j++) { try { var namespaceURl = xmlDocList[j].Attributes["NamespaceURI"].Value; if (namespaceURl.Contains("http://schemas.microsoft.com/sharepoint/events")) { byte[] data = Convert.FromBase64String(xmlDocList[j].InnerText); string decodedString = Encoding.UTF8.GetString(data); XmlDocument docReceivers = new XmlDocument(); docReceivers.LoadXml(decodedString); XmlNamespaceManager nsmgr = new XmlNamespaceManager(docReceivers.NameTable); nsmgr.AddNamespace("spe", "http://schemas.microsoft.com/sharepoint/events"); XmlNodeList receiverChilds = docReceivers.SelectNodes("/spe:Receivers/Receiver", nsmgr); if (receiverChilds != null && receiverChilds.Count > 0) { for (int y = 0; y < receiverChilds.Count; y++) { try { string ctAssemblyValue = receiverChilds[y]["Assembly"].InnerText; if (lstCustomErs.Where(c => ctAssemblyValue.Equals(c, StringComparison.CurrentCultureIgnoreCase)).Any()) { //isCustomEventReceiver = true; cTHavingCustomER.Append(xmlCTReceivers[i].Attributes["Name"].Value + ";"); Logger.LogInfoMessage("[DownloadAndModifyListTemplate: ProcessStpFile] Customized Event Receiver associated with Content Type Found for : " + objListCustOutput.ListTemplateName, true); break; } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifyListTemplate: ProcessStpFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Receivers tag in Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString, true); ExceptionCsv.WriteException(objListCustOutput.WebApplication, objListCustOutput.SiteCollection, objListCustOutput.WebUrl, "ListTemplate", ex.Message, ex.ToString(), "ProcessStpFile", ex.GetType().ToString(), "Exception while reading Receivers tag in Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString); } } } } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifyListTemplate: ProcessStpFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Receivers tag in Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString, true); ExceptionCsv.WriteException(objListCustOutput.WebApplication, objListCustOutput.SiteCollection, objListCustOutput.WebUrl, "ListTemplate", ex.Message, ex.ToString(), "ProcessStpFile", ex.GetType().ToString(), "Exception while reading Receivers tag in Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString); } } } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifyListTemplate: ProcessStpFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Receivers tag in Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString, true); ExceptionCsv.WriteException(objListCustOutput.WebApplication, objListCustOutput.SiteCollection, objListCustOutput.WebUrl, "ListTemplate", ex.Message, ex.ToString(), "ProcessStpFile", ex.GetType().ToString(), "Exception while reading Receivers tag in Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString); } } } #endregion #region custom contenttypes if (lstContentTypeIDs != null && lstContentTypeIDs.Count > 0) { //Iterate all ContentTypes in manifest.xml Logger.LogInfoMessage("[DownloadAndModifyListTemplate: ProcessStpFile] Searching for customized Content Types", true); for (int i = 0; i < xmlCTReceivers.Count; i++) { try { var docList = xmlCTReceivers[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("[DownloadAndModifyListTemplate: ProcessStpFile] Customized Content Type Found for: " + objListCustOutput.ListTemplateName, true); break; } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifyListTemplate: ProcessStpFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString, true); ExceptionCsv.WriteException(objListCustOutput.WebApplication, objListCustOutput.SiteCollection, objListCustOutput.WebUrl, "ListTemplate", ex.Message, ex.ToString(), "ProcessStpFile", ex.GetType().ToString(), "Exception while reading Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString); } } } #endregion #region CustomFields_In_Contenttyeps if (lstCustomFieldIDs != null && lstCustomFieldIDs.Count > 0) { //Checking Site Columns presence in Content Types Logger.LogInfoMessage("[DownloadAndModifyListTemplate: ProcessStpFile] Searching for customized Site Columns associated with Content Types", true); for (int i = 0; i < xmlCTReceivers.Count; i++) { try { var fieldRefs = xmlCTReceivers[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("[DownloadAndModifyListTemplate: ProcessStpFile] Customized Site Column associated with Content Type Found for: " + objListCustOutput.ListTemplateName, true); break; } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifyListTemplate: ProcessStpFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Site Columns tag in Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString, true); ExceptionCsv.WriteException(objListCustOutput.WebApplication, objListCustOutput.SiteCollection, objListCustOutput.WebUrl, "ListTemplate", ex.Message, ex.ToString(), "ProcessStpFile", ex.GetType().ToString(), "Exception while reading Site Columns tag in Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString); } } } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifyListTemplate: ProcessStpFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Site Columns tag in Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString, true); ExceptionCsv.WriteException(objListCustOutput.WebApplication, objListCustOutput.SiteCollection, objListCustOutput.WebUrl, "ListTemplate", ex.Message, ex.ToString(), "ProcessStpFile", ex.GetType().ToString(), "Exception while reading Site Columns tag in Content Types" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString); } } } #endregion } #region CustomFields if (lstCustomFieldIDs != null && lstCustomFieldIDs.Count > 0 && !isCustomSiteColumn) { Logger.LogInfoMessage("[DownloadAndModifyListTemplate: ProcessStpFile] Searching for customized Site Columns", true); if (!isCustomSiteColumn && xmlFields != null && xmlFields.Count > 0) { //Get all fields Column in manifest.xml 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("[DownloadAndModifyListTemplate: ProcessStpFile] Customized Site ColumnFound for : " + objListCustOutput.ListTemplateName, true); break; } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifyListTemplate: ProcessStpFile]. Exception Message: " + ex.Message + ", Exception Comments: Exception while reading Site Columns" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString, true); ExceptionCsv.WriteException(objListCustOutput.WebApplication, objListCustOutput.SiteCollection, objListCustOutput.WebUrl, "ListTemplate", ex.Message, ex.ToString(), "ProcessStpFile", ex.GetType().ToString(), "Exception while reading Site Columns" + " SolFileName: " + solFileName + ". XML File Path: " + xmlString); } } } } #endregion if (isCustomContentType || isCustomEventReceiver || isCustomSiteColumn) { if (cTHavingCustomER != null && cTHavingCustomER.Length > 0) { cTHavingCustomER.Length -= 1; objListCustOutput.CTHavingCustomEventReceiver = cTHavingCustomER.ToString(); } else { objListCustOutput.CTHavingCustomEventReceiver = Constants.NotApplicable; } objListCustOutput.IsCustomizationPresent = "YES"; isCustomizationPresent = true; //cTHavingCustomER.Remove(cTHavingCustomER.Length-1, 1); if (lstCustomErs != null && lstCustomErs.Count > 0) objListCustOutput.IsCustomizedEventReceiver = isCustomEventReceiver ? "YES" : "NO"; else objListCustOutput.IsCustomizedEventReceiver = Constants.NoInputFile; if (lstContentTypeIDs != null && lstContentTypeIDs.Count > 0) objListCustOutput.IsCustomizedContentType = isCustomContentType ? "YES" : "NO"; else objListCustOutput.IsCustomizedContentType = Constants.NoInputFile; if (lstCustomFieldIDs != null && lstCustomFieldIDs.Count > 0) objListCustOutput.IsCustomizedSiteColumn = isCustomSiteColumn ? "YES" : "NO"; else objListCustOutput.IsCustomizedSiteColumn = Constants.NoInputFile; } else { if (cTHavingCustomER != null && cTHavingCustomER.Length > 0) { cTHavingCustomER.Length -= 1; objListCustOutput.CTHavingCustomEventReceiver = cTHavingCustomER.ToString(); objListCustOutput.IsCustomizationPresent = "YES"; isCustomizationPresent = true; objListCustOutput.IsCustomizedContentType = "NO"; objListCustOutput.IsCustomizedEventReceiver = "NO"; objListCustOutput.IsCustomizedSiteColumn = "NO"; } else { objListCustOutput.CTHavingCustomEventReceiver = Constants.NotApplicable; isCustomizationPresent = false; } } reader.Dispose(); cTHavingCustomER.Clear(); Directory.SetCurrentDirectory(downloadFolder); System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(downloadFolder); foreach (System.IO.FileInfo file in directory.GetFiles("*.*", SearchOption.AllDirectories)) { 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. } } } catch (Exception ex) { Logger.LogErrorMessage("[DownloadAndModifyListTemplate: ProcessStpFile], Exception Message: " + ex.Message + " SolFileName: " + solFileName, true); ExceptionCsv.WriteException(objListCustOutput.WebApplication, objListCustOutput.SiteCollection, objListCustOutput.WebUrl, "ListTemplate", ex.Message, ex.ToString(), "ProcessStpFile", ex.GetType().ToString(), "SolFileName: " + solFileName); } return isCustomizationPresent; }