Exemplo n.º 1
0
        public override void Disconnect()
        {
            this.connected = false;

            if (this.rasDialer.IsBusy)
            {
                if (rasProperties != null)
                {
                    rasProperties.Info("Hanging up RAS connection asynchronously.");
                }

                // The connection attempt has not been completed, cancel the attempt.
                this.rasDialer.DialAsyncCancel();
            }
            else
            {
                foreach (RasConnection connection in RasConnection.GetActiveConnections())
                {
                    if (rasProperties != null)
                    {
                        rasProperties.Info("Hanging up RAS connection.");
                    }

                    // The connection has been found, disconnect it.
                    connection.HangUp();
                }
            }

            if (rasProperties != null)
            {
                rasProperties.Dispose();
                rasProperties = null;
            }
        }
Exemplo n.º 2
0
        public override bool Connect()
        {
            this.connected = false;

            try
            {
                this.rasProperties = new RasProperties(this.ParentForm, this);

                DirectoryInfo directoryInfo = (new FileInfo(this.GetType().Assembly.Location)).Directory;

                if ((directoryInfo == null || directoryInfo.Exists == false) && string.IsNullOrEmpty(this.PhonebookPath))
                {
                    rasProperties.Error("The phonebook path hasn't been set. Aborting RAS connection.");
                    return(this.connected = false);
                }

                this.Embed(this.rasProperties);

                // The 'RasDevice.GetDeviceByName([string], [RasDeviceType])' method is obsolete as of DotRas (ChangeSet 93435):
                RasEntry entry = RasEntry.CreateVpnEntry(this.Favorite.Name, this.Favorite.ServerName,
                                                         RasVpnStrategy.Default, (from d in RasDevice.GetDevices()
                                                                                  where
                                                                                  d.DeviceType == RasDeviceType.Vpn &&
                                                                                  d.Name.ToUpper()
                                                                                  .Contains("(PPTP)")
                                                                                  select d).FirstOrDefault());

                // Create the Ras phonebook or upen it under the below mentioned path.
                string phonebookPath = this.PhonebookPath ?? Path.Combine(directoryInfo.FullName, "rasphone.pbk");

                this.rasPhoneBook = new RasPhoneBook();
                this.rasPhoneBook.Open(phonebookPath);

                this.rasProperties.RasEntry = entry;

                // Check if the entry hasn't been added.
                if (!this.rasPhoneBook.Entries.Contains(entry.Name))
                {
                    this.rasPhoneBook.Entries.Add(entry);
                }

                this.rasDialer = new RasDialer
                {
                    PhoneBookPath = phonebookPath,
                    // Set the credentials later ...
                    Credentials = null,
                    // Initialize with default values (same as the designer would do)
                    EapOptions = new RasEapOptions(false, false, false),
                    // Initialize with default values (same as the designer would do)
                    Options   = new RasDialOptions(false, false, false, false, false, false, false, false, false, false, false),
                    EntryName = this.Favorite.Name
                };

                this.rasDialer.Error         += this.rasDialer_Error;
                this.rasDialer.DialCompleted += this.rasDialer_DialCompleted;
                this.rasDialer.StateChanged  += this.rasDialer_StateChanged;

                // Set the ras dialer credentials and checks if setting the credentials has been
                // successful; if not NULL will be set to the ras dealer credentials and in that
                // case we'll load the RAS connection from the phone book.
                if ((this.rasDialer.Credentials = this.Favorite.Credential) == null)
                {
                    rasProperties.Warn("Terminals has no credentials, showing dial dialog ...");

                    RasDialDialog rasDialDialog = new RasDialDialog
                    {
                        PhoneBookPath = phonebookPath,
                        EntryName     = entry.Name
                    };

                    if (rasDialDialog.ShowDialog() == DialogResult.OK)
                    {
                        rasProperties.Info(string.Format("{0} {1}", "Thank you for providing the credentials." + "Using the Terminals credentials, dialing ..."));
                        return(this.connected = true);
                    }

                    rasProperties.Error("Terminating RAS connection, either credentials haven't been supplied or error connecting to the target.");
                    return(this.connected = false);
                }

                rasProperties.Info("Using the Terminals credentials, dialing ...");
                this.rasDialer.Dial();

                return(this.connected = true);
            }
            catch (Exception ex)
            {
                rasProperties.Error(string.Format("Terminals  was unable to create the {0} connection.", this.Favorite.Protocol), ex);
                return(this.connected = false);
            }
        }
