Ejemplo n.º 1
0
 private void DequeuePollingLoop()
 {
     // Set the name of the thread for debugging purposes
     Thread.CurrentThread.Name = "Inbox.Dequeue polling thread";
     try {
         while ((_state != InboxState.Faulted && _state != InboxState.Closed))
         {
             // Do we have any requestors?
             if (_requests.Count > 0)
             {
                 MailSoap12TransportBinding msg = Dequeue();
                 // Was there a message?
                 if (msg != null)
                 {
                     InboxRequest requestor = _requests[0];
                     requestor.msg = msg;
                     requestor.onFinished.Set();
                     lock (_requests) {
                         _requests.Remove(requestor);
                     }
                 }
             }
             Thread.Sleep(200);
         }
     }
     catch (Exception e) {
         SetState(InboxState.Faulted);
         RaiseExceptionEvent(e);
     }
     finally {
         // Release all requests for a mail, now that the polling is shut down
         ReleaseAllRequestors();
     }
 }
Ejemplo n.º 2
0
        public async Task <HttpResponseMessage> Put([FromBody] InboxRequest request)
        {
            int?folderId = 0;

            var response = await _service.UpsertInbox(request, folderId, SystemDbStatus.Inserted, Request.GetSession()).ConfigureAwait(false);

            return(Request.SystemResponse(response.Status, new { FolderId = response.Data.Id, MessageRuleList = response.Data.Value }, message: response.Message));
        }
Ejemplo n.º 3
0
        public async Task<HttpResponseMessage> Post([FromBody] SingleData<GeneralKvPair<int, string>> request)
        {
            if (!Validation.Required(request.Data.Value, x => request.Data.Value, ActionContext, ModelState))
                return ActionContext.Response;

            var requestCasted = new InboxRequest { Name = request.Data.Value, UserId = request.UserId, DeviceId = request.DeviceId };
            var response = await _service.UpsertInbox(requestCasted, request.Data.Id, Request.GetSession()).ConfigureAwait(false);
            return Request.SystemResponse<string>(response.Status, message: response.Message);
        }
Ejemplo n.º 4
0
        public async Task <StatusData <int> > UpsertInbox(InboxRequest request, int folderId, SystemSession session)
        {
            var inboxRequest = new Kauwa.Inbox {
                UserId = request.UserId, Name = request.Name, FolderId = folderId
            };

            var response = await Task.Factory.StartNew(() => Client.InboxService.updateInboxFolderName(inboxRequest, session.GetSession())).ConfigureAwait(false);

            var result = response.GetStatusData <int>();

            result.Data = folderId;
            return(result);
        }
Ejemplo n.º 5
0
        public async Task <HttpResponseMessage> Post([FromBody] SingleData <GeneralKvPair <int, string> > request)
        {
            if (!Validation.Required(request.Data.Value, x => request.Data.Value, ActionContext, ModelState))
            {
                return(ActionContext.Response);
            }

            var requestCasted = new InboxRequest {
                Name = request.Data.Value, UserId = request.UserId, DeviceId = request.DeviceId
            };
            var response = await _service.UpsertInbox(requestCasted, request.Data.Id, Request.GetSession()).ConfigureAwait(false);

            return(Request.SystemResponse <string>(response.Status, message: response.Message));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// De-queues the first mail
        /// </summary>
        /// <param name="timeout">Maximum time to wait for a mail to come</param>
        /// <param name="onAbortDequeueing">AutoResetEvent that if set will abort the de-queueing</param>
        /// <returns></returns>
        public MailSoap12TransportBinding Dequeue(TimeSpan timeout, AutoResetEvent onAbortDequeueing)
        {
            // Is the mailbox closed?
            if (_state == InboxState.Closed ||
                _state == InboxState.Closing ||
                _state == InboxState.Faulted)
            {
                return(null);
            }

            InboxRequest request = new InboxRequest();

            // Make sure the request can be aborted from the outside as well
            if (onAbortDequeueing == null)
            {
                onAbortDequeueing = new AutoResetEvent(false);
            }
            request.onFinished = onAbortDequeueing;

            // Add the request to the list of requests currently pending
            lock (_requests) {
                _requests.Add(request);
            }

            // Wait until request is finished or until a timeout occurs
            if (!request.onFinished.WaitOne(Utilities.TimeSpanInMilliseconds(timeout), false))
            {
                lock (_requests) {
                    _requests.Remove(request);
                }
                //RaiseExceptionEvent(new TimeoutException());
                throw new TimeoutException();
            }

            // Remove the request from the list
            lock (_requests) {
                _requests.Remove(request);
            }

            // Return the message
            return(request.msg);
        }
Ejemplo n.º 7
0
        public async Task<StatusData<GeneralKvPair<int, List<long>>>> UpsertInbox(InboxRequest request, SystemSession session)
        {
            var result = new StatusData<GeneralKvPair<int, List<long>>>();
            if (request.Rule != null && request.Rule.Any())
                request.Rule.RemoveAll(x => x.UserSelection == SystemUserSelection.None && x.RuleTypeSubject == SystemRuleTypeSubject.None);

            var inboxRequest = new Kauwa.Inbox { UserId = request.UserId, Name = request.Name, FolderId = 0, InboxRules = request.Rule != null && request.Rule.Any() ? request.Rule.Select(x => new InboxRule { TypeUserSelection = (int)x.UserSelection, RuleTypeUser = (int)x.RuleTypeUser, ContactList = x.ContactList, GroupList = x.GroupList, RuleTypeSubject = (int)x.RuleTypeSubject, Subject = x.Subject, ApplyOnOldMessage = x.ApplyOnOldMessage }).ToList() : null };

            var response = await Task.Factory.StartNew(() => Client.InboxService.createInboxWithRules(inboxRequest, session.GetSession())).ConfigureAwait(false);
            result.Status = (SystemDbStatus)response.DbStatusCode;
            result.Data = new GeneralKvPair<int, List<long>>();
            result.Message = response.DbStatusMsg;

            result.Data = new GeneralKvPair<int, List<long>>
            {
                Id = response.FolderId,
                Value = response.InboxRules != null ? response.InboxRules.Select(x => x.RuleId).ToList() : null
            };

            return result;
        }
Ejemplo n.º 8
0
        public async Task <StatusData <GeneralKvPair <int, List <long> > > > UpsertInbox(InboxRequest request, int?folderId, SystemDbStatus dbMode)
        {
            var result            = new StatusData <GeneralKvPair <int, List <long> > >();
            var folderIdObj       = new ObjectParameter("FOLDERID", folderId ?? 0);
            var messageRuleIdsObj = new ObjectParameter("MESSAGERULEIDS", typeof(string));

            var rules = string.Empty;

            if (request.Rule != null && request.Rule.Any())
            {
                var sb = new StringBuilder();
                foreach (var rule in request.Rule)
                {
                    sb.Append(rule).Append("|");
                }
                rules = sb.ToString().Substring(0, sb.Length - 1);
            }
            result.Status = (SystemDbStatus)await Task.Factory.StartNew(() => Context.PROC_UPSERT_INBOX(request.UserId, request.Name, rules, (byte)dbMode, folderIdObj, messageRuleIdsObj).FirstOrDefault().GetValueOrDefault());

            result.Data = new GeneralKvPair <int, List <long> >();
            if (result.Status.IsOperationSuccessful())
            {
                result.Data.Id = Convert.ToInt32(folderIdObj.Value);
                rules          = messageRuleIdsObj.Value.ToString();
                if (!string.IsNullOrWhiteSpace(rules))
                {
                    result.Data.Value = (rules.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt64(x))).ToList();
                }
            }
            return(result);
        }
