Example #1
0
        private bool ConnectWithForm()
        {
            ConnectForm form = new ConnectForm();

            if (_connectionProfile == null)
            {
                form.ServerSettings = new ServerSettings();
            }
            else
            {
                form.ProfileName    = _connectionProfile.Name;
                form.ServerSettings = new ServerSettings()
                {
                    ServerName = _connectionProfile.ServerSettings.ServerName,
                    Port       = ServerSettings.DefaultHttpPort,
                    Transport  = ServiceTransport.Http
                };
            }
            if (form.ShowDialog(this) == DialogResult.OK)
            {
                _connectionProfile = new ConnectionProfile()
                {
                    ServerSettings = form.ServerSettings,
                    SavePassword   = form.SavePassword
                };
                if (!String.IsNullOrEmpty(form.ProfileName))
                {
                    _connectionProfile.Name = form.ProfileName;
                    ConnectionProfiles.Add(_connectionProfile);
                }
                RefreshFormTitle();
                return(true);
            }
            return(false);
        }
Example #2
0
        private void GenerateDesignMode()
        {
            var random = new Random();

            for (var x = 0; x < 10; x++)
            {
                var connectionInfo = new ConnectionInfo
                {
                    AuthenticationType      = RandomItem(AuthenticationTypes, random),
                    EncryptionType          = RandomItem(EncryptionTypes, random),
                    ConnectivityLevel       = RandomItem(ConnectivityLevels, random),
                    DomainConnectivityLevel = RandomItem(DomainLevels, random),
                    IncomingBitsPerSecond   = random.Next(0, int.MaxValue),
                    OutgoingBitsPerSecond   = random.Next(0, int.MaxValue),
                    IsWlan           = random.Next(0, 1) == 0,
                    IsWwan           = random.Next(0, 1) == 0,
                    Name             = Guid.NewGuid().ToString().Replace('-', ' '),
                    NetworkAdapterId = Guid.NewGuid(),
                    NetworkType      = RandomItem(NetworkTypeList, random),
                    CostType         = RandomItem(CostTypes, random),
                    SignalBars       = (short)random.Next(0, 5),
                    Flags            =
                        string.Format(
                            "{0} {1}",
                            random.Next(0, 1) == 0
                                                         ? (random.Next(0, 1) == 0
                                                                ? "Approaching Data Limit"
                                                                : "Over Data Limit")
                                                         : string.Empty,
                            random.Next(0, 1) == 0 ? "Roaming" : string.Empty)
                        .Trim()
                };
                if (random.Next(0, 1) == 0)
                {
                    var dataPlan = new DataPlanInfo
                    {
                        DataLimitMegabytes    = random.Next(0, int.MaxValue),
                        InboundBitsPerSecond  = (ulong)random.Next(0, int.MaxValue),
                        OutboundBitsPerSecond = (ulong)random.Next(0, int.MaxValue)
                    };
                    if (random.Next(0, 1) == 0)
                    {
                        dataPlan.NextBillingCycle = DateTime.Now.AddDays(random.Next(1, 30));
                    }
                    if (random.Next(0, 1) == 0)
                    {
                        dataPlan.MegabytesUsed = random.Next(0, int.MaxValue);
                        dataPlan.LastSyncTime  = DateTime.Now.AddHours(-1 * random.Next(2, 12));
                    }
                    connectionInfo.DataPlan = dataPlan;
                }
                connectionInfo.BytesReceivedLastDay = (ulong)random.Next(0, int.MaxValue);
                connectionInfo.BytesSentLastDay     = (ulong)random.Next(0, int.MaxValue);
                ConnectionProfiles.Add(connectionInfo);
            }
            CurrentConnectionInfo = ConnectionProfiles[random.Next(0, ConnectionProfiles.Count)];
        }
        private void DeleteServer(object cp)
        {
            if (!(cp is ConnectionProfile))
            {
                throw new ArgumentException("connProfile is not of type ConnectionProfile.", "connProfile");
            }
            var connProfile = (ConnectionProfile)cp;

            ConnectionProfiles.Remove(connProfile);
        }
        private void EditServer(object cp)
        {
            if (!(cp is ConnectionProfile))
            {
                throw new ArgumentException("connProfile is not of type ConnectionProfile.", "connProfile");
            }
            var connProfile = (ConnectionProfile)cp;

            ConnectionProfiles[ConnectionProfiles.IndexOf(connProfile)] = connProfile;
        }
