Esempio n. 1
0
        public static void Generate(string[] archiveFileNames, System.IO.Stream outputStream)
        {
            var archiveFiles = new AnnoRDA.FileDB.Writer.ArchiveFileMap();

            AnnoRDA.FileSystem fileSystem;

            if (archiveFileNames.Length == 1 && PathIsDirectory(archiveFileNames[0]))
            {
                var directoryLoader = new AnnoRDA.Loader.ContainerDirectoryLoader();
                var loadResult      = directoryLoader.Load(archiveFileNames[0], System.Threading.CancellationToken.None);

                fileSystem = loadResult.FileSystem;
                foreach (string path in loadResult.ContainerPaths)
                {
                    archiveFiles.Add(path, path);
                }
            }
            else
            {
                fileSystem = new AnnoRDA.FileSystem();
                var fileLoader = new AnnoRDA.Loader.ContainerFileLoader();
                foreach (var rdaFileName in archiveFileNames)
                {
                    var loadedFS = fileLoader.Load(rdaFileName);
                    fileSystem.OverwriteWith(loadedFS, null, System.Threading.CancellationToken.None);

                    archiveFiles.Add(rdaFileName, rdaFileName);
                }
            }

            using (var fileDBWriter = new AnnoRDA.FileDB.Writer.FileSystemWriter(outputStream, true)) {
                fileDBWriter.WriteFileSystem(fileSystem, archiveFiles);
            }
        }
