public NotificationService(INotificationProvider provider, IIdentityProvider identityProvider, INotificationChannelService channelService, IConnectionProvider connectionProvider) { _identityProvider = identityProvider; _connectionProvider = connectionProvider; }
public NotificationChannelsController(INotificationChannelService service) { _service = service; }
private async Task SendOneMessage( string customerCode, string instanceId, NotificationSenderConfig config, NotificationChannel channel, IMessageService service, Message message, SemaphoreSlim semaphore, TaskFactory factory, ChannelState state, INotificationChannelService channelService) { await factory.StartNew(() => { lock (state) { if (state.ErrorsCount >= config.ErrorCountBeforeWait) { return; } } var timer = new Stopwatch(); timer.Start(); string url = GetUrl(customerCode, instanceId, channel, message); try { semaphore.Wait(); _logger.Debug("Start processing message {messageId} ", message.Id); var request = (HttpWebRequest)WebRequest.Create(url); request.Method = message.Method.ToUpper(); request.Timeout = 1000 * config.TimeOut; var mediaType = !string.IsNullOrEmpty(channel.MediaType) ? channel.MediaType : "text/xml"; request.ContentType = $"{mediaType}; charset=utf-8"; byte[] data = Encoding.UTF8.GetBytes(message.Xml); request.ContentLength = data.Length; using (var streamWriter = request.GetRequestStream()) { streamWriter.Write(data, 0, data.Length); streamWriter.Flush(); } using (var httpResponse = (HttpWebResponse)request.GetResponse()) { timer.Stop(); _logger.Info() .Message( "Message {message} for channel {channel} has been sent on url {url}", message.Method, channel.Name, Uri.UnescapeDataString(url) ) .Property("productId", message.Key) .Property("statusCode", httpResponse.StatusCode) .Property("timeTaken", timer.ElapsedMilliseconds) .Property("messageId", message.Id) .Property("customerCode", customerCode) .Write(); channelService.UpdateNotificationChannel(customerCode, channel.Name, message.Key, message.Created, httpResponse.StatusCode.ToString()); } ; service.RemoveMessage(message.Id); } catch (WebException ex) { timer.Stop(); lock (state) { state.ErrorsCount++; } var httpResponse = ex.Response as HttpWebResponse; if (httpResponse != null) { _logger.Info() .Message( "Message {message} for channel {channel} has been sent on url {url}", message.Method, channel.Name, Uri.UnescapeDataString(url) ) .Property("productId", message.Key) .Property("statusCode", httpResponse.StatusCode) .Property("timeTaken", timer.ElapsedMilliseconds) .Property("messageId", message.Id) .Property("customerCode", customerCode) .Write(); channelService.UpdateNotificationChannel(customerCode, channel.Name, message.Key, message.Created, httpResponse.StatusCode.ToString()); } else { _logger.Info() .Message( "Message {message} for channel {channel} has not been sent on url {url}", message.Method, channel.Name, Uri.UnescapeDataString(url) ) .Property("productId", message.Key) .Property("statusCode", ex.Status) .Property("timeTaken", timer.ElapsedMilliseconds) .Property("messageId", message.Id) .Property("customerCode", customerCode) .Write(); channelService.UpdateNotificationChannel(customerCode, channel.Name, message.Key, message.Created, ex.Status.ToString()); } _logger.Error().Exception(ex) .Message( "Message {message} for channel {channel} has not been sent on url {url}", message.Method, channel.Name, Uri.UnescapeDataString(url) ) .Property("productId", message.Key) .Property("timeTaken", timer.ElapsedMilliseconds) .Property("messageId", message.Id) .Property("customerCode", customerCode) .Write(); } finally { semaphore.Release(); } }); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); Analytics.TrackEvent("Main page reached", new Dictionary <string, string>() { { "Size", $"{Window.Current.Bounds}" } }); prevWidth = Window.Current.Bounds.Width; Window.Current.SizeChanged += CurrentWindow_SizeChanged; if (e.Parameter is string argument && !string.IsNullOrEmpty(argument)) { Analytics.TrackEvent("Launched with parameter", new Dictionary <string, string>() { { "Parameter", argument } }); if (argument.Equals("ScoreChanged", StringComparison.Ordinal)) { NavigationView.SelectedItem = NavigationView.MenuItems.Last(); } } bool signedIn = Application.Current.GetService <ICredentialService>().IsSignedIn; IAsyncOperation <PushNotificationChannel> channelCreationTask = PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); Task wellknownUpdateTask = WellknownDataViewModel.StartUpdateAsync(signedIn); Task studentInfoUpdateTask = StudentInfoViewModel.StartUpdateAsync(signedIn); await wellknownUpdateTask; Task examsUpdateTask = ExamsViewModel.StartUpdateAsync(signedIn); Task scheduleUpdateTask = ScheduleViewModel.StartUpdateAsync(signedIn); if (!signedIn) { ISignInService signInService = Application.Current.GetService <ISignInService>(); try { await signInService.SignInAsync(false); signedIn = true; Application.Current.GetService <IMessageService <SignInMessage> >().SendMessage(new SignInMessage(true)); } catch (BackendAuthenticationFailedException ex) { Crashes.TrackError(ex); Analytics.TrackEvent("Authentication failed"); await((App)Application.Current).SignOutAsync(); } catch (BackendRequestFailedException ex) { Crashes.TrackError(ex); Application.Current.GetService <IMessageService <SignInMessage> >().SendMessage(new SignInMessage(false)); } } if (signedIn) { INotificationChannelService channelService = Application.Current.GetService <INotificationChannelService>(); Task channelUpdateTask; try { PushNotificationChannel channel = await channelCreationTask; channelUpdateTask = channelService.PostNotificationChannelAsync(new NotificationChannelItem(channel.Uri)); } catch (Exception ex) { Crashes.TrackError(ex); channelUpdateTask = Task.CompletedTask; } await Task.WhenAll(studentInfoUpdateTask, examsUpdateTask, scheduleUpdateTask, channelUpdateTask); } else { await Task.WhenAll(studentInfoUpdateTask, examsUpdateTask, scheduleUpdateTask); } }