Example #1
0
        public async Task <bool> NotificationDeleteAsync(Ekreta.Mobile.Core.Models.Profile profile, bool useGlobalMobileApiV1 = false)
        {
            if (profile == null)
            {
                throw new ArgumentNullException(nameof(profile));
            }
            PushSettings pushSettings;

            try
            {
                pushSettings = await this._globalMobileApi.NotificationDeleteAsync(profile?.PushSettings?.RegistrationId, NotificationMessageSource.Kreta, useGlobalMobileApiV1);
            }
            catch (KeyNotFoundException ex)
            {
                profile.PushSettings = (PushSettings)null;
                this._profileRepository.AddOrUpdate(profile);
                pushSettings = new PushSettings();
            }
            if (pushSettings != null)
            {
                pushSettings.FirstTimePushRun  = true;
                pushSettings.UpdateEugyintezes = true;
                profile.PushSettings           = pushSettings;
                this._profileRepository.AddOrUpdate(profile);
            }
            return(pushSettings != null);
        }
Example #2
0
 public Ekreta.Mobile.Core.Models.Profile GetProfile(
     string instituteCode,
     int instituteUserId,
     int roleId)
 {
     Ekreta.Mobile.Core.Models.Profile activeProfile = this.GetActiveProfile();
     return(roleId != 2 ? this._profileRepository.Query((ISpecification) new GetProfileByUserIdAndInstituteCodeSpecification(instituteCode, instituteUserId, roleId)).FirstOrDefault <Ekreta.Mobile.Core.Models.Profile>() : (activeProfile.TokenInfo.InstituteUserId == instituteUserId ? activeProfile : this._profileRepository.Query((ISpecification) new GetProfileByInstituteUserIdSpecification(instituteCode, instituteUserId)).FirstOrDefault <Ekreta.Mobile.Core.Models.Profile>()));
 }
Example #3
0
        public void UpdateTokenData(Ekreta.Mobile.Core.Models.Profile profile, TokenData tokenData)
        {
            TokenInfo tokenInfo = (TokenInfo)JsonConvert.DeserializeObject <TokenInfo>(TokenDecoder.Decode(tokenData.AccessToken));

            profile.TokenInfo = tokenInfo;
            this.AddOrUpdate(profile);
            this._secureStore.SaveTokenData(profile.Id, tokenData);
        }
Example #4
0
        public async Task <bool> NotificationRegistrationAsync(Ekreta.Mobile.Core.Models.Profile profile)
        {
            try
            {
                if (!this._pushNotificationPlatformSpecificService.IsPushNotificationEnabledByDevice())
                {
                    throw new DisabledPushByDeviceException().SetErrorCode <DisabledPushByDeviceException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Repository/DataServices/ProfileDataService.cs", 123);
                }
                string platform = this._pushNotificationHandler.Platform.ToString();
                NotificationMessageType notificationType = NotificationMessageType.All;
                string handle = this._pushNotificationHandler.Token;
                NotificationMessageSource notificationSource = NotificationMessageSource.Kreta;
                TokenData tokenData = this._secureStore.GetTokenData(profile.Id);
                if (tokenData.ExpiresAt <= DateTime.Now)
                {
                    tokenData = await((IAuthDataService)Mvx.get_IoCProvider().Resolve <IAuthDataService>()).RefreshToken(profile);
                }
                if (tokenData == null)
                {
                    return(false);
                }
                profile.TokenInfo = (TokenInfo)JsonConvert.DeserializeObject <TokenInfo>(TokenDecoder.Decode(tokenData.AccessToken));
                PushSettings pushSettings = await this._globalMobileApi.NotificationRegistrationAsync(profile.TokenInfo.InstituteCode, profile.TokenInfo.InstituteUserId, profile.TokenInfo.TutelaryId, platform, handle, profile.TokenInfo.Role, notificationSource, (int)notificationType, profile.Id);

                if (pushSettings != null)
                {
                    pushSettings.NotificationTypes = notificationType;
                    pushSettings.FirstTimePushRun  = true;
                    pushSettings.UpdateEugyintezes = true;
                    pushSettings.Token             = handle;
                    profile.PushSettings           = pushSettings;
                }
                else if (profile.PushSettings != null)
                {
                    profile.PushSettings.FirstTimePushRun = true;
                }
                else
                {
                    profile.PushSettings = new PushSettings()
                    {
                        FirstTimePushRun = true
                    }
                };
                this.AddOrUpdate(profile);
                return(pushSettings != null);
            }
            catch (DisabledPushByDeviceException ex)
            {
                ex.SetErrorCode <DisabledPushByDeviceException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Repository/DataServices/ProfileDataService.cs", 180);
                throw;
            }
            catch (Exception ex)
            {
                CrossMobileAnalytics.Current.TrackException(ex, (IDictionary <string, string>)null, "ProfileDataService.NotificationRegistrationAsync", "/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Repository/DataServices/ProfileDataService.cs", 75);
                return(false);
            }
        }
