/// <summary> /// メッセージを送信する(スレッドセーフ) /// IOエラーが起きた場合このメソッド自体は例外を出さずに勝手にDisposeする /// </summary> /// <param name="message">送信するメッセージ</param> public async Task Send(IPC.IPCMessage.IIPCMessage message) { var state = State; if (state != IPCModuleState.Connected && state != IPCModuleState.Receiving) { throw new InvalidOperationException($"Cannot call this method on current state. Current state is '{state}'"); } await sendLock.WaitAsync(); try { await tunnel.Send(message, new CancellationTokenSource(1000).Token).ConfigureAwait(false); } catch (IOException e) { await dispose(IPCModuleDisposeReason.SendFailure, e).ConfigureAwait(false); } catch (OperationCanceledException) { await dispose(IPCModuleDisposeReason.SendFailure).ConfigureAwait(false); } catch (Exception e) { await dispose(IPCModuleDisposeReason.UnexpectedError, e).ConfigureAwait(false); throw; } finally { sendLock.Release(); } //Debug.WriteLine("Sent: "+message); }
private void ipcModule_MessageReceived(IPC.IPCMessage.IIPCMessage message) { var commandMessage = message as IPC.IPCMessage.CommandIPCMessage; if (commandMessage == null) { return; } switch (commandMessage.CommandId) { case "ShowWindow": SynchronizationContext.Post(_ => ShowWindowCommandInvoked(), null); break; } }
private void ipc_MessageReceived(IPC.IPCMessage.IIPCMessage message) { IPC.IPCMessage.ChannelListIPCMessage chlistmsg = message as IPC.IPCMessage.ChannelListIPCMessage; IPC.IPCMessage.CurrentChannelIPCMessage curchmsg = message as IPC.IPCMessage.CurrentChannelIPCMessage; IPC.IPCMessage.TimeIPCMessage timemsg = message as IPC.IPCMessage.TimeIPCMessage; if (chlistmsg != null) { //選択できるチャンネルリストを伝えるメッセージ channelList.Clear(); channelList.AddRange(chlistmsg.ChannelList); } else if (curchmsg != null) { //現在のチャンネル・番組情報を伝えるメッセージ //NID,TSID,SIDがすべて同じならチャンネルは同じで変わってないと判定する if (this.currentChannel.Value == null || (this.currentChannel.Value.NetworkId != curchmsg.Channel.NetworkId || this.currentChannel.Value.TransportStreamId != curchmsg.Channel.TransportStreamId || this.currentChannel.Value.ServiceId != curchmsg.Channel.ServiceId)) { this.currentChannel.Value = curchmsg.Channel; } var currentChannel = ChannelList.Select((ch, idx) => new { Channel = ch, Index = idx }).FirstOrDefault((x) => curchmsg.Channel.NetworkId == x.Channel.NetworkId && curchmsg.Channel.TransportStreamId == x.Channel.TransportStreamId && curchmsg.Channel.ServiceId == x.Channel.ServiceId); //チャンネルリスト内に同じチャンネルがあればそれを今回のメッセージで得たインスタンスに置き換える if (currentChannel != null) { this.channelList[currentChannel.Index] = this.currentChannel.Value; } this.currentEvent.Value = curchmsg.Event; } else if (timemsg != null) { //TOTを伝えるメッセージ //精度は1秒単位で値が変わるごとに来る currentTime.Value = timemsg.Time; } }
private async void ipcManager_MessageReceived(IPC.IPCMessage.IIPCMessage message) { if (message is IPC.IPCMessage.SetChatOpacityIPCMessage) { await ipcModule.Send(message); } else if (message is IPC.IPCMessage.CloseIPCMessage) { isClosing = true; if (!closingResetEvent.IsSet) { //Closeの返事を待っていた closingResetEvent.Set(); } else { //Closeの返事を待っていたわけではない->相手がCloseした。 ApplicationClose();//thisがDisposeされる } } }