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(
            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(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(Assembly assembly, string resName)
 {
     return(MappingDictionary.Parse(assembly, resName, (Func <DataRow, IMapping>)null));
 }
 public static MappingDictionary Parse(Stream inStream)
 {
     return(MappingDictionary.Parse(inStream, (Func <DataRow, IMapping>)null));
 }
 public static MappingDictionary Parse(string fileName)
 {
     return(MappingDictionary.Parse(fileName, (Func <DataRow, IMapping>)null));
 }