public override void OnAfterBootStrapComplete(IFoundation foundation) { base.OnAfterBootStrapComplete(foundation); // Replace Exception Handlers foundation.Container.RegisterType <IHandleException, HealthFriendlyExceptionHandler>(new ContainerControlledLifetimeManager()); foundation.Container.RegisterType <IHandleExceptionProvider, HealthFriendlyExceptionHandlerProvider>(new ContainerControlledLifetimeManager()); foundation.Container.RegisterInstance <HealthFriendlyExceptionHandlerProvider>(new HealthFriendlyExceptionHandlerProvider(foundation, foundation.GetLogger()), new ContainerControlledLifetimeManager()); foundation.Container.RegisterType <IHandleException, HealthSwallowExceptionHandler>(Assumptions.SWALLOWED_EXCEPTION_HANDLER, new ContainerControlledLifetimeManager()); foundation.Container.RegisterType <IHandleExceptionProvider, HealthSwallowExceptionHandlerProvider>(Assumptions.SWALLOWED_EXCEPTION_HANDLER, new ContainerControlledLifetimeManager()); foundation.Container.RegisterInstance <HealthSwallowExceptionHandlerProvider>(Assumptions.SWALLOWED_EXCEPTION_HANDLER, new HealthSwallowExceptionHandlerProvider(foundation, foundation.GetLogger()), new ContainerControlledLifetimeManager()); foundation.Container.RegisterInstance <ServerHealthExtractor>(new ServerHealthExtractor(foundation), new ContainerControlledLifetimeManager()); DaemonConfig healthConfig = new DaemonConfig() { InstanceName = HealthReportDaemon.DAEMON_NAME, ContinueOnError = true, IntervalMilliSeconds = 15 * 1000, // every 15 seconds StartDelayMilliSeconds = 60 * 1000, TaskConfiguration = string.Empty }; foundation.GetDaemonManager().RegisterDaemon(healthConfig, new HealthReportDaemon(foundation), true); }
/// <summary> /// Not Aspect Wrapped /// </summary> protected static TWorker EnsureWorker <TWorker>(IFoundation foundation, string workerName, int millisecondInterval = 5000) where TWorker : WorkerBase <TRequest> { IDaemonManager daemonManager = foundation.GetDaemonManager(); IDaemonTask daemonTask = daemonManager.GetRegisteredDaemonTask(workerName); if (daemonTask == null) { lock (_RegistrationLock) { daemonTask = daemonManager.GetRegisteredDaemonTask(workerName); if (daemonTask == null) { if (millisecondInterval <= 1000) { millisecondInterval = 5000; // if you give bad data, we force to 5 seconds. } DaemonConfig config = new DaemonConfig() { InstanceName = workerName, ContinueOnError = true, IntervalMilliSeconds = millisecondInterval, StartDelayMilliSeconds = 0, TaskConfiguration = string.Empty }; TWorker worker = (TWorker)foundation.Container.Resolve(typeof(TWorker), null); daemonManager.RegisterDaemon(config, worker, true); } } daemonTask = daemonManager.GetRegisteredDaemonTask(workerName); } return(daemonTask as TWorker); }
protected virtual void RegisterErrorHandlers(IFoundation foundation) { // Replace Exception Handlers foundation.Container.RegisterType <IHandleException, FriendlyExceptionHandler>(new ContainerControlledLifetimeManager()); foundation.Container.RegisterType <IHandleExceptionProvider, FriendlyExceptionHandlerProvider>(new ContainerControlledLifetimeManager()); foundation.Container.RegisterInstance <FriendlyExceptionHandlerProvider>(new FriendlyExceptionHandlerProvider(foundation, foundation.GetLogger()), new ContainerControlledLifetimeManager()); }
public HealthReporter(IFoundation iFoundation) : base(iFoundation) { this.Extractors = new HashSet <IHealthExtractor>(); this.Generator = new HealthReportGenerator(iFoundation, new List <string>(), new Dictionary <string, decimal>()); this.ExclusionCache = new AspectCache("HealthReportStaticCache", iFoundation, new ExpireStaticLifetimeManager("HealthReportStaticCacheLifeTime", TimeSpan.FromMinutes(15), false)); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { IFoundation iFoundation = CoreFoundation.Current; Account account = null; bool isPreAuthorized = base.AuthorizeCore(httpContext); // already verified if (httpContext.Items.Contains(CURRENT_ACCOUNT_HTTP_CONTEXT_KEY)) { return(true); } if (isPreAuthorized) { StencilFormsAuthorizer authorizer = iFoundation.Resolve <StencilFormsAuthorizer>(); account = authorizer.Authorize(httpContext.User.Identity.Name); } if (account == null) { // try with headers or QS NameValueCollection query = httpContext.Request.QueryString; string key = query[API_PARAM_KEY]; string signature = query[API_PARAM_SIG]; // from headers string value = httpContext.Request.Headers[API_PARAM_KEY]; if (!string.IsNullOrEmpty(value)) { key = value; } value = httpContext.Request.Headers[API_PARAM_SIG]; if (!string.IsNullOrEmpty(value)) { signature = value; } StencilHashedTimeSignatureAuthorizer authorizer = iFoundation.Resolve <StencilHashedTimeSignatureAuthorizer>(); account = authorizer.Authorize(key, signature); } if (account != null) { httpContext.Items[CURRENT_ACCOUNT_HTTP_CONTEXT_KEY] = account; try { ApiIdentity apiIdentity = new ApiIdentity(account.account_id, string.Format("{0} {1}", account.first_name, account.last_name)); var context = HttpContext.Current; if (context != null) { context.User = new GenericPrincipal(apiIdentity, new string[0]); } } catch (Exception ex) { iFoundation.LogError(ex, "HttpContext.Current.Account"); } return(true); } return(false); }
public StencilAPI(IFoundation iFoundation) : base(iFoundation) { this.Direct = new StencilAPIDirect(iFoundation); Index = new StencilAPIIndex(iFoundation); this.Integration = new StencilAPIIntegration(iFoundation); }
public BusinessBase(IFoundation foundation, string trackPrefix) : base(foundation, trackPrefix) { this.DataContextFactory = foundation.Resolve <IStencilContextFactory>(); this.API = new StencilAPI(foundation); this.SharedCacheStatic15 = new AspectCache("BusinessBase", foundation, new ExpireStaticLifetimeManager("BusinessBase", TimeSpan.FromMinutes(15))); }
public HealthReportGenerator(IFoundation foundation, List <string> logs, Dictionary <string, decimal> metrics) : base(foundation) { this.LastReset = DateTime.UtcNow; this.Logs = logs; this.Metrics = metrics; this.Interim = new Dictionary <string, decimal>(); }
/// <summary> /// Creates a SynchronizerBase /// </summary> /// <param name="foundation"></param> /// <param name="entityName">Used to notify health system which entity this synchronizer references</param> public SynchronizerBase(IFoundation foundation, string entityName, int synchronousTimeoutMilliseconds = 5000) : base(foundation, foundation.Resolve <IHandleExceptionProvider>(Assumptions.SWALLOWED_EXCEPTION_HANDLER)) { this.EntityName = entityName; this.SynchronousTimeoutMilliseconds = synchronousTimeoutMilliseconds; this.SynchronousCriticalTimeoutMilliseconds = CRITICAL_SYNC_TIMEOUT_MILLISECONDS; this.API = foundation.Resolve <StencilAPI>(); }
/// <summary> /// Not Aspect Wrapped /// </summary> protected static TWorker EnqueueRequest <TWorker>(IFoundation foundation, string workerName, TRequest request, int millisecondInterval = 5000) where TWorker : WorkerBase <TRequest> { TWorker worker = EnsureWorker <TWorker>(foundation, workerName, millisecondInterval); worker.EnqueueRequest(request); return(worker); }
protected virtual void RegisterDataElements(IFoundation foundation) { foundation.Container.RegisterType <IGlobalSettingBusiness, GlobalSettingBusiness>(new HttpRequestLifetimeManager()); foundation.Container.RegisterType <IAccountBusiness, AccountBusiness>(new HttpRequestLifetimeManager()); foundation.Container.RegisterType <IAssetBusiness, AssetBusiness>(new HttpRequestLifetimeManager()); //Indexes foundation.Container.RegisterType <IAccountIndex, AccountIndex>(new HttpRequestLifetimeManager()); //Synchronizers foundation.Container.RegisterType <IAccountSynchronizer, AccountSynchronizer>(new HttpRequestLifetimeManager()); }
/// <summary> /// Not aspect wrapped /// </summary> public static string ProcessAgitateWebHook(IFoundation foundation, string secretkey, string daemonName) { string result = ""; if (secretkey == "codeable") { IDaemonManager daemonManager = foundation.GetDaemonManager(); if (null != daemonManager.GetRegisteredDaemonTask(daemonName)) { daemonManager.StartDaemon(daemonName); result = "Agitated"; } } return(result); }
public AzurePushNotifier(IFoundation iFoundation) : base(iFoundation) { this.API = iFoundation.Resolve <StencilAPI>(); this.Cache = new AspectCache("AzurePushNotifier", iFoundation, new ExpireStaticLifetimeManager("AzurePushNotifier.Life15", System.TimeSpan.FromMinutes(15), false)); try { // known to have bad config in debug this.HubClient = NotificationHubClient.CreateClientFromConnectionString(this.AzurePush_Connection, this.AzurePush_HubName); } catch (Exception ex) { iFoundation.LogError(ex, "AzurePushNotifier"); } }
public override void OnAfterSelfRegisters(IFoundation foundation) { base.OnAfterSelfRegisters(foundation); this.RegisterDataMapping(foundation); foundation.Container.RegisterType <IEmailer, SimpleEmailer>(new ContainerControlledLifetimeManager()); foundation.Container.RegisterType <ISettingsResolver, AppConfigSettingsResolver>(new ContainerControlledLifetimeManager()); foundation.Container.RegisterType <IStencilContextFactory, StencilContextFactory>(new ContainerControlledLifetimeManager()); foundation.Container.RegisterType <IStencilElasticClientFactory, StencilElasticClientFactory>(new ContainerControlledLifetimeManager()); foundation.Container.RegisterType <IDependencyCoordinator, DependencyCoordinator>(new ContainerControlledLifetimeManager()); this.RegisterDataElements(foundation); this.RegisterErrorHandlers(foundation); }
/// <summary> /// Abornal pattern, takes the first processMethod and uses that for all instances /// This means a potential memory leak, so ensure the caller has the same lifetime as this instance. /// [done so that dependencies can be visualized in one shared place] /// </summary> public static void EnqueueRequest(IFoundation foundation, Dependency dependencies, Guid entity_id, Action <Dependency, Guid> processMethod) { DependencyWorker <TEntity> worker = EnqueueRequest <DependencyWorker <TEntity> >(foundation, WORKER_NAME, new DependencyRequest() { Dependencies = dependencies, EntityID = entity_id }); if (worker != null) { if (worker.ProcessMethod == null) { worker.ProcessMethod = processMethod; worker.Execute(worker.IFoundation); // start it now (may have been waiting for processmethod) } } }
public void Execute(IFoundation iFoundation) { if (_executing) { return; } // safety base.ExecuteMethod("Execute", delegate() { try { _executing = true; this.PerformProcessPhotos(); } finally { _executing = false; } }); }
public virtual void Execute(IFoundation iFoundation) { if (this.Executing) { return; } // safety base.ExecuteMethod("Execute", delegate() { try { this.Executing = true; this.ProcessRequests(); } finally { this.Executing = false; } }); }
/// <summary> /// Not aspect wrapped /// </summary> public static string ProcessWebHook(IFoundation foundation, string secretkey, string hookType, string entityType, string argument) { string result = ""; if (secretkey == "codeable") { IDaemonManager daemonManager = foundation.GetDaemonManager(); switch (hookType) { case "sync": case "failed": daemonManager.StartDaemon(string.Format(ElasticSearchDaemon.DAEMON_NAME_FORMAT, Agents.AGENT_DEFAULT)); daemonManager.StartDaemon(string.Format(ElasticSearchDaemon.DAEMON_NAME_FORMAT, Agents.AGENT_STATS)); result = "Queued Normal Sync"; break; default: break; } } return(result); }
public bool AuthorizedRequest(HttpActionContext actionContext) { IFoundation iFoundation = CoreFoundation.Current; //weak usage of CoreFoundation.Current Account account = null; bool isPreAuthorized = base.IsAuthorized(actionContext); // already verified [same request?] if (actionContext.Request.Properties.ContainsKey(CURRENT_ACCOUNT_HTTP_CONTEXT_KEY)) { return(true); } if (isPreAuthorized) { StencilFormsAuthorizer authorizer = iFoundation.Resolve <StencilFormsAuthorizer>(); account = authorizer.Authorize(actionContext.RequestContext.Principal.Identity.Name); } if (account == null) { NameValueCollection query = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.ToString()); // from query string string key = query[API_PARAM_KEY]; string signature = query[API_PARAM_SIG]; // from headers if (actionContext.Request.Headers.Contains(API_PARAM_KEY)) { string value = actionContext.Request.Headers.GetValues(API_PARAM_KEY).FirstOrDefault(); if (!string.IsNullOrEmpty(value)) { key = value; } } if (actionContext.Request.Headers.Contains(API_PARAM_SIG)) { string value = actionContext.Request.Headers.GetValues(API_PARAM_SIG).FirstOrDefault(); if (!string.IsNullOrEmpty(value)) { signature = value; } } StencilHashedTimeSignatureAuthorizer authorizer = iFoundation.Resolve <StencilHashedTimeSignatureAuthorizer>(); account = authorizer.Authorize(key, signature); } if (account != null) { actionContext.Request.Properties[CURRENT_ACCOUNT_HTTP_CONTEXT_KEY] = account; try { ApiIdentity apiIdentity = new ApiIdentity(account.account_id, string.Format("{0} {1}", account.first_name, account.last_name)); var context = HttpContext.Current; if (context != null) { context.User = new GenericPrincipal(apiIdentity, new string[0]); } } catch (Exception ex) { iFoundation.LogError(ex, "HttpContext.Current.User"); } string platform = string.Empty; try { if (actionContext.Request.Headers.Contains(PARAM_PLATFORM)) { string value = actionContext.Request.Headers.GetValues(PARAM_PLATFORM).FirstOrDefault(); if (!string.IsNullOrEmpty(value)) { platform += value; } } if (actionContext.Request.Headers.Contains(PARAM_VERSION)) { string value = actionContext.Request.Headers.GetValues(PARAM_VERSION).FirstOrDefault(); if (!string.IsNullOrEmpty(value)) { platform += " - v" + value; } } } catch (Exception ex) { iFoundation.LogError(ex, "HttpContext.Current.User"); } AccountLoggedInWorker.EnqueueRequest(iFoundation, new LoggedInRequest() { account_id = account.account_id, platform = platform, login_utc = DateTime.UtcNow }); return(true); } return(false); }
public SimpleEmailer(IFoundation foundation) : base(foundation) { this.API = new StencilAPI(foundation); this.Cache = new AspectCache("SimpleEmailer", this.IFoundation, new ContainerControlledLifetimeManager()); }
public PluginController(IFoundation iFoundation) : base(iFoundation) { }
public AssetController(IFoundation foundation) : base(foundation, "Asset") { }
public FoundationViewModel(IFoundation foundation) { CardsEmpty = foundation.Cards.Count == 0; TopCard = foundation.TopCard; _foundation = foundation; }
public AccountController(IFoundation foundation) : base(foundation, "Account") { }
public DependencyCoordinator(IFoundation foundation) : base(foundation) { }
public static void EnqueueRequest(IFoundation foundation, LoggedInRequest request) { EnqueueRequest <AccountLoggedInWorker>(foundation, WORKER_NAME, request, (int)TimeSpan.FromMinutes(2).TotalMilliseconds); // updates every 2 mins }
public AccountLoggedInWorker(IFoundation iFoundation) : base(iFoundation, WORKER_NAME) { this.API = iFoundation.Resolve <StencilAPI>(); }
public AmazonWebHookController(IFoundation iFoundation) : base(iFoundation) { this.Cache = new AspectCache("AmazonWebHookController", iFoundation, new ExpireStaticLifetimeManager("AmazonWebHookController.Life15", System.TimeSpan.FromMinutes(15), false)); }
public GlobalSettingController(IFoundation foundation) : base(foundation, "GlobalSetting") { }
public HealthFriendlyExceptionHandlerProvider(IFoundation foundation, ILogger iLogger) : base(foundation, iLogger) { }