public override async Task OpenAsync(BuildStatusToken statusToken) { try { IsSyncing = true; IMqttServerOptions options = new MqttServerOptionsBuilder() .WithDefaultEndpointPort(Port) .WithApplicationMessageInterceptor(this) .Build(); if (statusToken?.IsEnded.HasValue == true) { return; } isOpen = true; await server.StartAsync(options); } catch { try { await CloseAsync(); } catch { } throw; } finally { IsSyncing = false; } }
public override async Task SyncService(BuildStatusToken statusToken) { try { isSyncing = true; connection.IsSynced = false; connection.Service = Service; Task publishTask = Task.Run(() => SendMessagesHandler(connection)); Task pingTask = Task.Run(() => SendPingsHandler(connection)); Task receiveTask = Task.Run(() => ReceiveHandler(connection)); Task processTask = Task.Run(() => ProcessHandler(connection)); await connection.SendCommand(SyncCmd, false, TimeSpan.FromSeconds(1000), statusToken.EndTask); connection.IsSynced = true; connection.Task = Task.WhenAll(publishTask, pingTask, receiveTask, processTask); } catch (Exception e) { try { await connection.CloseAsync(e, true); } catch { } throw; } finally { isSyncing = false; } }
public override async Task OpenAsync(BuildStatusToken statusToken) { if (IsOpen) { return; } try { IPAddress address; if (!IPAddress.TryParse(ServerAddress, out address)) { address = await GetIpAddress(ServerAddress); } TcpClient client = new TcpClient(); await client.ConnectAsync(address, Port ?? -1); connection = new OwnTcpClientConnection(client); connection.Disconnected += Connection_Disconnected; } catch { if (connection != null) { connection.Disconnected -= Connection_Disconnected; connection.Client.Dispose(); connection = null; } throw; } }
public override Task SetService(IAudioServiceBase service, BuildStatusToken statusToken) { Unsubscribe(Service); Service = service; Subscribe(Service); return(SyncService(statusToken)); }
public override async Task SyncService(BuildStatusToken statusToken) { try { connections = new List <OwnTcpServerConnection>(); processQueue = new AsyncQueue <OwnTcpSendMessage>(); openTask = Task.WhenAll(ProcessHandler(processQueue), NewConnectionsHandler(processQueue)); } catch (Exception e) { await CloseAsync(e, true); throw; } }
public override async Task SetService(IAudioServiceBase service, BuildStatusToken statusToken) { try { IsSyncing = true; Unsubscribe(Service); Service = service; InitPlaylists(); await SyncService(statusToken, false); } finally { IsSyncing = false; } }
public override async Task OpenAsync(BuildStatusToken statusToken) { if (isOpen) { return; } try { isOpen = true; listener.Start(); } catch { await CloseAsync(); throw; } }
private async Task SyncService(BuildStatusToken statusToken, bool unsubscribe) { try { IsSyncing = true; if (unsubscribe) { Unsubscribe(Service); } Subscribe(Service); if (statusToken?.IsEnded.HasValue == true) { return; } await PublishCurrentPlaylist(); if (statusToken?.IsEnded.HasValue == true) { return; } await Task.WhenAll(Service.SourcePlaylists.Select(PublishPlaylist)); if (statusToken?.IsEnded.HasValue == true) { return; } await Task.WhenAll(Service.Playlists.Select(PublishPlaylist)); if (statusToken?.IsEnded.HasValue == true) { return; } await PublishPlaylists(); if (statusToken?.IsEnded.HasValue == true) { return; } await PublishPlayState(); if (statusToken?.IsEnded.HasValue == true) { return; } await PublishVolume(); if (statusToken?.IsEnded.HasValue == true) { return; } await PublishAudioData(); if (statusToken?.IsEnded.HasValue == true) { return; } await PublishIsSearchShuffle(); if (statusToken?.IsEnded.HasValue == true) { return; } await PublishSearchKey(); if (statusToken?.IsEnded.HasValue == true) { return; } } finally { IsSyncing = false; } }
public override async Task SyncService(BuildStatusToken statusToken) { await SyncService(statusToken, true); }