Exemplo n.º 3
0
        public override bool Connect()
        {
            this.connected = false;

            try
            {
                this.rasProperties = new RasProperties(this.ParentForm, this);

                DirectoryInfo directoryInfo = (new FileInfo(this.GetType().Assembly.Location)).Directory;

                if ((directoryInfo == null || directoryInfo.Exists == false) && string.IsNullOrEmpty(this.PhonebookPath))
                {
                    rasProperties.Error("The phonebook path hasn't been set. Aborting RAS connection.");
                    return this.connected = false;
                }

                this.Embed(this.rasProperties);

                // The 'RasDevice.GetDeviceByName([string], [RasDeviceType])' method is obsolete as of DotRas (ChangeSet 93435):
                RasEntry entry = RasEntry.CreateVpnEntry(this.Favorite.Name, this.Favorite.ServerName,
                                                         RasVpnStrategy.Default, (from d in RasDevice.GetDevices()
                                                                                  where
                                                                                      d.DeviceType == RasDeviceType.Vpn &&
                                                                                      d.Name.ToUpper()
                                                                                       .Contains("(PPTP)")
                                                                                  select d).FirstOrDefault());

                // Create the Ras phonebook or upen it under the below mentioned path.
                string phonebookPath = this.PhonebookPath ?? Path.Combine(directoryInfo.FullName, "rasphone.pbk");

                this.rasPhoneBook = new RasPhoneBook();
                this.rasPhoneBook.Open(phonebookPath);

                this.rasProperties.RasEntry = entry;

                // Check if the entry hasn't been added.
                if (!this.rasPhoneBook.Entries.Contains(entry.Name))
                {
                    this.rasPhoneBook.Entries.Add(entry);
                }

                this.rasDialer = new RasDialer
                                     {
                                         PhoneBookPath = phonebookPath,
                                         // Set the credentials later ...
                                         Credentials = null,
                                         // Initialize with default values (same as the designer would do)
                                         EapOptions = new RasEapOptions(false, false, false),
                                         // Initialize with default values (same as the designer would do)
                                         Options = new RasDialOptions(false, false, false, false, false, false, false, false, false, false, false),
                                         EntryName = this.Favorite.Name
                                     };

                this.rasDialer.Error += this.rasDialer_Error;
                this.rasDialer.DialCompleted += this.rasDialer_DialCompleted;
                this.rasDialer.StateChanged += this.rasDialer_StateChanged;

                // Set the ras dialer credentials and checks if setting the credentials has been
                // successful; if not NULL will be set to the ras dealer credentials and in that
                // case we'll load the RAS connection from the phone book.
                if ((this.rasDialer.Credentials = this.Favorite.Credential) == null)
                {
					rasProperties.Warn("Terminals has no credentials, showing dial dialog ...");

                    RasDialDialog rasDialDialog = new RasDialDialog
                                                      {
                                                          PhoneBookPath = phonebookPath,
                                                          EntryName = entry.Name
                                                      };

                    if (rasDialDialog.ShowDialog() == DialogResult.OK)
                    {
						rasProperties.Info(string.Format("{0} {1}", "Thank you for providing the credentials." + "Using the Terminals credentials, dialing ..."));
                        return this.connected = true;
                    }

                    rasProperties.Error("Terminating RAS connection, either credentials haven't been supplied or error connecting to the target.");
                    return this.connected = false;
                }

				rasProperties.Info("Using the Terminals credentials, dialing ...");
                this.rasDialer.Dial();

                return this.connected = true;
            }
            catch (Exception ex)
            {
				rasProperties.Error(string.Format("Terminals  was unable to create the {0} connection.", this.Favorite.Protocol), ex);
                return this.connected = false;
            }
        }
Exemplo n.º 4
0
        public override void Disconnect()
        {
            this.connected = false;

            if (this.rasDialer.IsBusy)
            {
                if (rasProperties != null)
					rasProperties.Info("Hanging up RAS connection asynchronously.");

                // The connection attempt has not been completed, cancel the attempt.
                this.rasDialer.DialAsyncCancel();
            }
            else
            {
                foreach (RasConnection connection in RasConnection.GetActiveConnections())
                {
                    if (rasProperties != null)
						rasProperties.Info("Hanging up RAS connection.");

                    // The connection has been found, disconnect it.
                    connection.HangUp();
                }
            }

            if (rasProperties != null)
            {
                rasProperties.Dispose();
                rasProperties = null;
            }
        }