Esempio n. 1
0
        /// <summary>
        /// Removes from the file server list.
        /// </summary>
        /// <param name="server">The <see cref="FileServerInfo"/> to remove.</param>
        /// <returns>True if removed; otherwise false.</returns>
        public bool RemoveFileServer(FileServerInfo server)
        {
            bool removed;

            lock (_fileServersSync)
            {
                removed = _fileServers.Remove(server);
            }

            if (removed)
            {
                Save();
                UpdateFileServerListFile();

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

            return(removed);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds to the file server list.
        /// </summary>
        /// <param name="server">The <see cref="FileServerInfo"/> to add.</param>
        /// <returns>True if added; otherwise false.</returns>
        public bool AddFileServer(FileServerInfo server)
        {
            lock (_fileServersSync)
            {
                if (_fileServers.Contains(server))
                {
                    return(false);
                }

                _fileServers.Add(server);
            }

            Save();
            UpdateFileServerListFile();

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

            return(true);
        }
Esempio n. 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();
        }
Esempio n. 4
0
        /// <summary>
        /// Removes from the file server list.
        /// </summary>
        /// <param name="server">The <see cref="FileServerInfo"/> to remove.</param>
        /// <returns>True if removed; otherwise false.</returns>
        public bool RemoveFileServer(FileServerInfo server)
        {
            bool removed;
            lock (_fileServersSync)
            {
                removed = _fileServers.Remove(server);
            }

            if (removed)
            {
                Save();
                UpdateFileServerListFile();

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

            return removed;
        }
Esempio n. 5
0
        /// <summary>
        /// Adds to the file server list.
        /// </summary>
        /// <param name="server">The <see cref="FileServerInfo"/> to add.</param>
        /// <returns>True if added; otherwise false.</returns>
        public bool AddFileServer(FileServerInfo server)
        {
            lock (_fileServersSync)
            {
                if (_fileServers.Contains(server))
                    return false;

                _fileServers.Add(server);
            }

            Save();
            UpdateFileServerListFile();

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

            return true;
        }
Esempio n. 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();
        }
Esempio n. 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();
        }