/// <summary> /// Creates an IInbox /// </summary> /// <param name="serverConfiguration">The mail server configuration</param> /// <param name="inBoxImplementationType">The type of inbox implementation</param> /// <param name="user">The user</param> /// <returns>An IInbox instance</returns> public IInbox GetInbox(IMailServerConfiguration serverConfiguration, Type inBoxImplementationType, object user) { if (serverConfiguration == null) throw new NullArgumentException("serverConfiguration"); if (inBoxImplementationType == null) throw new NullArgumentException("inboxImplementationType"); if (user == null) throw new NullArgumentException("user"); string replyAddress = serverConfiguration.ReplyAddress; lock (_inboxFactoringLock) { try { IInbox inbox = null; if (!_inboxes.TryGetValue(replyAddress, out inbox)) { inbox = (IInbox)inBoxImplementationType.GetConstructor(new Type[0]).Invoke(null); inbox.InboxServerConfiguration = serverConfiguration; _inboxUsers[inbox] = 0; _inboxes[replyAddress] = inbox; inbox.BeginReceiving(); } _userInboxes[user] = inbox; _inboxUsers[inbox] = _inboxUsers[inbox] + 1; return inbox; } catch (Exception ex) { throw new FailedToGetInboxException(serverConfiguration, inBoxImplementationType, user, ex); } } }
/// <summary> /// Constructor /// </summary> public RaspMailHandler(IMailHandlerConfiguration configuration) { IMailServerConfiguration sendingServerConfiguration = configuration.SendingServerConfiguration; IMailServerConfiguration recievingServerConfiguration = configuration.RecievingServerConfiguration; Type outBoxImplementationType = configuration.OutBoxImplementationType; Type inBoxImplementationType = configuration.InBoxImplementationType; _inboxFactory = InboxFactory.GetInstance(); _inbox = _inboxFactory.GetInbox(recievingServerConfiguration, inBoxImplementationType, this); _outbox = (IOutbox)outBoxImplementationType.GetConstructor(new Type[0]).Invoke(null); _outbox.OutboxServerConfiguration = sendingServerConfiguration; if (_inbox != null) { _inbox.OnExceptionThrown += new MailboxExceptionThrown(CallbackExceptionThrown); _inbox.OnInboxStateChange += new OnInboxStateChangeDelegate(CallbackOnInboxStateChange); } if (_outbox != null) { _outbox.OnExceptionThrown += new MailboxExceptionThrown(CallbackExceptionThrown); } }
public StreamClient(EngineSettings settings, IInbox inbox, HttpClient client, GitterClient gitter, ILog log) : base(log) { _client = client; _inbox = inbox; _settings = settings; _log = log; _gitter = gitter; }
/// <summary> /// Constructor that duplicates another RaspMailHandler /// </summary> /// <param name="original">original mailhandler</param> public RaspMailHandler(RaspMailHandler original) { _inbox = original._inbox; _outbox = original._outbox; if (_inbox != null) { _inbox.OnExceptionThrown += new MailboxExceptionThrown(CallbackExceptionThrown); _inbox.OnInboxStateChange += new OnInboxStateChangeDelegate(CallbackOnInboxStateChange); } if (_outbox != null) { _outbox.OnExceptionThrown += new MailboxExceptionThrown(CallbackExceptionThrown); } }
/// <summary> /// Indicates that an inbox is no longer in use /// </summary> /// <param name="user">The user</param> public void FinishedUsingInbox(object user) { if (user == null) throw new NullArgumentException("user"); lock (_inboxFactoringLock) { try { IInbox inbox = _userInboxes[user]; _userInboxes.Remove(user); ulong inboxUsers = _inboxUsers[inbox] - 1; if (inboxUsers == 0) { string replyAddress = inbox.InboxServerConfiguration.ReplyAddress; if (inbox.InboxState == InboxState.Listening) inbox.Close(); _inboxes.Remove(replyAddress); _inboxUsers.Remove(inbox); } _inboxUsers[inbox] = inboxUsers; } catch (Exception ex) { throw new FailedToStopUsingInboxException(user, ex); } } }
public Engine(EngineSettings settings, IInbox inbox, ILog log, IEnumerable <RobotPart> handlers) : base(log) { if (string.IsNullOrWhiteSpace(settings.Token)) { throw new ArgumentException("No Gitter API key set.", nameof(settings)); } _log = log; var client = new HttpClient { Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite) }; client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", settings.Token); var gitter = new GitterClient(client); _inbox = inbox; _streamClient = new StreamClient(settings, _inbox, client, gitter, _log); _webJobShutdownListener = new WebJobShutdownListener(_log); _dispatcher = new EventDispatcher(gitter, _log, handlers); }
// Messages /// <summary> /// Searches the contents of messages from either inbox or sentbox. /// </summary> /// <param name="options">Object implementing the IInbox interface.</param> /// <returns>JSON response deserialized into Inbox object.</returns> public Inbox GetInbox(IInbox options) { var builder = new QueryBuilder("ajax.php?action=inbox"); if (options.DisplayUnreadFirst) builder.Append("sort", "unread"); builder.Append("type", options.MessageType); builder.Append("page", options.Page); builder.Append("search", options.SearchTerm); builder.Append("searchtype", options.SearchType); var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString()); return JsonConvert.DeserializeObject<Inbox>(json, JsonSettings); }
public HelpCommand(IInbox inbox) : base(new [] { "help" }) { _inbox = inbox; }
public InboxEventHandlerDecorator(IEventHandler <T> handler, IInbox inbox) { _handler = handler; _inbox = inbox; _module = _handler.GetModuleName(); }
public static InMemoryCourier Default(IInbox inbox) { return new InMemoryCourier(inbox); }