Esempio n. 1
0
        /// <summary>
        /// Internal carrier creation.  This includes the "stopRecursion" flag to prevent wildcard receptors from receiving ad-infinitum their own emissions.
        /// </summary>
        protected ICarrier CreateCarrier(IReceptorInstance from, ISemanticTypeStruct protocol, dynamic signal, bool stopRecursion)
        {
            Carrier carrier = new Carrier(protocol, signal);

            NewCarrier.Fire(this, new NewCarrierEventArgs(from, carrier));

            // We pass along the stopRecursion flag to prevent wild-card carrier receptor from receiving their own emissions, which would result in a new carrier,
            // ad-infinitum.
            ProcessReceptors(from, carrier, stopRecursion);

            // Recurse into SE's of the protocol and emit carriers for those as well, if a receiver exists.
            CreateCarriersForSemanticElements(from, protocol, signal, stopRecursion);

            return(carrier);
        }
Esempio n. 2
0
        /// <summary>
        /// Return an action representing what to do for a new carrier/protocol.
        /// </summary>
        protected Action GetProcessAction(IReceptorInstance from, Carrier carrier, bool stopRecursion)
        {
            // Construct an action...
            Action action = new Action(() =>
            {
                // Get the receptors receiving the protocol.
                List <IReceptorConnection> receptors = GetTargetReceptorsFor(ReceptorFromInstance(from), carrier);

                // For each receptor that is enabled...
                receptors.ForEach(receptor =>
                {
                    // The action is "ProcessCarrier".
                    // TODO: *** Pass in the carrier, not the carrier's fields!!! ***
                    // ************* A: MOVED HERE ************
                    NewCarrier.Fire(this, new NewCarrierEventArgs(from, carrier));
                    Action process = new Action(() => receptor.Receptor.Instance.ProcessCarrier(carrier));

                    // TODO: This flag is tied in with the visualizer, we should extricate this flag and logic.
                    if (receptor.Receptor.Instance.IsHidden)
                    {
                        // Don't visualize carriers to hidden receptors.
                        process();
                    }
                    else if (!stopRecursion)
                    {
                        // TODO: This should be handled externally somehow.
                        // Defer the action, such that the visualizer can invoke it when it determines the carrier rendering to the receiving receptor has completed.
                        ISemanticTypeStruct protocol = SemanticTypeSystem.GetSemanticTypeStruct("CarrierAnimation");
                        dynamic signal = SemanticTypeSystem.Create("CarrierAnimation");
                        signal.Process = process;
                        signal.From    = from;
                        signal.To      = receptor.Receptor.Instance;
                        signal.Carrier = carrier;
                        // Simulate coming from the system, as it IS a system message.
                        // Also note that the "stop recursion" flag is set to true on a receptor defining "receives everything" ("*").
                        CreateCarrier(from, protocol, protocol.DeclTypeName, signal, receptor.Receptor.Instance.GetEnabledReceiveProtocols().Select(rp => rp.Protocol).Contains("*"), true);
                    }
                });
            });

            return(action);
        }
Esempio n. 3
0
 protected void OnNewCarrier(object sender, NewCarrierEventArgs args)
 {
     // Forward to other listeners.
     NewCarrier.Fire(this, args);
 }