예제 #1
0
        private void GetSettingsHandler()
        {
            try
            {
                if (_appEnvironment.ServiceConnector == null)
                {
                    throw new NullReferenceException($"Null reference of { nameof(_appEnvironment.ServiceConnector) }");
                }

                var response = _appEnvironment.ServiceConnector.Get <EmptyRequestBodyDto, SettingDto, ErrorMsgDto>(new Request <EmptyRequestBodyDto>
                {
                    AuthToken   = new KeyValuePair <string, string>("session_token", SessionStorage.Instance.SessionId),
                    UrlSegments = new Dictionary <string, string>()
                    {
                        { "id", SessionStorage.Instance.ProfileId }
                    },
                    OpName = OperationType.GetSettings
                });

                if (response.SuccessBody != null)
                {
                    using (UntrackedContext <SettingsViewModel> .Untrack(this))
                    {
                        if (response.SuccessBody.ActivityCategories != null)
                        {
                            CategoriesRawText = String.Join(";", response.SuccessBody.ActivityCategories);
                        }

                        if (response.SuccessBody.TrackedSites != null)
                        {
                            SitesRawText = String.Join(";", response.SuccessBody.TrackedSites);
                        }

                        NeedBeginNotify   = response.SuccessBody.NotificationNeedStart;
                        EnableSoundNotify = response.SuccessBody.EnableSoundNotify;
                        EnablePopupNotify = response.SuccessBody.EnablePopupNotify;
                    }

                    _appEnvironment.EventHub.Publish <ChangeSettingsMessage>(new ChangeSettingsMessage()
                    {
                        NeedBegin       = NeedBeginNotify,
                        NeedPopupNotify = EnablePopupNotify,
                        NeedSoundNotify = EnableSoundNotify,
                        Categories      = _categories
                    });
                }
            }
            catch (ApplicationException e)
            {
                Logger.Log.Debug(e.Message);
            }
            catch (Exception e)
            {
                Logger.Log.Debug(e.Message);
            }
        }
예제 #2
0
        private void GetAllActivities()
        {
            try
            {
                if (_appEnvironment.ServiceConnector == null)
                {
                    throw new NullReferenceException($"Null reference of { nameof(_appEnvironment.ServiceConnector) }");
                }

                Double totalSeconds = default(Double);

                var userInfo = new UserInfoDto()
                {
                    ProfileId = SessionStorage.Instance.ProfileId
                };
                var response = _appEnvironment.ServiceConnector.Get <UserInfoDto, List <ActivityDto>, ErrorMsgDto>(new Request <UserInfoDto>
                {
                    AuthToken = new KeyValuePair <string, string>("session_token", SessionStorage.Instance.SessionId),
                    Body      = userInfo,
                    OpName    = OperationType.GetActivities
                });

                if (response.SuccessBody != null)
                {
                    foreach (var activityDto in response.SuccessBody)
                    {
                        var existedActivity = Activities.Where(a => { return(a.Id == activityDto.Id); }).FirstOrDefault();

                        if (existedActivity == null)
                        {
                            var newActivity = new ActivityDomainModel();
                            using (UntrackedContext <ActivityDomainModel> .Untrack(newActivity))
                            {
                                newActivity.Id               = activityDto.Id;
                                newActivity.ProfileId        = activityDto.ProfileId;
                                newActivity.IsStarted        = activityDto.IsStarted;
                                newActivity.Description      = activityDto.Description;
                                newActivity.Category         = activityDto.Category;
                                newActivity.DurationSeconds  = activityDto.ActualDuration;
                                newActivity.CreatedAt        = DateTimeHelpers.ConvertFromUnixTimestamp(activityDto.CreatedAt).ToLocalTime();
                                newActivity.BeginTime        = DateTimeHelpers.ConvertFromUnixTimestamp(activityDto.BeginTime).ToLocalTime();
                                newActivity.PlannedBeginTime = DateTimeHelpers.ConvertFromUnixTimestamp(activityDto.PlannedBeginTime).ToLocalTime();

                                if (activityDto.WorkIntervals != null)
                                {
                                    foreach (var interval in activityDto.WorkIntervals)
                                    {
                                        newActivity.WorkIntervals.Add(new WorkInterval()
                                        {
                                            Begin = DateTimeHelpers.ConvertFromUnixTimestamp(interval.Begin).ToLocalTime(),
                                            End   = DateTimeHelpers.ConvertFromUnixTimestamp(interval.End).ToLocalTime()
                                        });
                                    }
                                }

                                Activities.Add(newActivity);
                            };

                            totalSeconds        += activityDto.ActualDuration;
                            TotalDurationSeconds = totalSeconds;
                        }
                    }
                }
            }
            catch (ApplicationException e)
            {
                Logger.Log.Debug(e.Message);
            }
            catch (Exception e)
            {
                Logger.Log.Debug(e.Message);
            }
        }