*Cut & Paste

*Cut & Paste

using System; using System.IO; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Web; using Centralpoint.Web.Cms.DataTransfer; using System.Data.SqlClient; using Centralpoint.Web.Cms; using Centralpoint.Web; using Centralpoint.Web.UI; using Centralpoint.Web.UI.Controls; using System.Data.OleDb; using DTMappingType = Centralpoint.Web.Cms.DataTransfer.MappingType; using System.Data; using System.Text; using System.Net.Mail; using ICSharpCode.SharpZipLib.Zip; using System.Xml.Linq; //Centralpoint.Master.Custom.CHS_DataTransfer.TransformMdStaff namespace Centralpoint.Master { namespace Custom.Maximus_DataTransfer { public class Maximus : DataTransferV.DataTableReader { protected DataTable _mainTable { get; set; } public Maximus(DataTransfer dataTransfer) : base(dataTransfer) { } protected override DataTable GetDataTable(bool includeData) { string sourceFile = this.DataTransfer.Attributes.Get("SourceCustomParameters"); HttpContext.Current.Trace.Warn("Trace_Warn", $"sourceFile: {sourceFile}"); if (String.IsNullOrWhiteSpace(sourceFile) || !File.Exists(sourceFile)) return new DataTable(); DataTable _mainTableName = new DataTable(); HttpContext.Current.Trace.Warn("Trace_Warn", $"2 { File.Exists(sourceFile)}"); try { XDocument xml = XDocument.Load(sourceFile); var system = from systemData in xml.Elements()//Descendants("row/col") // select new { Row = from attrib in xml.Descendants("row") select new { Colum = from col in attrib.Descendants("col") select new { Name = col.Attribute("name").Value, Type = col.Attribute("type").Value, Value = col.Value }, Category = from at in attrib.Elements("categories") select new { taxonomyCode = at.Element("category").Value }, Attachments = from att in attrib.Elements("attachments").Elements("attmnt") select new { fileName = att.Element("file_name").Value }, } }; foreach (var val in system) { foreach (var attrib in val.Row) { DataRow row = _mainTableName.NewRow(); StringBuilder attachments = new StringBuilder(); if (!_mainTableName.Columns.Contains("Attachments")) _mainTableName.Columns.Add("Attachments", typeof(String)); foreach (var att in attrib.Attachments) { if (attachments.Length > 0) attachments.Append(", "); // HttpContext.Current.Trace.Warn("attmnt", $"{att.fileName}"); attachments.Append(att.fileName); } if (attachments.Length > 0) row["Attachments"] = attachments.ToString(); foreach (var cat in attrib.Category) { HttpContext.Current.Trace.Warn("cat.taxonomyCode", $"{cat.taxonomyCode}"); if (!_mainTableName.Columns.Contains("Category")) _mainTableName.Columns.Add("Category", typeof(String)); row["Category"] = cat.taxonomyCode; } foreach (var column in attrib.Colum) { HttpContext.Current.Trace.Warn("column.Name", $"{column.Name}"); if (!_mainTableName.Columns.Contains(column.Name)) _mainTableName.Columns.Add(column.Name, typeof(String)); row[column.Name] = column.Value; } _mainTableName.Rows.Add(row); } } } catch (Exception ex) { HttpContext.Current.Trace.Warn("Maximus.GetDataTable", $"{ex.Message}. {ex.StackTrace}"); } HttpContext.Current.Trace.Warn("Trace_Warn", $"3 . {_mainTableName.Rows.Count}"); return _mainTableName; } } } public partial class DataTransferCpScripting { partial void ExecuteCustom(string key, NameValueCollection collection, ref string result, ref bool found) { switch (key) { case "max_unixtimestamptodatetime": result = this.max_UnixTimeStampToDateTime(collection); break; case "max_formatguid": result = this.max_FormatGuid(collection); break; default: return; } found = true; } public string max_UnixTimeStampToDateTime(NameValueCollection collection) { string value = Scripting.CollectionValue(collection, "Name"); if (String.IsNullOrEmpty(value)) return String.Empty; value = this.Column(value); double unixTimeStamp; if (!Double.TryParse(value, out unixTimeStamp)) unixTimeStamp = 0; return DataTransferCpScripting.UnixTimeStampToDateTime(unixTimeStamp).ToString(); } public string max_FormatGuid(NameValueCollection collection) { string value = Scripting.CollectionValue(collection, "Name"); if (String.IsNullOrEmpty(value)) return String.Empty; value = this.Column(value); return new Guid(value).ToString(); } public static DateTime UnixTimeStampToDateTime(double unixTimeStamp) { // Unix timestamp is seconds past epoch System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime(); return dtDateTime; } } }