Example #5
0
        private void ExecuteDeleteProfile(object o)
        {
            var result = MessageBox.Show("Do you want to delete connection profile '" + SelectedProfile.Name + "' ?"
                                         , "Question", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                MtRegistryManager.RemoveConnectionProfile(SelectedProfile.Name);
                ConnectionProfiles.Remove(SelectedProfile);
            }
        }
Example #6
0
        public void Initialize()
        {
            var profiles = MtRegistryManager.LoadConnectionProfiles();

            if (profiles != null)
            {
                foreach (var prof in profiles)
                {
                    ConnectionProfiles.Add(prof);
                }
            }
        }
Example #7
0
 private void _profilesDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == _removeProfileColumn.Index)
     {
         IList <ConnectionProfile> list = (IList <ConnectionProfile>)_profilesBindingSource.DataSource;
         ConnectionProfiles.Remove(list[e.RowIndex].Name);
         ReloadProfiles();
     }
     else if (e.ColumnIndex == _editProfileColumn.Index)
     {
         _editSelectedProfile = true;
         _profilesDataGridView_DoubleClick(this, EventArgs.Empty);
     }
 }
Example #8
0
        private void ExecuteAddProfile(object o)
        {
            var dlg    = new AddProfileDialog(App.Current.MainWindow);
            var result = dlg.ShowDialog();

            if (result == true)
            {
                var profile = new MtConnectionProfile(dlg.ProfileName);
                profile.Host = dlg.Host;
                profile.Port = int.Parse(dlg.Port);

                MtRegistryManager.AddConnectionProfile(profile);
                ConnectionProfiles.Add(profile);
            }
        }
Example #9
0
        private void ReloadProfiles()
        {
            List <ConnectionProfile> list = new List <ConnectionProfile>(ConnectionProfiles.GetList());

            list.Add(new ConnectionProfile("New connection...", null, false));
            _profilesBindingSource.DataSource = list;
            _profilesBindingSource.ResetBindings(false);

            if (!String.IsNullOrEmpty(_selectedProfileName))
            {
                foreach (DataGridViewRow row in _profilesDataGridView.Rows)
                {
                    ConnectionProfile profile = row.DataBoundItem as ConnectionProfile;
                    if (profile.ServerSettings != null &&
                        profile.Name == _selectedProfileName)
                    {
                        row.Selected = true;
                        break;
                    }
                }
            }
        }
Example #10
0
        private void updateProfiles()
        {
            if (CPService != null)
            {
                ConnectionProfiles = CPService.getAvailableProfiles();
                SelectedProfile    = 0;
            }

            ConnectionProfile currentProfile = null;

            if (UserOptions != null)
            {
                var currentOptions = UserOptions.getOptions();
                if (currentOptions != null)
                {
                    currentProfile = currentOptions.CurrentConnection;
                    Options        = currentOptions;
                }
                else
                {
                    Options = new DiversityUserOptions();
                }
            }

            if (ConnectionProfiles != null && currentProfile != null)
            {
                var selectedIndices = from profile in ConnectionProfiles
                                      where profile.CompareTo(currentProfile) == 0
                                      select ConnectionProfiles.IndexOf(profile);

                if (selectedIndices.Count() > 0)
                {
                    SelectedProfile = selectedIndices.First();
                }
            }
        }
