Exemplo n.º 1
0
        public void InitFromSavedServer(SavedServer savedServer)
        {
            Log = Logger.GetLogger("RemoteServer." + savedServer.HostName);

            HostAddress = savedServer.HostAddress;
            Port        = savedServer.Port;
            HostName    = savedServer.HostName;

            Category = savedServer.Category;
            UserId   = savedServer.UserId;
            PW       = savedServer.PW;

            _savedViewedFiles   = savedServer.ViewedFiles ?? new List <ViewedPath>();
            _savedViewedFolders = savedServer.ViewedFolders ?? new List <ViewedPath>();
        }
Exemplo n.º 2
0
        private void SetServerProperties(SavedServer savedServer)
        {
            savedServer.HostAddress = txtAddress.Text;
            savedServer.HostName    = txtDispName.Text;
            savedServer.UserId      = txtUserID.Text;
            savedServer.PW          = _newPW;
            savedServer.Category    = comboCategories.Text.Trim();

            if (txtPort.Text == "")
            {
                savedServer.Port = -1;
            }
            else
            {
                savedServer.Port = int.Parse(txtPort.Text);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// If adding a new server pass null for serverToEdit.  This will cause
        /// a new SavedServer object to be created when the user clicks OK.
        /// To edit an existing server pass it in via the serverToEdit parameter.
        /// The specified server will be modified in-place when the user clicks OK.
        /// The otherNames parameter is used to prevent creating two servers
        /// with the same display name.
        /// </summary>
        public void Init(IEnumerable <string> categories, IEnumerable <string> otherNames, SavedServer serverToEdit, bool allowAddressEdit = true)
        {
            _otherServerNames = otherNames;
            comboCategories.Items.AddRange(categories.OrderBy(s => s).ToArray());

            if (serverToEdit == null)
            {
                // We'll be starting with empty controls. The "server address" will be
                // copied to the "display name" as the user types until he explicitly
                // changes the "display name".

                _keepNameEqualToAddress = true;
            }
            else
            {
                // Initialize the controls from serverToEdit.

                _keepNameEqualToAddress = false;
                _editServer             = serverToEdit;
                txtAddress.Text         = serverToEdit.HostAddress;
                txtDispName.Text        = serverToEdit.HostName;

                if (serverToEdit.Port > 0)
                {
                    txtPort.Text = serverToEdit.Port.ToString();
                }

                comboCategories.SelectedItem = serverToEdit.Category;
                txtUserID.Text = serverToEdit.UserId;
                _newPW         = serverToEdit.PW;

                if (!string.IsNullOrWhiteSpace(serverToEdit.PW))
                {
                    // Indicate the existence of a password with a placeholder string.
                    txtPassword.Text = "XXXXXXXXXX";
                }
            }

            txtAddress.Enabled = allowAddressEdit;
            txtPort.Enabled    = allowAddressEdit;

            _pwChanged = false;
        }
Exemplo n.º 4
0
        public ServerListEditor(List <RemoteServer> remoteServers)
        {
            InitializeComponent();
            _inputServers = remoteServers;

            foreach (RemoteServer originalObject in _inputServers)
            {
                // The user's edits will be kept in the editable objects (keys of _newToOld)
                // until he clicks OK, then the properties of each editableObject will be
                // copied to the corresponding originalObject.

                SavedServer editableObject = originalObject.MakeSavedServer();
                _newToOld[editableObject] = originalObject;
                AddServerItem(editableObject);
            }

            _sorter = new ListViewSorter(listView1);
            _sorter.Sort(colDispName.Index);
        }
Exemplo n.º 5
0
        private void ImportXmlFile(OpenFileDialog dlg)
        {
            HashSet <string> existingNames = GetDisplayNames(null);
            int dupCount  = 0;
            int keptCount = 0;

            using (var stream = dlg.OpenFile())
            {
                var serializer = new XmlSerializer(typeof(List <ExportableServer>));
                var servers    = serializer.Deserialize(stream) as List <ExportableServer>;

                foreach (ExportableServer import in servers)
                {
                    if (existingNames.Add(import.HostName))
                    {
                        if (!import.HostName.NullOrWhiteSpace())
                        {
                            if (!import.HostAddress.NullOrWhiteSpace())
                            {
                                SavedServer newServer = new SavedServer()
                                {
                                    Category    = import.Category,
                                    HostName    = import.HostName,
                                    HostAddress = import.HostAddress,
                                    Port        = import.Port,
                                };

                                AddServerItem(newServer);
                                btnOK.Enabled = true;
                                ++keptCount;
                            }
                        }
                    }
                    else
                    {
                        ++dupCount;
                    }
                }

                ShowImportResults(servers.Count, dupCount, keptCount);
            } // using stream
        }
Exemplo n.º 6
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (CheckProps() && CheckCreds())
            {
                if (_editServer == null)
                {
                    // We're in "add" mode.
                    NewServer = new SavedServer();
                    SetServerProperties(NewServer);
                }
                else
                {
                    // We're in "edit" mode.
                    SetServerProperties(_editServer);
                    NewServer = _editServer;
                }

                DoConnect    = sender == btnOkConnect;
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Exemplo n.º 7
0
 public RemoteServer(SavedServer savedServer)
 {
     InitFromSavedServer(savedServer);
 }