public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationContext>(options => { options.UseNpgsql(Configuration.GetConnectionString("Default"), m => { m.MigrationsAssembly("Infrastructure"); m.UseNodaTime(); }); }); services.AddControllers().AddFluentValidation(options => { options.RegisterValidatorsFromAssemblyContaining <Startup>(); options.ValidatorFactoryType = typeof(HttpContextServiceProviderValidatorFactory); });; services.AddAutoMapper(typeof(Startup)); ServiceInit.InitializeServices(services); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Web", Version = "v1" }); c.AddFluentValidationRules(); }); }
public ActionResult InitPost(ServiceInit payload) { if (String.IsNullOrEmpty(payload.BadgeNbr)) { payload.Status = "Error - Badge nbr can't be empty!"; payload.Links = null; return(new HttpStatusCodeResult(400, payload.Status)); } var badgeService = TenantFactory.Create <IRepository <Badge, string> >(); var badge = badgeService.GetBy(n => n.Nbr == payload.BadgeNbr); if (badge == null) { payload.Status = String.Format("Badge with number {0} not found!", payload.BadgeNbr); payload.Links = null; return(new HttpStatusCodeResult(404, payload.Status)); } payload.Status = badge.IsActive ? "Activate" : "Declare"; payload.Links = new[] { new Link { Href = _serviceHelper.Root + payload.Status + "/" + payload.BadgeNbr } }; string result = Serialize(payload); return(Content(result, "text/xml", Encoding.UTF8)); }
public void Execute(IJobExecutionContext context) { var configurationByserviceKey = ServiceHelper.ConfigurationByserviceKey; foreach (var serviceKey in configurationByserviceKey.Keys.ToArray()) { try { var serviceStateInfo = ServiceHelper.ServiceStateInfoByServuceKey[serviceKey]; if (serviceStateInfo.ServiceState != ServiceStateEnum.Normal && serviceStateInfo.ServiceState != ServiceStateEnum.Failed) { return; } string msg; var executeState = ServiceHelper.ServiceJobBaseByServiceKey[serviceKey].ActiveTest(out msg); if (executeState == ExecuteStateEnum.Normal) { _log.InfoFormat("服务 [{0}] 心跳测试成功", configurationByserviceKey[serviceKey].ServiceName); ServiceInit.ChangeServiceStateInfo(new ServiceStateInfo() { ServiceState = ServiceStateEnum.Normal }); } if (executeState == ExecuteStateEnum.Failed) { _log.InfoFormat("服务 [{0}] 心跳测试失败", configurationByserviceKey[serviceKey].ServiceName); ServiceInit.ChangeServiceStateInfo(new ServiceStateInfo() { ServiceState = ServiceStateEnum.Failed }); } if (executeState == ExecuteStateEnum.Exception) { throw new Exception(msg); } } catch (Exception ex) { _log.ErrorFormat("服务 [{0}] 心跳测试异常", ex, configurationByserviceKey[serviceKey].ServiceName); ServiceInit.ChangeServiceStateInfo(new ServiceStateInfo() { ExcuteDescription = ex.Message, ServiceState = ServiceStateEnum.Exception }); ServiceInit.UninstallServiceByServiceKey(serviceKey); } finally { if (ServiceHelper.ServiceStateInfoByServuceKey[serviceKey].ServiceState == ServiceStateEnum.Exception) { ServiceInit.ResetStartServiceByServiceKey(serviceKey); } } } }
private string Serialize(ServiceInit request) { using (MemoryStream stream = new MemoryStream()) { _serializer.Serialize(stream, request); return(Encoding.UTF8.GetString(stream.ToArray())); } }
public void Boot() { // Cms.Init(BootFlag.UnitTest,"../../../../UIApp/T2.Cms.WebUI/config/cms.conf"); Cms.Init(BootFlag.UnitTest, "./config/cms.conf"); //读取站点 if (Cms.IsInstalled()) { Cms.RegSites(SiteCacheManager.GetAllSites().ToArray()); } ServiceInit.Initialize(); }
public ContentResult InitGet() { ServiceInit data = new ServiceInit(); data.BadgeNbr = String.Empty; data.Status = "use POST to use the service"; data.Links = new[] { new Link { Href = _serviceHelper.Root + "Init" } }; string result = Serialize(data); return(Content(result, "text/xml")); }
public void Execute(IJobExecutionContext context) { var serviceKey = context.JobDetail.JobDataMap["ServiceKey"] as string; try { var serviceStateInfo = ServiceHelper.ServiceStateInfoByServuceKey[serviceKey]; if (serviceStateInfo.ServiceState != ServiceStateEnum.Normal && serviceStateInfo.ServiceState != ServiceStateEnum.Failed) { return; } string message; var executeState = ServiceHelper.ServiceJobBaseByServiceKey[serviceKey].Execute(out message); if (executeState == ExecuteStateEnum.Normal) { _log.InfoFormat("服务 [{0}] 业务执行成功", serviceStateInfo.ServiceName); } if (executeState == ExecuteStateEnum.Failed) { _log.InfoFormat("服务 [{0}] 业务执行失败", serviceStateInfo.ServiceName); ServiceInit.ChangeServiceStateInfo(new ServiceStateInfo() { ServiceState = ServiceStateEnum.Failed, ExcuteDescription = message }); } if (executeState == ExecuteStateEnum.Exception) { throw new Exception(message); } } catch (Exception ex) { _log.ErrorFormat("服务 [{0}] 执行异常", ex, ServiceHelper.ConfigurationByserviceKey[serviceKey].ServiceName); ServiceInit.ChangeServiceStateInfo(new ServiceStateInfo() { ServiceState = ServiceStateEnum.Exception, ExcuteDescription = ex.Message, ServiceStopTime = DateTime.Now }); ServiceInit.ResetStartServiceByServiceKey(serviceKey); } }
public void Setup() { ServiceInit.Init(ServiceRoles.APIProxy); Exception exception = null; _proxy = new AdsAPIProxy(); bool executeResult = _proxy.Login("luohu", "000000"); token = _proxy.GetUCUser().Token; if (!executeResult) { exception = new Exception("Login failed."); } if (exception != null) { throw exception; } }
public RedirectCallService() { ServiceInit.Initialize(); }
public SendCommandResult SendCommand(SendCommandParam sendCommandParam) { if (sendCommandParam == null) { _log.Info("[SendCommand]:服务调用失败 [sendCommandParam参数不能为null]"); return(new SendCommandResult() { Success = false, Message = "sendCommandParam参数不能为null" }); } if (sendCommandParam.Command == ServiceCommandEnum.Load) { ServiceInit.LoadService(); _log.InfoFormat("[SendCommand]:服务加载成功"); return(new SendCommandResult() { Success = true, Message = "指令执行成功" }); } if (!ServiceHelper.ServiceStateInfoByServuceKey.ContainsKey(sendCommandParam.ServiceKey)) { _log.InfoFormat("[SendCommand] 调用失败,找不到该指定的服务 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"找不到指定ID[{sendCommandParam.ServiceKey}]的服务" }); } var serviceStateInfo = ServiceHelper.ServiceStateInfoByServuceKey[sendCommandParam.ServiceKey]; SendCommandResult sendCommandResult; switch (sendCommandParam.Command) { case ServiceCommandEnum.Start: { if (serviceStateInfo.ServiceState == ServiceStateEnum.Uninstall) { _log.InfoFormat("[SendCommand] 调用失败,该指定的服务已卸载 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]该指定的服务已卸载" }); } if (serviceStateInfo.ServiceState == ServiceStateEnum.Normal || serviceStateInfo.ServiceState == ServiceStateEnum.Failed) { _log.InfoFormat("[SendCommand] 调用失败,该指定的服务已在运行中 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]的服务已在运行中" }); } sendCommandResult = ServiceInit.StartServiceByServiceKey(sendCommandParam.ServiceKey); if (!sendCommandResult.Success) { _log.InfoFormat("[SendCommand] 启动失败 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]的服务启动失败 失败信息:[{sendCommandResult.Message}]" }); } } break; case ServiceCommandEnum.Stop: { if (serviceStateInfo.ServiceState == ServiceStateEnum.Uninstall) { _log.InfoFormat("[SendCommand] 调用失败,该指定的服务已卸载 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]该指定的服务已卸载" }); } if ( serviceStateInfo.ServiceState == ServiceStateEnum.Stopped) { _log.InfoFormat("[SendCommand] 调用失败,该指定的服务未启动 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]的服务未启动" }); } sendCommandResult = ServiceInit.StopServiceByServiceKey(sendCommandParam.ServiceKey); if (!sendCommandResult.Success) { _log.InfoFormat("[SendCommand] 停止失败 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]的服务停止失败 失败信息:[{sendCommandResult.Message}]" }); } } break; case ServiceCommandEnum.ResetStart: { if (serviceStateInfo.ServiceState == ServiceStateEnum.Uninstall) { _log.InfoFormat("[SendCommand] 调用失败,该指定的服务已卸载 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]该指定的服务已卸载" }); } sendCommandResult = ServiceInit.ResetStartServiceByServiceKey(sendCommandParam.ServiceKey); if (!sendCommandResult.Success) { _log.InfoFormat("[SendCommand] 重新启动失败 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]的服务重新启动失败 失败信息:[{sendCommandResult.Message}]" }); } } break; case ServiceCommandEnum.Install: { if (serviceStateInfo.ServiceState != ServiceStateEnum.Uninstall) { _log.InfoFormat("[SendCommand] 调用失败,该指定的服务已安装 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]的服务已被安装" }); } sendCommandResult = ServiceInit.InstallServiceByServiceKey(sendCommandParam.ServiceKey); if (!sendCommandResult.Success) { _log.InfoFormat("[SendCommand] 加载失败 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]的服务安装失败 失败信息:[{sendCommandResult.Message}]" }); } } break; case ServiceCommandEnum.Uninstall: { if (serviceStateInfo.ServiceState == ServiceStateEnum.Uninstall) { _log.InfoFormat("[SendCommand] 调用失败,该指定的服务未被安装 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]的服务未被安装" }); } sendCommandResult = ServiceInit.UninstallServiceByServiceKey(sendCommandParam.ServiceKey); if (!sendCommandResult.Success) { _log.InfoFormat("[SendCommand] 卸载失败 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = false, Message = $"指定ID[{sendCommandParam.ServiceKey}]的服务卸载失败 失败信息:[{sendCommandResult.Message}]" }); } } break; default: return(new SendCommandResult() { Success = false, Message = $"[sendCommandParam.Command]指令不正确" }); } _log.InfoFormat("[SendCommand] 调用成功 [{0}]", sendCommandParam); return(new SendCommandResult() { Success = true, Message = "指令执行成功" }); }