Ejemplo n.º 1
0
 public async Task Initialize(string configPath, string ip, int port)
 {
     var config = TSST.Configuration.ROADMConfig.GetConfiguration(configPath);
     string roadmId = config.ID;
     networkInPorts = new List<InPort>();
     networkOutPorts = new List<OutPort>();
     clientInPorts = new List<InPort>();
     clientOutPorts = new List<OutPort>();
     for (int i = 0; i < config.NetInputPorts; i++)
     {
         var inPort = new InPort();
         await inPort.Initialize(ip, port, roadmId, i.ToString());
         inPort.DataReceived += InPort_NetworkDataReceived;
         networkInPorts.Add(inPort);
     }
     for (int i = config.NetInputPorts; i < config.NetInputPorts + config.ClientInputPorts; i++)
     {
         var inPort = new InPort();
         await inPort.Initialize(ip, port, roadmId, i.ToString());
         inPort.DataReceived += InPort_ClientDataReceived;
         clientInPorts.Add(inPort);
     }
     for (int i = 0; i < config.NetOutputPorts; i++)
     {
         var outPort = new OutPort();
         outPort.Initialize(ip, port, roadmId, i.ToString());
         networkOutPorts.Add(outPort);
     }
     for (int i = config.NetOutputPorts; i < config.NetOutputPorts + config.ClientOutputPorts; i++)
     {
         var outPort = new OutPort();
         outPort.Initialize(ip, port, roadmId, i.ToString());
         clientOutPorts.Add(outPort);
     }
 }
