private async Task Send(RPCMethodId id, object obj) { if (client != null) { byte[] bytes = RPCTypes.Serialize(id, obj); await client.GetStream().WriteAsync(bytes, 0, bytes.Length); } }
private async Task Send(RPCMethodId id, object obj) { byte[] bytes = RPCTypes.Serialize(id, obj); foreach (var client in ClientList.ToArray()) { try { await client.GetStream().WriteAsync(bytes, 0, bytes.Length); client.TotalSendCount++; } catch (Exception) { Util.AddLog("クライアント(" + client.HostName + ":" + client.Port + ")との接続が切れました", null); client.Close(); OnClientClosed(client); } } }
private async Task RunCommandHost() { try { // 子プロセスが終了するまでループ while (true) { var rpc = await RPCTypes.Deserialize(pipes.ReadPipe); string ret = ""; try { switch (rpc.id) { case RPCMethodId.AddTag: var tag = (string)rpc.arg; if (!string.IsNullOrEmpty(tag) && !Item.Tags.Contains(tag)) { Item.Tags.Add(tag); } ret = string.Join(";", Item.Tags); break; case RPCMethodId.SetOutDir: if (Phase == ScriptPhase.PostEncode) { ret = "エンコードが完了したアイテムの出力先は変更できません"; } else if (string.IsNullOrEmpty(rpc.arg as string)) { ret = "出力先を指定してください"; } else { var outdir = (rpc.arg as string).TrimEnd(Path.DirectorySeparatorChar); Item.DstPath = outdir + "\\" + Path.GetFileName(Item.DstPath); ret = "成功"; } break; case RPCMethodId.SetPriority: if (Phase != ScriptPhase.OnAdd) { ret = "追加時以外の優先度操作はできません"; } else { int priority; if (!int.TryParse(rpc.arg as string, out priority) || priority < 1 || priority > 5) { ret = "優先度が範囲外です"; } else { Item.Priority = priority; ret = "成功"; } } break; case RPCMethodId.GetOutFiles: if (Phase != ScriptPhase.PostEncode) { ret = "実行後ではないため、出力ファイルを取得できません"; } else { ret = GetOutFiles((string)rpc.arg); } break; case RPCMethodId.CancelItem: if (Phase == ScriptPhase.PostEncode) { ret = "エンコードが完了したアイテムはキャンセルできません"; } else { Item.State = QueueState.Canceled; ret = "成功"; } break; } } catch (Exception e) { ret = e.Message; } var bytes = RPCTypes.Serialize(rpc.id, ret); await pipes.WritePipe.WriteAsync(bytes, 0, bytes.Length); } } catch (Exception) { // 子プロセスが終了すると例外を吐く } }
private static T Copy <T>(T obj) { return((T)RPCTypes.Deserialize(typeof(T), RPCTypes.Serialize(typeof(T), obj))); }