private void ActionComplete()

in SmvLibrary/MasterSMVActionScheduler.cs [111:191]


        private void ActionComplete(SMVAction a, IEnumerable<SMVActionResult> results, object context)
        {
            Log.LogDebug("Reached ActionComplete of Master " + a.GetFullName());

            var entry = context as ActionsQueueEntry;
            SMVAction action = entry.Action;
            SMVActionCompleteCallBack callback = entry.Callback;
            try
            {
                if (action.result == null)
                {
                    action.result = new SMVActionResult(action.name, "NO OUTPUT?", false, false, 0);
                    Utility.scheduler.errorsEncountered = true;
                }

                entry.Results.AddRange(results);
                counters.AddOrUpdate("completed", 1, (k, v) => v + 1);
                times.Add(action.result.time);

                File.WriteAllText(Path.Combine(Utility.GetActionDirectory(action), "smvstats.txt"),
                    string.Format("Time: {0}", action.result.time));                

                // Add result to our global result set.
                string result = "Failed";
                if (action.result != null && action.result.isSuccessful)
                {
                    result = "Success";
                }

                // Otherwise, add the next action to the queue, if any.

lock (Utility.lockObject)
                {
                    Utility.result[action.GetFullName()] = result;
                }

                // If there was an error, simply call the callback function with whatever results we have, the callback is
                // expected to handle the errors by looking at the list of results.
                if (action.result == null || action.result.breakExecution)
                {
                    entry.Callback(action, entry.Results, entry.Context);
                }
                // Otherwise, add the next action to the queue, if any.
                else
                {
                    SMVAction nextAction = Utility.GetNextAction(action);
                    if (nextAction != null)
                    {
                        nextAction.analysisProperty = action.analysisProperty;

                        DebugUtility.DumpVariables(entry.Action.variables, "entry.action");
                        DebugUtility.DumpVariables(Utility.smvVars, "smvvars");
                        nextAction.variables = Utility.smvVars.Union(entry.Action.variables).ToDictionary(g => g.Key, g => g.Value);
                        this.AddAction(nextAction, entry.Callback, entry.Context);
                    }
                    else
                    {
                        entry.Callback(action, entry.Results, entry.Context);
                    }
                }
            }
            catch (Exception e)
            {
                Log.LogError("Error processing finalization for action " + action.GetFullName() + "\n" + e);

                action.result.output = e.ToString();
                entry.Callback(action, entry.Results, entry.Context);
            }

            // upate status line
            if (updateStatusMode)
            {
                string resultString = string.Format("\r[INFO] {0} of {1} jobs remaining. Avg(s): {2}. Std.Dev(s): {3}",
                        counters["queued"] - counters["completed"], counters["queued"],
                        times.Average().ToString("F2"),
                        Math.Sqrt(times.Average(v => Math.Pow(v - times.Average(), 2))).ToString("F2"));
                Console.Write(resultString);
                if (counters["queued"] == counters["completed"])
                    Console.WriteLine();
            }
        }