Ejemplo n.º 9
0
 public Task<StatusData<int>> UpsertInbox(InboxRequest request, int folderId, SystemSession session)
 {
     return _jUnitOfWork.Inbox.UpsertInbox(request, folderId, session);
 }
Ejemplo n.º 10
0
 public Task<StatusData<GeneralKvPair<int, List<long>>>> UpsertInbox(InboxRequest request, int? folderId, SystemDbStatus dbMode, SystemSession session)
 {
     return _jUnitOfWork.Inbox.UpsertInbox(request, session);
 }
Ejemplo n.º 11
0
        public async Task <StatusData <GeneralKvPair <int, List <long> > > > UpsertInbox(InboxRequest request, SystemSession session)
        {
            var result = new StatusData <GeneralKvPair <int, List <long> > >();

            if (request.Rule != null && request.Rule.Any())
            {
                request.Rule.RemoveAll(x => x.UserSelection == SystemUserSelection.None && x.RuleTypeSubject == SystemRuleTypeSubject.None);
            }

            var inboxRequest = new Kauwa.Inbox {
                UserId = request.UserId, Name = request.Name, FolderId = 0, InboxRules = request.Rule != null && request.Rule.Any() ? request.Rule.Select(x => new InboxRule {
                    TypeUserSelection = (int)x.UserSelection, RuleTypeUser = (int)x.RuleTypeUser, ContactList = x.ContactList, GroupList = x.GroupList, RuleTypeSubject = (int)x.RuleTypeSubject, Subject = x.Subject, ApplyOnOldMessage = x.ApplyOnOldMessage
                }).ToList() : null
            };

            var response = await Task.Factory.StartNew(() => Client.InboxService.createInboxWithRules(inboxRequest, session.GetSession())).ConfigureAwait(false);

            result.Status  = (SystemDbStatus)response.DbStatusCode;
            result.Data    = new GeneralKvPair <int, List <long> >();
            result.Message = response.DbStatusMsg;

            result.Data = new GeneralKvPair <int, List <long> >
            {
                Id    = response.FolderId,
                Value = response.InboxRules != null?response.InboxRules.Select(x => x.RuleId).ToList() : null
            };

            return(result);
        }
Ejemplo n.º 12
0
        public async Task<StatusData<int>> UpsertInbox(InboxRequest request, int folderId, SystemSession session)
        {
            var inboxRequest = new Kauwa.Inbox { UserId = request.UserId, Name = request.Name, FolderId = folderId };

            var response = await Task.Factory.StartNew(() => Client.InboxService.updateInboxFolderName(inboxRequest, session.GetSession())).ConfigureAwait(false);

            var result = response.GetStatusData<int>();
            result.Data = folderId;
            return result;
        }
Ejemplo n.º 13
0
 public Task <StatusData <int> > UpsertInbox(InboxRequest request, int folderId, SystemSession session)
 {
     return(_jUnitOfWork.Inbox.UpsertInbox(request, folderId, session));
 }
Ejemplo n.º 14
0
 public Task <StatusData <GeneralKvPair <int, List <long> > > > UpsertInbox(InboxRequest request, int?folderId, SystemDbStatus dbMode, SystemSession session)
 {
     return(_jUnitOfWork.Inbox.UpsertInbox(request, session));
 }