documents:tools:assistantseika:assistantseika-099
Seikactlのコード
ソース解説をすることはしません。最新版との同期もとれていません。
概要
同梱している Seikactl コマンドのソースコード。サンプルとして公開。
ソースコード
今日は counter_today人がこのページを訪れました。
Seikactlメインコード
- Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Seikactl { class Program { static int Main(string[] args) { Opts opt = new Opts(args); WCFClient scc =new WCFClient(); if (opt.isActive) { if (opt.isASBoot) { int times = 0; // 説明では3秒言うたが5秒やった for(times=0; times<50; times++) { try { scc.Version(); break; } catch (Exception) { Thread.Sleep(100); } } if (times == 50) { Console.WriteLine("not alive"); return 8; } } if (opt.isProdScan) { try { scc.ProductScan(); } catch (Exception e) { Console.WriteLine("fail. {0}", e.Message); } } if (opt.isBootHttpSrv) { try { scc.BootHttpService(); } catch (Exception e) { Console.WriteLine("fail. {0}", e.Message); } } } return 0; } } }
オプション解析
- Opt.cs
using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; namespace Seikactl { class Opts { public bool isActive { get; } public bool isProdScan { get; } public bool isBootHttpSrv { get; } public bool isASBoot { get; } public Opts(string[] args) { isActive = false; isProdScan = false; isBootHttpSrv = false; isASBoot = false; if (args.Length == 0) { Console.WriteLine("usage: Seikact < waitboot | prodscan | boothttp >"); } else { try { for (int i = 0; i < args.Length; i++) { switch (args[i]) { case "prodscan": isProdScan = true; break; case "boothttp": isBootHttpSrv = true; break; case "waitboot": isASBoot = true; break; default: Console.WriteLine("unknown {0}", args[i]); break; } } if ((isProdScan) || (isBootHttpSrv) || (isASBoot)) { isActive = true; } } catch (Exception e) { Console.WriteLine("err:{0}", e.Message); isActive = false; } } } } }
WCFクライアントコード
- WCFClient.cs
using System; using System.Collections.Generic; using System.IO; using System.Runtime.Serialization; using System.ServiceModel; using System.Threading; namespace Seikactl { public class WCFClient { NetNamedPipeBinding Binding = new NetNamedPipeBinding(); TimeSpan keeptime = new TimeSpan(24, 00, 00); string BaseAddr = "net.pipe://localhost/EchoSeika/CentralGate/ApiEntry"; public WCFClient() { } ~WCFClient() { } private ChannelFactory<IScAPIs> CreateChannelFactory() { var ans = new ChannelFactory<IScAPIs>(Binding, new EndpointAddress(BaseAddr)); while (ans.State != CommunicationState.Created) { Thread.Sleep(10); } return ans; } private IScAPIs CreateChannel(ChannelFactory<IScAPIs> ChannelSc) { var ans = ChannelSc.CreateChannel(); (ans as IContextChannel).OperationTimeout = keeptime; while (ChannelSc.State != CommunicationState.Opened) { Thread.Sleep(10); } return ans; } public string Version() { var cf = CreateChannelFactory(); var api = CreateChannel(cf); var ans = api.Version(); cf.Close(); return ans; } public void ProductScan() { var cf = CreateChannelFactory(); var api = CreateChannel(cf); api.ProductScan(); cf.Close(); } public void BootHttpService() { var cf = CreateChannelFactory(); var api = CreateChannel(cf); api.BootHttpService(); cf.Close(); } public Dictionary<int, string> AvatorList() { var cf = CreateChannelFactory(); var api = CreateChannel(cf); var ans = api.AvatorList(); cf.Close(); return ans; } public Dictionary<int, Dictionary<string, string>> AvatorList2() { var cf = CreateChannelFactory(); var api = CreateChannel(cf); var ans = api.AvatorList2(); cf.Close(); return ans; } public Dictionary<int, Dictionary<string, string>> AvatorListDetail2() { var cf = CreateChannelFactory(); var api = CreateChannel(cf); var list1 = api.AvatorListDetail2(); cf.Close(); var ans = new Dictionary<int, Dictionary<string, string>>(); foreach(var item1 in list1) { if (item1.Value["isalias"] == "False") { ans.Add(item1.Key, new Dictionary<string, string>()); foreach (var item2 in item1.Value) { ans[item1.Key].Add(item2.Key, item2.Value); } } } return ans; } public Dictionary<string, Dictionary<string, Dictionary<string, decimal>>> GetDefaultParams2(int cid) { var cf = CreateChannelFactory(); var api = CreateChannel(cf); var ans = api.GetDefaultParams2(cid); cf.Close(); return ans; } public Dictionary<string, Dictionary<string, Dictionary<string, decimal>>> GetCurrentParams2(int cid) { var cf = CreateChannelFactory(); var api = CreateChannel(cf); var ans = api.GetCurrentParams2(cid); cf.Close(); return ans; } public void ResetParams2(int cid) { var cf = CreateChannelFactory(); var api = CreateChannel(cf); api.ResetParams2(cid); cf.Close(); } public double Talk(int cid, string talktext, string filepath, Dictionary<string, decimal> effects, Dictionary<string, decimal> emotions) { var cf = CreateChannelFactory(); var api = CreateChannel(cf); var ans = api.Talk(cid, talktext, filepath == "" ? "" : MakeFullPath(filepath), effects, emotions); cf.Close(); return ans; } public double Talk2(int cid, string[] talktexts, string filepath, Dictionary<string, decimal> effects, Dictionary<string, decimal> emotions) { var cf = CreateChannelFactory(); var api = CreateChannel(cf); var ans = api.Talk2(cid, talktexts, filepath == "" ? "" : MakeFullPath(filepath), effects, emotions); cf.Close(); return ans; } public void TalkAsync(int cid, string talktext, Dictionary<string, decimal> effects, Dictionary<string, decimal> emotions) { var cf = CreateChannelFactory(); var api = CreateChannel(cf); api.TalkAsync(cid, talktext, effects, emotions); cf.Close(); } public void TalkAsync2(int cid, string[] talktexts, Dictionary<string, decimal> effects, Dictionary<string, decimal> emotions) { var cf = CreateChannelFactory(); var api = CreateChannel(cf); api.TalkAsync2(cid, talktexts, effects, emotions); cf.Close(); } private string MakeFullPath(string filepath) { return Path.GetFullPath(filepath); } } [ServiceContract(SessionMode = SessionMode.Required)] public interface IScAPIs { [OperationContract] string Version(); [OperationContract] void ProductScan(); [OperationContract] void BootHttpService(); [OperationContract] Dictionary<int, string> AvatorList(); [OperationContract] Dictionary<int, Dictionary<string, string>> AvatorList2(); [OperationContract] Dictionary<int, Dictionary<string, string>> AvatorListDetail2(); [OperationContract] Dictionary<string, Dictionary<string, Dictionary<string, decimal>>> GetDefaultParams2(int cid); [OperationContract] Dictionary<string, Dictionary<string, Dictionary<string, decimal>>> GetCurrentParams2(int cid); [OperationContract] void ResetParams2(int cid); [OperationContract] double Talk(int cid, string talktext, string filepath, Dictionary<string, decimal> effects, Dictionary<string, decimal> emotions); [OperationContract] double Talk2(int cid, string[] talktexts, string filepath, Dictionary<string, decimal> effects, Dictionary<string, decimal> emotions); [OperationContract] void TalkAsync(int cid, string talktext, Dictionary<string, decimal> effects, Dictionary<string, decimal> emotions); [OperationContract] void TalkAsync2(int cid, string[] talktexts, Dictionary<string, decimal> effects, Dictionary<string, decimal> emotions); [OperationContract] double Save(int cid, string talktext, string filepath, Dictionary<string, decimal> effects, Dictionary<string, decimal> emotions); } }
documents/tools/assistantseika/assistantseika-099.txt · 最終更新: 2023/04/28 21:34 by k896951