Ejemplo n.º 2
0
        private InPort Find(JInPort jInPort, Model sourceModel)
        {
            if (jInPort.Id is null)
            {
                throw logger.Error(new ModelException(sourceModel, "Property `id` not found."));
            }
            if (jInPort.InPortName is null)
            {
                throw logger.Error(new ModelException(sourceModel, "Property `in-port` not found."));
            }
            ModelSymbol modelSymbol = symbolTable.Lookup(jInPort.Id) as ModelSymbol;

            if (modelSymbol is null)
            {
                throw logger.Error(new LigralException($"Reference {jInPort.Id} not exist"));
            }
            Model  destinationModel = modelSymbol.GetValue() as Model;
            InPort inPort           = destinationModel.Expose(jInPort.InPortName) as InPort;

            if (inPort is null)
            {
                throw logger.Error(new LigralException($"{jInPort.InPortName} is not in port."));
            }
            return(inPort);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Evaluate script from a input reader
        /// </summary>
        /// <param name="input">the input source</param>
        /// <returns>the value of the last expression</returns>
        public EvaluationResult Evaluate(TextReader input)
        {
            InPort port = new InPort(input);
            object res  = null;

            while (true)
            {
                try
                {
                    var expr = Expand(Read(port), environment, macroTable, true);
                    if (Symbol.EOF.Equals(expr))
                    {
                        return(new EvaluationResult(null, res));
                    }
                    else
                    {
                        res = EvaluateExpression(expr, environment);
                    }
                }
                catch (Exception e)
                {
                    return(new EvaluationResult(e, null));
                }
            }
        }
Ejemplo n.º 4
0
        protected override void AfterConfigured()
        {
            base.AfterConfigured();
            Results[0].Clone(initial);
            InPort inPort = InPortList[0];

            inPort.InPortValueReceived += DerivativeUpdate;
        }
Ejemplo n.º 5
0
Archivo: Schemy.cs Proyecto: zer/schemy
        /// <summary>
        /// Reads an S-expression from the input source
        /// </summary>
        public static object Read(InPort port)
        {
            Func <object, object> readAhead = null;

            readAhead = token =>
            {
                Symbol quote;
                if (object.Equals(token, Symbol.EOF))
                {
                    throw new SyntaxError("unexpected EOF");
                }
                else if (token is string)
                {
                    string tokenStr = (string)token;
                    if (tokenStr == "(")
                    {
                        var L = new List <object>();
                        while (true)
                        {
                            token = port.NextToken();
                            if (token is string && (string)token == ")")
                            {
                                return(L);
                            }
                            else
                            {
                                L.Add(readAhead(token));
                            }
                        }
                    }
                    else if (tokenStr == ")")
                    {
                        throw new SyntaxError("unexpected )");
                    }
                    else if (Symbol.QuotesMap.TryGetValue(tokenStr, out quote))
                    {
                        object quoted = Read(port);
                        return(new List <object> {
                            quote, quoted
                        });
                    }
                    else
                    {
                        return(ParseAtom(tokenStr));
                    }
                }
                else
                {
                    throw new SyntaxError("unexpected token: " + token);
                }
            };

            var token1 = port.NextToken();

            return(Symbol.EOF.Equals(token1) ? Symbol.EOF : readAhead(token1));
        }
Ejemplo n.º 6
0
            public void Subscribe(ISubscriber <object> subscriber)
            {
                var sub = subscriber as TestSubscriber;

                if (sub != null)
                {
                    DownstreamModule = sub.Owner;
                    DownstreamPort   = sub.Port;
                    sub.OnSubscribe(this);
                }
            }
Ejemplo n.º 7
0
        /// <summary>
        /// Reads an S-expression from the input source
        /// </summary>
        public static object Read(InPort port)
        {
            Func <object, object> readAhead = null;

            readAhead = token =>
            {
                // Symbol quote;
                // if (object.Equals(token, Symbol.EOF))
                if (token is Symbol s && s.Equals(Symbol.EOF))
                {
                    throw new SyntaxError("unexpected EOF");
                }
Ejemplo n.º 8
0
        public void HandleRemoveData(InPort port)
        {
            if (port.Hidden)
            {
                return;
            }

            if (port.currentMessage != null)
            {
                port.currentMessage.gameObject.SetActive(false);
            }
        }
Ejemplo n.º 9
0
 public void Unload(IShip ship)
 {
     if (ship.Cargos.Count != 0)
     {
         Thread.Sleep(500);
         ship.Unload();
     }
     if (OnUnloading.Contains(ship))
     {
         OnUnloading.Remove(ship);
     }
     InPort.Add(ship);
 }
Ejemplo n.º 10
0
 public override InPort Expose(int inPortNO)
 {
     if (inPortNO == InPortCount())
     {
         InPort inPort = new InPort($"in{inPortNO}", this);
         InPortList.Add(inPort);
         return(inPort);
     }
     else
     {
         return(base.Expose(inPortNO));
     }
 }
Ejemplo n.º 11
0
 public override void Connect(int outPortNO, InPort inPort)
 {
     if (outPortNO == OutPortCount())
     {
         OutPort outPort = new OutPort($"out{outPortNO}", this);
         OutPortList.Add(outPort);
         outPort.Bind(inPort);
         Results.Add(new Signal(outPort));
     }
     else
     {
         base.Connect(outPortNO, inPort);
     }
 }
Ejemplo n.º 12
0
        public void PortConnection()
        {
            var inPort  = new InPort();
            var outPort = new OutPort();

            outPort.Connect(inPort);

            var rised = false;

            inPort.OnRecv += packet => rised = true;

            outPort.Transmitt(null);

            Assert.IsTrue(rised);
        }
Ejemplo n.º 13
0
        public void SelectVariableModeFor(PortInfo portInfo)
        {
            InPortsTitle.gameObject.SetActive(false);
            InPortsContainer.gameObject.SetActive(false);
            OutPortsTitle.gameObject.SetActive(false);
            OutPortsContainer.gameObject.SetActive(false);
            VariableSelectionTitle.gameObject.SetActive(true);
            VariableSelection.SetActive(true);

            foreach (Transform t in VariableSelection.transform)
            {
                Destroy(t.gameObject);
            }

            InPort Port = portInfo.Port as InPort;

            foreach (UnityGraphObject v in Port.Component.Graph.AssociatedInterlink.GetLinkedVariables())
            {
                // Type check
                bool found = false;
                for (int i = 0; i < Port.Types.Length; i++)
                {
                    if (Port.Types[i] == v.GetObjectType())
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    continue;
                }

                GameObject variableSelector = GameObject.Instantiate <GameObject>(VariableTemplate);
                variableSelector.transform.SetParent(VariableSelection.transform);
                variableSelector.GetComponentInChildren <Text>().text = v.GetObjectID() + " (" + v.GetObjectType() + ")";

                UnityGraphObject obj = v;
                variableSelector.GetComponent <Button>().onClick.AddListener(() => {
                    NormalMode();
                    Port.Component.Graph.SetDefaultValue(obj, Port);
                    portInfo.RefreshDefaultValueShown();
                });
            }

            LayoutRebuilder.ForceRebuildLayoutImmediate(VariableSelection.transform as RectTransform);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Position the label and two ports relative to the icon.
        /// </summary>
        /// <param name="childchanged"></param>
        /// <remarks>
        /// When <see cref="P:Northwoods.Go.GoObject.Initializing" /> is true, this method does nothing.
        /// This method also does nothing if there is no <see cref="P:Northwoods.Go.GoSimpleNode.Icon" />.
        /// </remarks>
        public override void LayoutChildren(GoObject childchanged)
        {
            if (base.Initializing)
            {
                return;
            }
            GoObject icon = Icon;

            if (icon == null)
            {
                return;
            }
            if (Orientation == Orientation.Horizontal)
            {
                if (Label != null)
                {
                    Label.SetSpotLocation(32, icon, 128);
                }
                if (InPort != null)
                {
                    InPort.SetSpotLocation(64, icon, 256);
                }
                if (OutPort != null)
                {
                    OutPort.SetSpotLocation(256, icon, 64);
                }
            }
            else
            {
                if (Label != null)
                {
                    Label.SetSpotLocation(256, icon, 64);
                }
                if (InPort != null)
                {
                    InPort.SetSpotLocation(128, icon, 32);
                }
                if (OutPort != null)
                {
                    OutPort.SetSpotLocation(32, icon, 128);
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Starts the Read-Eval-Print loop
        /// </summary>
        /// <param name="input">the input source</param>
        /// <param name="output">the output target</param>
        /// <param name="prompt">a string prompt to be printed before each evaluation</param>
        /// <param name="headers">a head text to be printed at the beginning of the REPL</param>
        public void REPL(TextReader input, TextWriter output, string prompt = null, string[] headers = null)
        {
            InPort port = new InPort(input);

            if (headers != null)
            {
                foreach (var line in headers)
                {
                    output.WriteLine(line);
                }
            }

            object res = null;

            while (true)
            {
                try
                {
                    if (!string.IsNullOrEmpty(prompt) && output != null)
                    {
                        output.Write(prompt);
                    }
                    var expr = Expand(Read(port), environment, macroTable, true);
                    if (Symbol.EOF.Equals(expr))
                    {
                        return;
                    }
                    else
                    {
                        res = EvaluateExpression(expr, environment);
                        if (output != null)
                        {
                            output.WriteLine(Utils.PrintExpr(res));
                        }
                    }
                }
                catch (Exception e)
                {
                    // Console.WriteLine(e.Message);
                    output.WriteLine(e.Message);
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Record a wiring between two copied ports, using (and reducing) the port mappings.
        /// </summary>
        /// <param name="outPort">TBD</param>
        /// <param name="inPort">TBD</param>
        /// <param name="indent">TBD</param>
        /// <exception cref="ArgumentException">TBD</exception>
        public void Wire(OutPort outPort, InPort inPort, int indent)
        {
            if (Fusing.IsDebug)
            {
                Fusing.Log(indent, $"wiring {outPort} ({Hash(outPort)}) -> {inPort} ({Hash(inPort)})");
            }
            var newOut = RemoveMapping(outPort, NewOutputs);

            if (!newOut.HasValue)
            {
                throw new ArgumentException($"wiring {outPort} -> {inPort}", nameof(outPort));
            }
            var newIn = RemoveMapping(inPort, NewInputs);

            if (!newIn.HasValue)
            {
                throw new ArgumentException($"wiring {outPort} -> {inPort}", nameof(inPort));
            }
            Downstreams.Add(newOut.Value, newIn.Value);
            Upstreams.Add(newIn.Value, newOut.Value);
        }
Ejemplo n.º 17
0
        public void UnsubscribeFromEvent(string eventName, InPort InPort)
        {
            List <InPort> list;

            if (!SubscribersByEventName.TryGetValue(eventName, out list))
            {
                list = new List <InPort>();
                SubscribersByEventName.Add(eventName, list);
            }

            if (!list.Contains(InPort))
            {
                throw new Exception("Port is not registered for event: " + eventName);
            }

            list.Remove(InPort);

            if (SubscribedComponents.Contains(InPort.Component))
            {
                SubscribedComponents.Remove(InPort.Component);
            }
        }
Ejemplo n.º 18
0
        public void SubscribeToEvent(string eventName, InPort InPort)
        {
            List <InPort> list;

            if (!SubscribersByEventName.TryGetValue(eventName, out list))
            {
                list = new List <InPort>();
                SubscribersByEventName.Add(eventName, list);
            }

            if (list.Contains(InPort))
            {
                throw new Exception("Port is already registered for event: " + eventName);
            }

            list.Add(InPort);

            if (!SubscribedComponents.Contains(InPort.Component)) // TODO take advantage of list indexing. Add the corresponding component at the same index as the port in it's own list
            {
                SubscribedComponents.Add(InPort.Component);
            }
        }
Ejemplo n.º 19
0
        public byte ReadPort(InPort inPort, DataPointerType pointerType)
        {
            if (deviceComPort_ == null || !deviceComPort_.IsOpen)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Внешнее устройство не подключено",
                    "Ошибка!",
                    System.Windows.Forms.MessageBoxButtons.OK,
                    System.Windows.Forms.MessageBoxIcon.Error);

                return(0);
            }

            byte[] req_buf   = new byte[CMD_REQUEST_PORT_READ_LENGTH];
            byte[] data_buf  = { (byte)inPort };
            byte   data_size = (byte)data_buf.Length;
            object res;

            PrepareRequestBuf(ref req_buf, CMD_REQUEST_PORT_READ_LENGTH, data_buf, data_size, CMD_PORT_READ);
            CmdSendRecv(ref deviceComPort_, req_buf, out res);

            if (res == null)
            {
                throw new ArgumentNullException("received value is null");
            }

            byte[] buf  = (byte[])res;
            var    port = buf[0] & CMD_DATA_LEN_MASK;

            if (port != (byte)inPort)
            {
                throw new ArgumentException("response port is invalid");
            }

            byte val = buf[1];

            return(val);
        }
Ejemplo n.º 20
0
        public void Setup(InPort Port, NodeInfoDialog NodeInfoDialog)
        {
            this.Port     = Port;
            PortName.text = Port.Name;
            PortType.text = Port.TypesToString();

            PortNameButton.onClick.AddListener(() => NodeInfoDialog.SelectDetailsModeFor(this));

            bool contentHasChanged = false;

            DefaultValueInput.gameObject.AddComponent <UIEventRedirector>().Setup(() => {
                if (UpdateDV())
                {
                    DefaultValueInput.text = DataTreatment.GetDataEditable(dv.Data);
                }
                contentHasChanged = false;
            }, null);

            DefaultValueInput.onEndEdit.AddListener((s) => {
                if (contentHasChanged)
                {
                    //if (s == "") {
                    // TODO Delete default value
                    //    Port.Component.Graph.RemoveDefaultValue(Port);
                    //    Debug.Log("removing dv from port: " + Port.Name);
                    //} else {
                    // TODO Check data types, if string, ok.
                    // If number, try to parse.

                    if (UpdateDV())
                    {
                        dv.SetData(s);
                        RefreshDefaultValueShown();
                    }
                    else
                    {
                        Port.Component.Graph.AddDefaultValue(s, Port);
                        RefreshDefaultValueShown();
                    }
                    //}
                }
                else
                {
                    RefreshDefaultValueShown();
                }
            });

            DefaultValueInput.onValueChanged.AddListener((s) => {
                contentHasChanged = true;
            });

            SelectVariable.onClick.AddListener(() => {
                NodeInfoDialog.SelectVariableModeFor(this);
            });

            ClearVariable.onClick.AddListener(() => {
                Port.Component.Graph.RemoveDefaultValue(Port);
                RefreshDefaultValueShown();
            });

            RefreshDefaultValueShown();
        }
Ejemplo n.º 21
0
 public TestSubscriber(IModule owner, InPort port)
 {
     Owner = owner;
     Port  = port;
 }