Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();

            services.AddMvcCore(config => {
                //IHttpRequestStreamReaderFactory readerFactory = services.BuildServiceProvider().GetRequiredService<IHttpRequestStreamReaderFactory>();
                //config.ModelBinderProviders.Insert(0, new Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinderProvider(config.InputFormatters, readerFactory));
                //config.ModelBinderProviders.Insert(0, new QueryModelBinderProvider(container));
            })
            .AddViews()
            .AddApiExplorer()
            .AddNewtonsoftJson();
            //.AddCors()

            /*.AddJsonFormatters()
             * .AddJsonOptions(options => {
             *  options.SerializerSettings.Converters.Add(new RequestHandlerConverter<IRequest>(container));
             * });*/

            services.Configure <OWSData.Models.OWSInstanceLauncherOptions>(Configuration.GetSection(OWSData.Models.OWSInstanceLauncherOptions.SectionName));
            services.Configure <OWSShared.Options.APIPathOptions>(Configuration.GetSection(OWSShared.Options.APIPathOptions.SectionName));

            owsInstanceLauncherOptions = new OWSData.Models.OWSInstanceLauncherOptions();
            Configuration.GetSection(OWSData.Models.OWSInstanceLauncherOptions.SectionName).Bind(owsInstanceLauncherOptions);
            var apiPathOptions = new OWSShared.Options.APIPathOptions();

            Configuration.GetSection(OWSShared.Options.APIPathOptions.SectionName).Bind(apiPathOptions);

            services.AddHttpClient("OWSInstanceManagement", c =>
            {
                c.BaseAddress = new Uri(apiPathOptions.InternalInstanceManagementApiURL);
                c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                c.DefaultRequestHeaders.Add("User-Agent", "OWSInstanceLauncher");
                c.DefaultRequestHeaders.Add("X-CustomerGUID", owsInstanceLauncherOptions.OWSAPIKey);
            });

            services.AddSimpleInjector(container, options => {
                options.AddHostedService <TimedHostedService <IInstanceLauncherJob> >();
                options.AddHostedService <TimedHostedService <IServerHealthMonitoringJob> >();
            });

            InitializeContainer(services);
        }
Пример #2
0
        public Startup(IConfiguration configuration)
        {
            container.Options.ResolveUnregisteredConcreteTypes = false;

            Configuration = configuration;

            owsInstanceLauncherOptions = new OWSData.Models.OWSInstanceLauncherOptions();
            Configuration.GetSection(OWSData.Models.OWSInstanceLauncherOptions.SectionName).Bind(owsInstanceLauncherOptions);

            //Check appsettings.json file for potential errors
            bool thereWasAStartupError = false;

            Console.ForegroundColor = ConsoleColor.Red;
            //Abort if there is not a valid OWSAPIKey in appsettings.json
            if (String.IsNullOrEmpty(owsInstanceLauncherOptions.OWSAPIKey))
            {
                thereWasAStartupError = true;
                Console.WriteLine("Please enter a valid OWSAPIKey in appsettings.json!");
            }
            //Abort if there is not a valid PathToDedicatedServer in appsettings.json
            else if (String.IsNullOrEmpty(owsInstanceLauncherOptions.PathToDedicatedServer))
            {
                thereWasAStartupError = true;
                Console.WriteLine("Please enter a valid PathToDedicatedServer in appsettings.json!");
            }
            //Abort if there is not a valid ServerArguments in appsettings.json
            else if (String.IsNullOrEmpty(owsInstanceLauncherOptions.ServerArguments))
            {
                thereWasAStartupError = true;
                Console.WriteLine("Please enter a valid ServerArguments in appsettings.json!");
            }
            //Check that a file exists at PathToDedicatedServer
            else if (!File.Exists(owsInstanceLauncherOptions.PathToDedicatedServer))
            {
                thereWasAStartupError = true;
                Console.WriteLine("Your PathToDedicatedServer in appsettings.json points to a file that does not exist!  Please either point PathToDedicatedServer to your UE4 Editor exe or to your packaged UE4 dedicated server exe!");
            }
            //If using the UE4 editor, make sure there is a project path in Server Arguments
            else if (owsInstanceLauncherOptions.PathToDedicatedServer.Contains("UE4Editor.exe"))
            {
                string          serverArgumentsProjectPattern = @"^"".*.uproject"" ";
                MatchCollection testForUprojectPath           = Regex.Matches(owsInstanceLauncherOptions.ServerArguments, serverArgumentsProjectPattern);
                if (testForUprojectPath.Count == 1)
                {
                    Match  testForUprojectPathMatch    = testForUprojectPath.First();
                    string foundUprojectPath           = testForUprojectPathMatch.Value;
                    string foundUprojectPathToValidate = foundUprojectPath.Trim().Replace("\"", "");

                    if (!File.Exists(foundUprojectPathToValidate))
                    {
                        thereWasAStartupError = true;
                        Console.WriteLine("Your ServerArguments in appsettings.json points to a uproject file that does not exist!");
                    }
                    else if (!owsInstanceLauncherOptions.ServerArguments.Contains("{0}"))
                    {
                        thereWasAStartupError = true;
                        Console.WriteLine("Your ServerArguments in appsettings.json is missing the {0} parameter.  See the sample appsettings.json for proper format!");
                    }
                    else if (!owsInstanceLauncherOptions.ServerArguments.Contains("{1}"))
                    {
                        thereWasAStartupError = true;
                        Console.WriteLine("Your ServerArguments in appsettings.json is missing the {1} parameter.  See the sample appsettings.json for proper format!");
                    }
                }
                else
                {
                    thereWasAStartupError = true;
                    Console.WriteLine("Because you are using UE4Editor.exe, your Server Arguments in appsettings.json must contain a path to the uproject file.  See the sample appsettings.json for proper format!");
                }
            }
            Console.ForegroundColor = ConsoleColor.White;

            //If there was a startup error, don't continue any further.  Wait for shutdown.
            if (thereWasAStartupError)
            {
                Console.WriteLine("Error encountered.  Shutting down...");
                Environment.Exit(-1);
            }
        }