public void NoJsonFileThrowsException()
 {
     _fileSystem.DeleteFile("AutoRest.json");
     AssertThrows<CodeGenerationException>(() => ExtensionsLoader.GetCodeGenerator
         (new Settings {CodeGenerator = "JavaScript", FileSystem = _fileSystem}),
         "AutoRest.json was not found in the current directory");
 }
Beispiel #2
0
        internal static MemoryFileSystem GenerateCodeInto(this string inputFile, MemoryFileSystem fileSystem, Settings settings)
        {
            string fileName = Path.GetFileName(inputFile);

            // If inputFile does not contain a path use the local Resource folder
            if (inputFile == fileName)
            {
                fileSystem.Copy(Path.Combine("Resource", inputFile));
            }
            else
            {
                fileSystem.Copy(inputFile);
            }

            settings.Input = fileName;

            var codeGenerator = new CSharpCodeGenerator(settings);
            var modeler       = ExtensionsLoader.GetModeler(settings);
            var sc            = modeler.Build();

            codeGenerator.NormalizeClientModel(sc);
            codeGenerator.Generate(sc).GetAwaiter().GetResult();

            return(fileSystem);
        }
Beispiel #3
0
        static private bool Process(string filePath, string[] outputExtensions)
        {
            string workingDirectory = Directory.GetCurrentDirectory();

            string rootedFilePath = Path.IsPathRooted(filePath) ? filePath : Path.Combine(workingDirectory, filePath);
            var    file           = new FileInfo(rootedFilePath);

            if (!file.Exists)
            {
                System.Console.WriteLine($"Error: {file.FullName} not found !");
                return(false);
            }

            var converter = new DastFileConverter();

            ExtensionsLoader.FromAssemblies(GetAssemblies(), converter);

            Stopwatch stopWatch = Stopwatch.StartNew();

            converter.Convert(rootedFilePath, workingDirectory, outputExtensions);

            stopWatch.Stop();
            System.Console.WriteLine(stopWatch.Elapsed.TotalSeconds);

            return(true);
        }
Beispiel #4
0
        private static void GenerateCodeInto(Action <IEnumerable <LogMessage> > processMessages)
        {
            using (NewContext)
            {
                var plugin   = ExtensionsLoader.GetPlugin();
                var modeler  = ExtensionsLoader.GetModeler();
                var messages = new List <LogMessage>();
                Logger.Instance.AddListener(new SignalingLogListener(Category.Info, message => messages.Add(message)));
                try
                {
                    var codeModel = modeler.Build();

                    using (plugin.Activate())
                    {
                        // load model into language-specific code model
                        codeModel = plugin.Serializer.Load(codeModel);

                        // apply language-specific tranformation (more than just language-specific types)
                        // used to be called "NormalizeClientModel" .
                        codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                        // Generate code from CodeModel.
                        plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
                    }
                }
                finally
                {
                    processMessages(messages);
                }
            }
        }
        public void TestParameterizedHostFromSwagger()
        {
            var settings = new Settings
            {
                Namespace     = "Test",
                Modeler       = "Swagger",
                CodeGenerator = "CSharp",
                Input         = Path.Combine("Swagger", "swagger-x-ms-parameterized-host.json"),
                Header        = "NONE"
            };

            var modeler = ExtensionsLoader.GetModeler(settings);
            var client  = modeler.Build();

            var hostExtension = client.Extensions["x-ms-parameterized-host"] as JObject;

            Assert.NotNull(hostExtension);

            var hostTemplate     = (string)hostExtension["hostTemplate"];
            var jArrayParameters = hostExtension["parameters"] as JArray;

            Assert.NotNull(jArrayParameters);

            Assert.Equal(2, jArrayParameters.Count);
            Assert.Equal("{accountName}.{host}", hostTemplate);
        }
        public void InvalidTypeThrowsException()
        {
            using (NewContext)
            {
                _fileSystem.WriteFile("AutoRest.json",
                                      File.ReadAllText(Path.Combine("Resource", "AutoRestWithInvalidType.json")));

                new Settings {
                    CodeGenerator = "CSharp", FileSystem = _fileSystem
                };

                AssertThrows <CodeGenerationException>(
                    () => ExtensionsLoader.GetPlugin(),
                    "Plugin CSharp does not have an assembly name in AutoRest.json");
            }

            using (NewContext)
            {
                new Settings {
                    CodeGenerator = "Java", FileSystem = _fileSystem
                };
                AssertThrows <CodeGenerationException>(() => ExtensionsLoader.GetPlugin(),
                                                       "Plugin Java does not have an assembly name in AutoRest.json");
            }
        }
 public void InvalidModelerNameThrowsException()
 {
     string modeler = "Foo.Bar";
     AssertThrows<CodeGenerationException>(
         () => ExtensionsLoader.GetModeler(new Settings {Modeler = modeler, FileSystem = _fileSystem}),
         string.Format("Plugin {0} does not have an assembly name in AutoRest.json", modeler));
 }
