Exemple #1
0
        // Attempt to import another type of movie file into a movie object.
        public static IMovie ImportFile(string path, out string errorMsg, out string warningMsg)
        {
            errorMsg   = "";
            warningMsg = "";
            string ext = path != null?Path.GetExtension(path).ToUpper() : "";

            var importerType = ImporterForExtension(ext);

            if (importerType == default)
            {
                errorMsg = $"No importer found for file type {ext}";
                return(null);
            }

            // Create a new instance of the importer class using the no-argument constructor
            IMovieImport importer = importerType
                                    .GetConstructor(new Type[] { })
                                    ?.Invoke(new object[] { }) as IMovieImport;

            if (importer == null)
            {
                errorMsg = $"No importer found for type {ext}";
                return(null);
            }

            Bk2Movie movie = null;

            try
            {
                var result = importer.Import(path);
                if (result.Errors.Count > 0)
                {
                    errorMsg = result.Errors.First();
                }

                if (result.Warnings.Count > 0)
                {
                    warningMsg = result.Warnings.First();
                }

                movie = result.Movie;
            }
            catch (Exception ex)
            {
                errorMsg = ex.ToString();
            }

            movie?.Save();
            return(movie);
        }
Exemple #2
0
        // Attempt to import another type of movie file into a movie object.
        public static ImportResult ImportFile(string path, Config config)
        {
            string ext          = Path.GetExtension(path) ?? "";
            var    importerType = ImporterForExtension(ext);

            if (importerType == default)
            {
                return(ImportResult.Error($"No importer found for file type {ext}"));
            }

            // Create a new instance of the importer class using the no-argument constructor
            IMovieImport importer = (IMovieImport)importerType
                                    .GetConstructor(new Type[] { })
                                    ?.Invoke(new object[] { });

            return(importer == null
                                ? ImportResult.Error($"No importer found for file type {ext}")
                                : importer.Import(path, config));
        }