/// <summary> /// Initializes a new instance of the <see cref="MasterServerInfo"/> class. /// </summary> /// <param name="type">The type of file uploader to use.</param> /// <param name="host">The host address.</param> /// <param name="user">The user.</param> /// <param name="password">The password.</param> /// <param name="downloadType">The type of file downloader to use.</param> /// <param name="downloadHost">The download host.</param> public MasterServerInfo(FileUploaderType type, string host, string user, string password, DownloadSourceType downloadType, string downloadHost) : base(type, host, user, password, downloadType, downloadHost) { // For the master server, we also want to update whenever the list of servers changes _settings.FileServerListChanged += _settings_FileServerListChanged; _settings.MasterServerListChanged += _settings_MasterServerListChanged; }
/// <summary> /// Initializes a new instance of the <see cref="ServerInfoBase"/> class. /// </summary> /// <param name="type">The type of file uploader to use.</param> /// <param name="host">The host address.</param> /// <param name="user">The user.</param> /// <param name="password">The password.</param> /// <param name="downloadType">The type of file downloader to use.</param> /// <param name="downloadHost">The download host.</param> protected ServerInfoBase(FileUploaderType type, string host, string user, string password, DownloadSourceType downloadType, string downloadHost) { _fileUploaderType = type; _host = host; _user = user; _password = password; _fileDownloaderType = downloadType; _downloadHost = downloadHost; _updateJobCountTimer = new Timer(InvokeProgressChanged, null, 1000, 1000); // Listen for when any versions change _settings.LiveVersionChanged += _settings_LiveVersionChanged; _settings.NextVersionCreated += _settings_NextVersionCreated; // Enqueue the live version and, if it exists, the next version, to ensure they are synchronized EnqueueSyncVersion(_settings.LiveVersion); if (_settings.DoesNextVersionExist()) { EnqueueSyncVersion(_settings.LiveVersion + 1); } // Create the initial file uploader RecreateFileUploader(); // Create the worker thread and start it _workerThread = new Thread(WorkerThreadLoop) { IsBackground = true }; try { _workerThread.Name = "MasterServerInfo [" + GetHashCode() + "] worker thread."; } catch (InvalidOperationException) { } _workerThread.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="ServerInfoBase"/> class. /// </summary> /// <param name="type">The type of file uploader to use.</param> /// <param name="host">The host address.</param> /// <param name="user">The user.</param> /// <param name="password">The password.</param> /// <param name="downloadType">The type of file downloader to use.</param> /// <param name="downloadHost">The download host.</param> protected ServerInfoBase(FileUploaderType type, string host, string user, string password, DownloadSourceType downloadType, string downloadHost) { _fileUploaderType = type; _host = host; _user = user; _password = password; _fileDownloaderType = downloadType; _downloadHost = downloadHost; _updateJobCountTimer = new Timer(InvokeProgressChanged, null, 1000, 1000); // Listen for when any versions change _settings.LiveVersionChanged += _settings_LiveVersionChanged; _settings.NextVersionCreated += _settings_NextVersionCreated; // Enqueue the live version and, if it exists, the next version, to ensure they are synchronized EnqueueSyncVersion(_settings.LiveVersion); if (_settings.DoesNextVersionExist()) EnqueueSyncVersion(_settings.LiveVersion + 1); // Create the initial file uploader RecreateFileUploader(); // Create the worker thread and start it _workerThread = new Thread(WorkerThreadLoop) { IsBackground = true }; try { _workerThread.Name = "MasterServerInfo [" + GetHashCode() + "] worker thread."; } catch (InvalidOperationException) { } _workerThread.Start(); }
/// <summary> /// Changes the server information. /// </summary> /// <param name="newHost">The new host.</param> /// <param name="newUser">The new user.</param> /// <param name="newPassword">The new password.</param> /// <param name="newType">The new type of <see cref="IFileUploader"/>.</param> /// <param name="newDownloadType">The new type of <see cref="IDownloadSource"/>.</param> /// <param name="newDownloadHost">The new download host.</param> /// <exception cref="ArgumentNullException"><paramref name="newHost"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="newUser"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="newPassword"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="newDownloadHost"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="newType"/> is not a valid enum value.</exception> /// <exception cref="ArgumentException"><paramref name="newDownloadType"/> is not a valid enum value.</exception> public void ChangeInfo(string newHost, string newUser, string newPassword, FileUploaderType newType, DownloadSourceType newDownloadType, string newDownloadHost) { if (newHost == null) throw new ArgumentNullException("newHost"); if (newUser == null) throw new ArgumentNullException("newUser"); if (newPassword == null) throw new ArgumentNullException("newPassword"); if (newDownloadHost == null) throw new ArgumentNullException("newDownloadHost"); if (!Enum.IsDefined(typeof(FileUploaderType), newType)) throw new ArgumentException("Invalid FileUploaderType value: " + newType, "newType"); if (!Enum.IsDefined(typeof(DownloadSourceType), newDownloadType)) throw new ArgumentException("Invalid DownloadSourceType value: " + newDownloadType, "newDownloadType"); lock (_infoSync) { // Check if any values are different var sc = StringComparer.Ordinal; if (sc.Equals(newHost, Host) && sc.Equals(newUser, User) && sc.Equals(newPassword, Password) && newType == FileUploaderType && newDownloadType == DownloadSourceType && sc.Equals(newDownloadHost, DownloadHost)) return; // Set the new values _host = newHost; _user = newUser; _password = newPassword; _fileUploaderType = newType; _downloadHost = newDownloadHost; _fileDownloaderType = newDownloadType; // Force saving _settings.Save(); // Recreate the uploader RecreateFileUploader(); try { if (ServerChanged != null) ServerChanged(this); } catch (NullReferenceException) { } } }
/// <summary> /// Initializes a new instance of the <see cref="FileServerInfo"/> class. /// </summary> /// <param name="type">The type of file uploader to use.</param> /// <param name="host">The host address.</param> /// <param name="user">The user.</param> /// <param name="password">The password.</param> /// <param name="downloadType">The type of file downloader to use.</param> /// <param name="downloadHost">The download host.</param> public FileServerInfo(FileUploaderType type, string host, string user, string password, DownloadSourceType downloadType, string downloadHost) : base(type, host, user, password, downloadType, downloadHost) { }
/// <summary> /// Changes the server information. /// </summary> /// <param name="newHost">The new host.</param> /// <param name="newUser">The new user.</param> /// <param name="newPassword">The new password.</param> /// <param name="newType">The new type of <see cref="IFileUploader"/>.</param> /// <param name="newDownloadType">The new type of <see cref="IDownloadSource"/>.</param> /// <param name="newDownloadHost">The new download host.</param> /// <exception cref="ArgumentNullException"><paramref name="newHost"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="newUser"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="newPassword"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="newDownloadHost"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="newType"/> is not a valid enum value.</exception> /// <exception cref="ArgumentException"><paramref name="newDownloadType"/> is not a valid enum value.</exception> public void ChangeInfo(string newHost, string newUser, string newPassword, FileUploaderType newType, DownloadSourceType newDownloadType, string newDownloadHost) { if (newHost == null) { throw new ArgumentNullException("newHost"); } if (newUser == null) { throw new ArgumentNullException("newUser"); } if (newPassword == null) { throw new ArgumentNullException("newPassword"); } if (newDownloadHost == null) { throw new ArgumentNullException("newDownloadHost"); } if (!Enum.IsDefined(typeof(FileUploaderType), newType)) { throw new ArgumentException("Invalid FileUploaderType value: " + newType, "newType"); } if (!Enum.IsDefined(typeof(DownloadSourceType), newDownloadType)) { throw new ArgumentException("Invalid DownloadSourceType value: " + newDownloadType, "newDownloadType"); } lock (_infoSync) { // Check if any values are different var sc = StringComparer.Ordinal; if (sc.Equals(newHost, Host) && sc.Equals(newUser, User) && sc.Equals(newPassword, Password) && newType == FileUploaderType && newDownloadType == DownloadSourceType && sc.Equals(newDownloadHost, DownloadHost)) { return; } // Set the new values _host = newHost; _user = newUser; _password = newPassword; _fileUploaderType = newType; _downloadHost = newDownloadHost; _fileDownloaderType = newDownloadType; // Force saving _settings.Save(); // Recreate the uploader RecreateFileUploader(); try { if (ServerChanged != null) { ServerChanged(this); } } catch (NullReferenceException) { } } }
/// <summary> /// Initializes a new instance of the <see cref="DownloadSourceDescriptor"/> class. /// </summary> /// <param name="type">The type.</param> /// <param name="rootPath">The root path.</param> public DownloadSourceDescriptor(DownloadSourceType type, string rootPath) { _rootPath = rootPath; _type = type; }
/// <summary> /// Gets a string that can be used to reconstruct a <see cref="DownloadSourceDescriptor"/>. /// </summary> /// <param name="type">The <see cref="DownloadSourceType"/>.</param> /// <param name="rootPath">The download host.</param> /// <returns> /// A string that can be used to reconstruct a <see cref="DownloadSourceDescriptor"/>. /// </returns> public static string GetDescriptorString(DownloadSourceType type, string rootPath) { return(string.Format("{0}|{1}", type, rootPath)); }
/// <summary> /// Gets a string that can be used to reconstruct a <see cref="DownloadSourceDescriptor"/>. /// </summary> /// <param name="type">The <see cref="DownloadSourceType"/>.</param> /// <param name="rootPath">The download host.</param> /// <returns> /// A string that can be used to reconstruct a <see cref="DownloadSourceDescriptor"/>. /// </returns> public static string GetDescriptorString(DownloadSourceType type, string rootPath) { return string.Format("{0}|{1}", type, rootPath); }