コード例 #1
0
        public static bool ImportFile(string filePath)
        {
            // Determine & check paths
            string srcFilePath, targetName, targetDir;

            PrepareImportFilePaths(filePath, out srcFilePath, out targetName, out targetDir);

            // Find an importer to handle the file import
            IFileImporter importer = importers.FirstOrDefault(i => i.CanImportFile(srcFilePath));

            if (importer != null)
            {
                try
                {
                    // Assure the directory exists
                    Directory.CreateDirectory(Path.GetDirectoryName(srcFilePath));

                    // Move file from data directory to source directory
                    if (File.Exists(srcFilePath))
                    {
                        File.Copy(filePath, srcFilePath, true);
                        File.Delete(filePath);
                    }
                    else
                    {
                        File.Move(filePath, srcFilePath);
                    }
                } catch (Exception) { return(false); }

                // Import it
                try
                {
                    importer.ImportFile(srcFilePath, targetName, targetDir);
                }
                catch (Exception ex)
                {
                    Log.Editor.WriteError("An error occurred while trying to import file {1}: {0}", Log.Exception(ex), srcFilePath);
                    return(false);
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: FileImportProvider.cs プロジェクト: Banbury/duality
        public static bool ImportFile(string filePath)
        {
            // Determine & check paths
            string srcFilePath, targetName, targetDir;

            PrepareImportFilePaths(filePath, out srcFilePath, out targetName, out targetDir);

            // Find an importer to handle the file import
            IFileImporter importer = CorePluginRegistry.GetFileImporter(i => i.CanImportFile(srcFilePath));

            if (importer != null)
            {
                try
                {
                    // Assure the directory exists
                    Directory.CreateDirectory(Path.GetDirectoryName(srcFilePath));

                    // Move file from data directory to source directory
                    if (File.Exists(srcFilePath))
                    {
                        File.Copy(filePath, srcFilePath, true);
                        File.Delete(filePath);
                    }
                    else
                    {
                        File.Move(filePath, srcFilePath);
                    }
                } catch (Exception) { return(false); }

                // Import it
                importer.ImportFile(srcFilePath, targetName, targetDir);
                GC.Collect();
                GC.WaitForPendingFinalizers();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
 public IEnumerable <DataItem> LoadData(string inputFile)
 {
     return(_fileImporter.ImportFile(inputFile));
 }