Beispiel #8
0
        /// <summary>
        /// Generates client using provided settings.
        /// </summary>
        /// <param name="settings">Code generator settings.</param>
        public static void Generate(Settings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            Logger.Entries.Clear();
            Logger.LogInfo(Resources.AutoRestCore, Version);
            CodeGenerator codeGenerator = ExtensionsLoader.GetCodeGenerator(settings);
            Modeler       modeler       = ExtensionsLoader.GetModeler(settings);

            settings.Validate();
            ServiceClient serviceClient;

            try
            {
                serviceClient = modeler.Build();
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorGeneratingClientModel, exception.Message);
            }
            try
            {
                codeGenerator.NormalizeClientModel(serviceClient);
                codeGenerator.Generate(serviceClient).GetAwaiter().GetResult();
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorSavingGeneratedCode, exception.Message);
            }
        }
        public void ModelerLoadsFromJsonFile()
        {
            var settings = new Settings {Modeler = "Swagger", Input = "RedisResource.json", FileSystem = _fileSystem};
            Modeler modeler = ExtensionsLoader.GetModeler(settings);

            Assert.Equal("Swagger", modeler.Name);
        }
        public void LanguageLoadsFromJsonFile()
        {
            var settings = new Settings {CodeGenerator = "CSharp", FileSystem = _fileSystem};
            CodeGenerator language = ExtensionsLoader.GetCodeGenerator(settings);

            Assert.Equal("CSharp", language.Name);
        }
Beispiel #11
0
        public void LanguageWithoutSettingsLoadsFromJsonFile()
        {
            CodeGenerator language =
                ExtensionsLoader.GetCodeGenerator(new Settings {
                CodeGenerator = "CSharp", FileSystem = _fileSystem
            });

            Assert.Equal("CSharp", language.Name);
        }
        public void NullOrEmptyAutoRestSettings()
        {
            Assert.Throws<ArgumentNullException>(() => ExtensionsLoader.GetCodeGenerator(null));
            Assert.Throws<ArgumentException>(() => ExtensionsLoader.GetCodeGenerator(
                new Settings {CodeGenerator = string.Empty, FileSystem = _fileSystem}));

            Assert.Throws<ArgumentNullException>(() => ExtensionsLoader.GetModeler(null));
            Assert.Throws<ArgumentException>(() => ExtensionsLoader.GetModeler(
                new Settings {Modeler = string.Empty, FileSystem = _fileSystem}));
        }
