Exemplo n.º 1
0
    // Get high score list for a single level
    public void GetHighScores(GetHighScoresCallback callback, int levelID)
    {
        // First make sure all player data is up to date on the server
        UpdateCompleteCallback cb = (s) => GetLeaderboardPlayerUpdateComplete(callback, levelID, s);

        UpdatePlayerData(cb);
    }
Exemplo n.º 2
0
        //private void SetVersionStatus()
        //{
        //    if (ServerVersion.IsNotSet() )
        //    { VersionStatus = "(Unable to get version information)"; }
        //    else if (LocalVersion.CompareTo(ServerVersion) > 0)
        //    { VersionStatus = string.Format("(Ahead of {1} Version - {0} )", ServerVersion.ToString(3), ServerVersionType); }
        //    else if (LocalVersion.CompareTo(ServerVersion) == 0)
        //    { VersionStatus = string.Format("(Latest {0} Version)", ServerVersionType); }
        //    else
        //    { VersionStatus = string.Format("(New {1} Version available - {0})", ServerVersion.ToString(3), ServerVersionType); }

        //    UpdateCompleteCallback();

        //    NotifyOfPropertyChange(() => VersionStatus);
        //}


        // This code runs async in a background worker
        private void PopulateServerVersionFromGithub(WebRequestFactory wrf)
        {
            Log.Information(Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(PopulateServerVersionFromGithub), "Start");

            using (System.Net.WebClient http = wrf.CreateWebClient())
            {
                string json = "";

                try
                {
                    //#if DEBUG
                    //                    json = File.ReadAllText(@"..\..\..\src\CurrentReleaseVersion.json");
                    //#else
                    Log.Information(Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(PopulateServerVersionFromGithub), "Starting download of CurrentVersion.json");
                    json = http.DownloadString(new Uri(WebRequestFactory.CurrentGithubVersionUrl));
//#endif
                }
                catch (System.Net.WebException wex)
                {
                    if (wex.Status == System.Net.WebExceptionStatus.ProtocolError && ((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.ProxyAuthenticationRequired)
                    {
                        Log.Information(Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(PopulateServerVersionFromGithub), "Re-trying download of CurrentVersion.json with proxy auth");
                        // assume proxy auth error and re-try with current user credentials
                        http.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
                        json = http.DownloadString(new Uri(WebRequestFactory.CurrentGithubVersionUrl));
                    }
                    else
                    {
                        throw;
                    }
                }

                JObject jobj = JObject.Parse(json);
                try
                {
                    _productionVersion     = Version.Parse((string)jobj["Version"]);
                    _productionDownloadUrl = new Uri((string)jobj["DownloadUrl"]);

                    ServerVersionType = "Production";
                    _globalOptions.CurrentDownloadVersion = _productionVersion;
                    DownloadUrl = _productionDownloadUrl;
                }
                catch (Exception ex)
                {
                    Log.Error(ex, Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(PopulateServerVersionFromGithub), $"Error parsing CurrentVersion.json: {ex.Message}");
                    _eventAggregator.PublishOnUIThread(new OutputMessage(MessageType.Warning, $"The following error occurred while checking if there is an updated release available: {ex.Message}"));
                }
                finally
                {
                    UpdateCompleteCallback?.Invoke();
                }
                Log.Information(Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(PopulateServerVersionFromGithub), "Finish");
            }
        }
Exemplo n.º 3
0
 // Player best time has attempted to be updated
 private void PlayerUpdateTimeCallback(UpdateCompleteCallback callback, int levelID, bool networkError, bool success)
 {
     if (!networkError && success)
     {
         PlayerPointsAndItems.Instance.playerData.bestTimeDataToUpload[levelID] = false;
         UpdatePlayerData(callback);
     }
     else
     {
         callback(false);
     }
 }
Exemplo n.º 4
0
        private void BackgroundGetGitHubVersion(object sender, DoWorkEventArgs e)
        {
            try
            {
                Log.Information(Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(BackgroundGetGitHubVersion), "Starting Background Version Check");
                _isCheckRunning = true;
                UpdateStartingCallback?.Invoke();

                //give DaxStudio a little time to get started up so we don't impede work people are doing with this version check
                if (_isAutomaticCheck)
                {
                    System.Threading.Thread.Sleep(CHECK_SECONDS_AFTER_STARTUP.SecondsToMilliseconds());
                    _isAutomaticCheck = false;
                }
                LastVersionCheck = DateTime.UtcNow;

                //VersionStatus = "Checking for updates...";
                //NotifyOfPropertyChange(() => VersionStatus);
                try
                {
                    if (_webRequestFactory == null)
                    {
                        Log.Information(Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(BackgroundGetGitHubVersion), "Creating WebRequestFactory");
                        _webRequestFactory = WebRequestFactory.CreateAsync(_globalOptions, _eventAggregator).Result;
                    }
                    Log.Information(Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(BackgroundGetGitHubVersion), "Starting Population of version information from Github");
                    PopulateServerVersionFromGithub(_webRequestFactory);
                    Log.Information(Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(BackgroundGetGitHubVersion), "Updating Version Status");
                    //SetVersionStatus();
                    UpdateCompleteCallback?.Invoke();
                }
                catch (Exception ex)
                {
                    Log.Error("{class} {method} {error}", "VersionCheck", "worker_DoWork", ex.Message);
                    _eventAggregator.PublishOnUIThread(new ErrorEventArgs(ex));
                }

                CheckVersion();
            }
            catch (Exception ex)
            {
                Log.Error(ex, Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(BackgroundGetGitHubVersion), ex.Message);
                _eventAggregator.PublishOnUIThread(new OutputMessage(MessageType.Warning, $"Error while checking for updates: {ex.Message}"));
            }
            finally
            {
                _isCheckRunning = false;
            }
            Log.Information(Common.Constants.LogMessageTemplate, nameof(VersionCheck), nameof(BackgroundGetGitHubVersion), "Finished Background Version Check");
        }
Exemplo n.º 5
0
 // Player has attempted to be created. Still need a player update
 private void PlayerCreateNeedUpdateCallback(UpdateCompleteCallback callback, bool updatePoints, int subtractPoints, bool networkError, bool success)
 {
     if (!networkError)
     {
         // If it was successfull that means the player data has been created in the database
         // If it was not successfull that means the player data was already in the database
         // Either way the player data has been created
         PlayerPointsAndItems.Instance.playerData.PlayerDataHasBeenCreated = true;
         UpdatePlayerData(callback, updatePoints, subtractPoints);
     }
     else
     {
         callback(false);
     }
 }
Exemplo n.º 6
0
        public VersionCheck(IEventAggregator eventAggregator, IGlobalOptions globalOptions)
        {
            _eventAggregator = eventAggregator;

            _globalOptions = globalOptions;

            if (_globalOptions.BlockVersionChecks)
            {
                UpdateCompleteCallback?.Invoke();
                return;
            }

            worker.DoWork += new DoWorkEventHandler(BackgroundGetGitHubVersion);
            if (Enabled && LastVersionCheck.AddHours(CHECK_EVERY_HOURS) < DateTime.UtcNow)
            {
                _isAutomaticCheck = true;
                worker.RunWorkerAsync();
            }
        }
Exemplo n.º 7
0
    // Update the player data
    // Steps to update player data:
    // 1. Make sure the player data has been created in the database
    // 2. Make sure all player data is up to date in the database
    // 3. Update all fastest times
    public void UpdatePlayerData(UpdateCompleteCallback callback, bool addPoints = false, int subtractPoints = 0)
    {
        Debug.Log("UpdatePlayer");
        // If the player data has not been created it needs to be created before doing the update
        if (!PlayerPointsAndItems.Instance.playerData.PlayerDataHasBeenCreated)
        {
            HTTPRequestHandler.BasicHTTPDelegate del = (n, s) => PlayerCreateNeedUpdateCallback(callback, addPoints, subtractPoints, n, s);
            StartCoroutine(_httpHandler.CreatePlayerData(SystemInfo.deviceUniqueIdentifier, PlayerPointsAndItems.Instance.playerData.Name, del));
        }
        else if (PlayerPointsAndItems.Instance.playerData.PlayerDataToUpload || addPoints || subtractPoints != 0)
        {
            int    points = PlayerPointsAndItems.Instance.playerData.Points;
            double dist   = PlayerPointsAndItems.Instance.playerData.DistanceTraveled;

            if (addPoints)
            {
                points = PlayerPointsAndItems.Instance.playerData.GetTotalPoints();
                dist   = PlayerPointsAndItems.Instance.playerData.GetTotalDistance();
            }
            if (subtractPoints != 0)
            {
                points -= subtractPoints;
            }

            HTTPRequestHandler.BasicHTTPDelegate del = (n, s) => PlayerUpdateCallback(callback, n, s);
            StartCoroutine(_httpHandler.UpdatePlayerData(SystemInfo.deviceUniqueIdentifier, PlayerPointsAndItems.Instance.playerData.Name,
                                                         points, dist, del));
        }
        else if (PlayerPointsAndItems.Instance.playerData.RequiresBestTimeUpdate())
        {
            int   levelID = PlayerPointsAndItems.Instance.playerData.GetLevelIDToUpdate();
            float time    = PlayerPointsAndItems.Instance.playerData.bestTimes[levelID];
            HTTPRequestHandler.BasicHTTPDelegate del = (n, s) => PlayerUpdateTimeCallback(callback, levelID, n, s);
            StartCoroutine(_httpHandler.UpdatePlayerBestTime(SystemInfo.deviceUniqueIdentifier, levelID.ToString(), time, del));
        }
        else
        {
            callback(true);
        }
    }