示例#1
0
        public async Task ValidSettings_VerifyFile(string settingsFile, string expectedSha256Hash)
        {
            var sha256 = SHA256.Create();

            await using var memoryStream = new MemoryStream();
            var settings = await SettingsLoader.LoadAndValidateSettings(settingsFile);

            var container = DependencyConfig.ConfigureContainer(settings, c =>
            {
                c.AddInstance <IProgressReporter>(new XUnitProgressReporter(testOutputHelper));
                c.AddTransient <IOutputDirectoryProvider, CurrentDirectoryProvider>();
            });

            var mp3Stream = container.Resolve <Mp3Stream>();
            await mp3Stream.Write(memoryStream);

            await memoryStream.FlushAsync();

            memoryStream.Seek(0, SeekOrigin.Begin);

            var hash       = sha256.ComputeHash(memoryStream);
            var hashString = BitConverter.ToString(hash).Replace("-", "").ToUpperInvariant();

            if (expectedSha256Hash != hashString)
            {
                memoryStream.Seek(0, SeekOrigin.Begin);
                await using var fileStream = new FileStream(settingsFile + ".mp3", FileMode.Create, FileAccess.Write);
                await memoryStream.CopyToAsync(fileStream);
            }
            Assert.Equal(expectedSha256Hash.Length, hashString.Length);
            Assert.Equal(expectedSha256Hash, hashString);
        }
 public IContainer GetFullFeatureContainer(SettingsCommon settings) => DependencyConfig.ConfigureContainer(settings, a =>
 {
     a.AddTransient <IProgressReporter, WebProgressReporter>();
     a.AddTransient <IJobProgressProvider, JobProgressProvider>();
     a.AddTransient <Ultimate.ORM.IObjectMapper, Ultimate.ORM.ObjectMapper>();
     a.AddInstance <IConfiguration>(configuration);
     a.AddInstance <ILoggerFactory>(loggerProvider);
     a.AddTransient <IOutputDirectoryProvider, WebOutputDirectoryProvider>();
 });
        public async Task Mp3ToFile()
        {
            var settings = await SettingsLoader.LoadAndValidateSettings("Settings_FrequencyLinked.json");

            var container = DependencyConfig.ConfigureContainer(settings, c =>
            {
                c.AddInstance <IProgressReporter>(new XUnitProgressReporter(testOutputHelper));
                c.AddTransient <IOutputDirectoryProvider, CurrentDirectoryProvider>();
            });

            var mp3Stream = container.Resolve <Mp3Stream>();
            await mp3Stream.Write("TestFile.mp3");
        }
示例#4
0
        public static async Task Main(string[] allArgs)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                string[] options = allArgs.Where(a => a.StartsWith("--")).Select(a => a.Substring(2)).ToArray();
                string[] args    = allArgs.Where(a => !a.StartsWith("--")).ToArray();
                acceptName = options.Contains("acceptName", StringComparer.CurrentCultureIgnoreCase);

                if (args.Length == 0)
                {
                    await Console.Out.WriteLineAsync($"No settings file passed.\nPlease copy and modify one of the example settings files to <name>.settings.json, then pass the modified file to the program on the command line.");
                }
                else if (args.Length > 2)
                {
                    throw new InvalidOperationException($"Too many files passed. Please only pass one file.");
                }
                else
                {
                    var filePath = args.Single();
                    var settings = await SettingsLoader.LoadAndValidateSettings(filePath);

                    var container = DependencyConfig.ConfigureContainer(settings, c =>
                    {
                        c.AddTransient <IOutputDirectoryProvider, CurrentDirectoryProvider>();
                        c.AddInstance <IProgressReporter>(new ConsoleProgressReporter());
                    });

                    var name = await GetName(settings);

                    Console.WriteLine($"Writing {name}...");

                    await WriteFile(container, settings, name);

                    stopwatch.Stop();
                    ConsoleWriter.WriteLine($"File successfully created in {stopwatch.Elapsed}", ConsoleColor.Green);
                }
            }
            catch (Exception ex)
            {
                var exceptionToReport = (ex.GetBaseException() as WaveGeneratorException) ?? ex;
                ConsoleWriter.WriteLine(exceptionToReport.Message, ConsoleColor.Red);
                Console.WriteLine();
                Console.WriteLine($"If the program will not accept the settings file you are using, please go to https://github.com/originalhedonist/waves_dotnet/issues and create an issue, attaching the file, and/or email [email protected], and I will convert the file into a format that can be read by the current version of the program for you. ");
            }
        }