Beispiel #13
0
    protected override async Task <bool> ProcessInternal()
    {
        var codeGenerator = await GetValue("codeGenerator");

        // build settings
        new Settings
        {
            Namespace  = await GetValue("namespace"),
            ClientName = await GetValue("clientNameOverride"),
            PayloadFlatteningThreshold = await GetValue <int>("payloadFlatteningThreshold"),
            AddCredentials             = await GetValue <bool>("addCredentials"),
        };
        var header = await GetValue("header");

        if (header != null)
        {
            Settings.Instance.Header = header;
        }
        Settings.Instance.CustomSettings.Add("InternalConstructors", await GetValue <bool>("internalConstructors"));
        Settings.Instance.CustomSettings.Add("SyncMethods", await GetValue <string>("syncMethods"));
        Settings.Instance.CustomSettings.Add("UseDateTimeOffset", await GetValue <bool>("useDateTimeOffset"));
        if (codeGenerator.EndsWith("Ruby"))
        {
            Settings.Instance.PackageName = await GetValue("rubyPackageName");
        }

        // process
        var files = await ListInputs();

        if (files.Length != 1)
        {
            return(false);
        }

        var plugin      = ExtensionsLoader.GetPlugin(codeGenerator);
        var modelAsJson = (await ReadFile(files[0])).EnsureYamlIsJson();

        using (plugin.Activate())
        {
            var codeModel = plugin.Serializer.Load(modelAsJson);
            codeModel = plugin.Transformer.TransformCodeModel(codeModel);
            plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
        }

        // write out files
        var outFS    = Settings.Instance.FileSystemOutput;
        var outFiles = outFS.GetFiles("", "*", System.IO.SearchOption.AllDirectories);

        foreach (var outFile in outFiles)
        {
            WriteFile(outFile, outFS.ReadAllText(outFile), null);
        }

        return(true);
    }
Beispiel #14
0
        internal static MemoryFileSystem GenerateCodeInto(this string testName, MemoryFileSystem fileSystem, Settings settings)
        {
            // copy the whole input directory into the memoryfilesystem.
            fileSystem.CopyFolder("Resource", testName, "");

            // find the appropriately named .yaml or .json file for the swagger.
            foreach (var ext in new[] { ".yaml", ".json", ".md" })
            {
                var name = testName + ext;
                if (fileSystem.FileExists(name))
                {
                    settings.Input = name;
                }
            }

            if (string.IsNullOrWhiteSpace(settings.Input))
            {
                throw new Exception($"Can't find swagger file ${testName} [.yaml] [.json] [.md]");
            }

            var plugin    = ExtensionsLoader.GetPlugin();
            var modeler   = ExtensionsLoader.GetModeler();
            var codeModel = modeler.Build();

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.AfterModelCreation, codeModel);

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.BeforeLoadingLanguageSpecificModel, codeModel);

            using (plugin.Activate())
            {
                // load model into language-specific code model
                codeModel = plugin.Serializer.Load(codeModel);

                // we've loaded the model, run the extensions for after it's loaded
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLoadingLanguageSpecificModel, codeModel);

                // apply language-specific tranformation (more than just language-specific types)
                // used to be called "NormalizeClientModel" .
                codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLanguageSpecificTransform, codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.BeforeGeneratingCode, codeModel);

                // Generate code from CodeModel.
                plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
            }

            return(fileSystem);
        }
