Ejemplo n.º 1
0
        private void AddEventToQueue(BaseEventDataViewModel baseEventDataViewModel)
        {
            if (_batchEventViewModel == null || _totalEventCount == 0)
            {
                _batchEventViewModel = new BatchEventViewModel();
                Invoke("SendByTime", MAX_TIME);
            }

            var className = GetClass(baseEventDataViewModel);

            switch (className)
            {
            case "AchievementEvent":
                _batchEventViewModel.Achievements.Add((AchievementEventViewModel)baseEventDataViewModel);
                break;

            case "AdvertisementEvent":
                _batchEventViewModel.Advertisements.Add((AdvertisementEventViewModel)baseEventDataViewModel);
                break;

            case "BusinessEvent":
                _batchEventViewModel.Businesses.Add((BusinessEventViewModel)baseEventDataViewModel);
                break;

            case "ContentViewEvent":
                _batchEventViewModel.ContentViews.Add((ContentViewEventViewModel)baseEventDataViewModel);
                break;

            case "DesignEvent":
                _batchEventViewModel.DesignEvent.Add((DesignEventViewModel)baseEventDataViewModel);
                break;

            case "ProgressionEvent":
                _batchEventViewModel.Progressions.Add((ProgressionEventViewModel)baseEventDataViewModel);
                break;

            case "SocialEvent":
                _batchEventViewModel.Socials.Add((SocialEventViewModel)baseEventDataViewModel);
                break;

            case "TapEvent":
                _batchEventViewModel.Taps.Add((TapEventViewModel)baseEventDataViewModel);
                break;

            default:
                className = "Default";
                break;
            }

            _totalEventCount++;

            if (_totalEventCount >= MAX_EVENT_COUNT)
            {
                if (_sending)
                {
                    return;
                }
                SendBatchEventAsync(_batchEventViewModel);
            }
        }
Ejemplo n.º 2
0
        private async void ExistingEvent(BaseEventDataViewModel baseEventDataViewModel)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                OldRecordCouldNotSent();
                return;
            }

            var className = GetClass(baseEventDataViewModel);

            try
            {
                var(success, statusCode) = await _probaHttpClient.SendEventAsync(baseEventDataViewModel, className);

                if (!success)
                {
                    OldRecordCouldNotSent();
                    return;
                }

                if (statusCode != HttpStatusCode.OK)
                {
                    OldRecordCouldNotSent();
                    _probaLogger.LogWarning($"couldn't send event with {statusCode} status");
                    return;
                }

                OldRecordSent();
            }
            catch (Exception e)
            {
                _probaLogger.LogError(e.Message, e.StackTrace);
                OldRecordCouldNotSent();
            }
        }
Ejemplo n.º 3
0
        private async void ExistingUpdateUsernameAsync(BaseEventDataViewModel baseEvent)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                OldRecordCouldNotSent();
                return;
            }
            try
            {
                var(success, statusCode) = await _probaHttpClient.UpdateUserInfoAsync(baseEvent);

                if (!success)
                {
                    OldRecordCouldNotSent();
                    return;
                }

                _basicData.CurrentUserName = baseEvent.UserName;
                PlayerPrefs.SetString("ProbaUserName", _basicData.CurrentUserName);

                OldRecordSent();
            }
            catch (Exception e)
            {
                _probaLogger.LogError(e.Message, e.StackTrace);
                OldRecordCouldNotSent();
            }
        }
Ejemplo n.º 4
0
        private async void GetUserProgressAsync()
        {
            var baseEventData = new BaseEventDataViewModel();

            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                PROBA.UserProgressCanceled(RequestResponse.NoInternet);
                return;
            }
            try
            {
                var(success, statusCode, configurations) = await _probaHttpClient.GetUserDataAsync(baseEventData);

                if (!success)
                {
                    PROBA.UserProgressCanceled(RequestResponse.Error);
                }

                PROBA.UserDataReceived(configurations.Progress, configurations.Configurations);
            }
            catch (Exception e)
            {
                PROBA.UserProgressCanceled(RequestResponse.Error);
                _probaLogger.LogError(e.Message, e.StackTrace);
            }
        }