Example #11
0
        public bool ConnectToArgusTVService(string currentProfileName, bool reconnect)
        {
            bool result                 = false;
            bool abortConnection        = false;
            bool tryConnectionWithoutUI = !reconnect;
            bool skipSelectionForm      = false;

            IList <ConnectionProfile> profiles = ConnectionProfiles.GetList();

            if (!reconnect &&
                !String.IsNullOrEmpty(currentProfileName))
            {
                _connectionProfile = FindConnectionProfileByName(profiles, currentProfileName);
                skipSelectionForm  = (_connectionProfile != null);
            }

            if (_connectionProfile != null)
            {
                currentProfileName = _connectionProfile.Name;
            }
            else
            {
                currentProfileName = Properties.Settings.Default.LastUsedConnectionProfile;
            }

            if (profiles.Count == 1)
            {
                _connectionProfile = profiles[0];
            }
            else if (profiles.Count > 1 &&
                     !skipSelectionForm)
            {
                if (!reconnect)
                {
                    Program.App.HideSplash();
                }
                SelectProfileForm selectProfileForm = new SelectProfileForm();
                selectProfileForm.SetSelectedProfileName(currentProfileName);
                if (selectProfileForm.ShowDialog(this) == DialogResult.OK)
                {
                    _connectionProfile = selectProfileForm.SelectedProfile;
                    if (_connectionProfile != null)
                    {
                        tryConnectionWithoutUI = !selectProfileForm.EditSelectedProfile;
                        if (tryConnectionWithoutUI &&
                            !reconnect)
                        {
                            Program.App.ShowSplash();
                        }
                    }
                }
                else
                {
                    result          = false;
                    abortConnection = true;
                }
            }

            if (!abortConnection)
            {
                if (tryConnectionWithoutUI &&
                    _connectionProfile != null)
                {
                    bool saveProfiles = false;

                    if (_connectionProfile.ServerSettings.Transport == ServiceProxy.ServiceTransport.Https &&
                        String.IsNullOrEmpty(_connectionProfile.ServerSettings.Password))
                    {
                        using (LogonForm logonForm = new LogonForm())
                        {
                            logonForm.UserName = _connectionProfile.ServerSettings.UserName;
                            Program.App.HideSplash();
                            if (DialogResult.OK == logonForm.ShowDialog(this))
                            {
                                _connectionProfile.ServerSettings.UserName = logonForm.UserName;
                                _connectionProfile.ServerSettings.Password = logonForm.Password;
                                _connectionProfile.SavePassword            = logonForm.SavePassword;
                                saveProfiles = _connectionProfile.SavePassword;
                            }
                        }
                    }

                    try
                    {
                        Cursor.Current = Cursors.WaitCursor;

                        string macAddresses = _connectionProfile.ServerSettings.WakeOnLan.MacAddresses;
                        string ipAddress    = _connectionProfile.ServerSettings.WakeOnLan.IPAddress;

                        if (!Proxies.Initialize(_connectionProfile.ServerSettings, false))
                        {
                            Program.App.HideSplash();
                            result = ConnectWithForm();
                        }
                        else
                        {
                            if (saveProfiles ||
                                !String.Equals(macAddresses, _connectionProfile.ServerSettings.WakeOnLan.MacAddresses) ||
                                !String.Equals(ipAddress, _connectionProfile.ServerSettings.WakeOnLan.IPAddress))
                            {
                                ConnectionProfiles.Save();
                            }
                            RefreshFormTitle();
                            result = true;
                        }
                    }
                    finally
                    {
                        Cursor.Current = Cursors.Default;
                    }
                }
                else
                {
                    if (!reconnect)
                    {
                        Program.App.HideSplash();
                    }
                    result = ConnectWithForm();
                }
            }

            if (result &&
                Properties.Settings.Default.LastUsedConnectionProfile != _connectionProfile.Name)
            {
                Properties.Settings.Default.LastUsedConnectionProfile = _connectionProfile.Name;
                Properties.Settings.Default.Save();
            }

            return(result);
        }