Ejemplo n.º 1
0
        internal void AcceptSystemBuilder(ISystemBuilder builder)
        {
            Dictionary <Guid, Guid> signalMappings = new Dictionary <Guid, Guid>();
            Dictionary <Guid, Guid> busMappings    = new Dictionary <Guid, Guid>();

            builder.BeginBuildSystem(_inputs.Count, _outputs.Count, _allBuses.Count);

            // Before
            foreach (Signal s in _allSignals)
            {
                signalMappings.Add(s.InstanceId, s.AcceptSystemBuilderBefore(builder));
            }
            foreach (Bus b in _allBuses)
            {
                busMappings.Add(b.InstanceId, b.AcceptSystemBuilderBefore(builder));
            }
            foreach (Port p in _allPorts)
            {
                p.AcceptSystemBuilder(builder, signalMappings, busMappings);
            }

            // After
            foreach (Signal s in _allSignals)
            {
                s.AcceptSystemBuilderAfter(builder, signalMappings, busMappings);
            }

            // System Interface
            foreach (Signal si in _inputs)
            {
                builder.AppendSystemInputSignal(signalMappings[si.InstanceId]);
            }
            foreach (Signal so in _outputs)
            {
                builder.AppendSystemOutputSignal(signalMappings[so.InstanceId]);
            }

            // Named Signals
            if (_namedBuses != null)
            {
                foreach (KeyValuePair <string, Signal> ns in _namedSignals)
                {
                    builder.AppendSystemNamedSignal(signalMappings[ns.Value.InstanceId], ns.Key);
                }
            }
            if (_namedBuses != null)
            {
                foreach (KeyValuePair <string, Bus> nb in _namedBuses)
                {
                    builder.AppendSystemNamedBus(busMappings[nb.Value.InstanceId], nb.Key);
                }
            }

            builder.EndBuildSystem();
        }
