Exemplo n.º 1
0
        /// <summary>
        /// Continues a distributed call flow on this LOGICAL thread (asynchronous call chain) from the supplied state (JsonDataMap).
        /// If the current logical thread is already set with distributed flow then throws exception.
        /// Otherwise, sets the existing code flow step as the first step of the distributed one
        /// </summary>
        public static DistributedCallFlow Continue(IApplication app, JsonDataMap existing, Guid?guid = null, string directorName = null, string callerAgent = null, string callerPort = null)
        {
            app.NonNull(nameof(app));
            existing.IsTrue(v => v != null && v.Count > 0, nameof(existing));

            var current = ExecutionContext.CallFlow;

            var result = current as DistributedCallFlow;

            if (result == null)
            {
                result = new DistributedCallFlow();

                result.ReadAsJson(existing, false, null);

                if (current == null)
                {
                    callerAgent = callerAgent.Default(System.Reflection.Assembly.GetCallingAssembly().GetName().Name);
                    callerPort  = callerPort.Default(System.Reflection.Assembly.GetEntryAssembly()?.GetName().Name);
                    current     = new CodeCallFlow(guid ?? Guid.NewGuid(), directorName, callerAgent, callerPort);
                }
                result.m_List.Add(new Step(app, ExecutionContext.Session, current));
                ExecutionContext.__SetThreadLevelCallContext(result);
            }
            else
            {
                throw new AzosException("Distributed flow error: The context is already injected with DistributedCallFlow");
            }

            return(result);
        }