Beispiel #15
0
 public void then_all_custom_implementations_should_be_loaded()
 {
     using (var domain = new DisposableDomain())
     {
         domain.DoCallBack(() =>
         {
             var sut = new ExtensionsLoader();
             Assert.IsTrue(sut.FormatterElements.Any(s => s.Value.GetType().FullName == "Test.TestFormatterElement"));
         });
     }
 }
 public void InvalidLanguageNameThrowsException()
 {
     string codeGenerator = "Foo.Bar";
     AssertThrows<CodeGenerationException>(
         () =>
             ExtensionsLoader.GetCodeGenerator(new Settings
             {
                 CodeGenerator = codeGenerator,
                 FileSystem = _fileSystem
             }),
         string.Format("Plugin {0} does not have an assembly name in AutoRest.json", codeGenerator));
 }
        public void InvalidTypeThrowsException()
        {
            _fileSystem.WriteFile("AutoRest.json", File.ReadAllText(Path.Combine("Resource", "AutoRestWithInvalidType.json")));

            AssertThrows<CodeGenerationException>(() => ExtensionsLoader.GetCodeGenerator
                (new Settings {CodeGenerator = "CSharp", FileSystem = _fileSystem}),
                string.Format("Error loading {0} assembly", "CSharp"));

            AssertThrows<CodeGenerationException>(() => ExtensionsLoader.GetCodeGenerator
                (new Settings {CodeGenerator = "Java", FileSystem = _fileSystem}),
                string.Format("Error loading {0} assembly", "Java"));
        }
        public void LanguageWithoutSettingsLoadsFromJsonFile()
        {
            using (NewContext)
            {
                var settings = new Settings {
                    CodeGenerator = "CSharp", FileSystem = _fileSystem
                };

                var language = ExtensionsLoader.GetPlugin();
                Assert.Equal("CSharp", language.Settings.Name);
            }
        }
        public void InvalidJsonFileThrowsException()
        {
            _fileSystem.WriteFile("AutoRest.json", "{'foo': 'bar'}");
            AssertThrows<CodeGenerationException>(() => ExtensionsLoader.GetCodeGenerator
                (new Settings {CodeGenerator = "JavaScript", FileSystem = _fileSystem}),
                string.Format("Plugin {0} does not have an assembly name in AutoRest.json", "JavaScript"));

            _fileSystem.WriteFile("AutoRest.json", "{'foo': ");
            AssertThrows<CodeGenerationException>(() => ExtensionsLoader.GetCodeGenerator
                (new Settings {CodeGenerator = "JavaScript", FileSystem = _fileSystem}),
                "Error parsing AutoRest.json file");
        }
Beispiel #20
0
 public void InvalidModelerNameThrowsException()
 {
     using (NewContext)
     {
         string modeler  = "Foo.Bar";
         var    settings = new Settings {
             Modeler = modeler, FileSystem = _fileSystem
         };
         AssertThrows <CodeGenerationException>(
             () => ExtensionsLoader.GetModeler(),
             string.Format("Plugin {0} not found", modeler));
     }
 }
Beispiel #21
0
        internal static MemoryFileSystem GenerateCodeInto(this string inputFile, MemoryFileSystem fileSystem, Settings settings)
        {
            string fileName = Path.GetFileName(inputFile);

            // If inputFile does not contain a path use the local Resource folder
            if (inputFile == fileName)
            {
                fileSystem.Copy(Path.Combine("Resource", inputFile));
            }
            else
            {
                fileSystem.Copy(inputFile);
            }

            settings.Input = fileName;


            var plugin    = ExtensionsLoader.GetPlugin();
            var modeler   = ExtensionsLoader.GetModeler();
            var codeModel = modeler.Build();

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.AfterModelCreation, codeModel);

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.BeforeLoadingLanguageSpecificModel, codeModel);

            using (plugin.Activate())
            {
                // load model into language-specific code model
                codeModel = plugin.Serializer.Load(codeModel);

                // we've loaded the model, run the extensions for after it's loaded
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLoadingLanguageSpecificModel, codeModel);

                // apply language-specific tranformation (more than just language-specific types)
                // used to be called "NormalizeClientModel" .
                codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLanguageSpecificTransform, codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.BeforeGeneratingCode, codeModel);

                // Generate code from CodeModel.
                plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
            }

            return(fileSystem);
        }
Beispiel #22
0
        /// <summary>
        /// Generates client using provided settings.
        /// </summary>
        /// <param name="settings">Code generator settings.</param>
        public static void Generate(Settings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            Logger.Entries.Clear();
            Logger.LogInfo(Resources.AutoRestCore, Version);
            Modeler       modeler       = ExtensionsLoader.GetModeler(settings);
            ServiceClient serviceClient = null;

            IEnumerable <ValidationMessage> messages = new List <ValidationMessage>();

            try
            {
                serviceClient = modeler.Build(out messages);
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorGeneratingClientModel, exception.Message);
            }
            finally
            {
                // Make sure to log any validation messages
                foreach (var message in messages)
                {
                    Logger.Entries.Add(new LogEntry(message.Severity, message.ToString()));
                }
                if (messages.Any(entry => entry.Severity >= settings.ValidationLevel))
                {
                    throw ErrorManager.CreateError(null, Resources.ErrorGeneratingClientModel, Resources.CodeGenerationError);
                }
            }

            CodeGenerator codeGenerator = ExtensionsLoader.GetCodeGenerator(settings);

            Logger.WriteOutput(codeGenerator.UsageInstructions);

            settings.Validate();
            try
            {
                codeGenerator.NormalizeClientModel(serviceClient);
                codeGenerator.Generate(serviceClient).GetAwaiter().GetResult();
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorSavingGeneratedCode, exception.Message);
            }
        }
