public void Subscribe(ManagedInstance instance) { _instances.Add(instance.Id, instance); instance.Statistics.PropertyChanged += OnStatisticsChanged; instance.Unmonitored += OnUnmonitored; }
public NeedQueueForm(ManagedInstance instance) { InitializeComponent(); _instance = instance; Text = String.Format("Downloading to {0}", _instance.Information.DisplayName); }
private void addButton_Click(object sender, EventArgs e) { var hostnameValidation = UserInputValidator.ValidateNetworkHostname(hostnameTextBox.Text); var portValidation = UserInputValidator.ValidateNetworkPortNumber(portTextBox.Text); var apiKeyValidation = UserInputValidator.ValidateSyncthingApiKey(apiKeyTextBox.Text); var displayNameValidation = UserInputValidator.ValidateSyncthingDisplayName(customNameTextBox.Text); var errorMessages = new List<string>(); // Validate port number if (!portValidation.IsValid) errorMessages.Add(portValidation.Message); // Validate hostname if (!hostnameValidation.IsValid) errorMessages.Add(hostnameValidation.Message); // Validate API key if (!apiKeyValidation.IsValid) errorMessages.Add(apiKeyValidation.Message); if (errorMessages.Count > 0) { MetroMessageBox.Show(this, String.Join(Environment.NewLine, errorMessages), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var instance = new ManagedInstance { UseHttps = useHttpsToggle.Checked, ApiKey = apiKeyValidation.ValidatedValue }; instance.PossibleEndpoints.Add(new RestEndpoint { Hostname = hostnameValidation.ValidatedValue, Port = portValidation.ValidatedValue, Priority = 100, IsPingable = true }); // Assign display name if (displayNameValidation.IsValid) instance.CustomName = customNameTextBox.Text.Trim(); Log.Logger.Information("New Syncthing instance created: {@Instance}", instance); Singleton<SyncthingInstanceManager>.Instance.Add(instance); AppSettings.Save(ParentForm); Close(); }
public void Subscribe(ManagedInstance instance) { instance.Folders.CollectionChanged += OnFolderChanged; instance.Unmonitored += OnUnmonitored; }
/// <summary> /// Restores the given snapshot back to the application /// </summary> /// <param name="snapshot">Deserialzable object created by Backup()</param> /// <param name="form">If given, its visual representation will also be restored</param> public static void Restore(SettingsSnapshot snapshot, Form form = null) { Singleton<SyncthingInstanceManager>.Instance.Clear(); foreach (var definition in snapshot.Instances) { try { var instance = new ManagedInstance { Id = definition.Id, CustomName = definition.Name, UseHttps = definition.UseHttps, ApiKey = definition.ApiKey }; foreach (var storedEndpoint in definition.Endpoints) { instance.PossibleEndpoints.Add(new RestEndpoint { Hostname = storedEndpoint.Hostname, Port = storedEndpoint.Port, Priority = storedEndpoint.Priority, IsPingable = true }); } Singleton<SyncthingInstanceManager>.Instance.Add(instance); } catch (InvalidOperationException) { // Ignore instances without an endpoint } } }
public async Task TestMissingEndpoints() { var instance = new ManagedInstance { ApiKey = "unittest" }; instance.Watch(); await Task.Delay(TimeSpan.FromSeconds(3)); Assert.IsTrue(instance.IsInState(ManagedInstance.State.Disconnected)); }
public async Task TestMissingApiKey() { var instance = new ManagedInstance { PossibleEndpoints = GetDefaultRestEndpointCollection() }; instance.Watch(); await Task.Delay(TimeSpan.FromSeconds(3)); Assert.IsTrue(instance.IsInState(ManagedInstance.State.Disconnected)); }