Ejemplo n.º 1
0
 public void Reload()
 {
     if (!canReload)
     {
         throw new InvalidOperationException();
     }
     endpointCollection = EndpointCollectionReader.ReadFromDirectory(directory);
     reloadTimestamps.Add(DateTime.Now);
 }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback =
                ((sender, certificate, chain, sslPolicyErrors) => true);

            ParsedCommandLine parsedArguments;

            try
            {
                parsedArguments = CommandLineParser.ParseArguments(args);
            }
            catch (CommandLineParsingException clpe)
            {
                Error.WriteLine($"ERROR: {clpe.Message}");
                return;
            }

            Debug.Assert(Directory.Exists(parsedArguments.EndpointCollectionDirectory));
            var endpointCollection = EndpointCollectionReader.ReadFromDirectory(parsedArguments.EndpointCollectionDirectory);

            if (parsedArguments.Command != CommandLineParser.COMMAND_SERVICE)
            {
                SetUtf8OutputEncodingIfOutputIsRedirected();
            }

            switch (parsedArguments.Command)
            {
            case CommandLineParser.COMMAND_NORMAL:
                WriteLine("Admin interface available on /__netmockery");
                Startup.TestMode = parsedArguments.TestMode;
                CreateWebHost(parsedArguments.EndpointCollectionDirectory, Directory.GetCurrentDirectory(), parsedArguments.Url).Run();
                break;

            case CommandLineParser.COMMAND_SERVICE:
                RunAsService(parsedArguments);
                break;

            case CommandLineParser.COMMAND_TEST:
                Test(parsedArguments, endpointCollection);
                break;

            case CommandLineParser.COMMAND_DUMP:
                Dump(endpointCollection);
                break;
            }
        }
Ejemplo n.º 3
0
        public static async Task MainAsync(string[] args, CancellationToken token)
        {
            WriteLine($"Netmockery v {NetmockeryVersion} ({FrameworkVersion})");

#if NET462
            System.Net.ServicePointManager.ServerCertificateValidationCallback =
                ((sender, certificate, chain, sslPolicyErrors) => true);
#endif
            ParsedCommandLine parsedArguments;
            try
            {
                parsedArguments = CommandLineParser.ParseArguments(args);
            }
            catch (CommandLineParsingException clpe)
            {
                Error.WriteLine($"ERROR: {clpe.Message}");
                return;
            }

            if (!Directory.Exists(parsedArguments.EndpointCollectionDirectory))
            {
                Error.WriteLine("Directory not found");
                return;
            }

            var endpointCollection = EndpointCollectionReader.ReadFromDirectory(parsedArguments.EndpointCollectionDirectory);

            if (parsedArguments.Command != CommandLineParser.COMMAND_SERVICE)
            {
                SetUtf8OutputEncodingIfOutputIsRedirected();
            }

            switch (parsedArguments.Command)
            {
            case CommandLineParser.COMMAND_NORMAL:
                if (endpointCollection.Endpoints.Count() == 0)
                {
                    Error.WriteLine("No endpoints found");
                    return;
                }
                WriteLine("Admin interface available on /__netmockery");
                Startup.TestMode = parsedArguments.TestMode;
                CreateWebHost(parsedArguments.EndpointCollectionDirectory, Directory.GetCurrentDirectory(), parsedArguments.Url).Run();
                break;

            case CommandLineParser.COMMAND_SERVICE:
                RunAsService(parsedArguments);
                break;

            case CommandLineParser.COMMAND_TEST:
                await TestAsync(parsedArguments, endpointCollection);

                break;

            case CommandLineParser.COMMAND_DUMP:
                Dump(endpointCollection);
                break;

            case CommandLineParser.COMMAND_DUMPREFS:
                foreach (var metadataReference in DynamicResponseCreatorBase.GetDefaultMetadataReferences())
                {
                    Console.WriteLine(metadataReference.Display);
                }
                break;
            }
        }