コード例 #1
0
 /// <summary>
 /// Attemps to get the appropriate module for importing the specified data.
 /// </summary>
 /// <param name="data">The data to import.</param>
 /// <param name="module">The out parameter containing the found module, if none are found then it will be null.</param>
 /// <param name="filename">Optional filename parameter. Might be required by some modules.</param>
 /// <returns>Whether or not a module was found.</returns>
 public static bool TryGetModuleForImport(byte[] data, out IFormatModule module, string filename = null)
 {
     using (var stream = new MemoryStream(data))
     {
         return(TryGetModuleForImport(stream, out module, filename));
     }
 }
コード例 #2
0
 /// <summary>
 /// Attemps to get the appropriate module for importing the specified file.
 /// </summary>
 /// <param name="filepath">The file to import.</param>
 /// <param name="module">The out parameter containing the found module, if none are found then it will be null.</param>
 /// <returns>Whether or not a module was found.</returns>
 public static bool TryGetModuleForImport(string filepath, out IFormatModule module)
 {
     using (var stream = File.OpenRead(filepath))
     {
         return(TryGetModuleForImport(stream, out module, Path.GetFileName(filepath)));
     }
 }
コード例 #3
0
        /// <summary>
        /// Attemps to get the appropriate module for importing the specified stream data.
        /// </summary>
        /// <param name="stream">The stream containing data to import.</param>
        /// <param name="module">The out parameter containing the found module, if none are found then it will be null.</param>
        /// <param name="filename">Optional filename parameter. Might be required by some modules.</param>
        /// <returns>Whether or not a module was found.</returns>
        public static bool TryGetModuleForImport(Stream stream, out IFormatModule module, string filename = null)
        {
            // try to find a module that can import this file
            module = FormatModuleRegistry.Modules.SingleOrDefault(x => x.CanImport(stream, filename));

            // simplicity is nice sometimes c:
            return(module != null);
        }
コード例 #4
0
        public static void Register(IFormatModule module)
        {
            if (sModules.ContainsKey(module.ModelType))
            {
                return;
            }

            sModules[module.ModelType] = module;
        }
コード例 #5
0
        public static void Register(IFormatModule module)
        {
            if (sModules.ContainsKey(module.ModelType))
            {
                throw new ArgumentException("Format module is already registered", nameof(module));
            }

            sModules.Add(module.ModelType, module);
        }
コード例 #6
0
        public static bool TryRegister(IFormatModule module)
        {
            if (sModules.ContainsKey(module.ModelType))
            {
                return(false);
            }

            sModules.Add(module.ModelType, module);
            return(true);
        }
コード例 #7
0
        //
        // Methods for registration of modules
        //

        /// <summary>
        /// Registers a format IO module.
        /// </summary>
        /// <param name="module">The module to register.</param>
        public static void Register(IFormatModule module)
        {
            Trace.TraceInformation($"Registering module {module.GetType()} for object type {module.ModelType}");

            if (sModules.ContainsKey(module.ModelType))
            {
                throw new Exception($"FormatModule registry already contains module for type: {module.ModelType}");
            }

            sModules[module.ModelType] = module;
        }
コード例 #8
0
 public static string GenerateFilter(IFormatModule module)
 {
     return($"{module.Name}|{string.Join( ";", module.Extensions.Select( x => $"*.{x}" ) )}");
 }
コード例 #9
0
 public static string GenerateFilter(IFormatModule module, FormatExtensionFlags flags)
 {
     return(string.Join("|", module.Extensions.Where(x => x.Flags.HasFlag(flags)).Select(x => $"{x.Name}|*.{x.Extension}")));
 }
コード例 #10
0
        public static bool HasAnyExtension(string fileName, IFormatModule module)
        {
            string extension = Path.GetExtension(fileName).Trim('.');

            return(module.Extensions.Any(x => x == "*" || x.Equals(extension, StringComparison.OrdinalIgnoreCase)));
        }
コード例 #11
0
 public static string GetFilter(IFormatModule module)
 {
     return(string.Join("|", module.Extensions.Select(x => $"{x.ToUpperInvariant()} {module.Name} Files|*.{x}")));
 }