示例#1
0
        ///// <summary>
        /////     Sets the language
        ///// </summary>
        //public void SetLanguage()
        //{
        //    string languageFilePath = Path.Combine(Program.LanguagesDirectory,
        //        String.Format("{0}.json", Settings.Default.Language.Name));
        //    if (File.Exists(languageFilePath))
        //        _lp = Serializer.Deserialize<LocalizationProperties>(File.ReadAllText(languageFilePath));
        //    else
        //    {
        //        string resourceName = "nUpdate.Administration.Core.Localization.en.xml";
        //        using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
        //        {
        //            _lp = Serializer.Deserialize<LocalizationProperties>(stream);
        //        }
        //    }

        //    Text = _lp.NewProjectDialogTitle;
        //    Text = String.Format(Text, _lp.ProductTitle);

        //    cancelButton.Text = _lp.CancelButtonText;
        //    continueButton.Text = _lp.ContinueButtonText;

        //    keyPairHeaderLabel.Text = _lp.PanelSignatureHeader;
        //    keyPairInfoLabel.Text = _lp.PanelSignatureInfoText;
        //    keyPairGenerationLabel.Text = _lp.PanelSignatureWaitText;

        //    generalHeaderLabel.Text = _lp.PanelGeneralHeader;
        //    nameLabel.Text = _lp.PanelGeneralNameText;
        //    nameTextBox.Cue = _lp.PanelGeneralNameWatermarkText;

        //    ftpHeaderLabel.Text = _lp.PanelFtpHeader;
        //    ftpHostLabel.Text = _lp.PanelFtpServerText;
        //    ftpUserLabel.Text = _lp.PanelFtpUserText;
        //    ftpUserTextBox.Cue = _lp.PanelFtpUserWatermarkText;
        //    ftpPasswordLabel.Text = _lp.PanelFtpPasswordText;
        //    ftpPortLabel.Text = _lp.PanelFtpPortText;
        //    ftpPortTextBox.Cue = _lp.PanelFtpPortWatermarkText;
        //}

        private void NewProjectDialog_Load(object sender, EventArgs e)
        {
            if (!ConnectionChecker.IsConnectionAvailable())
            {
                Popup.ShowPopup(this, SystemIcons.Error, "No network connection available.",
                                "No active network connection was found. In order to create a project a network connection is required in order to communicate with the server.",
                                PopupButtons.Ok);
                Close();
                return;
            }

            ftpPortTextBox.ShortcutsEnabled   = false;
            ftpModeComboBox.SelectedIndex     = 0;
            ftpProtocolComboBox.SelectedIndex = 0;
            ipVersionComboBox.SelectedIndex   = 0;

            //SetLanguage();
            Text = string.Format(Text, Program.VersionString);
            localPathTextBox.ButtonClicked += BrowsePathButtonClick;
            localPathTextBox.Initialize();
            controlPanel1.Visible = false;
            GenerateKeyPair();

            _isSetByUser = true;
        }
示例#2
0
        /// <summary>
        ///     Searches for updates.
        /// </summary>
        /// <returns>Returns <c>true</c> if updates were found; otherwise, <c>false</c>.</returns>
        /// <exception cref="SizeCalculationException">The calculation of the size of the available updates has failed.</exception>
        /// <exception cref="OperationCanceledException">The update search was canceled.</exception>
        public bool SearchForUpdates()
        {
            if (_searchCancellationTokenSource != null)
            {
                _searchCancellationTokenSource.Dispose();
            }
            _searchCancellationTokenSource = new CancellationTokenSource();

            if (!ConnectionChecker.IsConnectionAvailable())
            {
                return(false);
            }

            // Check for SSL and ignore it
            ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); };
            var configuration = UpdateConfiguration.Download(_updateConfigurationFileUri, Proxy);

            var result = new UpdateResult(configuration, CurrentVersion,
                                          IncludeAlpha, IncludeBeta);

            if (!result.UpdatesFound)
            {
                return(false);
            }


            _updateConfigurations = _configurationUpdateCallback == null ? result.NewestConfigurations : _configurationUpdateCallback.Invoke(result.NewestConfigurations);
            double updatePackageSize = 0;

            foreach (var updateConfiguration in _updateConfigurations)
            {
                var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri);
                if (newPackageSize == null)
                {
                    throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText);
                }

                updatePackageSize += newPackageSize.Value;
                _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion),
                                       updateConfiguration.Operations);
            }

            TotalSize = updatePackageSize;
            if (_searchCancellationTokenSource.Token.IsCancellationRequested)
            {
                _packageOperations.Clear();
                _packageFilePaths.Clear();
                throw new OperationCanceledException();
            }

            return(true);
        }