Esempio n. 2
0
        public override int Run(string[] remainingArguments)
        {
            var archiveFiles = new AnnoRDA.FileDB.Writer.ArchiveFileMap();
            AnnoRDA.FileSystem fileSystem;

            if (remainingArguments.Length == 1 && this.PathIsDirectory(remainingArguments[0])) {
                var directoryLoader = new AnnoRDA.Loader.ContainerDirectoryLoader();
                var loadResult = directoryLoader.Load(remainingArguments[0], System.Threading.CancellationToken.None);

                fileSystem = loadResult.FileSystem;
                foreach (string path in loadResult.ContainerPaths) {
                    archiveFiles.Add(path, path);
                }
            } else {
                fileSystem = new AnnoRDA.FileSystem();
                var fileLoader = new AnnoRDA.Loader.ContainerFileLoader();
                foreach (var rdaFileName in remainingArguments) {
                    var loadedFS = fileLoader.Load(rdaFileName);
                    fileSystem.OverwriteWith(loadedFS, null, System.Threading.CancellationToken.None);

                    archiveFiles.Add(rdaFileName, rdaFileName);
                }
            }

            using (var outputStream = new System.IO.FileStream(this.outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) {
                using (var writer = new AnnoRDA.FileDB.Writer.FileDBWriter(outputStream, false)) {
                    writer.WriteFileDB(fileSystem, archiveFiles);
                }
            }

            return 0;
        }
        private async void button_Generate_Click(object sender, RoutedEventArgs e)
        {
            this.cancellationTokenSource = new System.Threading.CancellationTokenSource();
            this.viewModel.IsGenerating  = true;

            ICollection <RDAFileListItem> enabledItems = viewModel.RDAFileList.Items.Where((item) => item.IsEnabled).ToList();

            int numSteps = enabledItems.Count * 2; // reading

            numSteps += 1;                         // writing

            this.statusBar_progressBar_Progress.Minimum = 0;
            this.statusBar_progressBar_Progress.Maximum = numSteps;
            this.statusBar_progressBar_Progress.Value   = 0;

            var archiveFiles = new AnnoRDA.FileDB.Writer.ArchiveFileMap();
            var fileSystem   = new AnnoRDA.FileSystem();
            var fileLoader   = new AnnoRDA.Loader.ContainerFileLoader();

            try {
                foreach (var rdaFile in enabledItems)
                {
                    this.statusBar_textBlock_Message.Text = System.String.Format("Loading {0}", rdaFile.Name);
                    archiveFiles.Add(rdaFile.LoadPath, rdaFile.Name);

                    var progress = new System.Progress <string>((string fileName) => {
                        this.statusBar_textBlock_Message.Text = System.String.Format("Loading {0}: {1}", rdaFile.Name, fileName);
                    });
                    var containerFileSystem = await Task.Run(() => fileLoader.Load(rdaFile.LoadPath, progress, this.cancellationTokenSource.Token));

                    this.statusBar_progressBar_Progress.Value += 1;

                    this.statusBar_textBlock_Message.Text = System.String.Format("Loading {0}", rdaFile.Name);
                    await Task.Run(() => fileSystem.OverwriteWith(containerFileSystem, null, this.cancellationTokenSource.Token));

                    this.statusBar_progressBar_Progress.Value += 1;
                }

                this.statusBar_textBlock_Message.Text = "Writing...";

                using (var outputStream = new System.IO.FileStream(this.viewModel.OutputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) {
                    using (var writer = new AnnoRDA.FileDB.Writer.FileDBWriter(outputStream, false)) {
                        await Task.Run(() => writer.WriteFileDB(fileSystem, archiveFiles));
                    }
                }
                this.statusBar_progressBar_Progress.Value += 1;

                this.statusBar_textBlock_Message.Text = "Done";
            } catch (System.OperationCanceledException) {
                this.statusBar_textBlock_Message.Text = "Canceled";
            } finally {
                this.viewModel.IsGenerating = false;
                this.cancellationTokenSource.Dispose();
                this.cancellationTokenSource = null;
            }
        }
Esempio n. 4
0
        public override int Run(string[] remainingArguments)
        {
            var archiveFiles = new AnnoRDA.FileDB.Writer.ArchiveFileMap();

            AnnoRDA.FileSystem fileSystem;

            if (remainingArguments.Length == 1 && this.PathIsDirectory(remainingArguments[0]))
            {
                var directoryLoader = new AnnoRDA.Loader.ContainerDirectoryLoader();
                var loadResult      = directoryLoader.Load(remainingArguments[0], System.Threading.CancellationToken.None);

                fileSystem = loadResult.FileSystem;
                foreach (string path in loadResult.ContainerPaths)
                {
                    archiveFiles.Add(path, path);
                }
            }
            else
            {
                fileSystem = new AnnoRDA.FileSystem();
                var fileLoader = new AnnoRDA.Loader.ContainerFileLoader();
                foreach (var rdaFileName in remainingArguments)
                {
                    var loadedFS = fileLoader.Load(rdaFileName);
                    fileSystem.OverwriteWith(loadedFS, null, System.Threading.CancellationToken.None);

                    archiveFiles.Add(rdaFileName, rdaFileName);
                }
            }

            using (var outputStream = new System.IO.FileStream(this.outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) {
                using (var writer = new AnnoRDA.FileDB.Writer.FileSystemWriter(outputStream, false)) {
                    writer.WriteFileSystem(fileSystem, archiveFiles);
                }
            }

            return(0);
        }
        private async void button_Generate_Click(object sender, RoutedEventArgs e)
        {
            this.cancellationTokenSource = new System.Threading.CancellationTokenSource();
            this.viewModel.IsGenerating = true;

            ICollection<RDAFileListItem> enabledItems = viewModel.RDAFileList.Items.Where((item) => item.IsEnabled).ToList();

            int numSteps = enabledItems.Count * 2; // reading
            numSteps += 1; // writing

            this.statusBar_progressBar_Progress.Minimum = 0;
            this.statusBar_progressBar_Progress.Maximum = numSteps;
            this.statusBar_progressBar_Progress.Value = 0;

            var archiveFiles = new AnnoRDA.FileDB.Writer.ArchiveFileMap();
            var fileSystem = new AnnoRDA.FileSystem();
            var fileLoader = new AnnoRDA.Loader.ContainerFileLoader();

            try {
                foreach (var rdaFile in enabledItems) {
                    this.statusBar_textBlock_Message.Text = System.String.Format("Loading {0}", rdaFile.Name);
                    archiveFiles.Add(rdaFile.LoadPath, rdaFile.Name);

                    var progress = new System.Progress<string>((string fileName) => {
                        this.statusBar_textBlock_Message.Text = System.String.Format("Loading {0}: {1}", rdaFile.Name, fileName);
                    });
                    var containerFileSystem = await Task.Run(() => fileLoader.Load(rdaFile.LoadPath, progress, this.cancellationTokenSource.Token));
                    this.statusBar_progressBar_Progress.Value += 1;

                    this.statusBar_textBlock_Message.Text = System.String.Format("Loading {0}", rdaFile.Name);
                    await Task.Run(() => fileSystem.OverwriteWith(containerFileSystem, null, this.cancellationTokenSource.Token));
                    this.statusBar_progressBar_Progress.Value += 1;
                }

                this.statusBar_textBlock_Message.Text = "Writing...";

                using (var outputStream = new System.IO.FileStream(this.viewModel.OutputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) {
                    using (var writer = new AnnoRDA.FileDB.Writer.FileDBWriter(outputStream, false)) {
                        await Task.Run(() => writer.WriteFileDB(fileSystem, archiveFiles));
                    }
                }
                this.statusBar_progressBar_Progress.Value += 1;

                this.statusBar_textBlock_Message.Text = "Done";

            } catch(System.OperationCanceledException) {
                this.statusBar_textBlock_Message.Text = "Canceled";

            } finally {
                this.viewModel.IsGenerating = false;
                this.cancellationTokenSource.Dispose();
                this.cancellationTokenSource = null;
            }
        }