Ejemplo n.º 2
0
        public void ReadSystems(XmlReader reader, bool multiple)
        {
            _reader     = reader;
            _fsm.Reader = reader;
            _fsm.Reset();

            Dictionary <Guid, Guid> signalMappings = new Dictionary <Guid, Guid>();
            Dictionary <Guid, Guid> busMappings    = new Dictionary <Guid, Guid>();

            bool active = false;

            BuilderState state;

            while (BuilderState.Idle != (state = _fsm.ReadNextState()) || active)
            {
                switch (state)
                {
                case BuilderState.System:
                    int inputCnt  = int.Parse(_reader.GetAttribute("inputCount"), Context.NumberFormat);
                    int outputCnt = int.Parse(_reader.GetAttribute("outputCount"), Context.NumberFormat);
                    int busCnt    = int.Parse(_reader.GetAttribute("busCount"), Context.NumberFormat);
                    _reader.Read();
                    _builder.BeginBuildSystem(inputCnt, outputCnt, busCnt);
                    active = true;
                    break;

                case BuilderState.Signals:
                    _reader.Read();
                    while (ReadToElement() && _reader.LocalName == "Signal")
                    {
                        Guid   myGuid   = new Guid(_reader.GetAttribute("iid"));
                        string label    = _reader.GetAttribute("label");
                        bool   hold     = bool.Parse(_reader.GetAttribute("hold"));
                        bool   isSource = bool.Parse(_reader.GetAttribute("isSource"));
                        _reader.Read();
                        Guid tGuid = _builder.BuildSignal(label, hold, isSource);
                        signalMappings.Add(myGuid, tGuid);
                    }
                    break;

                case BuilderState.Buses:
                    _reader.Read();
                    while (ReadToElement() && _reader.LocalName == "Bus")
                    {
                        Guid   myGuid = new Guid(_reader.GetAttribute("iid"));
                        string label  = _reader.GetAttribute("label");
                        _reader.Read();
                        Guid tGuid = _builder.BuildBus(label);
                        busMappings.Add(myGuid, tGuid);
                    }
                    break;

                case BuilderState.Ports:
                    _reader.Read();
                    while (ReadToElement() && _reader.LocalName == "Port")
                    {
                        InstanceIdSet inputSignals  = new InstanceIdSet();
                        InstanceIdSet outputSignals = new InstanceIdSet();
                        InstanceIdSet buses         = new InstanceIdSet();
                        //Guid myGuid = new Guid(_reader.GetAttribute("iid"));
                        MathIdentifier entityId = MathIdentifier.Parse(_reader.GetAttribute("entityId"));
                        _reader.ReadToDescendant("InputSignals");
                        _reader.Read();
                        while (_reader.IsStartElement("SignalRef"))
                        {
                            inputSignals.Add(signalMappings[new Guid(_reader.ReadElementString())]);
                        }
                        _reader.ReadEndElement();
                        _reader.ReadToFollowing("OutputSignals");
                        _reader.Read();
                        while (_reader.IsStartElement("SignalRef"))
                        {
                            outputSignals.Add(signalMappings[new Guid(_reader.ReadElementString())]);
                        }
                        _reader.ReadEndElement();
                        _reader.ReadToFollowing("Buses");
                        _reader.Read();
                        while (_reader.IsStartElement("BusRef"))
                        {
                            buses.Add(busMappings[new Guid(_reader.ReadElementString())]);
                        }
                        _reader.ReadEndElement();
                        _builder.BuildPort(entityId, inputSignals, outputSignals, buses);
                    }
                    break;

                case BuilderState.SignalDetails:
                    _reader.Read();
                    while (ReadToElement())
                    {
                        Guid tGuid = signalMappings[new Guid(_reader.GetAttribute("iid"))];
                        switch (_reader.LocalName)
                        {
                        case "SignalValue":
                        {
                            StructurePack pack = StructurePack.Repack(_reader.ReadInnerXml(), signalMappings, busMappings);
                            _builder.AppendSignalValue(tGuid, pack);
                        }
                        break;

                        case "SignalProperty":
                        {
                            PropertyPack pack = PropertyPack.Repack(_reader.ReadInnerXml(), signalMappings, busMappings);
                            _builder.AppendSignalProperty(tGuid, pack);
                        }
                        break;

                        case "SignalConstraint":
                        {
                            PropertyPack pack = PropertyPack.Repack(_reader.ReadInnerXml(), signalMappings, busMappings);
                            _builder.AppendSignalConstraint(tGuid, pack);
                        }
                        break;
                        }
                    }
                    break;

                case BuilderState.InputSignals:
                    _reader.Read();
                    while (ReadToElement() && _reader.LocalName == "SignalRef")
                    {
                        Guid tGuid = signalMappings[new Guid(_reader.ReadElementString())];
                        _builder.AppendSystemInputSignal(tGuid);
                    }
                    break;

                case BuilderState.OutputSignals:
                    _reader.Read();
                    while (ReadToElement() && _reader.LocalName == "SignalRef")
                    {
                        Guid tGuid = signalMappings[new Guid(_reader.ReadElementString())];
                        _builder.AppendSystemOutputSignal(tGuid);
                    }
                    break;

                case BuilderState.NamedSignals:
                    _reader.Read();
                    while (ReadToElement() && _reader.LocalName == "SignalRef")
                    {
                        string name  = _reader.GetAttribute("name");
                        Guid   tGuid = signalMappings[new Guid(_reader.ReadElementString())];
                        _builder.AppendSystemNamedSignal(tGuid, name);
                    }
                    break;

                case BuilderState.NamedBuses:
                    _reader.Read();
                    while (ReadToElement() && _reader.LocalName == "BusRef")
                    {
                        string name  = _reader.GetAttribute("name");
                        Guid   tGuid = busMappings[new Guid(_reader.ReadElementString())];
                        _builder.AppendSystemNamedBus(tGuid, name);
                    }
                    break;

                case BuilderState.Idle:
                    _builder.EndBuildSystem();
                    active = false;
                    if (!multiple)
                    {
                        return;
                    }
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public void AcceptSystemBuilder(ISystemBuilder builder)
        {
            Dictionary<Guid, Guid> signalMappings = new Dictionary<Guid, Guid>();
            Dictionary<Guid, Guid> busMappings = new Dictionary<Guid, Guid>();

            builder.BeginBuildSystem(_inputs.Count, _outputs.Count, _allBuses.Count);

            // Before
            foreach(Signal s in _allSignals)
                signalMappings.Add(s.InstanceId, ((ISignal_BuilderAdapter)s).AcceptSystemBuilderBefore(builder));
            foreach(Bus b in _allBuses)
                busMappings.Add(b.InstanceId, ((IBus_BuilderAdapter)b).AcceptSystemBuilderBefore(builder));
            foreach(Port p in _allPorts)
                ((IPort_BuilderAdapter)p).AcceptSystemBuilder(builder, signalMappings, busMappings);

            // After
            foreach(Signal s in _allSignals)
                ((ISignal_BuilderAdapter)s).AcceptSystemBuilderAfter(builder, signalMappings, busMappings);

            // System Interface
            foreach(Signal si in _inputs)
                builder.AppendSystemInputSignal(signalMappings[si.InstanceId]);
            foreach(Signal so in _outputs)
                builder.AppendSystemOutputSignal(signalMappings[so.InstanceId]);

            // Named Signals
            if(_namedBuses != null)
                foreach(KeyValuePair<string, Signal> ns in _namedSignals)
                    builder.AppendSystemNamedSignal(signalMappings[ns.Value.InstanceId], ns.Key);
            if(_namedBuses != null)
                foreach(KeyValuePair<string, Bus> nb in _namedBuses)
                    builder.AppendSystemNamedBus(busMappings[nb.Value.InstanceId], nb.Key);

            builder.EndBuildSystem();
        }