Ejemplo n.º 1
0
 public List <BaseNotification> CollectNotifications(GetNotificationsResponse response)
 {
     return(EnumerateValidNotifications(logger, response.AddFriendshipInvitation, NotificationValidator.Validate).Concat(EnumerateValidNotifications(logger, response.AddFriendship, NotificationValidator.Validate)).Concat(EnumerateValidNotifications(logger, response.RemoveFriendship, NotificationValidator.Validate)).Concat(EnumerateValidNotifications(logger, response.RemoveFriendshipInvitation, NotificationValidator.Validate))
            .Concat(EnumerateValidNotifications(logger, response.RemoveFriendshipTrust, NotificationValidator.Validate))
            .Concat(EnumerateValidNotifications(logger, response.AddAlert, NotificationValidator.Validate))
            .Concat(EnumerateValidNotifications(logger, response.ClearAlert, NotificationValidator.Validate))
            .ToList());
 }
        public GetNotificationsResponse GetNotifications(LacesRequest request)
        {
            GetNotificationsResponse response = new GetNotificationsResponse();

            try
            {
                if (request.SecurityString == ConfigurationManager.AppSettings[Constants.APP_SETTING_SECURITY_TOKEN])
                {
                    StoredProcedure proc = new StoredProcedure(Constants.CONNECTION_STRING, Constants.STORED_PROC_GET_NOTIFICATIONS);

                    proc.AddInput("@userId", request.UserId, System.Data.SqlDbType.Int);

                    DataSet resultSet = proc.ExecuteDataSet();

                    if (resultSet.Tables.Count > 0 && resultSet.Tables[0].Rows != null && resultSet.Tables[0].Rows.Count > 0)
                    {
                        response.Notifications = new List <Notification>();

                        foreach (DataRow row in resultSet.Tables[0].Rows)
                        {
                            Notification alert = new Notification();

                            alert.CreatedDate      = Convert.ToDateTime(row["CreatedDate"]);
                            alert.NotificationType = Convert.ToInt32(row["NotificationTypeId"]);
                            alert.ProductId        = Convert.ToInt32(row["ProductId"]);
                            alert.UserName         = Convert.ToString(row["UserName"]);

                            response.Notifications.Add(alert);
                        }

                        response.Success = true;
                        response.Message = "Notifications retrieved succesfully.";
                    }
                    else
                    {
                        response.Success = true;
                        response.Message = "Could not find any notifications to display.";
                    }
                }
                else
                {
                    response.Success = false;
                    response.Message = "Invalid security token.";
                }
            }
            catch
            {
                response         = new GetNotificationsResponse();
                response.Success = false;
                response.Message = "An unexpected error has occurred; please verify the format of your request.";
            }

            return(response);
        }
Ejemplo n.º 3
0
        private void HandleGetNotificationsResponse(GetNotificationsResponse response)
        {
            isPolling = false;
            if (isDisposed)
            {
                return;
            }
            if (!Validate(response))
            {
                logger.Critical("Invalid notifications response:\n" + JsonParser.ToJson(response));
                return;
            }
            long?lastNotificationTimestamp = response.LastNotificationTimestamp;
            List <BaseNotification> list   = getStateResponseParser.CollectNotifications(response);

            RemoveMissingNotificationTimes(list, missedNotificationTimes);
            RemoveInvalidNotifications(list, queue);
            SortNotificationsBySequenceNumber(list);
            long               value                  = response.NotificationSequenceCounter.Value;
            long               requestedSince         = queue.LatestSequenceNumber + 1;
            List <long>        queued                 = queue.SequenceNumbers.ToList();
            IEnumerable <long> missingSequenceNumbers = GetMissingSequenceNumbers(requestedSince, queued, list, value);
            long               milliseconds           = epochTime.Milliseconds;

            AddTimes(missingSequenceNumbers, missedNotificationTimes, milliseconds);
            bool anyMissing   = missedNotificationTimes.Count > 0;
            bool anyReceived  = list.Count > 0;
            int  numIntervals = CurIntervals.Length;

            IntervalIndex = GetNextIntervalIndex(IntervalIndex, numIntervals, anyMissing, anyReceived);
            queue.Dispatch(list, delegate
            {
            }, delegate
            {
            });
            DispatchOnNotificationsPolledIfNotNull(lastNotificationTimestamp);
            PollAgain();
            if (IsNotificationMissingTooLong)
            {
                Pause();
                missedNotificationTimes.Clear();
                DispatchOnSynchronizationError();
            }
        }
Ejemplo n.º 4
0
        private void LoadNotification()
        {
            ThreadPool.QueueUserWorkItem(delegate
            {
                LungCare.SupportPlatform.WebAPIWorkers.NotificationsWorker.GetNotificationRequest(
                    this._userInfo.PhoneNumber,
                    successCallback : delegate(LungCare.SupportPlatform.Models.GetNotificationsResponse response)
                {
                    Dispatcher.Invoke(new Action(delegate
                    {
                        if (response.NotificationList != null)
                        {
                            response.NotificationList.Sort(delegate(NotificationItem t1, NotificationItem t2)
                            {
                                return(-t1.TimeStamp.CompareTo(t2.TimeStamp));
                            });
                        }
                        this._notifications = response;
                        ResumeGUI();

                        MaWindow wnd = new MaWindow(_userInfo, _downloadUserIcon, _certificateRespnse, _certificateApproveStatus, this._notifications);
                        wnd.Loaded  += delegate
                        {
                            Visibility = Visibility.Hidden;
                        };
                        wnd.ShowDialog();
                    }));
                },
                    failureCallback : delegate(string failureReason)
                {
                    Dispatcher.Invoke(new Action(delegate
                    {
                        MessageBox.Show(failureReason);
                    }));
                },
                    errorCallback : delegate(Exception ex)
                {
                    Dispatcher.Invoke(new Action(delegate
                    {
                        LungCare.SupportPlatform.WebAPIWorkers.Util.ShowExceptionMessage(ex, "获取消息列表出错。");
                    }));
                });
            });
        }
Ejemplo n.º 5
0
 private static bool Validate(GetNotificationsResponse response)
 {
     return(response.NotificationSequenceCounter.HasValue);
 }