public void Error(IJobExecutionContext jobContext, Exception ex) { try { var _context = CastleWindsorService.Resolve <QuartzExecutionContext>(); var job = _context.data.Jobs.FirstOrDefault(x => x.Key == jobContext.JobDetail.Key.Name); if (job != null) { var err = new Error { Message = ex.Message, StackTrace = ex.StackTrace }; if (job.Calls.FirstOrDefault(x => x.FireInstenceID == jobContext.FireInstanceId) != null) { job.Calls.FirstOrDefault(x => x.FireInstenceID == jobContext.FireInstanceId).Error = err; } job.Executing = false; } _context.Commit(); CastleWindsorService.Release(_context); } catch (Exception ex1) { LogsAppendersManager.Instance.Error(this.GetType(), MethodBase.GetCurrentMethod(), "", ex1); } }
public void CallStart(IJobExecutionContext jobContext) { try { var _context = CastleWindsorService.Resolve <QuartzExecutionContext>(); var call = new Call { FireInstenceID = jobContext.FireInstanceId, StartedAt = jobContext.FireTimeUtc.DateTime, NextStart = jobContext.NextFireTimeUtc.HasValue ? jobContext.NextFireTimeUtc.Value.DateTime : DateTime.Parse("01/01/1753"), EndedAt = DateTime.Parse("01/01/1753") }; var job = _context.data.Jobs.FirstOrDefault(x => x.Key == jobContext.JobDetail.Key.Name); if (job == null) { job = new Job { Key = jobContext.JobDetail.Key.Name, Calls = new List <Call>() }; _context.data.Jobs.Add(job); } job.Calls.Add(call); job.Executing = true; job.StartedAt = jobContext.FireTimeUtc.DateTime; _context.Commit(); CastleWindsorService.Release(_context); } catch (Exception ex) { LogsAppendersManager.Instance.Error(this.GetType(), MethodBase.GetCurrentMethod(), "", ex); } }
//CancellationTokenSource fsToken; public IceQuartzScheduler() { InitializeComponent(); CastleWindsorService.Init(); LogsAppendersManager.Instance.Info(this.GetType(), MethodBase.GetCurrentMethod(), "Service inizilization"); _service = CastleWindsorService.Resolve <QuartzService>(); _service.Init(); }
public override void Configure() { var config = Utilities.Config.Sections.LoggerSection.GetConfig(); foreach (var logger in config.Loggers.Cast <LoggerSectionElement>()) { var loggerInstance = CastleWindsorService.Resolve(logger.Type, null); loggers.Add(loggerInstance as ILoggingService); } }
public override void Configure() { var config = LoggerSection.GetConfig(); foreach (var logger in config.Loggers.Cast <LoggerSectionElement>()) { var loggerInstance = CastleWindsorService.Resolve(logger.Type, null); if (loggerInstance.GetType().GetInterface(typeof(IWebApiLogger).Name) != null) { loggers.Add(loggerInstance as IWebApiLogger); } } }
public void Error(IJobExecutionContext jobContext, Exception ex) { try { var httpService = CastleWindsorService.Resolve <HttpComunicationService>(); var err = new Error { Message = ex.Message, StackTrace = ex.StackTrace }; var call = new Call { FireInstenceID = jobContext.FireInstanceId, EndedAt = DateTime.Now, Error = err }; var req = new ApiHttpRequest <Call> { AppID = AppId, AppToken = AppToken, data = call }; LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "Calling API: " + Endpoint + "/Calls/End with body: " + req.Stringify()); var resp = httpService.Post <ApiHttpResponse <HttpDataSingle <bool> > >(Endpoint + "/Calls/End?jobKey=" + GetJobKey(jobContext.JobDetail), AppId, AppToken, false, req); LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "response " + resp.Stringify()); if (resp.Code != System.Net.HttpStatusCode.OK) { throw new HttpCommunicationException(resp.operationResult.Code + " : " + resp.operationResult.Message + " -> " + resp.operationResult.Stack); } else { LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "Http Comunication 'Call Ended with Error' for job" + jobContext.JobDetail.Key.Name + " to Endpoint : " + Endpoint + " exit with code " + resp.Code.ToString() + " returns message " + resp.operationResult.Message); } } catch (Exception ex1) { LogsAppendersManager.Instance.Error(this.GetType(), MethodBase.GetCurrentMethod(), ex.Message, ex1); } }
public void CallEnd(IJobExecutionContext jobContext) { try { var _context = CastleWindsorService.Resolve <QuartzExecutionContext>(); var job = _context.data.Jobs.FirstOrDefault(x => x.Key == jobContext.JobDetail.Key.Name); if (job != null) { if (job.Calls.FirstOrDefault(x => x.FireInstenceID == jobContext.FireInstanceId) != null) { job.Calls.FirstOrDefault(x => x.FireInstenceID == jobContext.FireInstanceId).EndedAt = DateTime.Now; } job.Executing = false; } _context.Commit(); CastleWindsorService.Release(_context); } catch (Exception ex) { LogsAppendersManager.Instance.Error(this.GetType(), MethodBase.GetCurrentMethod(), "", ex); } }
public void AddJob(IJobDetail jobDetail) { try { var httpService = CastleWindsorService.Resolve <HttpComunicationService>(); var job = new Job { Key = GetJobKey(jobDetail), Executing = false, StartedAt = DateTime.Parse("01/01/1753"), Description = jobDetail.Description }; var req = new ApiHttpRequest <Job> { AppID = AppId, AppToken = AppToken, data = job }; LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "Calling API: " + Endpoint + "/Jobs/Add with body: " + req.Stringify()); var resp = httpService.Post <ApiHttpResponse <HttpDataSingle <long> > >(Endpoint + "/Jobs/Add", AppId, AppToken, false, req); LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "response " + resp.Stringify()); if (resp.Code != System.Net.HttpStatusCode.OK) { throw new HttpCommunicationException(resp.operationResult.Code + " : " + resp.operationResult.Message + " -> " + resp.operationResult.Stack); } else { LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "Http Comunication 'Job Add' for job" + jobDetail.Key.Name + " to Endpoint : " + Endpoint + " exit with code " + resp.Code.ToString() + " returns message " + resp.operationResult.Message); } } catch (Exception ex) { LogsAppendersManager.Instance.Error(this.GetType(), MethodBase.GetCurrentMethod(), ex.Message, ex); } }
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext) { //Check if ip is in configured list, unauthorize if is not if (AuthorizedIps != null && AuthorizedIps.Count > 0 && AuthorizedIps.FirstOrDefault(x => actionContext.Request.RequestUri.AbsoluteUri.Contains(x)) == null) { actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized); } //check if has autorization header, unathorize if has not if (actionContext.Request.Headers.Authorization != null) { // Gets header parameters string authenticationString = actionContext.Request.Headers.Authorization.Parameter; string originalString = Encoding.UTF8.GetString(Convert.FromBase64String(authenticationString)); // Gets username and password var username = actionContext.Request.Username(); var password = actionContext.Request.Password(); //var appId = actionContext.Request.AppID(); //var appToken = actionContext.Request.AppToken(); string ip = HttpContext.Current.Request.UserHostAddress; bool isAuthorized = false; //Check if is authorized via DB if (dbAuth) { //DbContext initilization var _context = CastleWindsorService.Resolve <QuartzExecutionDataService>(); //Validate username password and appid apptoken or admin isAuthorized = _context.data.Accounts .Where(x => x.Username == username && x.Password == password) .SingleOrDefault() != null; if (!isAuthorized) { isAuthorized = _context.data.Servers .Where(x => x.AppId == username && x.AppToken == password) .SingleOrDefault() != null; } CastleWindsorService.Release(_context); } if (!isAuthorized) { var configUsername = ConfigurationManager.AppSettings["AuthorizedUsername"]; var configPassword = ConfigurationManager.AppSettings["AuthorizedPassword"]; if (!username.ToLower().Equals(configUsername) && !password.Equals(configPassword)) { // returns unauthorized error isAuthorized = false; } else { isAuthorized = true; } } if (!isAuthorized) { LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "Not Authotirzed username: " + username); actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized); } } else { actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized); } base.OnAuthorization(actionContext); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); CastleWindsorService.Init(); var jobsInspector = new Jobs.JobsInspector() { Name = "Inspector", Group = "InspectorGroup", Description = "Jobs che si occupa di controllare se i job dai clienti stanno eseguendo correttamente", Triggers = new List <TasksEverywhere.Quartz.Context.Jobs.Abstract.ICustomTrigger> { new Quartz.Context.Jobs.Concrete.CustomTrigger { Name = "InspectorTrigger", Group = "InspectorTriggerGroup", Interval = 1, IntervalUnit = IntervalUnit.Minute, Life = 23, LifeUnit = IntervalUnit.Hour, Period = TasksEverywhere.Utilities.Enums.PeriodType.Settimanale, StartDate = DateTime.Parse("12/01/2019 00:00:00"), WeekDays = new List <DayOfWeek> { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday }, } } }; var quartzService = CastleWindsorService.Resolve <Quartz.Services.QuartzService>(); quartzService.Init(); quartzService.AddJob(jobsInspector); quartzService.Start(); using (var _context = new QuartzExecutionDataContext()) { var account = new Account { Username = "******", Password = "******", Roles = RoleType.AdminAndInspector }; if (_context.Accounts .Where(x => x.Username == account.Username) .FirstOrDefault() == null) { _context.Accounts.Add(account); } _context.SaveChanges(); } try { WebSocketClient.Init(ConfigurationManager.AppSettings["WebSocketUrl"]); } catch (Exception e) { LogsAppendersManager.Instance.Error(this.GetType(), MethodBase.GetCurrentMethod(), e.Message, e); } }