Пример #1
0
        private async void TimerDownload(EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString());

            if (!IsExistUserData)
            {
                return;
            }

            var downloadModel = await httpDataService.PostUserAsync(current);

            if (downloadModel.UserStatus != current.UserStatus)
            {
                var newModel = new UserDataModel()
                {
                    UserUuid   = current.UserUuid,
                    Major      = current.Major,
                    Minor      = current.Minor,
                    UserStatus = current.UserStatus
                };
                await SetAsync(newModel);
            }
        }
Пример #2
0
        private async void TimerDownload(EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString());
            if (!IsExistUserData)
            {
                return;
            }
            UserDataModel downloadModel;

            try
            {
                downloadModel = await httpDataService.PostUserAsync(current);

                if (downloadModel == null)
                {
                    return;
                }
            }
            catch { return; }
            var hasNotification = downloadModel.LastNotificationTime != current.LastNotificationTime;
            var hasStatusChange = downloadModel.UserStatus != current.UserStatus;

            if (hasStatusChange)
            {
                // Notification Contacted

                /*
                 * if (downloadModel.UserStatus == UserStatus.Contactd)
                 * {
                 *  // TOOD Change to Resouce String
                 *  notificationService.ScheduleNotification("TEST", "MESSAGE");
                 * }
                 */
                var newModel = new UserDataModel()
                {
                    UserUuid             = current.UserUuid,
                    Major                = current.Major,
                    Minor                = current.Minor,
                    UserStatus           = downloadModel.UserStatus,
                    LastNotificationTime = current.LastNotificationTime
                };
                await SetAsync(newModel);
            }
            if (hasNotification)
            {
                // Pull Notification.
                try
                {
                    var newModel = new UserDataModel()
                    {
                        UserUuid             = current.UserUuid,
                        Major                = current.Major,
                        Minor                = current.Minor,
                        UserStatus           = current.UserStatus,
                        LastNotificationTime = downloadModel.LastNotificationTime
                    };
                    var result = await httpDataService.PostNotificationPullAsync(newModel);

                    foreach (var notify in result.Messages)
                    {
                        notificationService.ReceiveNotification(notify.Title, notify.Message);
                    }
                    await SetAsync(newModel);
                }
                catch (Exception) { }
            }
        }