コード例 #1
0
ファイル: Login.xaml.cs プロジェクト: JOrtins/Quiddler
        /// <summary>
        /// Animates the login window's progress bar
        /// </summary>
        /// <param name="theProgBarDelegate"></param>
        /// <param name="max"></param>
        /// <param name="min"></param>
        /// <param name="val"></param>
        private void AnimateProgressBar(UpdateProgBarDelegate theProgBarDelegate, int max, int min, int val)
        {
            try
            {
                // setup progress bar starting properties
                progressBar1.Maximum = max;
                progressBar1.Minimum = min;
                progressBar1.Value = val;

                // update the progress bar
                double counter = 0;
                for (int i = 0; i <= 2000; ++i)
                {
                    // synchronous delegate
                    // using the windows object dispatcher property
                    this.Dispatcher.Invoke(theProgBarDelegate,
                        System.Windows.Threading.DispatcherPriority.Background,
                        new object[] { ProgressBar.ValueProperty, counter++ });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
ファイル: Login.xaml.cs プロジェクト: JOrtins/Quiddler
        private void btnJoinNetworked_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Clear previous status
                UpdateStatus("");

                if (txtServAddr.Text != "")
                {
                    // Valid IP Address
                    if (Regex.IsMatch(txtServAddr.Text, ipCheck))
                    {
                        if (txtUserName.Text != "")
                        {
                            // Configure server endpoint
                            ConfigureEndpoint(txtServAddr.Text, txtServPort.Text);

                            // Indicate waiting condition
                            UpdateStatus("Connecting to " + remoteFactory.Endpoint.Address.ToString() + "...");

                            // Create an instance of my UpdateProgressarDelegate
                            UpdateProgBarDelegate theProgBarDelegate = new UpdateProgBarDelegate(progressBar1.SetValue);

                            // Activate a remote QuiddlerService object
                            remoteProxy = remoteFactory.CreateChannel();

                            // Animate progress bar
                            AnimateProgressBar(theProgBarDelegate, 2000, 0, 0);

                            // Username already taken
                            if (remoteProxy.usernameExists(txtUserName.Text))
                            {
                                UpdateStatus("That username is already taken");
                            }
                            else
                            {
                                // Create a new client instance
                                Tuple<int, string> result = remoteProxy.Register_client();
                                if (result.Item1 != -1)
                                {
                                    widQuiddler = new QuiddlerUI(remoteProxy, result.Item1);
                                    widQuiddler.join(txtUserName.Text);
                                    widQuiddler.lblWelcome2.Content = txtUserName.Text;
                                    widQuiddler.Show();
                                    this.Close();
                                }
                                else
                                {
                                    UpdateStatus(result.Item2);
                                }
                            }

                            // Reset progress bar
                            progressBar1.Value = 0;
                        }
                        else
                        {
                            UpdateStatus("Please enter a valid username");
                        }
                    }
                    else
                    {
                        UpdateStatus("Invalid address, please try again");
                    }
                }
                else
                {
                    UpdateStatus("Please enter a valid IP address");
                }
            }
            catch (Exception ex)
            {
                UpdateStatus(ex.Message);
            }
        }