/// <summary> /// Dump the properties from the given Item to an XML file in the given /// destination folder. /// </summary> /// <param name="item">Loaded Item whose properties are to be dumped</param> /// <param name="destinationFolderPath">Folder to save messages to</param> public static void DumpXML( Item item, string destinationFolderPath) { DebugLog.WriteVerbose("Writing item to file."); // Create a file path to save the item properties to string fileName = null; fileName = string.Format( System.Globalization.CultureInfo.CurrentCulture, "{0}\\{1}.xml", destinationFolderPath, FileHelper.SanitizeFileName(item.Subject)); XmlDocument xmlDoc = new XmlDocument(); XmlNode xmlMessage = xmlDoc.CreateNode(XmlNodeType.Element, "Message", string.Empty); xmlDoc.AppendChild(xmlMessage); XmlNode xmlProperties = xmlDoc.CreateNode(XmlNodeType.Element, "Properties", string.Empty); xmlMessage.AppendChild(xmlProperties); foreach (PropertyDefinitionBase baseProp in item.GetLoadedPropertyDefinitions()) { if (baseProp != ItemSchema.ExtendedProperties) { PropertyInterpretation propInter = new PropertyInterpretation(item, baseProp); xmlProperties.AppendChild(propInter.ToXML(xmlDoc)); } } // Write XML content to file System.IO.File.WriteAllText( FileHelper.EnsureUniqueFileName(fileName), xmlDoc.OuterXml); DebugLog.WriteVerbose(String.Concat("Wrote item to file, {0}", fileName)); }
/// <summary> /// Dump an error response as XML /// </summary> /// <param name="response">Response to get data from</param> /// <param name="destinationFolderPath">Folder to save messages to</param> private static void DumpErrorResponseXML( GetItemResponse response, string destinationFolderPath) { DebugLog.WriteVerbose("Writing error to file."); XmlDocument xmlDoc = new XmlDocument(); XmlNode xmlMessage = xmlDoc.CreateNode(XmlNodeType.Element, "Message", string.Empty); xmlDoc.AppendChild(xmlMessage); XmlNode xmlProperties = xmlDoc.CreateNode(XmlNodeType.Element, "Properties", string.Empty); xmlMessage.AppendChild(xmlProperties); // Create a file path to save the error message to string fileName = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}\\_ERROR.txt", destinationFolderPath); // Get error message contents XmlNode xmlError = xmlDoc.CreateNode(XmlNodeType.Element, "Error", string.Empty); XmlNode xmlErrorCode = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorCode", string.Empty); xmlErrorCode.InnerText = response.ErrorCode.ToString(); xmlError.AppendChild(xmlErrorCode); XmlNode xmlErrorMessage = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorMessage", string.Empty); xmlErrorMessage.InnerText = response.ErrorMessage; xmlError.AppendChild(xmlErrorMessage); if (response.ErrorDetails != null && response.ErrorDetails.Count > 0) { XmlNode xmlErrorDetails = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorDetails", string.Empty); StringBuilder detailsText = new StringBuilder(); foreach (KeyValuePair<string, string> detail in response.ErrorDetails) { XmlNode xmlErrorDetail = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorDetail", string.Empty); XmlNode xmlKeyAttr = xmlDoc.CreateNode(XmlNodeType.Attribute, "Key", string.Empty); xmlKeyAttr.Value = detail.Key; xmlErrorDetail.AppendChild(xmlKeyAttr); xmlErrorDetail.InnerText = detail.Value; xmlErrorDetails.AppendChild(xmlErrorDetail); } xmlError.AppendChild(xmlErrorDetails); } if (response.ErrorProperties != null && response.ErrorProperties.Count > 0) { XmlNode xmlErrorProps = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorProperties", string.Empty); StringBuilder propsText = new StringBuilder(); foreach (PropertyDefinitionBase baseProp in response.ErrorProperties) { PropertyInterpretation prop = new PropertyInterpretation(response.Item, baseProp); xmlErrorProps.AppendChild(prop.ToXML(xmlDoc)); } xmlError.AppendChild(xmlErrorProps); } xmlProperties.AppendChild(xmlError); // Write MIME content to file System.IO.File.WriteAllText( FileHelper.EnsureUniqueFileName(fileName), xmlDoc.OuterXml); DebugLog.WriteVerbose(String.Format("Wrote error to file, {0}.", fileName)); }
/// <summary> /// Dump an error response as XML /// </summary> /// <param name="response">Response to get data from</param> /// <param name="destinationFolderPath">Folder to save messages to</param> private static void DumpErrorResponseXML( GetItemResponse response, string destinationFolderPath) { DebugLog.WriteVerbose("Writing error to file."); XmlDocument xmlDoc = new XmlDocument(); XmlNode xmlMessage = xmlDoc.CreateNode(XmlNodeType.Element, "Message", string.Empty); xmlDoc.AppendChild(xmlMessage); XmlNode xmlProperties = xmlDoc.CreateNode(XmlNodeType.Element, "Properties", string.Empty); xmlMessage.AppendChild(xmlProperties); // Create a file path to save the error message to string fileName = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}\\_ERROR.txt", destinationFolderPath); // Get error message contents XmlNode xmlError = xmlDoc.CreateNode(XmlNodeType.Element, "Error", string.Empty); XmlNode xmlErrorCode = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorCode", string.Empty); xmlErrorCode.InnerText = response.ErrorCode.ToString(); xmlError.AppendChild(xmlErrorCode); XmlNode xmlErrorMessage = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorMessage", string.Empty); xmlErrorMessage.InnerText = response.ErrorMessage; xmlError.AppendChild(xmlErrorMessage); if (response.ErrorDetails != null && response.ErrorDetails.Count > 0) { XmlNode xmlErrorDetails = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorDetails", string.Empty); StringBuilder detailsText = new StringBuilder(); foreach (KeyValuePair <string, string> detail in response.ErrorDetails) { XmlNode xmlErrorDetail = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorDetail", string.Empty); XmlNode xmlKeyAttr = xmlDoc.CreateNode(XmlNodeType.Attribute, "Key", string.Empty); xmlKeyAttr.Value = detail.Key; xmlErrorDetail.AppendChild(xmlKeyAttr); xmlErrorDetail.InnerText = detail.Value; xmlErrorDetails.AppendChild(xmlErrorDetail); } xmlError.AppendChild(xmlErrorDetails); } if (response.ErrorProperties != null && response.ErrorProperties.Count > 0) { XmlNode xmlErrorProps = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorProperties", string.Empty); StringBuilder propsText = new StringBuilder(); foreach (PropertyDefinitionBase baseProp in response.ErrorProperties) { PropertyInterpretation prop = new PropertyInterpretation(response.Item, baseProp); xmlErrorProps.AppendChild(prop.ToXML(xmlDoc)); } xmlError.AppendChild(xmlErrorProps); } xmlProperties.AppendChild(xmlError); // Write MIME content to file System.IO.File.WriteAllText( FileHelper.EnsureUniqueFileName(fileName), xmlDoc.OuterXml); DebugLog.WriteVerbose(String.Format("Wrote error to file, {0}.", fileName)); }