private void Unsubscribe(ISubcriber subcriber) { lock (_lock) { _subscribers.Remove(subcriber); } }
public void Register(int channel, ISubcriber subcriber) { if (!ExistNotifier(channel)) throw new AntelopeNotiferNotFound(); _subcribers[channel].Add(subcriber); }
public void Notify(ISubcriber subcriber, BaseNotifierData data) { var emailSubcriber = subcriber as EmailSubcriber; var emailData = data as EmailNotifierData; if(emailData == null || emailSubcriber == null) throw new AntelopeInvalidParameter(); try { var fromAddress = new MailAddress(_emailAddr, _emailDisplayName); var toAddress = new MailAddress(emailSubcriber.Email, emailSubcriber.DisplayName); using (var message = new MailMessage(fromAddress, toAddress) { Subject = emailData.Title, Body = Formatter.Format(emailData.Content) }) { _smtp.Send(message); } } catch(FormatException) { throw new AntelopeInvalidEmailFormat(); } catch(SmtpException ex) { throw new AntelopeSmtpException(ex.ToString()); } catch (Exception ex) { _logger.Error("Caught exception when sending notification through email to {0}: {1}", emailSubcriber.Email, ex.ToString()); } }
public async void Notify(ISubcriber subcriber, BaseNotifierData data) { var signalrSubcriber = subcriber as SignalRSubcriber; var signalrData = data as MessageNotifierData; if (signalrSubcriber == null || signalrData == null) throw new AntelopeInvalidParameter(); try { _connection = new HubConnection(signalrSubcriber.Url); _proxy = _connection.CreateHubProxy(HubName()); _connection.Closed += OnConnectionClosed; await _connection.Start(); } catch (HttpRequestException) { _logger.Info("Can't connect to {0}", signalrSubcriber.Url); } await _proxy.Invoke(HubMethod(), Formatter.Format(signalrData.Content)); }
public void Notify(ISubcriber subcriber, BaseNotifierData data) { var skypeData = data as SkypeNotifierData; var skypeSubcriber = subcriber as SkypeSubcriber; if (skypeData == null || skypeSubcriber == null) throw new AntelopeInvalidParameter(); if (_friends.Find(fr => fr.Handle == skypeSubcriber.Handle) == null) throw new AntelopeUnknownTarget(); try { _skypeHandler.SendMessage(skypeSubcriber.Handle, Formatter.Format(skypeData.Message)); } catch (Exception ex) { _logger.Error("Caught exception when sending notification through skype to {0}: {1}", skypeSubcriber.Handle, ex.ToString()); } }