Example #5
0
        public void DeleteOnlyProfileData(Ekreta.Mobile.Core.Models.Profile profile)
        {
            switch (profile.PushSettings?.RegistrationId)
            {
            case null:
                this._profileRepository.Remove(profile);
                break;

            default:
                this._pushSettingsRepository.Remove(profile.PushSettings);
                goto case null;
            }
        }
Example #6
0
        public void Delete(Ekreta.Mobile.Core.Models.Profile profile)
        {
            ((ICredentialsDataService)Mvx.get_IoCProvider().Resolve <ICredentialsDataService>()).DeleteCredentialByProfileId(profile.Id);
            this._tokenInfoRepository.Remove(profile.TokenInfo);
            switch (profile.PushSettings?.RegistrationId)
            {
            case null:
                this._profileRepository.Remove(profile);
                break;

            default:
                this._pushSettingsRepository.Remove(profile.PushSettings);
                goto case null;
            }
        }
Example #7
0
        public void SetActiveProfile(Ekreta.Mobile.Core.Models.Profile profile)
        {
            IEnumerable <Ekreta.Mobile.Core.Models.Profile> profiles = this.GetProfiles();

            foreach (Ekreta.Mobile.Core.Models.Profile profile1 in profiles)
            {
                profile1.IsActive = profile1.Id == profile.Id;
            }
            if (profiles.Any <Ekreta.Mobile.Core.Models.Profile>((Func <Ekreta.Mobile.Core.Models.Profile, bool>)(x => x.PushSettings != null && x.PushSettings.IsPushActive)) && !this._pushNotificationPlatformSpecificService.IsPushNotificationEnabledByDevice())
            {
                Dialogs.ShowToast("Push_SubscribedNeedEnable");
            }
            profile.IsActive = true;
            this._profileRepository.AddOrUpdate(profiles);
            this.DefaultPushRegistration().Wait(30000);
        }
Example #8
0
        public async Task <bool> NotificationUpdateAsync(
            Ekreta.Mobile.Core.Models.Profile profile,
            NotificationMessageType notificationType,
            string token)
        {
            try
            {
                PushSettings pushSettings = await this._globalMobileApi.NotificationUpdateAsync(profile.PushSettings.RegistrationId, (int)notificationType, NotificationMessageSource.Kreta, token);

                profile.PushSettings.NotificationTypes = notificationType;
                profile.PushSettings.Token             = token;
                this.AddOrUpdate(profile);
                return(true);
            }
            catch (Exception ex)
            {
                CrossMobileAnalytics.Current.TrackException(ex, (IDictionary <string, string>)null, nameof(NotificationUpdateAsync), "/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Repository/DataServices/ProfileDataService.cs", 206);
                return(false);
            }
        }
Example #9
0
 public void AddOrUpdate(Ekreta.Mobile.Core.Models.Profile profile)
 {
     this._profileRepository.AddOrUpdate(profile);
 }