public MusketeerModule(IAppConfigurationManager appconf, ILogStore logStore, IValidator <Application> appvalidator, IValidator <ApplicationServerConfig> appconfvalidator) { Post["conf/appsrvconfig", true] = async(x, ct) => { var configs = this.Bind <ApplicationServerConfig[]>(); var apppaths = new List <String>(); foreach (var conf in configs) { var validationResult = appconfvalidator.Validate(conf); if (!validationResult.IsValid) { logger.TraceEvent(TraceEventType.Error, 0, "Validation failed for config {@0}, errors: {1}", conf, validationResult.Errors); continue; } var app = await appconf.FindAppAsync(conf.AppPath); if (app == null) { app = new Application { IsExcluded = true, Path = conf.AppPath }; await appconf.AddOrUpdateAppAsync(app); } else if (app != null && !app.IsExcluded) { apppaths.Add(conf.AppPath); } await appconf.AddOrUpdateAppServerConfigAsync(conf); } return(Response.AsJson(apppaths)); }; }
public Task AddOrUpdateAppAsync(Application app) { if (IsCachingEnabled) { cache.Remove(CachePrefixForApplications + app.Path); } return(wrappedInstance.AddOrUpdateAppAsync(app)); }
public CollectModule(IAppConfigurationManager config, IValidator <LogRecord> logRecordValidator, ILogStore logStore) { Post["/collect", true] = async(x, ct) => { var logrec = this.Bind <LogRecord>(new BindingConfig { BodyOnly = true }); var validationResult = logRecordValidator.Validate(logrec); if (!validationResult.IsValid) { return("VALIDATION ERROR"); } logrec.ApplicationPath = logrec.ApplicationPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); var app = await config.FindAppAsync(logrec.ApplicationPath); if (app == null) { app = new Application { IsExcluded = true, Path = logrec.ApplicationPath }; await config.AddOrUpdateAppAsync(app); } if (!app.IsExcluded) { await logStore.AddLogRecordAsync(logrec); await logStore.UpdateApplicationStatusAsync( CreateApplicationStatus(logrec)); } return("OK"); }; Post["/collectall", true] = async(x, ct) => { var logrecs = this.Bind <LogRecord[]>(new BindingConfig { BodyOnly = true }); var logsToSave = new List <LogRecord>(logrecs.Length); foreach (var logrec in logrecs) { var validationResult = logRecordValidator.Validate(logrec); if (validationResult.IsValid) { logrec.ApplicationPath = logrec.ApplicationPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); // add new application to the configuration as excluded (it could be later renamed or unexcluded) var app = await config.FindAppAsync(logrec.ApplicationPath); if (app == null) { app = new Application { IsExcluded = true, Path = logrec.ApplicationPath }; await config.AddOrUpdateAppAsync(app); } if (!app.IsExcluded) { logsToSave.Add(logrec); } else { logger.TraceEvent(TraceEventType.Verbose, 0, "Log record for the application '{0}' was not stored as the application is excluded."); } } else { if (logger.Switch.ShouldTrace(TraceEventType.Warning)) { logger.TraceEvent(TraceEventType.Warning, 0, "Validation error(s) occured when saving a logrecord: {0}, errors: {1}", logrec, validationResult.Errors); } } } if (logsToSave.Count > 0) { await logStore.AddLogRecordsAsync(logsToSave); await logStore.UpdateApplicationStatusesAsync(CreateApplicationStatusesList(logsToSave)); } return("OK"); }; }