示例#3
0
        /// <summary>
        ///     Searches for updates.
        /// </summary>
        /// <returns>Returns <c>true</c> if updates were found; otherwise, <c>false</c>.</returns>
        /// <exception cref="SizeCalculationException">The calculation of the size of the available updates has failed.</exception>
        /// <exception cref="OperationCanceledException">The update search was canceled.</exception>
        public bool SearchForUpdates()
        {
            // It may be that this is not the first search call and previously saved data needs to be disposed.
            Cleanup();
            _searchCancellationTokenSource?.Dispose();
            _searchCancellationTokenSource = new CancellationTokenSource();

            if (!ConnectionChecker.IsConnectionAvailable())
            {
                return(false);
            }

            // Check for SSL and ignore it
            ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); };
            var configuration = UpdateConfiguration.Download(UpdateConfigurationFileUri, Proxy);

            var result = new UpdateResult(configuration, CurrentVersion,
                                          IncludeAlpha, IncludeBeta);

            if (!result.UpdatesFound)
            {
                return(false);
            }

            PackageConfigurations = result.NewestConfigurations;
            double updatePackageSize = 0;

            foreach (var updateConfiguration in PackageConfigurations)
            {
                var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri);
                if (newPackageSize == null)
                {
                    throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText);
                }

                updatePackageSize += newPackageSize.Value;
                _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion),
                                       updateConfiguration.Operations);
            }

            TotalSize = updatePackageSize;
            if (_searchCancellationTokenSource.Token.IsCancellationRequested)
            {
                Cleanup();
                throw new OperationCanceledException();
            }

            return(true);
        }
示例#4
0
        /// <summary>
        ///     Searches for updates.
        /// </summary>
        /// <exception cref="InvalidOperationException">There is already a search process running.</exception>
        /// <exception cref="NetworkException">There is no network connection available.</exception>
        /// <seealso cref="SearchForUpdatesAsync"/>
        public void SearchForUpdates()
        {
            if (_searchWebClient.IsBusy)
            {
                throw new InvalidOperationException(_lp.SearchProcessRunningExceptionText);
            }

            if (!ConnectionChecker.IsConnectionAvailable())
            {
                throw new NetworkException(_lp.NetworkConnectionExceptionText);
            }

            // Check for SSL and ignore it
            ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); };

            var configurations = UpdateConfiguration.Download(UpdateConfigurationFileUri, Proxy);
            var result         = new UpdateResult(configurations, CurrentVersion,
                                                  IncludeAlpha, IncludeBeta);

            if (!result.UpdatesFound)
            {
                OnUpdateSearchFinished(false);
            }
            else
            {
                _updateConfiguration = result.NewestConfiguration;
                NewestVersion        = new UpdateVersion(_updateConfiguration.LiteralVersion);
                Changelog            = _updateConfiguration.Changelog.ContainsKey(LanguageCulture)
                    ? _updateConfiguration.Changelog.First(item => item.Key.Name == LanguageCulture.Name).Value
                    : _updateConfiguration.Changelog.First(item => item.Key.Name == new CultureInfo("en").Name).Value;
                Signature  = Convert.FromBase64String(_updateConfiguration.Signature);
                MustUpdate = _updateConfiguration.MustUpdate;
                Operations = _updateConfiguration.Operations;

                var updatePackageSize = GetUpdatePackageSize(_updateConfiguration.UpdatePackageUri);
                if (updatePackageSize == null)
                {
                    throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText);
                }

                PackageSize = updatePackageSize.Value;
                OnUpdateSearchFinished(true);
            }
        }
