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); }
private string SaveAcall(string callId , clsCallStatus callObj) { string ret = ""; string callDir = fileUtl.pb(CALL_PATH, callId); string callFile = fileUtl.pb(callDir, $"{genCallId()}.json"); string json = jsonUtl.encodeJson(callObj); ret = fileUtl.string2file(callFile, json); return(ret); }
private string ReadAcall(string callId , out clsCallStatus callObj) { string ret = ""; string callDir = fileUtl.pb(CALL_PATH, callId); string callFile = fileUtl.newestFile(callDir); string json = fileUtl.file2string(fileUtl.pb( callDir, callFile)); callObj = jsonUtl.decodeJson <clsCallStatus>(json); return(ret); }
public string callId2callBase(string callId , out clsCallStatus ccb) { string ret = "", json = ""; ret = callId2json(callId, out json); ccb = null; if (ret.Length > 0) { return(ret); } ccb = jsonUtl.decodeJson <clsCallStatus>(json); return(ret); }
public string persistentCall(string systemName, string serviceName, string methodName, string paraType , string paraJson, string returnType, out string callId , out string returnJson) { // persistentCall //1. call status objct //2. run exe string ret = ""; returnJson = ""; callId = callExe.genCallId(); try { clsCallStatus ccs = new clsCallStatus(callId); ccs.systemName = systemName; ccs.callId = callId; ccs.serviceName = serviceName; ccs.methodName = methodName; ccs.callTypeName = paraType; ccs.callTime = DateTime.Now; ccs.callPara = paraJson; ccs.returnTypeName = returnType; //ccs.callFilepath = "..."; // todo !!... string json = jsonUtl.encodeJson(ccs); ret = ce.MakeAcall(callId, json); if (ret.Length > 0) { throw new Exception(ret); } dbg.o("before spawn exe"); // change to use hangire... string callIdOut = callId; BackgroundJob.Enqueue(() => ce.spawnEXE(callIdOut, serviceName) ); dbg.o("after spawn exe"); } catch (Exception ex) { Exception inner = ex; while (inner.InnerException != null) { inner = inner.InnerException; } ret = ex.Message + "\n" + ex.StackTrace; } return(ret); }
/// <summary> /// thread activate content /// </summary> /// <param name="callId"></param> /// <param name="serviceName"></param> /// <returns></returns> private static string thread1call(string callId , string serviceName, ref clsCallStatus ccb)// string callJson) { string retJson = ""; string callJson = jsonUtl.encodeJson(ccb); retJson = invokeService.run(callId, "", serviceName, "", callJson, out retJson); ccb.returnPara = retJson; ccb.returnTime = DateTime.Now; // when done, use callId, notify caller //to move to done dir, with returnJson return(retJson); }
/// <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); }