Ejemplo n.º 5
0
        private async void ExsitingCheckProgressionStatusAsync(BaseEventDataViewModel baseEvent)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable || _sending)
            {
                OldRecordCouldNotSent();
                return;
            }
            try
            {
                var(success, statusCode, progressionStatus) = await _probaHttpClient.CheckProgressionStatusAsync(baseEvent);

                if (!success)
                {
                    OldRecordCouldNotSent();
                    return;
                }
                PROBA.ProgressionStatusReceived(progressionStatus);
                OldRecordSent();
            }
            catch (Exception e)
            {
                _probaLogger.LogError(e.Message, e.StackTrace);
                OldRecordCouldNotSent();
            }
        }
Ejemplo n.º 6
0
        private async void CheckProgressionStatusAsync()
        {
            var baseEvent = new BaseEventDataViewModel();

            if (Application.internetReachability == NetworkReachability.NotReachable || _sending)
            {
                SaveCheckProgressionStatusInDB(baseEvent);
                return;
            }
            try
            {
                var(success, statusCode, progressionStatus) = await _probaHttpClient.CheckProgressionStatusAsync(baseEvent);

                if (!success)
                {
                    SaveCheckProgressionStatusInDB(baseEvent);
                    return;
                }
                PROBA.ProgressionStatusReceived(progressionStatus);
            }
            catch (Exception e)
            {
                _probaLogger.LogError(e.Message, e.StackTrace);
                SaveCheckProgressionStatusInDB(baseEvent);
            }
        }
Ejemplo n.º 7
0
        private string GetClass(BaseEventDataViewModel baseEventDataViewModel)
        {
            string className;

            switch (baseEventDataViewModel.Class)
            {
            case "AchievementEventViewModel":
                className = "AchievementEvent";
                break;

            case "AdvertisementEventViewModel":
                className = "AdvertisementEvent";
                break;

            case "BusinessEventViewModel":
                className = "BusinessEvent";
                break;

            case "ContentViewEventViewModel":
                className = "ContentViewEvent";
                break;

            case "DesignEventViewModel":
                className = "DesignEvent";
                break;

            case "ProgressionEventViewModel":
                className = "ProgressionEvent";
                break;

            case "SocialEventViewModel":
                className = "SocialEvent";
                break;

            case "TapEventViewModel":
                className = "TapEvent";
                break;

            default:
                className = "Default";
                break;
            }

            return(className);
        }
Ejemplo n.º 8
0
        private async void RegisterAsync(string username, bool newUser)
        {
            var baseEvent = new BaseEventDataViewModel {
                UserName = username, NewUser = newUser
            };

            if (Application.internetReachability == NetworkReachability.NotReachable || _sending)
            {
                SaveRegisterInDB(baseEvent);
                return;
            }
            try
            {
                var(success, statusCode, registerResponse) = await _probaHttpClient.RegisterAsync(baseEvent);

                if (!success)
                {
                    SaveRegisterInDB(baseEvent);
                    return;
                }

                _basicData.UserId                = registerResponse.UserId;
                _basicData.ABTest                = registerResponse.AbTest;
                _basicData.CurrentUserName       = username;
                _basicData.SessionCount          = 0;
                _basicData.PurchesesCount        = 0;
                _basicData.VirtualPurchesesCount = 0;
                _basicData.CreationTime          = DateTime.UtcNow;
                _basicData.OverallPlayTime       = 0;

                PlayerPrefs.SetString("ProbaUserID", _basicData.UserId);
                PlayerPrefs.SetString("ProbaUserName", _basicData.CurrentUserName);
                PlayerPrefs.SetString("ProbaABTest", _basicData.ABTest);

                PROBA.ABTestReceive(_basicData.ABTest);

                new StartSessionViewModel(true);
            }
            catch (Exception e)
            {
                _probaLogger.LogError(e.Message, e.StackTrace);
                SaveRegisterInDB(baseEvent);
            }
        }
