Exemple #1
0
        public string executeCall()
        {
            string ret        = "";
            string returnJson = "";

            try
            {
                dbg.o("executeCall 1");
                ret = invokeService.run(callId, ccs.systemName,
                                        ccs.serviceName, ccs.methodName,
                                        ccs.callPara, out returnJson);
                if (ret.Length > 0)
                {
                    throw new Exception(ret);
                }
                ccs.SetReturnTime();
                ccs.returnPara = returnJson;
                string retCallId;
                ret = ce.ReturnAcall(callId, returnJson, out retCallId);
                dbg.o($"executeCall ret={ret} returnJson={returnJson}" +
                      $" retCallId={retCallId}");
                // call done, remove call json file
                //add call done json file
            }
            catch (Exception ex)
            {
                Exception inner = ex;
                while (inner.InnerException != null)
                {
                    inner = inner.InnerException;
                }
                ret = $"{ex.Message}\n{ex.StackTrace}";
            }
            return(ret);
        }
Exemple #2
0
        /// <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);
        }