Beispiel #1
0
 protected NewPortCommand(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     _entityId = MathIdentifier.Parse(info.GetString("entityId"));
     _inputCnt = info.GetInt32("inputCount");
     _busCnt   = info.GetInt32("busCount");
 }
Beispiel #2
0
 public override void ReadXml(XmlReader reader)
 {
     reader.ReadStartElement("NewPortCommand", Context.YttriumNamespace);
     base.ReadXml(reader);
     _entityId = MathIdentifier.Parse(reader.ReadElementString("EntityId"));
     _inputCnt = int.Parse(reader.ReadElementString("InputCount"));
     _busCnt   = int.Parse(reader.ReadElementString("BusCount"));
     reader.ReadEndElement();
 }
        protected static AlgebraicStructureCategory InnerDeserialize(Context context, XmlReader reader)
        {
            EAlgebraicStructure structure = (EAlgebraicStructure)Enum.Parse(typeof(EAlgebraicStructure), reader.ReadElementString("Structure"));
            Entity ae = context.Library.LookupEntity(MathIdentifier.Parse(reader.ReadElementString("AdditiveEntity")));

            if (reader.IsStartElement("MultiplicativeEntity"))
            {
                Entity me = context.Library.LookupEntity(MathIdentifier.Parse(reader.ReadElementString("MultiplicativeEntity")));
                return(new AlgebraicStructureCategory(structure, ae, me));
            }
            return(new AlgebraicStructureCategory(structure, ae));
        }
Beispiel #4
0
        private static AlgebraicStructureCategory Deserialize(XmlReader reader, IDictionary <Guid, Signal> signals, IDictionary <Guid, Bus> buses)
        {
            EAlgebraicStructure structure = (EAlgebraicStructure)Enum.Parse(typeof(EAlgebraicStructure), reader.ReadElementString("Structure"));
            IEntity             ae        = Service <ILibrary> .Instance.LookupEntity(MathIdentifier.Parse(reader.ReadElementString("AdditiveEntity")));

            if (reader.IsStartElement("MultiplicativeEntity"))
            {
                IEntity me = Service <ILibrary> .Instance.LookupEntity(MathIdentifier.Parse(reader.ReadElementString("MultiplicativeEntity")));

                return(new AlgebraicStructureCategory(structure, ae, me));
            }
            return(new AlgebraicStructureCategory(structure, ae));
        }
 private MathIdentifier ScanEntityMathIdentifierOrLabel(bool defaultToWorkDomain)
 {
     if (tokenizer.LookaheadFistToken.IsType(TokenTypes.MathIdentifier)) //id
     {
         LexerToken token = tokenizer.MatchGet(TokenTypes.MathIdentifier);
         return(MathIdentifier.Parse(token.Text));
     }
     else //label
     {
         LexerToken token  = tokenizer.MatchGet(TokenTypes.TextIdentifier);
         string     domain = defaultToWorkDomain ? "Work" : library.FindEntityByLabel(token.Text).Domain;
         return(new MathIdentifier(token.Text, domain));
     }
 }
Beispiel #6
0
        internal void ImportBindings(IEnumerable <RawBinding> bindings)
        {
            Dictionary <string, object> factoryCache = new Dictionary <string, object>();

            foreach (RawBinding binding in bindings)
            {
                MathIdentifier id = MathIdentifier.Parse(binding.id);
                Type           contractType;
                try
                {
                    contractType = Type.GetType(binding.contractType, true);
                }
                catch (TypeLoadException e)
                {// usually a bad practice to repack exceptions,
                    // but since TypeLoadException isn't that helpful, this will help the users more:
                    throw new MicrokernelException(
                              string.Format(Config.UserCulture, Resources.BindingContractLoadFailed, binding.comment, binding.id, binding.contractType), e);
                }
                object factory;
                if (!factoryCache.TryGetValue(binding.factoryType, out factory))
                {
                    Type factoryType;
                    try
                    {
                        factoryType = Type.GetType(binding.factoryType, true);
                    }
                    catch (TypeLoadException e)
                    {
                        // usually a bad practice to repack exceptions,
                        // but since TypeLoadException isn't that helpful, this will help the users more:
                        throw new MicrokernelException(
                                  string.Format(Config.UserCulture, Resources.BindingFactoryLoadFailed, binding.comment, binding.id, binding.factoryType), e);
                    }
                    //if(factoryType == null)
                    //    continue;
                    ConstructorInfo ctor = factoryType.GetConstructor(new Type[] { });
                    if (ctor == null)
                    {
                        continue;
                    }
                    factory = ctor.Invoke(new object[] { });
                    factoryCache.Add(binding.factoryType, factory);
                }
                AddBinding(factory, contractType, id);
            }
        }
 private IEntity ScanEntity(LexerToken token, InfixNotation notation, int inputs)
 {
     if (token.IsType(TokenTypes.MathIdentifier))
     {
         return(library.LookupEntity(MathIdentifier.Parse(token.Text)));
     }
     else if (token.IsType(TokenTypes.Literal) || token.IsType(TokenTypes.SymbolIdentifier)) //symbol
     {
         return(library.LookupEntity(token.Text, notation, inputs));
     }
     else //textsymbol or label
     {
         IEntity entity;
         if (library.TryLookupEntity(token.Text, notation, inputs, out entity))
         {
             return(entity);
         }
         else
         {
             MathIdentifier id = library.FindEntityByLabel(token.Text);
             return(library.LookupEntity(id));
         }
     }
 }
 private Entity ScanEntity(LexerToken token, InfixNotation notation, int inputs)
 {
     if (token.IsType(TokenTypes.MathIdentifier))
     {
         return(context.Library.LookupEntity(MathIdentifier.Parse(token.Text)));
     }
     else if (token.IsType(TokenTypes.Literal) || token.IsType(TokenTypes.SymbolIdentifier)) //symbol
     {
         return(context.Library.LookupEntity(token.Text, notation, inputs));
     }
     else //textsymbol or label
     {
         Entity entity;
         if (context.Library.TryLookupEntity(token.Text, notation, inputs, out entity))
         {
             return(entity);
         }
         else
         {
             string domain = context.Library.Entities.FindDomainOfLabel(token.Text);
             return(context.Library.LookupEntity(new MathIdentifier(token.Text, domain)));
         }
     }
 }
        private MathIdentifier ScanMathIdentifier()
        {
            LexerToken token = tokenizer.MatchGet(TokenTypes.MathIdentifier);

            return(MathIdentifier.Parse(token.Text));
        }
Beispiel #10
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;
                }
            }
        }