Beispiel #23
0
        public void LanguageWithSettingsLoadsFromJsonFile()
        {
            var settings = new Settings
            {
                CodeGenerator   = "NodeJS",
                FileSystem      = _fileSystem,
                Input           = "X:\\RedisResource.json",
                OutputDirectory = "X:\\Output"
            };
            CodeGenerator language = ExtensionsLoader.GetCodeGenerator(settings);

            settings.Validate();

            Assert.Equal("NodeJS", language.Name);
        }
        public void InvalidLanguageNameThrowsException()
        {
            using (NewContext)
            {
                string codeGenerator = "Foo.Bar";
                var    settings      = new Settings
                {
                    CodeGenerator = codeGenerator,
                    FileSystem    = _fileSystem
                };


                AssertThrows <CodeGenerationException>(
                    () => ExtensionsLoader.GetPlugin(),
                    $"Plugin {codeGenerator} does not have an assembly name in AutoRest.json");
            }
        }
 public void NullOrEmptyAutoRestSettings()
 {
     using (NewContext)
     {
         var settings = new Settings {
             CodeGenerator = string.Empty, FileSystem = _fileSystem
         };
         Assert.Throws <ArgumentException>(() => ExtensionsLoader.GetPlugin());
     }
     using (NewContext)
     {
         var settings = new Settings {
             Modeler = string.Empty, FileSystem = _fileSystem
         };
         Assert.Throws <ArgumentException>(() => ExtensionsLoader.GetModeler());
     }
 }
Beispiel #26
0
        private static void GenerateCodeInto(Action <IEnumerable <LogMessage> > processMessages)
        {
            using (NewContext)
            {
                var plugin   = ExtensionsLoader.GetPlugin();
                var modeler  = ExtensionsLoader.GetModeler();
                var messages = new List <LogMessage>();
                Logger.Instance.AddListener(new SignalingLogListener(Category.Info, message => messages.Add(message)));
                try
                {
                    var codeModel = modeler.Build();

                    // After swagger Parser
                    codeModel = AutoRestController.RunExtensions(Trigger.AfterModelCreation, codeModel);

                    // After swagger Parser
                    codeModel = AutoRestController.RunExtensions(Trigger.BeforeLoadingLanguageSpecificModel, codeModel);

                    using (plugin.Activate())
                    {
                        // load model into language-specific code model
                        codeModel = plugin.Serializer.Load(codeModel);

                        // we've loaded the model, run the extensions for after it's loaded
                        codeModel = AutoRestController.RunExtensions(Trigger.AfterLoadingLanguageSpecificModel, codeModel);

                        // apply language-specific tranformation (more than just language-specific types)
                        // used to be called "NormalizeClientModel" .
                        codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                        // next set of extensions
                        codeModel = AutoRestController.RunExtensions(Trigger.AfterLanguageSpecificTransform, codeModel);

                        // next set of extensions
                        codeModel = AutoRestController.RunExtensions(Trigger.BeforeGeneratingCode, codeModel);

                        // Generate code from CodeModel.
                        plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
                    }
                }
                finally
                {
                    processMessages(messages);
                }
            }
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            ExtensionsLoader loader = new ExtensionsLoader();

            loader.ImportPlugins();

            System.Console.WriteLine(string.Format("{0} plugins are loaded", loader.NumberOfImportedOperations));

            var result = loader.CallImportedPlugins("Mef Plugins example ", "Plugins");

            foreach (string item in result)
            {
                System.Console.WriteLine(item);
            }

            Console.ReadKey();
        }
        public void TestSettingsFromSwagger()
        {
            var settings = new Settings
            {
                Namespace = "Test",
                Modeler = "Swagger",
                CodeGenerator = "CSharp",
                Input = Path.Combine("Swagger", "swagger-x-ms-code-generation-settings.json"),
                Header = "NONE"
            };
            var modeler = ExtensionsLoader.GetModeler(settings);
            var client = modeler.Build();
            var codeGenerator = ExtensionsLoader.GetCodeGenerator(settings) as CSharpCodeGenerator;
            settings.Validate();

            Assert.Equal("MIT", settings.Header);
            Assert.Equal(true, codeGenerator.InternalConstructors);
        }
