public async Task TestFileReadMissing()
 {
     string tempFile = "TEMPDATADOESNTEXISTS";
     var    sut      = new FileReaderProvider();
     var    result   = await Assert.
                       ThrowsAnyAsync <IOException>(async() => await sut.ReadFileAsStringAsync(tempFile));
 }
Beispiel #2
0
        private void LoadFile(string path, List <string> pathArgs = null)
        {
            var projectLoader = new GameLoader();

            this.FileReaderProvider = projectLoader.Load(path);
            project = FileReaderProvider.GetProjectReader().Load();

            BasePath = project.BaseDir;

            PixelsDown   = project.ScreenHeight;
            PixelsAcross = project.ScreenWidth;

            if (ScreenSizeChanged != null)
            {
                ScreenSizeChangedEventArgs args = new ScreenSizeChangedEventArgs(PixelsAcross, PixelsDown);
                ScreenSizeChanged(this, args);
            }

            if (project.MusicNSF != null)
            {
                Engine.Instance.SoundSystem.LoadMusicNSF(project.MusicNSF.Absolute);
            }
            if (project.EffectsNSF != null)
            {
                Engine.Instance.SoundSystem.LoadSfxNSF(project.EffectsNSF.Absolute);
            }

            foreach (var stageInfo in project.Stages)
            {
                stageFactory.Load(stageInfo);
            }

            _tileProperties.LoadProperties(project.EntityProperties);
            _entitySource.LoadEntities(project.Entities);
            EffectParser.LoadEffectsList(project.Functions);
            Engine.Instance.SoundSystem.LoadEffectsFromInfo(project.Sounds);
            Scene.LoadScenes(project.Scenes);
            Menu.LoadMenus(project.Menus);
            FontSystem.Load(project.Fonts);
            PaletteSystem.LoadPalettes(project.Palettes);

            currentPath = path;

            if (pathArgs != null && pathArgs.Any())
            {
                ProcessCommandLineArgs(pathArgs);
            }
            else if (project.StartHandler != null)
            {
                _stateMachine.ProcessHandler(project.StartHandler);
            }
            else
            {
                throw new GameRunException("The game file loaded correctly, but it failed to specify a starting point!");
            }

            Player = new Player();
        }
        public async Task TestFileLocked()
        {
            string tempFile = Path.GetTempFileName();

            try
            {
                using FileStream fs = new FileStream(tempFile, FileMode.Open);
                var sut    = new FileReaderProvider();
                var result = await Assert.ThrowsAsync <IOException>(async() => await sut.ReadFileAsStringAsync(tempFile));
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
        public async Task TestFileReadExists(string testText)
        {
            string tempFile = Path.GetTempFileName();

            try
            {
                File.WriteAllText(tempFile, testText);

                var    sut    = new FileReaderProvider();
                string result = await sut.ReadFileAsStringAsync(tempFile);

                Assert.Equal(testText, result);
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
Beispiel #5
0
        static int Main(string[] args)
        {
            if (args.Length != 3 || false)
            {
                "Please specify all input arguments.".PrintOnConsole();
                return(1);
            }
            // args = new[] { "compress", "G:\\Win10.vhd", "G:\\ArchivedVHD.arh" };
            // args = new[] { "decompress", "G:\\ArchivedVHD.arh", "K:\\DecompressedVHD.vhd" };


            // args = new[] { "compress", "G:\\Input.txt", "G:\\InputArc.txt" };
            //args = new[] { "decompress", "G:\\InputArc.txt", "G:\\DecompressedInput.txt" };
            switch (args[0])
            {
            case "compress":
            {
                var fileToArchive = args[1];
                var archiveName   = args[2];

                var fileReader   = new FileReader(fileToArchive);
                var inpuQueues   = QueueProvider.GetQueues(Configuration.CountOfCompressors, Configuration.QueueBufferLength);
                var reader       = FileReaderProvider.StartReader(fileReader, inpuQueues, Configuration.BlockSize);
                var outputQueues = QueueProvider.GetQueues(Configuration.CountOfCompressors, Configuration.QueueBufferLength);

                var compressors = Enumerable.Zip(inpuQueues, outputQueues, (a, b) => (inQueue: a, outQueue: b))
                                  .Select(i => CompressorProvider.StartCompressor(i.inQueue, i.outQueue, CompressionLevel.Optimal))
                                  .ToArray();

                var fileWriter = new ArchiveFileWriter(new FileWriter(archiveName));
                var writer     = FileWriterProvider.StartWriting(fileWriter, outputQueues);

                var monitor = MonitorProvider.StartMonitor(inpuQueues, outputQueues);

                writer.Join();

                break;
            }

            case "decompress":
            {
                var archiveName    = args[1];
                var outputFileName = args[2];

                var inpuCompressedQueues     = QueueProvider.GetQueues(Configuration.CountOfDecompressors, Configuration.QueueBufferLength);
                var archiveReader            = FileReaderProvider.StartReader(new ArchiveFileReader(new FileReader(archiveName)), inpuCompressedQueues, Configuration.BlockSize + 100);
                var outputDecompressedQueues = QueueProvider.GetQueues(Configuration.CountOfDecompressors, Configuration.QueueBufferLength);

                var decompressors = Enumerable.Zip(inpuCompressedQueues, outputDecompressedQueues, (a, b) => (inQueue: a, outQueue: b))
                                    .Select(i => DecompressorProvider.StartDecompressor(i.inQueue, i.outQueue, Configuration.BlockSize))
                                    .ToArray();

                var decompressedWriter = FileWriterProvider.StartWriting(new FileWriter(outputFileName), outputDecompressedQueues);

                var monitor = MonitorProvider.StartMonitor(inpuCompressedQueues, outputDecompressedQueues);

                decompressedWriter.Join();
                break;
            }

            default:
                break;
            }

            return(0);
        }