public static IXmlMapping Convert(IMapping mapping, MappingDictionary mDict) { if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } if (mDict == null) { throw new ArgumentNullException(nameof(mDict)); } if (!(mapping is IXmlMapping)) { throw new InvalidCastException("Can't convert current mapping to IXmlMapping."); } IXmlMapping xmlMapping = mapping as IXmlMapping; string xpath = xmlMapping.XPath; if (xpath.StartsWith("@@")) { string xpathByMacro = XmlMapping.GetXPathByMacro(xpath, mDict); if (!string.IsNullOrWhiteSpace(xpathByMacro)) { xmlMapping.XPath = xpathByMacro; } } return(xmlMapping); }
public static MappingDictionary ParseText( IList <string> fieldIDs, TextMappingParser parser) { MemoryStream memoryStream = new MemoryStream(); try { StreamWriter streamWriter = new StreamWriter((Stream)memoryStream); try { foreach (string fieldId in (IEnumerable <string>)fieldIDs) { streamWriter.WriteLine(fieldId); } streamWriter.Flush(); return(MappingDictionary.ParseText((Stream)memoryStream, parser)); } finally { streamWriter?.Close(); } } finally { memoryStream?.Close(); } }
public static string GetXPathByMacro(string xpath, MappingDictionary mDict) { if (string.IsNullOrWhiteSpace(xpath)) { throw new ArgumentNullException(nameof(xpath)); } if (mDict == null) { throw new ArgumentNullException(nameof(mDict)); } string[] parameters; string name; if (Translator.ParseMacro(xpath, out name, out parameters, out string _)) { object[] array = ((IEnumerable <string>)parameters).Select <string, object>((Func <string, object>)(p => XmlMapping.ProcessParameter(p))).ToArray <object>(); if (mDict.InnerData.Tables.Contains("_XPathGroup")) { string format = mDict.InnerData.Tables["_XPathGroup"].Rows.Cast <DataRow>().Where <DataRow>((Func <DataRow, bool>)(r => string.Format("{0}", r["Name"]) == name)).Select <DataRow, string>((Func <DataRow, string>)(r => string.Format("{0}", r["XPath"]))).FirstOrDefault <string>(); if (!string.IsNullOrWhiteSpace(format)) { try { return(string.Format(format, array)); } catch (Exception ex) { } } } } return(string.Empty); }
public string GetSetting(string key, string defaultValue) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } return(MappingDictionary.GetSetting(this, key, defaultValue)); }
public static string GetSetting(MappingDictionary mDict, string key, string defaultValue) { if (mDict == null) { throw new ArgumentNullException(nameof(mDict)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } return(MappingDictionary.GetSetting(mDict.Settings, key, defaultValue)); }
public static IXmlMapping Convert( IMapping mapping, MappingDictionary mDict, bool nameAsXPath) { if (nameAsXPath && string.IsNullOrWhiteSpace(mapping.GetProperty("XPath"))) { string columnName = mapping.ColumnName; mapping.Properties["XPath"] = columnName; if (mapping is IXmlMapping) { (mapping as IXmlMapping).XPath = columnName; } } return(XmlMapping.Convert(mapping, mDict)); }
public static MappingDictionary ParseText( Assembly assembly, string resName, TextMappingParser parser) { Stream manifestResourceStream = assembly.GetManifestResourceStream(resName); try { return(MappingDictionary.ParseText(manifestResourceStream, parser)); } finally { manifestResourceStream?.Close(); } }
public static MappingDictionary Parse( Assembly assembly, string resName, Func <DataRow, IMapping> convert) { Stream manifestResourceStream = assembly.GetManifestResourceStream(resName); try { MappingDictionary mappingDictionary = MappingDictionary.Parse(manifestResourceStream, convert); mappingDictionary.IsEmpty = mappingDictionary.Mappings.Count == 0; return(mappingDictionary); } finally { manifestResourceStream?.Close(); } }
public static MappingDictionary GetDict(string configKey) { if (string.IsNullOrEmpty(configKey)) { throw new ArgumentNullException(nameof(configKey)); } switch (GlobalConfiguration.Mode) { case RunMode.EncompassServer: using (Stream inStream = GlobalConfiguration.CurrentSession.DataExchange.GetCustomDataObject(GlobalConfiguration.AppSettings[configKey]).OpenStream()) return(MappingDictionary.Parse(inStream)); case RunMode.WebServer: case RunMode.Client: return(MappingDictionary.Parse(string.Format("{0}//{1}", (object)Environment.CurrentDirectory, (object)GlobalConfiguration.AppSettings[configKey]))); default: throw new ArgumentNullException("Can't support get mapping dictionary for current mode."); } }
public static MappingDictionary getMappingDictFromServer( Session session, string mappingFile) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (string.IsNullOrEmpty(mappingFile)) { throw new ArgumentNullException(nameof(mappingFile)); } DataObject customDataObject = session.DataExchange.GetCustomDataObject(mappingFile); if (customDataObject == null || customDataObject.Size == 0) { throw new FileNotFoundException(string.Format("Can't find mapping file: {0}", (object)mappingFile)); } using (Stream inStream = customDataObject.OpenStream()) return(MappingDictionary.Parse(inStream)); }
public static MappingDictionary Parse(Session session, string mappingFile) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (string.IsNullOrEmpty(mappingFile)) { throw new ArgumentNullException(nameof(mappingFile)); } switch (GlobalConfiguration.Mode) { case RunMode.EncompassServer: return(MappingDictionary.getMappingDictFromServer(session, mappingFile)); case RunMode.WebServer: case RunMode.Client: return(File.Exists(mappingFile) ? MappingDictionary.Parse(new FileInfo(mappingFile).FullName) : MappingDictionary.getMappingDictFromServer(session, mappingFile)); default: throw new NotSupportedException(string.Format("Invalid support mode:{0}", (object)GlobalConfiguration.Mode)); } }
public static MappingDictionary Parse( string fileName, Func <DataRow, IMapping> convert) { if (string.IsNullOrWhiteSpace(fileName)) { throw new ArgumentNullException(nameof(fileName)); } if (!File.Exists(fileName)) { throw new FileNotFoundException(string.Format("Can't find mapping file:{0}", (object)fileName)); } FileStream fileStream = File.OpenRead(fileName); try { return(MappingDictionary.Parse((Stream)fileStream, convert)); } finally { fileStream?.Close(); } }
public static MappingDictionary Parse(Assembly assembly, string resName) { return(MappingDictionary.Parse(assembly, resName, (Func <DataRow, IMapping>)null)); }
public static string GetSetting(IDictionary <string, string> settings, string key) { return(MappingDictionary.GetSetting(settings, key, string.Empty)); }
public static MappingDictionary Parse(string fileName) { return(MappingDictionary.Parse(fileName, (Func <DataRow, IMapping>)null)); }
public static string GetSetting(MappingDictionary mDict, string key) { return(MappingDictionary.GetSetting(mDict, key, string.Empty)); }
public static MappingDictionary Parse(Stream inStream) { return(MappingDictionary.Parse(inStream, (Func <DataRow, IMapping>)null)); }