Beispiel #29
0
        internal static MemoryFileSystem GenerateCodeInto(this string inputDir, MemoryFileSystem fileSystem, Settings settings)
        {
            fileSystem.Copy(Path.Combine("Resource", inputDir));
            var fileExt = (File.Exists(Path.Combine("Resource", Path.Combine(inputDir, inputDir + ".yaml"))) ? ".yaml" : ".json");

            settings.Input = Path.Combine("Resource", Path.Combine(inputDir, inputDir + fileExt));


            var plugin    = ExtensionsLoader.GetPlugin();
            var modeler   = ExtensionsLoader.GetModeler();
            var codeModel = modeler.Build();

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.AfterModelCreation, codeModel);

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.BeforeLoadingLanguageSpecificModel, codeModel);

            using (plugin.Activate())
            {
                // load model into language-specific code model
                codeModel = plugin.Serializer.Load(codeModel);

                // we've loaded the model, run the extensions for after it's loaded
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLoadingLanguageSpecificModel, codeModel);

                // apply language-specific tranformation (more than just language-specific types)
                // used to be called "NormalizeClientModel" .
                codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLanguageSpecificTransform, codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.BeforeGeneratingCode, codeModel);

                // Generate code from CodeModel.
                plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
            }

            return(fileSystem);
        }
        /// <summary>
        /// Creates an instance of the <see cref="AgentManager"/> class./>
        /// </summary>
        /// <remarks>
        /// The agent should be constructed as early as possible in order to perform
        /// initialization of the logging system.
        /// </remarks>
        private AgentManager()
        {
            _container = AgentServices.GetContainer();
            AgentServices.RegisterServices(_container);

            // Resolve IConfigurationService (so that it starts listening to config changes) before loading newrelic.config
            _container.Resolve <IConfigurationService>();
            var config = ConfigurationLoader.Initialize();

            LoggerBootstrapper.ConfigureLogger(config.LogConfig);

            AssertAgentEnabled(config);

            EventBus <KillAgentEvent> .Subscribe(OnShutdownAgent);

            //Initialize the extensions loader with extensions folder based on the the install path
            ExtensionsLoader.Initialize(AgentInstallConfiguration.InstallPathExtensionsDirectory);

            // Resolve all services once we've ensured that the agent is enabled
            // The AgentApiImplementation needs to be resolved before the WrapperService, because
            // resolving the WrapperService triggers an agent connect but it doesn't instantiate
            // the CustomEventAggregator, so we need to resolve the AgentApiImplementation to
            // get the CustomEventAggregator instantiated before the connect process is triggered.
            // If that doesn't happen the CustomEventAggregator will not start its harvest timer
            // when the agent connect response comes back. The agent DI, startup, and connect
            // process really needs to be refactored so that it's more explicit in its behavior.
            var agentApi = _container.Resolve <IAgentApi>();

            _wrapperService = _container.Resolve <IWrapperService>();

            //We need to attempt to auto start the agent once all services have resolved
            _container.Resolve <IConnectionManager>().AttemptAutoStart();

            AgentServices.StartServices(_container);

            // Setup the internal API first so that AgentApi can use it.
            InternalApi.SetAgentApiImplementation(agentApi);
            AgentApi.SetSupportabilityMetricCounters(_container.Resolve <IApiSupportabilityMetricCounters>());

            Initialize();
            _isInitialized = true;
        }