Beispiel #1
0
        private static async Task LoadService(HttpContext context)
        {
            var model = ServiceInfoHelper.ParseRequest(context);

            await serviceBootstrap.LoadService(model);

            await WriteResultAsync(context, serviceBootstrap.ServiceInfo);
        }
 /// <summary>
 /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 /// </summary>
 /// <param name="app"></param>
 /// <param name="env"></param>
 /// <param name="loggerFactory"></param>
 /// <param name="apiExplorer"></param>
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApiDescriptionGroupCollectionProvider apiExplorer)
 {
     app.UseSession();
     ServiceInfoHelper.WriteJs(apiExplorer, FileHandler.GetMapPath(Path.Combine(UpLoadFilePathCode.BaseFileDirectory, "Res")));
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     app.UseSwagger();
     app.UseSwaggerUI(options =>
     {
         options.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
         //如果不想带/swagger路径访问的话,就放开下面的注释
         //options.RoutePrefix = string.Empty;
     });
     app.UseCors("all");
     app.UseMvc();
 }
        public async Task LoadService(ServiceInfo model)
        {
            try
            {
                if (ServiceInfo?.Id == model.Id)
                {
                    return;
                }

                var service = AvaliableServices.FirstOrDefault(s => s.Id == model.Id);
                if (service != null)
                {
                    ServiceInfo = service;
                }
                else
                {
                    var path = Path.Combine(serviceDir,
                                            $"{model.Name}-v{model.Version}{Path.GetExtension(model.ArchiveUrl)}");
                    using (HttpClient client = new HttpClient())
                    {
                        await DownloadFile(client, model.ArchiveUrl, path);
                    }

                    var targetDir = Path.Combine(serviceDir, Path.GetFileNameWithoutExtension(path));
                    Unzip(path, targetDir);
                    File.Delete(path);

                    model.Guid     = Guid.NewGuid();
                    model.LoadedAt = DateTime.Now;
                    model.Location = targetDir;
                    ServiceInfoHelper.Save(Path.Combine(targetDir, "serviceInfo.json"), model);

                    ServiceInfo = model;
                }

                Restart();
            }
            catch (Exception ex)
            {
                throw new Exception("Load service failed.", ex);
            }
        }
        public void Boot(IConsulClient consulClient, ILoggerFactory logerFactory)
        {
            foreach (var dir in Directory.GetDirectories(serviceDir))
            {
                var serviceFilePath = Path.Combine(dir, "serviceInfo.json");
                if (!File.Exists(serviceFilePath))
                {
                    continue;
                }

                AvaliableServices.Add(ServiceInfoHelper.Load(serviceFilePath));
            }

            if (File.Exists(serviceInfoFilePath))
            {
                serviceInfo = ServiceInfoHelper.Load(serviceInfoFilePath);
            }
            else if (AvaliableServices.Count > 0)
            {
                ServiceInfo = AvaliableServices.OrderByDescending(s => s.LoadedAt).First();
            }

            Start(consulClient, logerFactory);
        }
Beispiel #5
0
 public ResultObj <int> GetWebAPIAndModel()
 {
     // ServiceInfoHelper.WriteWebAPI();
     ServiceInfoHelper.WriteWebModels();
     return(Content(1));
 }