private async void ProcessStarting() { // Things will attempt to talk to Syncthing over http. If Syncthing is set to 'https only', this will redirect. var preferredAddressWithScheme = new Uri("https://" + this.PreferredHostAndPort); var port = this.freePortFinder.FindFreePort(preferredAddressWithScheme.Port); var uriBuilder = new UriBuilder(preferredAddressWithScheme) { Port = port }; this.Address = uriBuilder.Uri; this.processRunner.ApiKey = this.ApiKey; // Don't pass a scheme here - we want Syncthing to choose http / https as appropriate this.processRunner.HostAddress = $"{this.Address.Host}:{this.Address.Port}"; this.processRunner.ExecutablePath = this.ExecutablePath; this.processRunner.CustomHomeDir = this.SyncthingCustomHomeDir; this.processRunner.CommandLineFlags = this.SyncthingCommandLineFlags; this.processRunner.EnvironmentalVariables = this.SyncthingEnvironmentalVariables; this.processRunner.DebugFacilities = this.DebugFacilities.DebugFacilities.Where(x => x.IsEnabled).Select(x => x.Name).ToList(); this.processRunner.DenyUpgrade = this.SyncthingDenyUpgrade; this.processRunner.SyncthingPriorityLevel = this.SyncthingPriorityLevel; this.processRunner.HideDeviceIds = this.SyncthingHideDeviceIds; var isRestart = (this.State == SyncthingState.Restarting); this.SetState(SyncthingState.Starting); // Catch restart cases, and re-start the API // This isn't ideal, as we don't get to nicely propagate any exceptions to the UI if (isRestart) { try { await this.StartClientAsync(); } catch (SyncthingDidNotStartCorrectlyException) { // We've already logged this } } }
private async void ProcessStarting() { var port = this.freePortFinder.FindFreePort(this.PreferredAddress.Port); var uriBuilder = new UriBuilder(this.PreferredAddress); uriBuilder.Port = port; this.Address = uriBuilder.Uri; this.processRunner.ApiKey = this.ApiKey; this.processRunner.HostAddress = this.Address.ToString(); this.processRunner.ExecutablePath = this.ExecutablePath; this.processRunner.CustomHomeDir = this.SyncthingCustomHomeDir; this.processRunner.CommandLineFlags = this.SyncthingCommandLineFlags; this.processRunner.EnvironmentalVariables = this.SyncthingEnvironmentalVariables; this.processRunner.DebugFacilities = this.DebugFacilities.DebugFacilities.Where(x => x.IsEnabled).Select(x => x.Name).ToList(); this.processRunner.DenyUpgrade = this.SyncthingDenyUpgrade; this.processRunner.SyncthingPriorityLevel = this.SyncthingPriorityLevel; this.processRunner.HideDeviceIds = this.SyncthingHideDeviceIds; var isRestart = (this.State == SyncthingState.Restarting); this.SetState(SyncthingState.Starting); // Catch restart cases, and re-start the API // This isn't ideal, as we don't get to nicely propagate any exceptions to the UI if (isRestart) { try { await this.StartClientAsync(); } catch (SyncthingDidNotStartCorrectlyException) { // We've already logged this } } }