示例#5
0
        ///// <summary>
        /////     Sets the language
        ///// </summary>
        //public void SetLanguage()
        //{
        //    string languageFilePath = Path.Combine(Program.LanguagesDirectory,
        //        String.Format("{0}.json", Settings.Default.Language.Name));
        //    if (File.Exists(languageFilePath))
        //        _lp = Serializer.Deserialize<LocalizationProperties>(File.ReadAllText(languageFilePath));
        //    else
        //    {
        //        string resourceName = "nUpdate.Administration.Core.Localization.en.xml";
        //        using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
        //        {
        //            _lp = Serializer.Deserialize<LocalizationProperties>(stream);
        //        }
        //    }

        //    Text = _lp.NewProjectDialogTitle;
        //    Text = String.Format(Text, _lp.ProductTitle);

        //    cancelButton.Text = _lp.CancelButtonText;
        //    continueButton.Text = _lp.ContinueButtonText;

        //    keyPairHeaderLabel.Text = _lp.PanelSignatureHeader;
        //    keyPairInfoLabel.Text = _lp.PanelSignatureInfoText;
        //    keyPairGenerationLabel.Text = _lp.PanelSignatureWaitText;

        //    generalHeaderLabel.Text = _lp.PanelGeneralHeader;
        //    nameLabel.Text = _lp.PanelGeneralNameText;
        //    nameTextBox.Cue = _lp.PanelGeneralNameWatermarkText;

        //    ftpHeaderLabel.Text = _lp.PanelFtpHeader;
        //    ftpHostLabel.Text = _lp.PanelFtpServerText;
        //    ftpUserLabel.Text = _lp.PanelFtpUserText;
        //    ftpUserTextBox.Cue = _lp.PanelFtpUserWatermarkText;
        //    ftpPasswordLabel.Text = _lp.PanelFtpPasswordText;
        //    ftpPortLabel.Text = _lp.PanelFtpPortText;
        //    ftpPortTextBox.Cue = _lp.PanelFtpPortWatermarkText;
        //}

        private void NewProjectDialog_Load(object sender, EventArgs e)
        {
            if (!ConnectionChecker.IsConnectionAvailable())
            {
                Popup.ShowPopup(this, SystemIcons.Error, "No network connection available.",
                                "No active network connection was found. In order to create a project a network connection is required in order to communicate with the server.",
                                PopupButtons.Ok);
                Close();
                return;
            }

            ftpPortTextBox.ShortcutsEnabled   = false;
            ftpModeComboBox.SelectedIndex     = 0;
            ftpProtocolComboBox.SelectedIndex = 0;

            //SetLanguage();

            controlPanel1.Visible = false;
            ThreadPool.QueueUserWorkItem(arg => GenerateKeyPair());
        }
示例#6
0
 public void CanReturnConnectionStatus()
 {
     Assert.IsTrue(ConnectionChecker.IsConnectionAvailable());
 }
示例#7
0
        /// <summary>
        ///     Downloads the update package from the server.
        /// </summary>
        /// <exception cref="NetworkException">There is no network connection available.</exception>
        /// <exception cref="WebException">The download process has failed because of an <see cref="WebException"/>.</exception>
        /// <exception cref="ArgumentException">The URI of the update package is null.</exception>
        /// <seealso cref="DownloadPackageAsync"/>
        public void DownloadPackage()
        {
            if (_packageDownloader.IsBusy)
            {
                throw new InvalidOperationException(_lp.DownloadingProcessRunningExceptionText);
            }

            if (!ConnectionChecker.IsConnectionAvailable())
            {
                throw new NetworkException(_lp.NetworkConnectionExceptionText);
            }

            if (_updateConfiguration.UpdatePackageUri == null)
            {
                throw new ArgumentException("UpdatePackageUri");
            }

            if (!Directory.Exists(_applicationUpdateDirectory))
            {
                Directory.CreateDirectory(_applicationUpdateDirectory);
            }

            _updateFilePath = Path.Combine(_applicationUpdateDirectory, "update.zip");
            OnPackageDownloadStarted(this, EventArgs.Empty);
            _packageDownloader.Proxy = Proxy;
            _packageDownloader.DownloadFileCompleted += DownloadFileCompleted;
            _packageDownloader.DownloadFileAsync(_updateConfiguration.UpdatePackageUri,
                                                 _updateFilePath);
            _downloadResetEvent.WaitOne();

            if (_hasDownloadCancelled)
            {
                if (MustUpdate)
                {
                    Application.Exit();
                }
                return;
            }

            if (_hasDownloadFailed)
            {
                return;
            }

            if (_updateConfiguration.UseStatistics && _includeCurrentPcIntoStatistics)
            {
                try
                {
                    string response = new WebClient().DownloadString(String.Format("{0}?versionid={1}&os={2}",
                                                                                   _updateConfiguration.UpdatePhpFileUri, _updateConfiguration.VersionId,
                                                                                   SystemInformation.GetOperatingSystemName())); // Only for calling it
                    if (!String.IsNullOrEmpty(response))
                    {
                        OnStatisticsEntryFailed(new Exception(
                                                    String.Format(
                                                        _lp.StatisticsScriptExceptionText, response)));
                    }
                }
                catch (Exception ex)
                {
                    OnStatisticsEntryFailed(ex);
                }
            }

            OnPackageDownloadFinished(this, EventArgs.Empty);
        }