public ApplicationInsightAop( ILogger <ApplicationInsightAop> logger, IApplicationInsights insights) { _logger = logger; _insights = insights; }
public ViewModel(IExrinContainer exrinContainer, IVisualState visualState, [CallerFilePath] string caller = nameof(ViewModel)) { if (exrinContainer == null) throw new ArgumentNullException(nameof(IExrinContainer)); _applicationInsights = exrinContainer.ApplicationInsights; _displayService = exrinContainer.DisplayService; _navigationService = exrinContainer.NavigationService; _errorHandlingService = exrinContainer.ErrorHandlingService; VisualState = visualState; if (VisualState != null) Task.Run(() => visualState.Init()) .ContinueWith((task) => { if (task.Exception != null) _applicationInsights.TrackException(task.Exception); }); Execution = new Execution() { HandleTimeout = TimeoutHandle, NotifyOfActivity = NotifyActivity, NotifyActivityFinished = NotifyActivityFinished, HandleResult = HandleResult }; }
public ViewModel(IExrinContainer exrinContainer, IVisualState visualState, [CallerFilePath] string caller = nameof(ViewModel)) { if (exrinContainer == null) { throw new ArgumentNullException(nameof(IExrinContainer)); } _applicationInsights = exrinContainer.ApplicationInsights; _displayService = exrinContainer.DisplayService; _navigationService = exrinContainer.NavigationService; _errorHandlingService = exrinContainer.ErrorHandlingService; VisualState = visualState; if (VisualState != null) { Task.Run(() => visualState.Init()) .ContinueWith((task) => { if (task.Exception != null) { _applicationInsights.TrackException(task.Exception); } }); } Execution = new Execution() { HandleTimeout = TimeoutHandle, NotifyOfActivity = NotifyActivity, NotifyActivityFinished = NotifyActivityFinished, HandleResult = HandleResult }; }
public AuthenticationService(IApplicationInsights insight, KeyVaultClient keyVault, string tableIdentifier, string signKeyIdentifier, string encryptionKeyIdentifier) { this.insight = insight ?? throw new ArgumentNullException("insight"); this.keyVaultClient = keyVault ?? throw new ArgumentNullException("keyVault"); this.tableIdentifier = tableIdentifier; this.signKeyIdentifier = signKeyIdentifier; this.encryptionKeyIdentifier = encryptionKeyIdentifier; }
public ExrinContainer(IApplicationInsights applicationInsights, IDisplayService displayService, IErrorHandlingService errorHandlingService, INavigationService navigationService) { ApplicationInsights = applicationInsights; DisplayService = displayService; ErrorHandlingService = errorHandlingService; NavigationService = navigationService; }
public HttpService(HttpClient httpClient, BaseUrlConfiguration baseUrlConfiguration , IApplicationInsights applicationInsights) { _httpClient = httpClient; _applicationInsights = applicationInsights ?? throw new ArgumentNullException(nameof(applicationInsights)); _apiUrl = baseUrlConfiguration.ApiBase; //Activity activity = new Activity("CallAPI"); //activity.Start(); //_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("traceparent", activity.Id); //_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("tracestate", activity.TraceStateString); }
public Model(IDisplayService displayService, IApplicationInsights applicationInsights, IErrorHandlingService errorHandlingService, IModelState modelState) { _displayService = displayService; _errorHandlingService = errorHandlingService; _applicationInsights = applicationInsights; ModelState = modelState; Execution = new ModelExecution() { HandleTimeout = TimeoutHandle, HandleUnhandledException = HandleError }; }
public ShowWelcomeJob( ILogger <ShowWelcomeJob> logger, IApplicationInsights applicationInsights, IIndexedDbRepo <AfMetadata, string> afMetadataRepo, IOptions <StaticUrlOptions> staticUrlOptions, INewNotification newNotification) { _logger = logger; _applicationInsights = applicationInsights; _afMetadataRepo = afMetadataRepo; _staticUrlOptions = staticUrlOptions; _newNotification = newNotification; }
public Model(IExrinContainer exrinContainer, IModelState modelState) { if (exrinContainer == null) throw new ArgumentNullException(nameof(IExrinContainer)); _displayService = exrinContainer.DisplayService; _errorHandlingService = exrinContainer.ErrorHandlingService; _applicationInsights = exrinContainer.ApplicationInsights; ModelState = modelState; Execution = new ModelExecution() { HandleTimeout = TimeoutHandle, HandleUnhandledException = HandleError }; }
public Model(IExrinContainer exrinContainer, IModelState modelState) { if (exrinContainer == null) { throw new ArgumentNullException(nameof(IExrinContainer)); } _displayService = exrinContainer.DisplayService; _errorHandlingService = exrinContainer.ErrorHandlingService; _applicationInsights = exrinContainer.ApplicationInsights; ModelState = modelState; Execution = new ModelExecution() { HandleTimeout = TimeoutHandle, HandleUnhandledException = HandleError }; }
public AzureServices(ManagementModel managementModel) { _managementModel = managementModel; _applicationInsight = new ApplicationInsights(); _account = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage")); _client = _account.CreateCloudTableClient(); _table = _client.GetTableReference(managementModel.MessageType); _telemetry = _applicationInsight.Create(); Task.Run(async() => { if (!await _table.ExistsAsync()) { await _table.CreateIfNotExistsAsync(); } }); }
public Processor(IApplicationInsights applicationInsights) { _applicationInsights = applicationInsights; }
/// <summary> /// Singular Operation /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sender"></param> /// <param name="operation"></param> /// <param name="handleUnhandledException"></param> /// <param name="handleTimeout"></param> /// <param name="timeoutMilliseconds"></param> /// <param name="insights"></param> /// <param name="name"></param> /// <param name="parameter"></param> /// <returns></returns> private static async Task <T> ModelExecute <T>(IModelExecution sender, IOperation <T> operation, Func <Exception, Task <bool> > handleUnhandledException = null, Func <ITimeoutEvent, Task> handleTimeout = null, int timeoutMilliseconds = 0, IApplicationInsights insights = null, string name = "" ) { if (sender == null) { throw new Exception($"The IModelExecution sender can not be null"); } // Background thread Task insight = Task.Run(() => { try { if (insights != null) { insights.TrackEvent(name, $"User activated {name}"); } } catch (Exception ex) { Debug.WriteLine($"insights.TrackEvent({name}) {ex.Message}"); } }); List <Func <IResult, Task> > rollbacks = new List <Func <IResult, Task> >(); bool transactionRunning = false; // Setup Cancellation of Tasks if long running var task = new CancellationTokenSource(); var exceptionState = new PropertyArgs() { Value = false }; if (timeoutMilliseconds > 0) { if (handleTimeout != null) { task.Token.Register(async(state) => { if (!(bool)((PropertyArgs)state).Value) { await handleTimeout(new TimeoutEvent("", timeoutMilliseconds)); } }, exceptionState); } else if (handleUnhandledException != null) { task.Token.Register(async(state) => { if (!(bool)((PropertyArgs)state).Value) { await handleUnhandledException(new TimeoutException()); } }, exceptionState); } else { throw new Exception($"You must specify either {nameof(handleTimeout)} or {nameof(handleUnhandledException)} to handle a timeout."); } task.CancelAfter(timeoutMilliseconds); } T result = default(T); try { // Transaction Block transactionRunning = true; if (operation.Function != null) { try { await Task.Run(async() => { result = await operation.Function(task.Token); }, task.Token); // Background Thread } catch { exceptionState.Value = true; // Stops registered cancel function from running, since this is exception not timeout task?.Cancel(); // Cancel all tasks throw; // Go to unhandled exception } } transactionRunning = false; // End of Transaction Block } catch (Exception e) { if (handleUnhandledException == null) { throw; } var handled = await handleUnhandledException(e); if (!handled) { throw; } } finally { try { task?.Dispose(); if (transactionRunning) { await operation.Rollback(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } return(result); }
private static async Task ViewModelExecute(IExecution sender, List<IBaseOperation> operations, Func<Task> notifyOfActivity = null, Func<Task> notifyActivityFinished = null, Func<Exception, Task<bool>> handleUnhandledException = null, Func<Task> handleTimeout = null, int timeoutMilliseconds = 0, IApplicationInsights insights = null, string name = "", object parameter = null) { // If currently executing, ignore the latest request lock (sender) { if (!_status.ContainsKey(sender)) _status.Add(sender, true); else if (_status[sender]) return; else _status[sender] = true; } if (sender == null) throw new Exception($"The {nameof(IExecution)} sender can not be null"); if (notifyOfActivity == null) throw new Exception($"{nameof(notifyOfActivity)} is null: You must notify the user that something is happening"); await notifyOfActivity(); // Background thread var insightTask = Task.Run(() => { try { if (insights != null) insights.TrackEvent(name, $"User activated {name}"); } catch (Exception ex) { Debug.WriteLine($"insights.TrackEvent({name}) {ex.Message}"); } }).ConfigureAwait(false); await Task.Run(async () => { // Debug Remove Timeout if (App.IsDebugging) timeoutMilliseconds = 0; sender.Result = null; List<Func<Task>> rollbacks = new List<Func<Task>>(); bool transactionRunning = false; // Setup Cancellation of Tasks if long running var task = new CancellationTokenSource(); var exceptionState = new PropertyArgs() { Value = false }; if (timeoutMilliseconds > 0) { if (handleTimeout != null) task.Token.Register(async (state) => { if (!(bool)((PropertyArgs)state).Value) await handleTimeout(); }, exceptionState); else if (handleUnhandledException != null) task.Token.Register(async (state) => { if (!(bool)((PropertyArgs)state).Value) await handleUnhandledException(new TimeoutException()); }, exceptionState); else throw new Exception($"You must specify either {nameof(handleTimeout)} or {nameof(handleUnhandledException)} to handle a timeout."); task.CancelAfter(timeoutMilliseconds); } IList<IResult> results = new List<IResult>(); try { // Transaction Block transactionRunning = true; foreach (var operation in operations) { if (operation.Rollback != null) rollbacks.Add(operation.Rollback); if (operation is IOperation || operation is IChainedOperation) { var op = operation as IOperation; if (op.Function != null) { try { await op.Function(results, parameter, task.Token); } catch { exceptionState.Value = true; // Stops registered cancel function from running, since this is exception not timeout task?.Cancel(); // Cancel all tasks throw; // Go to unhandled exception } } } else { var op = operation as ISingleOperation; try { if (op.Function != null) { var resultList = await op.Function(parameter, task.Token); if (resultList != null) foreach (var result in resultList) results.Add(result); } } catch { exceptionState.Value = true; // Stops registered cancel function from running, since this is exception not timeout task?.Cancel(); // Cancel all tasks throw; // Go to unhandled exception } } if (!operation.ChainedRollback) rollbacks.Remove(operation.Rollback); } rollbacks.Clear(); transactionRunning = false; // End of Transaction Block } catch (Exception e) { if (handleUnhandledException == null) throw; var handled = await handleUnhandledException(e); if (!handled) throw; } finally { try { task?.Dispose(); if (transactionRunning) { rollbacks.Reverse(); // Do rollbacks in reverse order foreach (var rollback in rollbacks) await rollback(); } // Set final result sender.Result = results; // Handle the result await sender.HandleResult(sender.Result); } finally { if (notifyActivityFinished == null) throw new Exception($"{nameof(notifyActivityFinished)} is null: You need to specify what happens when the operations finish"); try { await notifyActivityFinished(); } catch (Exception e) { var handled = await handleUnhandledException(e); if (!handled) throw; } finally { _status.Remove(sender); } } } }); }
public ViewModelExecuteBuilder(IApplicationInsights insights) { _insights = insights; }
private static async Task ViewModelExecute(IExecution sender, List <IOperation> operations, Func <Task> notifyOfActivity = null, Func <Task> notifyActivityFinished = null, Func <Exception, Task <bool> > handleUnhandledException = null, Func <Task> handleTimeout = null, int timeoutMilliseconds = 0, IApplicationInsights insights = null, string name = "", object parameter = null ) { // If current executing, ignore the latest request lock (sender) { if (!_status.ContainsKey(sender)) { _status.Add(sender, true); } else if (_status[sender]) { return; } else { _status[sender] = true; } } if (sender == null) { throw new Exception($"The IExecution sender can not be null"); } sender.Result = null; // Background thread Task insight = Task.Run(() => { try { if (insights != null) { insights.TrackEvent(name, $"User activated {name}"); } } catch (Exception ex) { Debug.WriteLine($"insights.TrackEvent({name}) {ex.Message}"); } }); List <Func <Task> > rollbacks = new List <Func <Task> >(); bool transactionRunning = false; // Setup Cancellation of Tasks if long running var task = new CancellationTokenSource(); if (timeoutMilliseconds > 0) { if (handleTimeout != null) { task.Token.Register(async() => { await handleTimeout(); }); } else if (handleUnhandledException != null) { task.Token.Register(async() => { await handleUnhandledException(new TimeoutException()); }); } else { throw new Exception($"You must specify either {nameof(handleTimeout)} or {nameof(handleUnhandledException)} to handle a timeout."); } task.CancelAfter(timeoutMilliseconds); } IList <IResult> result = new List <IResult>(); try { if (notifyOfActivity == null) { throw new Exception($"{nameof(notifyOfActivity)} is null: You must notify the user that something is happening"); } await notifyOfActivity(); // Transaction Block transactionRunning = true; foreach (var operation in operations) { rollbacks.Add(operation.Rollback); if (operation.Function != null) { await Task.Run(async() => { await operation.Function(result, parameter); }, task.Token); // Background Thread } if (!operation.ChainedRollback) { rollbacks.Remove(operation.Rollback); } } rollbacks.Clear(); transactionRunning = false; // End of Transaction Block } catch (Exception e) { if (handleUnhandledException == null) { throw; } var handled = await handleUnhandledException(e); if (!handled) { throw; } } finally { try { if (transactionRunning) { rollbacks.Reverse(); // Do rollbacks in reverse order foreach (var rollback in rollbacks) { await rollback(); } } // Set final result sender.Result = result; // Handle the result await Task.Run(async() => await sender.HandleResult(sender.Result)); //TODO: why am I passing this in again? } finally { if (notifyActivityFinished == null) { throw new Exception($"{nameof(notifyActivityFinished)} is null: You need to specify what happens when the operations finish"); } try { await notifyActivityFinished(); } catch (Exception e) { var handled = await handleUnhandledException(e); if (!handled) { throw; } } finally { _status.Remove(sender); } } } }
public AiLoggerProvider(IApplicationInsights applicationInsights) { _applicationInsights = applicationInsights; }
public JwtAuthenticationMiddleware(RequestDelegate next, IAuthenticationService service, IApplicationInsights insight) { this.next = next; this.service = service; this.insight = insight; }
private static async Task ViewModelExecute(IExecution sender, List <IBaseOperation> operations, Func <Task> notifyOfActivity = null, Func <Task> notifyActivityFinished = null, Func <Exception, Task <bool> > handleUnhandledException = null, Func <Task> handleTimeout = null, int timeoutMilliseconds = 0, IApplicationInsights insights = null, string name = "", object parameter = null) { // If currently executing, ignore the latest request lock (sender) { if (!_status.ContainsKey(sender)) { _status.Add(sender, true); } else if (_status[sender]) { return; } else { _status[sender] = true; } } if (sender == null) { throw new Exception($"The {nameof(IExecution)} sender can not be null"); } if (notifyOfActivity == null) { throw new Exception($"{nameof(notifyOfActivity)} is null: You must notify the user that something is happening"); } await notifyOfActivity(); // Background thread var insightTask = Task.Run(() => { try { if (insights != null) { insights.TrackEvent(name, $"User activated {name}"); } } catch (Exception ex) { Debug.WriteLine($"insights.TrackEvent({name}) {ex.Message}"); } }).ConfigureAwait(false); await Task.Run(async() => { sender.Result = null; List <Func <Task> > rollbacks = new List <Func <Task> >(); bool transactionRunning = false; // Setup Cancellation of Tasks if long running var task = new CancellationTokenSource(); var exceptionState = new PropertyArgs() { Value = false }; if (timeoutMilliseconds > 0) { if (handleTimeout != null) { task.Token.Register(async(state) => { if (!(bool)((PropertyArgs)state).Value) { await handleTimeout(); } }, exceptionState); } else if (handleUnhandledException != null) { task.Token.Register(async(state) => { if (!(bool)((PropertyArgs)state).Value) { await handleUnhandledException(new TimeoutException()); } }, exceptionState); } else { throw new Exception($"You must specify either {nameof(handleTimeout)} or {nameof(handleUnhandledException)} to handle a timeout."); } task.CancelAfter(timeoutMilliseconds); } IList <IResult> results = new List <IResult>(); try { // Transaction Block transactionRunning = true; foreach (var operation in operations) { if (operation.Rollback != null) { rollbacks.Add(operation.Rollback); } if (operation is IOperation || operation is IChainedOperation) { var op = operation as IOperation; if (op.Function != null) { try { await op.Function(results, parameter, task.Token); } catch { exceptionState.Value = true; // Stops registered cancel function from running, since this is exception not timeout task?.Cancel(); // Cancel all tasks throw; // Go to unhandled exception } } } else { var op = operation as ISingleOperation; try { if (op.Function != null) { var resultList = await op.Function(parameter, task.Token); if (resultList != null) { foreach (var result in resultList) { results.Add(result); } } } } catch { exceptionState.Value = true; // Stops registered cancel function from running, since this is exception not timeout task?.Cancel(); // Cancel all tasks throw; // Go to unhandled exception } } if (!operation.ChainedRollback) { rollbacks.Remove(operation.Rollback); } } rollbacks.Clear(); transactionRunning = false; // End of Transaction Block } catch (Exception e) { if (handleUnhandledException == null) { throw; } var handled = await handleUnhandledException(e); if (!handled) { throw; } } finally { try { task?.Dispose(); if (transactionRunning) { rollbacks.Reverse(); // Do rollbacks in reverse order foreach (var rollback in rollbacks) { await rollback(); } } // Set final result sender.Result = results; // Handle the result await sender.HandleResult(sender.Result); } finally { if (notifyActivityFinished == null) { throw new Exception($"{nameof(notifyActivityFinished)} is null: You need to specify what happens when the operations finish"); } try { await notifyActivityFinished(); } catch (Exception e) { var handled = await handleUnhandledException(e); if (!handled) { throw; } } finally { _status.Remove(sender); } } } }); }
public ExceptionHandlingMiddleware(RequestDelegate next, ExceptionHandlingOptions options, IApplicationInsights insight) { this.next = next; this.options = options; this.insight = insight; }
public ClientInfoMiddleware(RequestDelegate next, IApplicationInsights insight) { this.next = next; this.insight = insight; }
public ApplicationInsightsLogger(IApplicationInsights applicationInsights) { _applicationInsights = applicationInsights; }
public ClientManagementService(IApplicationInsights insight, KeyVaultClient keyVault, string tableIdentifier) { this.insight = insight; this.keyVaultClient = keyVault; this.tableIdentifier = tableIdentifier; }
public static void Init(IApplicationInsights platform) { target = platform; }