Ejemplo n.º 9
0
        private async void ExistingRegister(BaseEventDataViewModel baseEvent)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                OldRecordCouldNotSent();
                return;
            }
            try
            {
                var(success, statusCode, registerResponse) = await _probaHttpClient.RegisterAsync(baseEvent);

                if (!success)
                {
                    OldRecordCouldNotSent();
                    return;
                }

                _basicData.UserId                = registerResponse.UserId;
                _basicData.ABTest                = registerResponse.AbTest;
                _basicData.CurrentUserName       = baseEvent.UserName;
                _basicData.SessionCount          = 0;
                _basicData.PurchesesCount        = 0;
                _basicData.VirtualPurchesesCount = 0;
                _basicData.CreationTime          = DateTime.UtcNow;
                _basicData.OverallPlayTime       = 0;

                PlayerPrefs.SetString("ProbaUserID", _basicData.UserId);
                PlayerPrefs.SetString("ProbaUserName", _basicData.CurrentUserName);
                PlayerPrefs.SetString("ProbaABTest", _basicData.ABTest);

                PROBA.ABTestReceive(_basicData.ABTest);

                OldRecordSent();
            }
            catch (Exception e)
            {
                _probaLogger.LogError(e.Message, e.StackTrace);
                OldRecordCouldNotSent();
            }
        }
Ejemplo n.º 10
0
        private async void UpdateUsernameAsync(string username)
        {
            if (string.IsNullOrEmpty(username))
            {
                _probaLogger.LogWarning("UpdateUserName: Username is Empty ,Username Changed to Random Value");
                username = "******" + Random.Range(0, 1000);
            }
            var baseEvent = new BaseEventDataViewModel {
                UserName = username
            };

            if (Application.internetReachability == NetworkReachability.NotReachable || _sending)
            {
                SaveUpdateUserInDB(baseEvent);
                return;
            }
            try
            {
                var(success, statusCode) = await _probaHttpClient.UpdateUserInfoAsync(baseEvent);

                if (!success)
                {
                    SaveUpdateUserInDB(baseEvent);
                    return;
                }

                _basicData.CurrentUserName = username;

                PlayerPrefs.SetString("ProbaUserName", _basicData.CurrentUserName);
            }
            catch (Exception e)
            {
                _probaLogger.LogError(e.Message, e.StackTrace);
                SaveUpdateUserInDB(baseEvent);
            }
        }
Ejemplo n.º 11
0
        public async Task <(bool sucess, HttpStatusCode statusCode, RegisterResponseViewModel sessionResponse)> RegisterAsync(BaseEventDataViewModel baseEventDataViewModel)
        {
            try
            {
                var(sucess, statusCode, content) = await PostJsonRequestAsync($"{BaseURL}/{APIVersion}/Account/Register/{ProjectId}", baseEventDataViewModel.ToJson(), CancellationTokenSource);

                if (sucess)
                {
                    var res = content.FromJson <RegisterResponseViewModel>();
                    if (!string.IsNullOrWhiteSpace(res.Progress))
                    {
                        res.Progress = res.Progress.FromBase64String().ToUTF8();
                    }
                    if (!string.IsNullOrWhiteSpace(res.Configurations))
                    {
                        res.Configurations = res.Configurations.FromBase64String().ToUTF8();
                    }
                    return(sucess, statusCode, res);
                }
                //TODO: handdle errors
                return(default, statusCode, default);
Ejemplo n.º 12
0
 private void EVENT(BaseEventDataViewModel baseEventDataViewModel)
 {
     AddEventToQueue(baseEventDataViewModel);
 }
Ejemplo n.º 13
0
        private void SaveEventInDB(BaseEventDataViewModel eventViewModel)
        {
            var eDB = JsonConvert.SerializeObject(eventViewModel);

            DatabaseConnection.InsertUnsentEvent("EVENT", eDB);
        }
Ejemplo n.º 14
0
        private void SaveCheckProgressionStatusInDB(BaseEventDataViewModel progressionStatus)
        {
            var progStatDB = JsonConvert.SerializeObject(progressionStatus);

            DatabaseConnection.InsertUnsentEvent("STATUS", progStatDB);
        }
Ejemplo n.º 15
0
        private void SaveUpdateUserInDB(BaseEventDataViewModel updatedUser)
        {
            var userDB = JsonConvert.SerializeObject(updatedUser);

            DatabaseConnection.InsertUnsentEvent("UPDATE", userDB);
        }
Ejemplo n.º 16
0
        private void SaveRegisterInDB(BaseEventDataViewModel registerViewModel)
        {
            var regDB = JsonConvert.SerializeObject(registerViewModel);

            DatabaseConnection.InsertUnsentEvent("REGISTER", regDB);
        }