示例#1
0
 /// <summary>
 /// Switch connector to a different OKAPI installation.
 /// </summary>
 public void SwitchInstallation(ApiInstallation apiInstallation)
 {
     this.currentInstallation = apiInstallation;
 }
示例#2
0
 /// <summary>
 /// Create new OKAPI connector.
 /// </summary>
 /// <param name="installation">
 ///     OKAPI Installation which to initally use. This can be
 ///     switched later.
 /// </param>
 public ApiConnector(ApiInstallation installation)
 {
     this.currentInstallation = installation;
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
            {
                System.Deployment.Application.ApplicationDeployment ad = System.Deployment.Application.ApplicationDeployment.CurrentDeployment;
                this.Title += " (v. " + ad.CurrentVersion.ToString() + ")";
            }

            this.varsCache.BindWithTextBox("consumer_key", this.consumerKeyTextbox);
            this.varsCache.BindWithTextBox("consumer_secret", this.consumerSecretTextbox);
            this.varsCache.BindWithTextBox("token", this.tokenTextbox);
            this.varsCache.BindWithTextBox("token_secret", this.tokenSecretTextbox);

            /* We use a "mother installation" for the first OKAPI request. We need to
             * get a list of all OKAPI installations. */

            var motherInstallation = new ApiInstallation
            {
                base_url = "http://opencaching.pl/okapi/"
            };
            this.apiConnector = new ApiConnector(motherInstallation);
            this.apiConnector.BeginRequest += new EventHandler(apiConnector_BeginRequest);
            this.apiConnector.EndRequest += new EventHandler(apiConnector_EndRequest);

            /* Fill up the installations list. */

            try
            {
                this.installationsComboBox.Items.Clear();
                foreach (var installation in this.apiConnector.GetInstallations())
                {
                    this.installationsComboBox.Items.Add(new ComboBoxItem
                    {
                        Content = installation.base_url,
                        Tag = installation
                    });
                }
            }
            catch (WebException)
            {
                MessageBox.Show("Error occured when trying to access OKAPI mother server. Could not populate OKAPI installations list.",
                    "Network error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }

            if (this.installationsComboBox.Items.Count > 0)
            {
                /* Now we have a list of all installations in a combo box. We choose
                 * one of them. */

                this.installationsComboBox.SelectedIndex = 0;
                this.ReloadInstallation();
            }
        }