Пример #1
0
        /// <summary>
        /// Removes from the master server list.
        /// </summary>
        /// <param name="server">The <see cref="MasterServerInfo"/> to remove.</param>
        /// <returns>True if removed; otherwise false.</returns>
        public bool RemoveMasterServer(MasterServerInfo server)
        {
            bool removed;

            lock (_masterServersSync)
            {
                removed = _masterServers.Remove(server);
            }

            if (removed)
            {
                Save();
                UpdateMasterServerListFile();

                if (MasterServerListChanged != null)
                {
                    MasterServerListChanged(this);
                }
            }

            return(removed);
        }
Пример #2
0
        /// <summary>
        /// Adds to the master server list.
        /// </summary>
        /// <param name="server">The <see cref="MasterServerInfo"/> to add.</param>
        /// <returns>True if added; otherwise false.</returns>
        public bool AddMasterServer(MasterServerInfo server)
        {
            lock (_masterServersSync)
            {
                if (_masterServers.Contains(server))
                {
                    return(false);
                }

                _masterServers.Add(server);
            }

            Save();
            UpdateMasterServerListFile();

            if (MasterServerListChanged != null)
            {
                MasterServerListChanged(this);
            }

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Handles the Click event of the btnCreate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnCreate_Click(object sender, EventArgs e)
        {
            // Confirm
            const string confirmMsg =
                "Are you sure you wish to create this server?{0}It is highly recommended that you test the settings" +
                " first and make sure they pass, but not required. Although you can change the settings later, it is best to avoid" +
                " doing so whenever possible.";

            if (MessageBox.Show(string.Format(confirmMsg, Environment.NewLine), "Create server?", MessageBoxButtons.YesNo) ==
                DialogResult.No)
            {
                return;
            }

            try
            {
                var type         = (FileUploaderType)cmbType.SelectedItem;
                var host         = txtHost.Text;
                var user         = txtUser.Text;
                var pass         = txtPassword.Text;
                var downloadType = (DownloadSourceType)cmbDownloadType.SelectedItem;
                var downloadHost = txtDownloadHost.Text;

                if (string.IsNullOrEmpty(host))
                {
                    MessageBox.Show("Please enter a valid host.", "Invalid value", MessageBoxButtons.OK);
                    txtHost.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(downloadHost))
                {
                    MessageBox.Show("Please enter a valid download host.", "Invalid value", MessageBoxButtons.OK);
                    txtDownloadHost.Focus();
                    return;
                }

                if (!Enum.IsDefined(typeof(FileUploaderType), type))
                {
                    const string errmsg =
                        "Invalid FileUploaderType type ({0}) supplied - not a known enum value. Please select a valid type.";
                    cmbType.SelectedIndex = 0;
                    throw new InvalidEnumArgumentException(string.Format(errmsg, type));
                }

                if (!Enum.IsDefined(typeof(DownloadSourceType), downloadType))
                {
                    const string errmsg =
                        "Invalid DownloadSourceType type ({0}) supplied - not a known enum value. Please select a valid type.";
                    cmbDownloadType.SelectedIndex = 0;
                    throw new InvalidEnumArgumentException(string.Format(errmsg, downloadType));
                }

                // Create
                if (_isMasterServer)
                {
                    var server = new MasterServerInfo(type, host, user, pass, downloadType, downloadHost);
                    ManagerSettings.Instance.AddMasterServer(server);
                }
                else
                {
                    var server = new FileServerInfo(type, host, user, pass, downloadType, downloadHost);
                    ManagerSettings.Instance.AddFileServer(server);
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to create the server instance. Reason: {0}";
                MessageBox.Show(string.Format(errmsg, ex));
                return;
            }

            MessageBox.Show("Server successfully created!", "Success!", MessageBoxButtons.OK);
            Close();
        }
Пример #4
0
        /// <summary>
        /// Removes from the master server list.
        /// </summary>
        /// <param name="server">The <see cref="MasterServerInfo"/> to remove.</param>
        /// <returns>True if removed; otherwise false.</returns>
        public bool RemoveMasterServer(MasterServerInfo server)
        {
            bool removed;
            lock (_masterServersSync)
            {
                removed = _masterServers.Remove(server);
            }

            if (removed)
            {
                Save();
                UpdateMasterServerListFile();

                if (MasterServerListChanged != null)
                    MasterServerListChanged(this);
            }

            return removed;
        }
Пример #5
0
        /// <summary>
        /// Adds to the master server list.
        /// </summary>
        /// <param name="server">The <see cref="MasterServerInfo"/> to add.</param>
        /// <returns>True if added; otherwise false.</returns>
        public bool AddMasterServer(MasterServerInfo server)
        {
            lock (_masterServersSync)
            {
                if (_masterServers.Contains(server))
                    return false;

                _masterServers.Add(server);
            }

            Save();
            UpdateMasterServerListFile();

            if (MasterServerListChanged != null)
                MasterServerListChanged(this);

            return true;
        }
Пример #6
0
        /// <summary>
        /// Loads the settings from file.
        /// </summary>
        void Load(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return;
            }

            var lines  = File.ReadAllLines(filePath);
            var values = lines.Select(x => x.Trim()).Where(x => x.Length > 0).Select(GetSettingLine);

            // Read the settings
            foreach (var v in values)
            {
                switch (v.Key)
                {
                case _headerLiveVersion:
                    // Read the live version
                    int i;
                    if (!int.TryParse(v.Value, out i))
                    {
                        const string errmsg = "Encountered invalid {0} value in settings file.";
                        MessageBox.Show(string.Format(errmsg, _headerLiveVersion));
                        break;
                    }

                    _liveVersion = i;
                    UpdateLiveVersionFile();
                    break;

                case _headerFileServer:
                    // Read a file server
                    try
                    {
                        var server = FileServerInfo.Create(v.Value);
                        lock (_fileServersSync)
                        {
                            _fileServers.Add(server);
                        }
                    }
                    catch (Exception ex)
                    {
                        const string errmsg = "Encountered invalid {0} value in settings file: {1}";
                        MessageBox.Show(string.Format(errmsg, _headerFileServer, ex));
                    }
                    break;

                case _headerMasterServer:
                    // Read a master server
                    try
                    {
                        var server = MasterServerInfo.Create(v.Value);
                        lock (_masterServersSync)
                        {
                            _masterServers.Add(server);
                        }
                    }
                    catch (Exception ex)
                    {
                        const string errmsg = "Encountered invalid {0} value in settings file: {1}";
                        MessageBox.Show(string.Format(errmsg, _headerMasterServer, ex));
                    }
                    break;

                default:
                    MessageBox.Show("Encountered unknown setting: " + v.Key);
                    break;
                }
            }

            // Update the info files
            UpdateMasterServerListFile();
            UpdateFileServerListFile();
            UpdateLiveVersionFile();
        }
Пример #7
0
        /// <summary>
        /// Handles the Click event of the btnCreate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnCreate_Click(object sender, EventArgs e)
        {
            // Confirm
            const string confirmMsg =
                "Are you sure you wish to create this server?{0}It is highly recommended that you test the settings" +
                " first and make sure they pass, but not required. Although you can change the settings later, it is best to avoid" +
                " doing so whenever possible.";

            if (MessageBox.Show(string.Format(confirmMsg, Environment.NewLine), "Create server?", MessageBoxButtons.YesNo) ==
                DialogResult.No)
                return;

            try
            {
                var type = (FileUploaderType)cmbType.SelectedItem;
                var host = txtHost.Text;
                var user = txtUser.Text;
                var pass = txtPassword.Text;
                var downloadType = (DownloadSourceType)cmbDownloadType.SelectedItem;
                var downloadHost = txtDownloadHost.Text;

                if (string.IsNullOrEmpty(host))
                {
                    MessageBox.Show("Please enter a valid host.", "Invalid value", MessageBoxButtons.OK);
                    txtHost.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(downloadHost))
                {
                    MessageBox.Show("Please enter a valid download host.", "Invalid value", MessageBoxButtons.OK);
                    txtDownloadHost.Focus();
                    return;
                }

                if (!Enum.IsDefined(typeof(FileUploaderType), type))
                {
                    const string errmsg =
                        "Invalid FileUploaderType type ({0}) supplied - not a known enum value. Please select a valid type.";
                    cmbType.SelectedIndex = 0;
                    throw new InvalidEnumArgumentException(string.Format(errmsg, type));
                }

                if (!Enum.IsDefined(typeof(DownloadSourceType), downloadType))
                {
                    const string errmsg =
                        "Invalid DownloadSourceType type ({0}) supplied - not a known enum value. Please select a valid type.";
                    cmbDownloadType.SelectedIndex = 0;
                    throw new InvalidEnumArgumentException(string.Format(errmsg, downloadType));
                }

                // Create
                if (_isMasterServer)
                {
                    var server = new MasterServerInfo(type, host, user, pass, downloadType, downloadHost);
                    ManagerSettings.Instance.AddMasterServer(server);
                }
                else
                {
                    var server = new FileServerInfo(type, host, user, pass, downloadType, downloadHost);
                    ManagerSettings.Instance.AddFileServer(server);
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to create the server instance. Reason: {0}";
                MessageBox.Show(string.Format(errmsg, ex));
                return;
            }

            MessageBox.Show("Server successfully created!", "Success!", MessageBoxButtons.OK);
            Close();
        }