Beispiel #1
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");
            }
        }
Beispiel #2
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");
        }
Beispiel #3
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();
            }
        }