protected string initialize(string callId) { string ret = ""; try { string json; ret = ce.callId2json(callId, out json); ccs = jsonUtl.decodeJson <clsCallStatus>(json); if (ccs == null) { throw new Exception("fail to proceed with callId " + callId); } } catch (Exception ex) { Exception inner = ex; while (inner.InnerException != null) { inner = inner.InnerException; } ret = $"{ex.Message}\n{ex.StackTrace}"; } return(ret); }
/// <summary> /// the main loop /// </summary> /// <param name="CALL_PATH"></param> /// <returns></returns> public string theMainLoop(string CALL_PATH) { //const string CALL_PATH = @"C:\Users\maoch\Desktop\temp\git\planAndTest\planAndTest\exeMission\Data\calls\"; string ret = ""; dbg d = new dbg(); // check thread status, if stopped, move to done foreach (KeyValuePair <string, Thread> pair in callThreads) { Thread theThread = pair.Value; if (theThread.ThreadState == ThreadState.Stopped) { clsCallStatus ccb = null; if (!calls.TryGetValue(pair.Key, out ccb)) { throw new Exception( "cannot find ccb in collection"); } string retCallId; ret = ce.ReturnAcall(pair.Key, ccb.returnPara , out retCallId); if (ret.Length > 0) { return(ret); } // the way to get return json calls.Remove(pair.Key); callThreads.Remove(pair.Key); } } //keep looping,不斷去檢查calls目錄有沒有新目錄 //若有的話,spawn new thread去計算 //one service call done to call ReturnAcall List <string> allCallsUndone = null; bool hasMyself = true; while (hasMyself) // keep looping for { // find all calls undone allCallsUndone = ce.allCallsInprogress( cml.callId); // loop through the active running calls // to find a new call hasMyself = false; foreach (string callId in allCallsUndone) { if (callId == cml.callId) { hasMyself = true; continue; } else if (calls.ContainsKey(callId)) { continue; } // get service name, json by callId string json = ""; ret = ce.callId2json(callId, out json); if (ret.Length > 0) { return(ret); } clsCallStatus ccb = jsonUtl.decodeJson < clsCallStatus>(json); string serviceName = ccb.serviceName; // execute the new call Thread newCallThread = new Thread(() => thread1call(callId, serviceName, ref ccb)); newCallThread.Start(); calls.Add(callId, ccb); callThreads.Add(callId, newCallThread); } Thread.Sleep(50);//loop once sleep 50ms } return(ret); }