Ejemplo n.º 1
0
        public void NoBuilderWillBeReturnedIfTheFileDoesntExists()
        {
            var mockFileSystemhelper = new Mock<IFileSystemHelper>();
            mockFileSystemhelper.Setup(f => f.FileExists(It.IsAny<string>())).Returns(false);

            var factory = new FileConverterFactory(mockFileSystemhelper.Object);
            Assert.Null(factory.ParseFile("irrelevant"));
        }
Ejemplo n.º 2
0
        public void NoBuilderWillBeReturnedIfTheFileExistsButExtensionDoesNotMatchAKnownType(string extension)
        {
            var mockFileSystemhelper = new Mock<IFileSystemHelper>();
            mockFileSystemhelper.Setup(f => f.FileExists(It.IsAny<string>())).Returns(true);

            var factory = new FileConverterFactory(mockFileSystemhelper.Object);
            Assert.Null(factory.ParseFile("abc" + extension));
        }
Ejemplo n.º 3
0
        public void BuilderExtensionComaprisonsAreCaseInsensitive(string path)
        {
            var mockFileSystemhelper = new Mock<IFileSystemHelper>();
            mockFileSystemhelper.Setup(f => f.FileExists(It.IsAny<string>())).Returns(true);

            var factory = new FileConverterFactory(mockFileSystemhelper.Object);

            Assert.NotNull(factory.ParseFile(path));
        }
Ejemplo n.º 4
0
        public void ABuilderWillBeReturnedIfAKnownExtensionIsRecognisedAndTheFileExists(string extension)
        {
            var mockFileSystemhelper = new Mock<IFileSystemHelper>();
            mockFileSystemhelper.Setup(f => f.FileExists(It.IsAny<string>())).Returns(true);

            var factory = new FileConverterFactory(mockFileSystemhelper.Object);

            Assert.NotNull(factory.ParseFile("abc" + extension));
        }
Ejemplo n.º 5
0
        private void On_Load()
        {
            _tunes = new List<Tune>();

            //var p = new Project { TuneFilenames = new[] { "abc", "def" } };
            //string x = JsonConvert.SerializeObject(p);

            var fileConverterFactory = new FileConverterFactory(new FileSystemHelper());

            try
            {
                var project = Project.OpenProject(Path.Combine(Directory.GetCurrentDirectory(), "TestProject"));

                foreach (var fileName in project.TuneFilenames)
                {
                    var metaDataPath = Path.Combine(project.WorkingFolder, "MetaData");
                    Directory.CreateDirectory(metaDataPath);

                    var tunePath = Path.Combine(project.WorkingFolder, fileName);

                    var rawTunePath = Path.ChangeExtension(Path.Combine(metaDataPath, fileName), "m6raw");
                    var summaryPath = Path.ChangeExtension(Path.Combine(metaDataPath, fileName), "summary");

                    IFileConverter converter;
                    if ((converter = fileConverterFactory.ParseFile(rawTunePath)) == null)
                    {
                        converter = fileConverterFactory.ParseFile(tunePath);
                    }
                    if (converter == null) continue;

                    var waveData = converter.ProcessFile();
                    if (waveData == null) continue;

                    if (!File.Exists(rawTunePath))
                    {
                        try
                        {
                            using (var rawFile = File.Create(rawTunePath))
                            {
                                Serializer.Serialize(rawFile, waveData);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }

                    var tune = new Tune(waveData);

                    SummaryCollection summaryData = null;
                    try
                    {
                        using (var summaryFile = File.OpenRead(summaryPath))
                        {
                            summaryData = Serializer.Deserialize<SummaryCollection>(summaryFile);
                        }

                        tune.SummaryCollection = summaryData;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }

                    if (summaryData == null)
                    {
                        tune.BuildSummaries();
                        try
                        {
                            using (var summaryFile = File.Create(summaryPath))
                            {
                                Serializer.Serialize(summaryFile, tune.SummaryCollection);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }

                    tune.StartTick = 0;
                    tune.Track = _tunes.Count;

                    _tunes.Add(tune);
                }

                _delta = new Delta();

                _ticksPerPixel = 1024;

                _bbBitmap = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);

                _desktopRange = new Range(0, ClientRectangle.Width*_ticksPerPixel);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }