async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                ObservableCollection <WeatherApiResonseData>
                storedWeatherApiResponseData = LocalDataRepository.GetStoredWeatherData();

                _storedWeatherApiResponseData = new ObservableCollection <WeatherApiResonseData>(storedWeatherApiResponseData.OrderByDescending(a => a.search_time));
                OnPropertyChanged("StoredWeatherApiResponseData");

                await ValidateListVisibility();
                await CalculateListHeight();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #2
0
        public ItemsViewModel()
        {
            Title = "OpenWeather";

            _homepageCurrentWeatherData    = LocalDataRepository.GetHomePageWeatherData();
            _homepageCurrentWeatherDetails = LocalDataRepository.GetHomePageWeatherDetails();

            Task.Run(async() =>
            {
                if (_homepageCurrentWeatherData == null && _homepageCurrentWeatherDetails == null)
                {
                    await ExecuteSearchCommand("Mabalacat City");
                }
                else
                {
                    await ExecuteLoadItemsCommand();
                }
            });

            MessagingCenter.Subscribe <WeatherApiResonseData>(this, "LoadData", async(obj) =>
            {
                WeatherApiResonseData weatherApiResponse = obj as WeatherApiResonseData;
                await ExecuteSearchCommand(weatherApiResponse.name);
            });

            MessagingCenter.Subscribe <object>(this, "LoadLocation", async(obj) =>
            {
                await ExecuteGetLocationCommand();
            });
        }
Example #3
0
        private async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                await Task.Run(() =>
                {
                    _homepageCurrentWeatherData    = LocalDataRepository.GetHomePageWeatherData();
                    _homepageCurrentWeatherDetails = LocalDataRepository.GetHomePageWeatherDetails();


                    OnPropertyChanged("HomepageCurrentWeatherDetails");
                    OnPropertyChanged("HomepageCurrentWeatherData");
                });

                await ValidateListVisibility();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
        private void EndAuthorizationContext()
        {
            EndContext(_authorizationContext);
            ResetActiveChunk(); // In case if this context end fails, this will fail next authorizaiton context. Prevent it by putting them into different chunks

            LocalDataRepository.RemoveData(UserId, typeof(AuthorizationContext).Name);
        }
        private void EndInterruptedAuthorizationContext()
        {
            _authorizationContext = LocalDataRepository.LoadData <AuthorizationContext>(UserId, typeof(AuthorizationContext).Name); // Load previously saved authorization context

            if (_authorizationContext != null)
            {
                EndAuthorizationContext(); // End it
            }
        }
        /// <summary>
        /// Waits for all user data chunks to be sent to the server
        /// </summary>
        private IEnumerator WaitForAllChunksToBeProcessed()
        {
            float startTime = Time.time;

            while (LocalDataRepository.LoadDataChunksJson(UserId).ToList().Count > 0 && Time.time < startTime + chunkTimer)
            {
                yield return(null);
            }
        }
        private Queue <RDataBaseContext> _contextTreeTraversalHelperQueue = new Queue <RDataBaseContext>(); // Used to not allocate a new queue when traversing the context tree

        public RDataClient()
        {
            JsonRpcClient = new JsonRpcClient();
            ChunkLifeTime = 1f;                   // 1 second
            ContextDataTrackRefreshTime = 0.100f; // 100 milliseconds
            GameVersion = 1;
            SupressNonAuthorizedException = false;

            LocalDataRepository   = new LocalDataRepository();           // Instantiate the local data repository
            AuthorizationStrategy = new UserAuthorizationStrategy(this); // Instantiate the user authorization strategy
        }
Example #8
0
        private async Task UpdateStoredWeatherData(WeatherApiResonseData weatherApiResonse, OneCallWeatherAPIResponseData weatherAPIResponseDetails)
        {
            await Task.Run(() =>
            {
                weatherApiResonse.search_time = DateTime.Now;

                _homepageCurrentWeatherData    = weatherApiResonse;
                _homepageCurrentWeatherDetails = weatherAPIResponseDetails;
                OnPropertyChanged("HomepageCurrentWeatherData");
                OnPropertyChanged("HomepageCurrentWeatherDetails");

                LocalDataRepository.InsertHomePageWeatherData(weatherApiResonse);
                LocalDataRepository.InsertHomePageWeatherDetails(weatherAPIResponseDetails);
                LocalDataRepository.UpsertStoredWeatherData(weatherApiResonse);
            });
        }
 async Task InitializeHistory()
 {
     await Task.Run(() =>
     {
         ObservableCollection <WeatherApiResonseData>
         storedWeatherApiResponseData = LocalDataRepository.GetStoredWeatherData();
         if (storedWeatherApiResponseData.Count > 0)
         {
             _storedWeatherApiResponseData = new ObservableCollection <WeatherApiResonseData>(storedWeatherApiResponseData.OrderByDescending(a => a.search_time));
         }
         else
         {
             _storedWeatherApiResponseData = new ObservableCollection <WeatherApiResonseData>();
         }
     });
 }
Example #10
0
 public List <WebLink> getLocalWebLinks()
 {
     return(LocalDataRepository.getUrlLinks());
 }
 private void SaveActiveChunk()
 {
     LocalDataRepository.SaveDataChunk(UserId, _activeChunk);
 }
        private IEnumerator ProcessBulkedRequests()
        {
            while (true)
            {
                //Debug.Log(DateTime.UtcNow + ": Checking bulked requests");

                // When available, authorized, and root context is restored try to send out chunks
                if (IsAvailable && Authorized && _authorizationContext.Status != RDataContextStatus.Interrupted)
                {
                    bool hasErrors       = false;
                    var  localDataChunks = LocalDataRepository.LoadDataChunksJson(UserId);

                    if (localDataChunks != null)
                    {
                        foreach (var chunk in localDataChunks)
                        {
                            if (RData.RDataLogging.DoLog)
                            {
                                Debug.Log(DateTime.UtcNow + ": Sending the chunk " + chunk.requestId);
                            }
                            yield return(CoroutineManager.StartCoroutine(JsonRpcClient.SendJson <BooleanResponse>(chunk.requestJson, chunk.requestId, (response) =>
                            {
                                if (RData.RDataLogging.DoLog)
                                {
                                    Debug.Log(DateTime.UtcNow + ": Sent the chunk " + chunk.requestId);
                                }

                                if (response.Result)
                                {
                                    LocalDataRepository.RemoveDataChunk(UserId, chunk.requestId); // At this point we received a positive answer from the server
                                }
                                // Most realistic scenario here is
                                if (response.HasError)
                                {
                                    if (response.Error.Data == kContextValidationError)
                                    {
                                        // This is a very specific case that happens when we are trying to re-send a chunk with context operations after that context was closed.
                                        // This means this chunk was already received by the server and we can safely delete it.
                                        LocalDataRepository.RemoveDataChunk(UserId, chunk.requestId);
                                        if (RData.RDataLogging.DoError)
                                        {
                                            Debug.LogError("Context validation error. This chunk was already received by the server. Deletting the chunk");
                                        }
                                    }
                                    else
                                    {
                                        hasErrors = true;
                                    }
                                }
                            })));

                            // If any unknown errors happened this means that most likely something horribly wrong with the server.
                            // Let's take some timeout to prevent spamming it
                            if (hasErrors)
                            {
                                if (RData.RDataLogging.DoLog)
                                {
                                    Debug.Log(DateTime.UtcNow + ": Unknown error happened, waiting for " + kTimeoutAfterError + " seconds");
                                }
                                yield return(new WaitForSeconds(kTimeoutAfterError));
                            }
                        }
                    }

                    // Check if the current chunk has items and expired. If so, save and refresh it
                    if (_activeChunk.Length > 0 && DateTime.UtcNow > Tools.Time.UnixTimeMillisecondsToDateTime(_activeChunk.CreatedAt) + TimeSpan.FromSeconds(ChunkLifeTime))
                    {
                        ResetActiveChunk();
                    }
                }

                yield return(null);
            }
        }
 private void StartAuthorizationContext()
 {
     _authorizationContext = new AuthorizationContext();
     StartRootContext(_authorizationContext);
     LocalDataRepository.SaveData(UserId, typeof(AuthorizationContext).Name, _authorizationContext);
 }