Inheritance: Generated.NameSpace, Utils.ISubDeclarator, Utils.IFinder
コード例 #1
0
            public override void visit(NameSpace obj, bool visitSubNodes)
            {
                Types.NameSpace nameSpace = (Types.NameSpace)obj;

                if (nameSpace.allNameSpaceRefs() != null)
                {
                    foreach (NameSpaceRef nameSpaceRef in nameSpace.allNameSpaceRefs())
                    {
                        Types.NameSpace subNameSpace = nameSpaceRef.LoadNameSpace(LockFiles, AllowErrorsDuringLoad);
                        if (subNameSpace != null)
                        {
                            nameSpace.appendNameSpaces(subNameSpace);
                            subNameSpace.NameSpaceRef = nameSpaceRef;
                        }
                        else
                        {
                            ErrorsDuringLoad.Add(new ElementLog(ElementLog.LevelEnum.Error,
                                                                "Cannot load file " + nameSpaceRef.FileName));
                        }
                    }
                    nameSpace.allNameSpaceRefs().Clear();
                }

                base.visit(obj, visitSubNodes);
            }
コード例 #2
0
        /// <summary>
        ///     Either provides the requested namespace or creates it if it cannot be found
        ///     This method can create many levels of nested namespaces
        /// </summary>
        /// <param name="levels">The name of the namespace, with the levels separated into separate Strings</param>
        /// <param name="initialDictionary">The dictionary the namespace structure is being copied form</param>
        /// <returns></returns>
        public Types.NameSpace GetNameSpaceUpdate(String[] levels, Dictionary initialDictionary)
        {
            Types.NameSpace retVal = null;

            if (levels.Length > 0)
            {
                retVal = FindNameSpace(levels[0]);
                Types.NameSpace initialNameSpace = initialDictionary.FindNameSpace(levels[0]);

                if (retVal == null)
                {
                    retVal = (Types.NameSpace)acceptor.getFactory().createNameSpace();
                    retVal.setName(levels[0]);
                    appendNameSpaces(retVal);

                    // set the updates link for the new namespace
                    retVal.setUpdates(initialNameSpace.Guid);
                }

                for (int index = 1; index < levels.Length; index++)
                {
                    initialNameSpace = initialNameSpace.findNameSpaceByName((levels[index]));
                    retVal           = retVal.FindOrCreateNameSpaceUpdate(levels[index], initialNameSpace);
                }
            }

            return(retVal);
        }
コード例 #3
0
        public void TestRefactorStructureName()
        {
            Dictionary test       = CreateDictionary("Test");
            NameSpace  n1         = CreateNameSpace(test, "N1");
            Collection collection = CreateCollection(n1, "Col", "Integer", 10);
            Variable   v          = CreateVariable(n1, "V", "Col");

            v.setDefaultValue("[]");
            RuleCondition rc1 = CreateRuleAndCondition(n1, "Rule1");
            Action        a1  = CreateAction(rc1, "INSERT 1 IN V");
            RuleCondition rc2 = CreateRuleAndCondition(n1, "Rule2");
            Action        a2  = CreateAction(rc2, "INSERT 2 IN V");

            // ReSharper disable once UseObjectOrCollectionInitializer
            Runner runner = new Runner(false);

            runner.CheckForCompatibleChanges = true;
            runner.Cycle();

            ListValue listValue = v.Value as ListValue;

            Assert.IsNotNull(listValue);
            Assert.AreEqual(2, listValue.Val.Count);
            Assert.AreEqual(0, a1.Messages.Count);
            Assert.AreEqual(0, a2.Messages.Count);
        }
コード例 #4
0
        private static string format_euroloop_message(DBMessage message)
        {
            EfsSystem system = EfsSystem.Instance;

            NameSpace      nameSpace     = findNameSpace("Messages.EUROLOOP");
            Structure      structureType = (Structure)system.FindType(nameSpace, "Message");
            StructureValue structure     = new StructureValue(structureType);

            int currentIndex = 0;

            FillStructure(nameSpace, message.Fields, ref currentIndex, structure);


            // then we fill the packets
            IVariable subSequenceVariable;

            if (structure.SubVariables.TryGetValue("Sequence1", out subSequenceVariable))
            {
                subSequenceVariable.Value = get_message_packets(message, nameSpace, system);
            }
            else
            {
                throw new Exception("Cannot find SubSequence in variable");
            }

            return(structure.Name);
        }
コード例 #5
0
            public override void visit(NameSpace obj, bool visitSubNodes)
            {
                base.visit(obj, visitSubNodes);

                Types.NameSpace nameSpace = (Types.NameSpace)obj;

                if (_beforeSave)
                {
                    nameSpace.ClearTempFiles();
                    nameSpace.allNameSpaceRefs().Clear();

                    if (nameSpace.allNameSpaces() != null)
                    {
                        foreach (Types.NameSpace subNameSpace in nameSpace.allNameSpaces())
                        {
                            nameSpace.appendNameSpaceRefs(referenceNameSpace(nameSpace, subNameSpace));
                        }
                    }
                    nameSpace.StoreInfo();
                }
                else
                {
                    nameSpace.RestoreInfo();
                }
            }
コード例 #6
0
        public void TestSubRulesPriority()
        {
            Dictionary test = CreateDictionary("Test");
            NameSpace  n1   = CreateNameSpace(test, "N1");
            Variable   v1   = CreateVariable(n1, "V", "Integer");

            v1.setDefaultValue("0");
            Variable v2 = CreateVariable(n1, "V2", "Integer");

            v2.setDefaultValue("0");
            // Priority is Processing
            RuleCondition rc1 = CreateRuleAndCondition(n1, "Rule1");
            Action        a1  = CreateAction(rc1, "V2 <- V2 + 1");
            // Priority is Update out
            RuleCondition rc2 = CreateRuleAndCondition(rc1, "Rule2");

            rc2.EnclosingRule.setPriority(acceptor.RulePriority.aUpdateOUT);
            Action a2 = CreateAction(rc2, "V <- V + 1");

            // ReSharper disable once UseObjectOrCollectionInitializer
            Runner runner = new Runner(false);

            runner.Cycle();

            IntValue value = v1.Value as IntValue;

            Assert.IsNotNull(value);
            Assert.AreEqual(1, value.Val);

            value = v2.Value as IntValue;
            Assert.IsNotNull(value);
            Assert.AreEqual(1, value.Val);
        }
コード例 #7
0
        public override NameSpace createNameSpace()
        {
            NameSpace retVal = new Types.NameSpace();

            _defaultValueSetter.SetDefaultValue(retVal);

            return(retVal);
        }
コード例 #8
0
        /// <summary>
        /// Saves the namespace provided associated to this namespace ref
        /// </summary>
        /// <param name="nameSpace"></param>
        public void SaveNameSpace(NameSpace nameSpace)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(FileName));

            VersionedWriter writer = new VersionedWriter(FileName);
            nameSpace.unParse(writer, false);
            writer.Close();
        }
コード例 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="model"></param>
 /// <param name="index"></param>
 public SelectionButton(NameSpace model, int index)
 {
     Model = model;
     Index = index;
     Image = NameSpaceImages.Instance.Images.Images[index-1];
     Click += OnClick;
     Size = new Size(32, 32);
 }
コード例 #10
0
            GetStandardValues(ITypeDescriptorContext context)
            {
                ItemEditor editor = (ItemEditor)context.Instance;

                DataDictionary.Types.NameSpace nameSpace = editor.Item.NameSpace;
                DataDictionary.Types.Type      type      = editor.Item.Type;

                return(GetValues(nameSpace, type));
            }
コード例 #11
0
        public void CreateNamespaceSection(FunctionalAnalysisReport report, NameSpace nameSpace,
            List<AccessMode> accesses)
        {
            Log.Info("..generating name space " + nameSpace.Name);

            report.CreateNameSpaceSection(nameSpace, accesses);
            foreach (NameSpace subNameSpace in nameSpace.NameSpaces)
            {
                CreateNamespaceSection(report, subNameSpace, accesses);
            }
        }
コード例 #12
0
        /// <summary>
        ///     Refactors a single element
        /// </summary>
        /// <param name="element"></param>
        /// <param name="originalName">The original element's name</param>
        /// <param name="newName">The new element's name</param>
        private void RefactorElement(ModelElement element, string originalName, string newName)
        {
            if (element != null)
            {
                NameSpace nameSpace = element as NameSpace;
                if (nameSpace != null)
                {
                    NameSpaceRefactorer refactorer = new NameSpaceRefactorer(nameSpace);
                    foreach (Dictionary dictionary in EfsSystem.Instance.Dictionaries)
                    {
                        refactorer.visit(dictionary);
                    }
                }
                else
                {
                    // the system keeps track where the element is used
                    List <Usage>      usageList = EfsSystem.Instance.FindReferences(element);
                    SortedSet <Usage> usages    = new SortedSet <Usage>(usageList, new CompareUsages());
                    foreach (Usage usage in usages)
                    {
                        RefactorIExpressionable(element, usage.User as IExpressionable);
                        RefactorTypedElement(element, usage.User as ITypedElement);
                    }

                    if (element is StructureElement)
                    {
                        Structure structure = element.Enclosing as Structure;
                        if (structure != null && structure.IsAbstract)
                        {
                            usages = new SortedSet <Usage>(EfsSystem.Instance.FindReferences(structure));
                            foreach (Usage usage in usages)
                            {
                                if (usage.Mode == Usage.ModeEnum.Interface)
                                {
                                    Structure redefiningStructure = usage.User as Structure;
                                    if (redefiningStructure != null)
                                    {
                                        ModelElement el = redefiningStructure.FindStructureElement(originalName);
                                        if (el != null)
                                        {
                                            el.Name = newName;
                                            RefactorElement(el, originalName, newName);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
ファイル: Collection.cs プロジェクト: fakoor/ERTMSFormalSpecs
        /// <summary>
        ///     Creates a copy of the collection in the designated dictionary. The namespace structure is copied over.
        ///     The new collection is set to update this one.
        /// </summary>
        /// <param name="dictionary">The target dictionary of the copy</param>
        /// <returns></returns>
        public Collection CreateCollectionUpdate(Dictionary dictionary)
        {
            Collection retVal = (Collection)Duplicate();

            retVal.setUpdates(Guid);
            retVal.ClearAllRequirements();

            String[] names = FullName.Split('.');
            names = names.Take(names.Count() - 1).ToArray();
            NameSpace nameSpace = dictionary.GetNameSpaceUpdate(names, Dictionary);

            nameSpace.appendCollections(retVal);

            return(retVal);
        }
コード例 #14
0
        /// <summary>
        ///     Loads a namespace and locks the file
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="enclosing"></param>
        /// <param name="lockFiles"></param>
        /// <param name="allowErrors"></param>
        /// <returns></returns>
        public static Types.NameSpace LoadNameSpace(string filePath, ModelElement enclosing, bool lockFiles,
                                                    bool allowErrors)
        {
            Types.NameSpace retVal = LoadFile <Types.NameSpace>(filePath, enclosing, lockFiles);

            if (retVal == null)
            {
                if (!allowErrors)
                {
                    throw new Exception("Cannot read file " + filePath);
                }
            }

            return(retVal);
        }
コード例 #15
0
        /// <summary>
        ///     Creates a copy of the variable in the designated dictionary. The namespace structure is copied over.
        ///     The new variable is set to update this one.
        /// </summary>
        /// <param name="dictionary">The target dictionary of the copy</param>
        /// <returns></returns>
        public Variable CreateVariableUpdate(Dictionary dictionary)
        {
            Variable retVal = (Variable)Duplicate();

            retVal.setUpdates(Guid);
            retVal.ClearAllRequirements();

            String[] names = FullName.Split('.');
            names = names.Take(names.Count() - 1).ToArray();
            NameSpace nameSpace = dictionary.GetNameSpaceUpdate(names, Dictionary);

            nameSpace.appendVariables(retVal);

            return(retVal);
        }
コード例 #16
0
ファイル: NameSpace.cs プロジェクト: fakoor/ERTMSFormalSpecs
        /// <summary>
        ///     Either provides the requested state machine or creates it if it cannot be found
        /// </summary>
        /// <param name="name">The name pf the state machine</param>
        /// <param name="initialNameSpace">The namespace the state machine is being copied from</param>
        /// <returns></returns>
        public StateMachine GetStateMachineUpdate(string name, NameSpace initialNameSpace)
        {
            StateMachine retVal = null;

            if (name != null)
            {
                retVal = findStateMachineByName(name);
                StateMachine initialStateMachine = initialNameSpace.findStateMachineByName(name);
                if (retVal == null)
                {
                    retVal = initialStateMachine.CreateStateMachineUpdate(Dictionary);
                }
            }
            return(retVal);
        }
コード例 #17
0
            private NameSpaceRef referenceNameSpace(ModelElement enclosing, Types.NameSpace nameSpace)
            {
                NameSpaceRef retVal = nameSpace.NameSpaceRef;

                if (retVal == null)
                {
                    retVal = (NameSpaceRef)acceptor.getFactory().createNameSpaceRef();
                }

                retVal.Name = nameSpace.Name;
                retVal.setFather(enclosing);
                retVal.SaveNameSpace(nameSpace);

                return(retVal);
            }
コード例 #18
0
ファイル: NameSpace.cs プロジェクト: fakoor/ERTMSFormalSpecs
        /// <summary>
        ///     Finds or creates a new namespace, and indicates that the original namespace is updated
        /// </summary>
        /// <param name="name">The name of the namespace to find or create</param>
        /// <param name="initialNameSpace">The namespace that is updated</param>
        /// <returns></returns>
        public NameSpace FindOrCreateNameSpaceUpdate(string name, NameSpace initialNameSpace)
        {
            NameSpace retVal = findNameSpaceByName(name);

            if (retVal == null)
            {
                retVal = (NameSpace)acceptor.getFactory().createNameSpace();
                retVal.setName(name);
                appendNameSpaces(retVal);

                // set the updates link for the new namespace
                retVal.setUpdates(initialNameSpace.Guid);
            }

            return(retVal);
        }
コード例 #19
0
        /// <summary>
        ///     Creates a copy of the structure in the designated dictionary. The namespace structure is copied over.
        ///     The new structure is set to update this one.
        /// </summary>
        /// <param name="dictionary">The target dictionary of the copy</param>
        /// <returns></returns>
        public Structure CreateStructureUpdate(Dictionary dictionary)
        {
            Structure retVal = (Structure)acceptor.getFactory().createStructure();

            retVal.Name       = Name;
            retVal.Comment    = Comment;
            retVal.IsAbstract = IsAbstract;
            retVal.SetUpdateInformation(this);

            String[] names = FullName.Split('.');
            names = names.Take(names.Count() - 1).ToArray();
            NameSpace nameSpace = dictionary.GetNameSpaceUpdate(names, Dictionary);

            nameSpace.appendStructures(retVal);

            return(retVal);
        }
コード例 #20
0
        private static NameSpace findNameSpace(string name)
        {
            NameSpace retVal = null;

            EfsSystem system = EfsSystem.Instance;

            foreach (Dictionary dictionary in system.Dictionaries)
            {
                retVal = OverallNameSpaceFinder.INSTANCE.findByName(dictionary, name);
                if (retVal != null)
                {
                    break;
                }
            }

            return(retVal);
        }
コード例 #21
0
 /// <summary>
 ///     Adds a model element in this model element
 /// </summary>
 /// <param name="element"></param>
 public override void AddModelElement(IModelElement element)
 {
     {
         Types.NameSpace item = element as Types.NameSpace;
         if (item != null)
         {
             appendNameSpaces(item);
         }
     }
     {
         Frame item = element as Frame;
         if (item != null)
         {
             appendTests(item);
         }
     }
 }
コード例 #22
0
ファイル: Enum.cs プロジェクト: fakoor/ERTMSFormalSpecs
        /// <summary>
        ///     Creates a copy of the enum in the designated dictionary. The namespace structure is copied over.
        ///     The new enum is set to update this one.
        /// </summary>
        /// <param name="dictionary">The target dictionary of the copy</param>
        /// <returns></returns>
        public Enum CreateEnumUpdate(Dictionary dictionary)
        {
            Enum retVal = (Enum)GetTopLevelEnum().Duplicate();

            retVal.SetUpdateInformation(GetTopLevelEnum());
            retVal.ClearAllRequirements();

            String[] names = GetTopLevelEnum().FullName.Split('.');
            names = names.Take(names.Count() - 1).ToArray();
            NameSpace nameSpace = dictionary.GetNameSpaceUpdate(names, Dictionary);

            if (nameSpace != null)
            {
                nameSpace.appendEnumerations(retVal);
            }

            return(retVal);
        }
コード例 #23
0
            public override void visit(Generated.Dictionary obj, bool visitSubNodes)
            {
                Dictionary dictionary = (Dictionary)obj;

                if (dictionary.allNameSpaceRefs() != null)
                {
                    foreach (NameSpaceRef nameSpaceRef in dictionary.allNameSpaceRefs())
                    {
                        Types.NameSpace nameSpace = nameSpaceRef.LoadNameSpace(LockFiles, AllowErrorsDuringLoad);
                        if (nameSpace != null)
                        {
                            dictionary.appendNameSpaces(nameSpace);
                            nameSpace.NameSpaceRef = nameSpaceRef;
                        }
                        else
                        {
                            ErrorsDuringLoad.Add(new ElementLog(ElementLog.LevelEnum.Error,
                                                                "Cannot load file " + nameSpaceRef.FileName));
                        }
                    }
                    dictionary.allNameSpaceRefs().Clear();
                }
                if (dictionary.allTestRefs() != null)
                {
                    foreach (FrameRef testRef in dictionary.allTestRefs())
                    {
                        Frame frame = testRef.LoadFrame(LockFiles, AllowErrorsDuringLoad);
                        if (frame != null)
                        {
                            dictionary.appendTests(frame);
                            frame.FrameRef = testRef;
                        }
                        else
                        {
                            ErrorsDuringLoad.Add(new ElementLog(ElementLog.LevelEnum.Error,
                                                                "Cannot load file " + testRef.FileName));
                        }
                    }
                    dictionary.allTestRefs().Clear();
                }

                base.visit(obj, visitSubNodes);
            }
コード例 #24
0
        /// <summary>
        ///     Finds the type of the structure corresponding to the provided NID_PACKET
        /// </summary>
        /// <param name="nameSpace">The namespace where the type has to be found</param>
        /// <param name="nidPacket">The id of the packet</param>
        /// <returns></returns>
        private static StructureValue FindStructure(int nidPacket)
        {
            EfsSystem system    = EfsSystem.Instance;
            Structure structure = null;
            NameSpace nameSpace = findNameSpace("Messages.PACKET.TRACK_TO_TRAIN");

            foreach (NameSpace packetNameSpace in nameSpace.NameSpaces)
            {
                Structure structureType =
                    (Structure)system.FindType(packetNameSpace, packetNameSpace.FullName + ".Message");
                StructureValue structureValue = new StructureValue(structureType);

                foreach (KeyValuePair <string, IVariable> pair in structureValue.SubVariables)
                {
                    string variableName = pair.Key;
                    if (variableName.Equals("NID_PACKET"))
                    {
                        IntValue value = pair.Value.Value as IntValue;
                        if (value.Val == nidPacket)
                        {
                            structure = structureType;
                        }
                    }
                    if (structure != null)
                    {
                        break;
                    }
                }
                if (structure != null)
                {
                    break;
                }
            }

            StructureValue retVal = null;

            if (structure != null)
            {
                retVal = new StructureValue(structure);
            }

            return(retVal);
        }
コード例 #25
0
        /// <summary>
        ///     Creates a copy of the structure element in the designated dictionary. The namespace structure is copied over.
        ///     The new structure element is set to update this one.
        /// </summary>
        /// <param name="dictionary">The target dictionary of the copy</param>
        /// <returns></returns>
        public StructureElement CreateStructureElementUpdate(Dictionary dictionary)
        {
            StructureElement retVal = new StructureElement();

            retVal.Name     = Name;
            retVal.TypeName = TypeName;
            retVal.Comment  = Comment;
            retVal.setUpdates(Guid);

            String[] names = FullName.Split('.');
            names = names.Take(names.Count() - 1).ToArray();
            String[] nameSpaceRef = names.Take(names.Count() - 1).ToArray();

            NameSpace nameSpace = dictionary.GetNameSpaceUpdate(nameSpaceRef, Dictionary);
            Structure structure = nameSpace.GetStructureUpdate(names.Last(), (NameSpace)nameSpace.Updates);

            structure.appendElements(retVal);

            return(retVal);
        }
コード例 #26
0
ファイル: NameSpace.cs プロジェクト: fakoor/ERTMSFormalSpecs
        /// <summary>
        ///     Provides the type which corresponds to the given name
        /// </summary>
        /// <param name="name">the type name to find</param>
        /// <param name="findInEnclosingNameSpaces">indicates that the search must be performed in the enclosing namespaces</param>
        /// <returns></returns>
        private Type innerFindTypeByName(string name, bool findInEnclosingNameSpaces)
        {
            Type retVal = null;

            string[] names = name.Split('.');
            if (names.Length == 1)
            {
                retVal = (Type)NamableUtils.FindByName(name, Types);
            }
            else
            {
                NameSpace nameSpace = (NameSpace)NamableUtils.FindByName(names[0], NameSpaces);
                if (nameSpace != null)
                {
                    retVal = nameSpace.innerFindTypeByName(name.Substring(nameSpace.Name.Length + 1), false);
                }
            }

            if (retVal == null && findInEnclosingNameSpaces && EnclosingNameSpace != null)
            {
                retVal = EnclosingNameSpace.innerFindTypeByName(name, true);
            }

            //HacK: get the unified structure to take care of Updates
            Structure structure = retVal as Structure;

            if (structure != null)
            {
                retVal = structure.UnifiedStructure;
            }

            //HacK: get the unified state machine to take care of Updates
            StateMachine stateMachine = retVal as StateMachine;

            if (stateMachine != null)
            {
                retVal = stateMachine.UnifiedStateMachine;
            }

            return(retVal);
        }
コード例 #27
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="model"></param>
        public ImagesSelector(NameSpace model)
        {
            InitializeComponent();

            Model = model;

            Point location = new Point(0,0);
            for (int imageIndex = 1; imageIndex<=NameSpaceImages.Instance.Images.Images.Count; imageIndex++)
            {
                Button button= new SelectionButton(model, imageIndex);
                button.Location = location;
                panel.Controls.Add(button);
                if (imageIndex % 6 == 0)
                {
                    location = new Point(0, location.Y + 32);
                }
                else
                {
                    location = new Point(location.X + 32, location.Y);
                }
            }
        }
コード例 #28
0
        /// <summary>
        /// Provides the type associated to the name
        /// </summary>
        /// <param name="nameSpace"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Types.Type findType(Types.NameSpace nameSpace, string name)
        {
            Types.Type retVal = null;

            if (name != null)
            {
                foreach (Dictionary dictionary in Dictionaries)
                {
                    retVal = dictionary.findType(nameSpace, name);
                    if (retVal != null)
                    {
                        break;
                    }
                }

                if (retVal == null)
                {
                    PredefinedTypes.TryGetValue(name, out retVal);
                }
            }

            return(retVal);
        }
コード例 #29
0
 /// <summary>
 /// Adds a model element in this model element
 /// </summary>
 /// <param name="copy"></param>
 public override void AddModelElement(Utils.IModelElement element)
 {
     {
         Types.NameSpace item = element as Types.NameSpace;
         if (item != null)
         {
             appendNameSpaces(item);
         }
     }
     {
         Rules.RuleDisabling item = element as Rules.RuleDisabling;
         if (item != null)
         {
             appendRuleDisablings(item);
         }
     }
     {
         Tests.Frame item = element as Tests.Frame;
         if (item != null)
         {
             appendTests(item);
         }
     }
 }
コード例 #30
0
        /// <summary>
        ///     Provides the type associated to the name, if it exists.
        ///     If it does not exist, does not raise any errors.
        /// </summary>
        /// <param name="nameSpace"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Type FindType_silent(NameSpace nameSpace, string name)
        {
            Type retVal = null;

            ModelElement.DontRaiseError(() =>
            {
                retVal = FindType(nameSpace, name);
            });

            return retVal;
        }
コード例 #31
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="nameSpace"></param>
 public NameSpaceRefactorer(NameSpace nameSpace)
 {
     NameSpace = nameSpace;
 }
コード例 #32
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="panel"></param>
 /// <param name="model"></param>
 public NameSpaceModelControl(ModelDiagramPanel panel, NameSpace model)
     : base(panel, model)
 {
     NormalColor = Color.LightGreen;
     BoxMode = BoxModeEnum.RoundedCorners;
 }
コード例 #33
0
        /// <summary>
        ///     Indicates whether a call should be considered in the ProcedureOrFunctionCalls
        /// </summary>
        /// <param name="variableReference"></param>
        /// <param name="container"></param>
        /// <param name="sourceNameSpace"></param>
        /// <param name="targetNameSpace"></param>
        /// <returns></returns>
        private static bool considerVariableReference(Usage variableReference, IEnclosesNameSpaces container,
            NameSpace sourceNameSpace, NameSpace targetNameSpace)
        {
            bool retVal = considerCommon(container, sourceNameSpace, targetNameSpace);

            // Only consider variables
            retVal = retVal && variableReference.Referenced is IVariable;

            // Only consider variable accesses when the mode is known
            retVal = retVal && variableReference.Mode != null;

            return retVal;
        }
コード例 #34
0
        /// <summary>
        ///     Indicates whether a call should be considered in the ProcedureOrFunctionCalls
        /// </summary>
        /// <param name="functionCall"></param>
        /// <param name="container"></param>
        /// <param name="sourceNameSpace"></param>
        /// <param name="targetNameSpace"></param>
        /// <returns></returns>
        private static bool considerCall(Usage functionCall, IEnclosesNameSpaces container, NameSpace sourceNameSpace,
            NameSpace targetNameSpace)
        {
            bool retVal = considerCommon(container, sourceNameSpace, targetNameSpace);

            // Only consider callables
            retVal = retVal && functionCall.Referenced is ICallable;

            // Ignore casting
            retVal = retVal && !(functionCall.Referenced is Range);

            return retVal;
        }
コード例 #35
0
            private NameSpaceRef referenceNameSpace(ModelElement enclosing, NameSpace nameSpace)
            {
                NameSpaceRef retVal = (NameSpaceRef)Generated.acceptor.getFactory().createNameSpaceRef();
                retVal.Name = nameSpace.Name;
                retVal.setFather(enclosing);
                retVal.SaveNameSpace(nameSpace);

                return retVal;
            }
コード例 #36
0
        private static string format_euroradio_message(DBMessage message)
        {
            EfsSystem system = EfsSystem.Instance;

            NameSpace rbcRoot = findNameSpace("Messages.MESSAGE");

            // Get the EFS namespace corresponding to the message
            // Select the appropriate message type, tracktotrain or traintotrack
            DBField nidMessage = message.Fields[0] as DBField;
            string  msg_id     = get_namespace_from_ID(nidMessage.Value);

            NameSpace nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(rbcRoot, msg_id);

            if (nameSpace == null)
            {
                throw new Exception("Message type not found in EFS");
            }

            // The EURORADIO messages are defined in the namespaces TRACK_TO_TRAIN and TRAIN_TO_TRACK, which enclose the specific message namespaces
            // So we get the message type from nameSpace.EnclosingNameSpace and the actual structure corresponding to the message in nameSpace
            Structure      enclosingStructureType = (Structure)system.FindType(nameSpace.EnclosingNameSpace, "Message");
            StructureValue Message = new StructureValue(enclosingStructureType);


            // Within the message, get the appropriate field and get that structure
            Structure      structureType = (Structure)system.FindType(nameSpace, "Message");
            StructureValue structure     = new StructureValue(structureType);


            // Fill the structure
            int currentIndex = 0;

            FillStructure(nameSpace, message.Fields, ref currentIndex, structure);

            // Fill the default packets
            int translatedPackets = 0;

            foreach (KeyValuePair <string, IVariable> subVariable in structure.SubVariables)
            {
                if (subVariable.Value.TypeName.EndsWith("Message"))
                {
                    // The structure of packets will always be a Message, but in some cases, it is a message that contains
                    // the different options for a single field in the message
                    structure.GetVariable(subVariable.Value.Name).Value = FillDefaultPacket(message, subVariable.Value);

                    translatedPackets++;
                }
            }

            // and fill the packets
            IVariable subSequenceVariable;

            if (structure.SubVariables.TryGetValue("Sequence1", out subSequenceVariable) &&
                message.Packets.Count > translatedPackets)
            {
                subSequenceVariable.Value = get_message_packets(message, nameSpace, system);
            }


            // Fill the correct field in Message with the structure.
            foreach (KeyValuePair <string, IVariable> pair in Message.SubVariables)
            {
                if (msg_id.EndsWith(pair.Key))
                {
                    pair.Value.Type  = structureType;
                    pair.Value.Value = structure;
                }
            }

            return(Message.Name);
        }
コード例 #37
0
        public void CreateNamespaceSection(ModelReport report, NameSpace aNameSpace)
        {
            bool informationAdded = false;

            if (!aNameSpace.FullName.StartsWith("Messages"))
            {
                if (AddRanges)
                {
                    if (report.CountDisplayedReqRelated(aNameSpace.Ranges) > 0)
                    {
                        report.AddSubParagraph("Namespace " + aNameSpace.FullName);
                        report.CreateRangesSection(aNameSpace.Ranges, AddRangesDetails);
                        informationAdded = true;
                    }
                }
                if (AddEnumerations)
                {
                    if (report.CountDisplayedReqRelated(aNameSpace.Enumerations) > 0)
                    {
                        if (!informationAdded)
                        {
                            report.AddSubParagraph("Namespace " + aNameSpace.FullName);
                            informationAdded = true;
                        }
                        report.CreateEnumerationsSection(aNameSpace.Enumerations, AddEnumerationsDetails);
                    }
                }
                if (AddStructures)
                {
                    if (report.CountDisplayedReqRelated(aNameSpace.Structures) > 0)
                    {
                        if (!informationAdded)
                        {
                            report.AddSubParagraph("Namespace " + aNameSpace.FullName);
                            informationAdded = true;
                        }
                        report.CreateStructuresSection(aNameSpace.Structures, AddStructuresDetails);
                    }
                }
                if (AddCollections)
                {
                    if (report.CountDisplayedReqRelated(aNameSpace.Collections) > 0)
                    {
                        if (!informationAdded)
                        {
                            report.AddSubParagraph("Namespace " + aNameSpace.FullName);
                            informationAdded = true;
                        }
                        report.CreateCollectionsSection(aNameSpace.Collections, AddCollectionsDetails);
                    }
                }
                if (AddStateMachines)
                {
                    if (report.CountDisplayedReqRelated(aNameSpace.StateMachines) > 0)
                    {
                        if (!informationAdded)
                        {
                            report.AddSubParagraph("Namespace " + aNameSpace.FullName);
                            informationAdded = true;
                        }
                        report.CreateStateMachinesSection(aNameSpace.StateMachines, AddStateMachinesDetails);
                    }
                }
                if (AddFunctions)
                {
                    if (report.CountDisplayedReqRelated(aNameSpace.Functions) > 0)
                    {
                        if (!informationAdded)
                        {
                            report.AddSubParagraph("Namespace " + aNameSpace.FullName);
                            informationAdded = true;
                        }
                        report.CreateFunctionsSection(aNameSpace.Functions, AddFunctionsDetails);
                    }
                }
                if (AddProcedures)
                {
                    if (report.CountDisplayedReqRelated(aNameSpace.Procedures) > 0)
                    {
                        if (!informationAdded)
                        {
                            report.AddSubParagraph("Namespace " + aNameSpace.FullName);
                            informationAdded = true;
                        }
                        report.CreateProceduresSection(aNameSpace.Procedures, AddProceduresDetails, false);
                    }
                }
                if (AddVariables)
                {
                    if (report.CountDisplayedVariables(aNameSpace.Variables, InOutOnly) > 0)
                    {
                        if (!informationAdded)
                        {
                            report.AddSubParagraph("Namespace " + aNameSpace.FullName);
                            informationAdded = true;
                        }
                        report.CreateVariablesSection(aNameSpace.Variables, AddVariablesDetails, InOutOnly);
                    }
                }
                if (AddRules)
                {
                    if (report.CountDisplayedReqRelated(aNameSpace.Rules) > 0)
                    {
                        if (!informationAdded)
                        {
                            report.AddSubParagraph("Namespace " + aNameSpace.FullName);
                            informationAdded = true;
                        }
                        report.CreateRulesSection(aNameSpace.Rules, AddRulesDetails, false);
                    }
                }

                if (informationAdded)
                {
                    report.CloseSubParagraph();
                }

                foreach (NameSpace nameSpace in aNameSpace.NameSpaces)
                {
                    CreateNamespaceSection(report, nameSpace);
                }
            }
        }
コード例 #38
0
        private static ListValue get_message_packets(DBMessage message, NameSpace nameSpace, EfsSystem system)
        {
            ListValue retVal;

            Collection collectionType    = (Collection)system.FindType(nameSpace, "Collection1");
            Structure  subStructure1Type = (Structure)system.FindType(nameSpace, "SubStructure1");

            string packetLocation = "Messages.PACKET.";

            if (nameSpace.FullName.Contains("TRAIN_TO_TRACK"))
            {
                packetLocation += "TRAIN_TO_TRACK.Message";
            }
            else
            {
                packetLocation += "TRACK_TO_TRAIN.Message";
            }

            Structure packetStructureType = (Structure)system.FindType(nameSpace, packetLocation);

            retVal = new ListValue(collectionType, new List <IValue>());

            foreach (DBPacket packet in message.Packets)
            {
                DBField nidPacketField = packet.Fields[0] as DBField;
                if (nidPacketField.Value != "255") // 255 means "end of information"
                {
                    int            packetId     = int.Parse(nidPacketField.Value);
                    StructureValue subStructure = FindStructure(packetId);

                    int currentIndex = 0;
                    FillStructure(nameSpace, packet.Fields, ref currentIndex, subStructure);

                    StructureValue subStructure1 = new StructureValue(subStructure1Type);

                    // For Balise messages, we have an extra level of information to fill, so here we define StructureVal in one of two ways
                    StructureValue structureVal;
                    if (subStructure1.SubVariables.Count == 1 &&
                        subStructure1.SubVariables.ContainsKey("TRACK_TO_TRAIN"))
                    {
                        // For a Balise message, we have an extra level of structures for TRACK_TO_TRAIN
                        structureVal = new StructureValue(packetStructureType);

                        subStructure1.SubVariables["TRACK_TO_TRAIN"].Value = structureVal;
                    }
                    else
                    {
                        // For RBC, the collection directly holds the different packet types
                        structureVal = subStructure1;
                    }

                    // Find the right variable in the packet to add the structure we just created
                    foreach (KeyValuePair <string, IVariable> pair in structureVal.SubVariables)
                    {
                        string variableName = pair.Key;
                        if (subStructure.Structure.FullName.Contains(variableName))
                        {
                            pair.Value.Value = subStructure;

                            retVal.Val.Add(subStructure1);

                            break;
                        }
                    }
                }
            }

            return(retVal);
        }
コード例 #39
0
ファイル: NameSpace.cs プロジェクト: fakoor/ERTMSFormalSpecs
        /// <summary>
        ///     Creates a copy of the namespace in the designated dictionary. The enclosing namespace structure is copied over.
        ///     The new namespace is set to update this one.
        /// </summary>
        /// <param name="dictionary">The target dictionary of the copy</param>
        /// <returns></returns>
        public NameSpace CreateUpdateInDictionary(Dictionary dictionary)
        {
            NameSpace retVal = dictionary.GetNameSpaceUpdate(FullName.Split('.'), Dictionary);

            return(retVal);
        }
コード例 #40
0
        /// <summary>
        ///     Fills the given structure with the values provided from the database
        /// </summary>
        /// <param name="aNameSpace">Namespace of the structure</param>
        /// <param name="fields">Fields to be copied into the structure</param>
        /// <param name="index">Index (of fields list) from which we have to start copying</param>
        /// <param name="aStructure">The structure to be filled</param>
        private static void FillStructure(NameSpace aNameSpace, ArrayList fields, ref int currentIndex,
            StructureValue aStructure)
        {
            EFSSystem system = EFSSystem.INSTANCE;

            int j = 0;
            while (currentIndex < fields.Count)
            {
                DBField field = fields[currentIndex] as DBField;

                KeyValuePair<string, IVariable> pair = aStructure.SubVariables.ElementAt(j);
                IVariable variable = pair.Value;

                // conditional variables can be missing in the database fields, but present in our structure => skip them
                while (!variable.Name.StartsWith(field.Variable) && j < aStructure.SubVariables.Count - 1)
                {
                    j++;
                    pair = aStructure.SubVariables.ElementAt(j);
                    variable = pair.Value;
                }

                if (variable.Name.StartsWith(field.Variable))
                    // we use StartsWith and not Equals because we can have N_ITER_1 and N_ITER
                {
                    if (variable.Type is Enum)
                    {
                        Enum type = variable.Type as Enum;
                        foreach (EnumValue enumValue in type.Values)
                        {
                            int value = int.Parse(enumValue.getValue());
                            int other = int.Parse(field.Value);
                            if (value == other)
                            {
                                variable.Value = enumValue;
                                j++;
                                break;
                            }
                        }
                    }
                    else if (variable.Type is Range)
                    {
                        Range type = variable.Type as Range;
                        object v = VariableConverter.INSTANCE.Convert(variable.Name, field.Value);
                        variable.Value = new IntValue(type, (int) v);
                        j++;
                    }
                    else if (variable.Type is StringType)
                    {
                        StringType type = variable.Type as StringType;
                        variable.Value = new StringValue(type, field.Value);
                        j++;
                    }
                    else
                    {
                        throw new Exception("Unhandled variable type");
                    }
                    if (variable.Name.StartsWith("N_ITER")) // we have to create a sequence
                    {
                        KeyValuePair<string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j);
                        IVariable sequenceVariable = sequencePair.Value;
                        Collection collectionType = (Collection) system.FindType(aNameSpace, sequenceVariable.TypeName);
                        ListValue sequence = new ListValue(collectionType, new List<IValue>());

                        int value = int.Parse(field.Value);
                        for (int k = 0; k < value; k++)
                        {
                            currentIndex++;
                            Structure structureType =
                                (Structure) system.FindType(aNameSpace, sequence.CollectionType.Type.FullName);
                            StructureValue structureValue = new StructureValue(structureType);
                            FillStructure(aNameSpace, fields, ref currentIndex, structureValue);
                            sequence.Val.Add(structureValue);
                        }
                        sequenceVariable.Value = sequence;
                        j++;
                    }
                }

                // if all the fields of the structue are filled, we terminated
                if (j == aStructure.SubVariables.Count)
                {
                    break;
                }
                else
                {
                    currentIndex += 1;
                }
            }
        }
コード例 #41
0
        private static IValue FillDefaultPacket(DBMessage message, IVariable structure)
        {
            IValue retVal = structure.Value;

            if (isPacket(structure))
            {
                Structure      defaultPacketType = (Structure)structure.Type;
                StructureValue defaultPacket     = new StructureValue(defaultPacketType);

                NameSpace packetNameSpace = structure.NameSpace;

                foreach (DBPacket packet in message.Packets)
                {
                    DBField nidPacketField = packet.Fields[0] as DBField;
                    int     packetID       = int.Parse(nidPacketField.Value);

                    Structure packetType = (Structure)FindStructure(packetID).Type;

                    if (packetType == defaultPacketType)
                    {
                        int defaultPacketIndex = 0;
                        FillStructure(packetNameSpace, packet.Fields, ref defaultPacketIndex, defaultPacket);

                        retVal = defaultPacket;
                    }
                }
            }
            else
            {
                Structure      structureType = structure.Type as Structure;
                StructureValue Structure     = new StructureValue(structureType);
                if (Structure != null)
                {
                    foreach (KeyValuePair <string, IVariable> subVariable in Structure.SubVariables)
                    {
                        if (isPacket(subVariable.Value))
                        {
                            Structure      defaultPacketType = (Structure)subVariable.Value.Type;
                            StructureValue defaultPacket     = new StructureValue(defaultPacketType);

                            NameSpace packetNameSpace = subVariable.Value.NameSpace;

                            foreach (DBPacket packet in message.Packets)
                            {
                                DBField nidPacketField = packet.Fields[0] as DBField;
                                int     packetID       = int.Parse(nidPacketField.Value);

                                Structure packetType = (Structure)FindStructure(packetID).Type;

                                if (packetType == defaultPacketType)
                                {
                                    int defaultPacketIndex = 0;
                                    FillStructure(packetNameSpace, packet.Fields, ref defaultPacketIndex, defaultPacket);

                                    Structure.GetVariable(subVariable.Value.Name).Value = defaultPacket;
                                }
                            }
                        }
                    }
                    retVal = Structure;
                }
            }

            return(retVal);
        }
コード例 #42
0
        /// <summary>
        ///     Creates a section for a namespace
        /// </summary>
        /// <param name="nameSpace">The namespace to consider</param>
        /// <param name="accesses">The accesses performed in the system</param>
        /// <returns></returns>
        public void CreateNameSpaceSection(NameSpace nameSpace, List<AccessMode> accesses)
        {
            AddSubParagraph("Namespace " + nameSpace.FullName);

            Dictionary<Procedure, List<ProcedureOrFunctionCall>> procedureCalls =
                new Dictionary<Procedure, List<ProcedureOrFunctionCall>>();
            Dictionary<Function, List<ProcedureOrFunctionCall>> functionCalls =
                new Dictionary<Function, List<ProcedureOrFunctionCall>>();
            Dictionary<IVariable, List<AccessToVariable>> accessesToVariables =
                new Dictionary<IVariable, List<AccessToVariable>>();

            foreach (AccessMode access in accesses)
            {
                ProcedureOrFunctionCall call = access as ProcedureOrFunctionCall;
                if (call != null)
                {
                    if (call.Target == nameSpace)
                    {
                        {
                            Function function = call.ReferencedModel as Function;
                            if (function != null)
                            {
                                List<ProcedureOrFunctionCall> calls;
                                if (!functionCalls.TryGetValue(function, out calls))
                                {
                                    calls = new List<ProcedureOrFunctionCall>();
                                    functionCalls.Add(function, calls);
                                }
                                calls.Add(call);
                            }
                        }

                        {
                            Procedure procedure = call.ReferencedModel as Procedure;
                            if (procedure != null)
                            {
                                List<ProcedureOrFunctionCall> calls;
                                if (!procedureCalls.TryGetValue(procedure, out calls))
                                {
                                    calls = new List<ProcedureOrFunctionCall>();
                                    procedureCalls.Add(procedure, calls);
                                }
                                calls.Add(call);
                            }
                        }
                    }
                }

                AccessToVariable accessToVariable = access as AccessToVariable;
                if (accessToVariable != null)
                {
                    if (accessToVariable.Target == nameSpace)
                    {
                        List<AccessToVariable> variableAccesses;
                        if (!accessesToVariables.TryGetValue(accessToVariable.Variable, out variableAccesses))
                        {
                            variableAccesses = new List<AccessToVariable>();
                            accessesToVariables.Add(accessToVariable.Variable, variableAccesses);
                        }
                        variableAccesses.Add(accessToVariable);
                    }
                }
            }

            if (procedureCalls.Keys.Count > 0)
            {
                AddSubParagraph("Exposed procedures");
                foreach (KeyValuePair<Procedure, List<ProcedureOrFunctionCall>> pair in procedureCalls)
                {
                    Procedure procedure = pair.Key;
                    AddSubParagraph("Procedure " + procedure.Name);
                    CreateProcedureOrFunctionHeader(procedure);
                    CreateProcedureOrFunctionUsage(pair.Value);
                    CloseSubParagraph();
                }
                CloseSubParagraph();
            }

            if (functionCalls.Keys.Count > 0)
            {
                AddSubParagraph("Exposed functions");
                foreach (KeyValuePair<Function, List<ProcedureOrFunctionCall>> pair in functionCalls)
                {
                    Function function = pair.Key;
                    AddSubParagraph("Function " + function.Name);
                    CreateProcedureOrFunctionHeader(function);
                    CreateProcedureOrFunctionUsage(pair.Value);
                    CloseSubParagraph();
                }
                CloseSubParagraph();
            }

            if (accessesToVariables.Count > 0)
            {
                AddSubParagraph("Exposed variables");
                foreach (KeyValuePair<IVariable, List<AccessToVariable>> pair in accessesToVariables)
                {
                    IVariable variable = pair.Key;
                    AddSubParagraph("Variable " + variable.Name);
                    CreateVariableHeader(variable);
                    CreateVariableUsage(pair.Value);
                    CloseSubParagraph();
                }
                CloseSubParagraph();
            }
            CloseSubParagraph();
        }
コード例 #43
0
        /// <summary>
        ///     Fills the given structure with the values provided from the database
        /// </summary>
        /// <param name="aNameSpace">Namespace of the structure</param>
        /// <param name="fields">Fields to be copied into the structure</param>
        /// <param name="index">Index (of fields list) from which we have to start copying</param>
        /// <param name="aStructure">The structure to be filled</param>
        private static void FillStructure(NameSpace aNameSpace, ArrayList fields, ref int currentIndex,
            StructureValue aStructure)
        {
            EfsSystem system = EfsSystem.Instance;

            int j = 0;
            while (currentIndex < fields.Count)
            {
                bool foundMatch = false;

                DBField field = fields[currentIndex] as DBField;

                KeyValuePair<string, IVariable> pair = aStructure.SubVariables.ElementAt(j);
                IVariable variable = pair.Value;

                // Conditioned variables can be missing in the database fields, but present in our structure => skip them
                while (!variable.Name.StartsWith(field.Variable) && j < aStructure.SubVariables.Count - 1)
                {
                    j++;
                    pair = aStructure.SubVariables.ElementAt(j);
                    variable = pair.Value;
                }

                // We use StartsWith and not Equals because we can have N_ITER_1 and N_ITER
                if (variable.Name.StartsWith(field.Variable))
                {
                    foundMatch = true;
                    if (variable.Type is Enum)
                    {
                        Enum type = variable.Type as Enum;
                        foreach (EnumValue enumValue in type.Values)
                        {
                            int value = int.Parse(enumValue.getValue());
                            int other = int.Parse(field.Value);
                            if (value == other)
                            {
                                variable.Value = enumValue;
                                j++;
                                break;
                            }
                        }
                    }
                    else if (variable.Type is Range)
                    {
                        Range type = variable.Type as Range;
                        object v = VariableConverter.INSTANCE.Convert(variable.Name, field.Value);

                        string stringValue = v as string;
                        if (stringValue != null)
                        {
                            int intValue;
                            if (int.TryParse(stringValue, out intValue))
                            {
                                v = intValue;
                            }
                            else if (stringValue.EndsWith(" b"))
                            {
                                stringValue = stringValue.Substring(0, stringValue.Length - 2);
                                v = Convert.ToInt32(stringValue, 2);
                            }
                        }
                        variable.Value = new IntValue(type, (int) v);
                        j++;
                    }
                    else if (variable.Type is StringType)
                    {
                        StringType type = variable.Type as StringType;
                        variable.Value = new StringValue(type, field.Value);
                        j++;
                    }
                    else
                    {
                        throw new Exception("Unhandled variable type");
                    }

                    if (variable.Name.StartsWith("N_ITER")) // we have to create a sequence
                    {
                        KeyValuePair<string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j);
                        IVariable sequenceVariable = sequencePair.Value;
                        Collection collectionType = (Collection) system.FindType(aNameSpace, sequenceVariable.TypeName);
                        ListValue sequence = new ListValue(collectionType, new List<IValue>());

                        int value = int.Parse(field.Value);
                        for (int k = 0; k < value; k++)
                        {
                            currentIndex++;
                            Structure structureType =
                                (Structure) system.FindType(aNameSpace, sequence.CollectionType.Type.FullName);
                            StructureValue structureValue = new StructureValue(structureType);
                            FillStructure(aNameSpace, fields, ref currentIndex, structureValue);
                            sequence.Val.Add(structureValue);
                        }
                        sequenceVariable.Value = sequence;
                        j++;
                    }
                }

                // Special case for X_TEXT
                if ("Sequence1".Equals(variable.Name) && "X_TEXT".Equals(field.Variable))
                {
                    foundMatch = true;

                    KeyValuePair<string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j);
                    IVariable sequenceVariable = sequencePair.Value;
                    Collection collectionType = (Collection)system.FindType(aNameSpace, sequenceVariable.TypeName);
                    ListValue sequence = new ListValue(collectionType, new List<IValue>());
                    while (field != null && "X_TEXT".Equals(field.Variable))
                    {
                        if (string.IsNullOrEmpty(field.Value))
                        {
                            field.Value = " ";
                        }
                        Structure structureType =
                            (Structure)system.FindType(aNameSpace, sequence.CollectionType.Type.FullName);
                        StructureValue structureValue = new StructureValue(structureType);
                        FillStructure(aNameSpace, fields, ref currentIndex, structureValue);
                        sequence.Val.Add(structureValue);
                        currentIndex += 1;
                        if ( currentIndex < fields.Count)
                        {
                            field = fields[currentIndex] as DBField;
                        }
                        else
                        {
                            field = null;
                        }
                    }
                    sequenceVariable.Value = sequence;
                    j++;
                }

                // if all the fields of the structue are filled, we terminated
                if (j == aStructure.SubVariables.Count )
                {
                    break;
                }
                else if (!foundMatch)
                {
                    // We used a lookahead to determine if we needed to fill the structure
                    // But the encountered field is not the right one
                    // (for instance, because of a conditional field determiner by a Q_XXX value)
                    //  => Rollback
                    currentIndex -= 1;
                    break;
                }
                else
                {
                    currentIndex += 1;
                }
            }
        }
コード例 #44
0
        /// <summary>
        ///     Common part of the consideration of an access
        /// </summary>
        /// <param name="container"></param>
        /// <param name="sourceNameSpace"></param>
        /// <param name="targetNameSpace"></param>
        /// <param name="retVal"></param>
        /// <returns></returns>
        private static bool considerCommon(IEnclosesNameSpaces container, NameSpace sourceNameSpace,
            NameSpace targetNameSpace)
        {
            bool retVal = true;

            // Only display things that are relevant namespacewise
            retVal = retVal && sourceNameSpace != null && targetNameSpace != null;

            // Do not consider internal accesses
            retVal = retVal && sourceNameSpace != targetNameSpace;

            if (container != null)
            {
                // Only display things that can be displayed in this functional view
                // TODO : also consider sub namespaces in the diagram
                retVal = retVal &&
                         (container.NameSpaces.Contains(sourceNameSpace) ||
                          container.NameSpaces.Contains(targetNameSpace));
            }

            return retVal;
        }
コード例 #45
0
        private static ListValue get_message_packets(DBMessage message, NameSpace nameSpace, EfsSystem system)
        {
            ListValue retVal;

            Collection collectionType = (Collection) system.FindType(nameSpace, "Collection1");
            Structure subStructure1Type = (Structure) system.FindType(nameSpace, "SubStructure1");

            string packetLocation = "Messages.PACKET.";
            if (nameSpace.FullName.Contains("TRAIN_TO_TRACK"))
            {
                packetLocation += "TRAIN_TO_TRACK.Message";
            }
            else
            {
                packetLocation += "TRACK_TO_TRAIN.Message";
            }

            Structure packetStructureType = (Structure) system.FindType(nameSpace, packetLocation);

            retVal = new ListValue(collectionType, new List<IValue>());

            foreach (DBPacket packet in message.Packets)
            {
                DBField nidPacketField = packet.Fields[0] as DBField;
                if (nidPacketField.Value != "255") // 255 means "end of information"
                {
                    int packetId = int.Parse(nidPacketField.Value);
                    StructureValue subStructure = FindStructure(packetId);

                    int currentIndex = 0;
                    FillStructure(nameSpace, packet.Fields, ref currentIndex, subStructure);

                    StructureValue subStructure1 = new StructureValue(subStructure1Type);

                    // For Balise messages, we have an extra level of information to fill, so here we define StructureVal in one of two ways
                    StructureValue structureVal;
                    if (subStructure1.SubVariables.Count == 1 &&
                        subStructure1.SubVariables.ContainsKey("TRACK_TO_TRAIN"))
                    {
                        // For a Balise message, we have an extra level of structures for TRACK_TO_TRAIN
                        structureVal = new StructureValue(packetStructureType);

                        subStructure1.SubVariables["TRACK_TO_TRAIN"].Value = structureVal;
                    }
                    else
                    {
                        // For RBC, the collection directly holds the different packet types
                        structureVal = subStructure1;
                    }

                    // Find the right variable in the packet to add the structure we just created
                    foreach (KeyValuePair<string, IVariable> pair in structureVal.SubVariables)
                    {
                        string variableName = pair.Key;
                        string[] ids = subStructure.Structure.FullName.Split('.');
                        if (ids[ids.Length-2].Equals(variableName))
                        {
                            pair.Value.Value = subStructure;

                            retVal.Val.Add(subStructure1);

                            break;
                        }
                    }
                }
            }

            return retVal;
        }
コード例 #46
0
        public override NameSpace createNameSpace()
        {
            NameSpace retVal = new Types.NameSpace();

            _defaultValueSetter.SetDefaultValue(retVal);

            return retVal;
        }
コード例 #47
0
        /// <summary>
        ///     Provides the type associated to the name
        /// </summary>
        /// <param name="nameSpace"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Type FindType(NameSpace nameSpace, string name)
        {
            Type retVal = null;

            if (name != null)
            {
                foreach (Dictionary dictionary in Dictionaries)
                {
                    retVal = dictionary.FindType(nameSpace, name);
                    if (retVal != null)
                    {
                        break;
                    }
                }

                if (retVal == null)
                {
                    PredefinedTypes.TryGetValue(name, out retVal);
                }
            }

            return retVal;
        }
コード例 #48
0
        /// <summary>
        ///     Fills the tree view with the namespace and enclosed namespaces
        /// </summary>
        /// <param name="treeNode"></param>
        /// <param name="nameSpace"></param>
        /// <param name="filterConfiguration">The filter configuration used to set up the check boxes</param>
        private void GatherNamespaces(TreeNode treeNode, NameSpace nameSpace, FilterConfiguration filterConfiguration)
        {
            NamableTreeNode nameSpaceTreeNode = new NamableTreeNode(nameSpace);
            nameSpaceTreeNode.Checked = filterConfiguration.NameSpaces.Contains(nameSpace);
            nameSpaceTreeNode.Collapse();
            treeNode.Nodes.Add(nameSpaceTreeNode);

            // Adds the variables to the selection
            List<Variable> variables = new List<Variable>();
            foreach (Variable variable in nameSpace.Variables)
            {
                variables.Add(variable);
            }
            variables.Sort();

            foreach (Variable variable in variables)
            {
                NamableTreeNode variableTreeNode = new NamableTreeNode(variable);
                variableTreeNode.Checked = filterConfiguration.Variables.Contains(variable);
                nameSpaceTreeNode.Nodes.Add(variableTreeNode);
            }

            // Adds the subnamespaces to the selection
            List<NameSpace> subNameSpaces = new List<NameSpace>();
            foreach (NameSpace otherNameSpace in nameSpace.NameSpaces)
            {
                subNameSpaces.Add(otherNameSpace);
            }
            subNameSpaces.Sort();

            foreach (NameSpace subNameSpace in subNameSpaces)
            {
                GatherNamespaces(nameSpaceTreeNode, subNameSpace, filterConfiguration);
            }
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="item"></param>
 /// <param name="buildSubNodes"></param>
 public NameSpaceSubNameSpacesTreeNode(NameSpace item, bool buildSubNodes)
     : base(item, buildSubNodes, "Namespaces", true)
 {
 }
コード例 #50
0
        public StandardValuesCollection GetValues(NameSpace nameSpace, Type type)
        {
            FinderRepository.INSTANCE.ClearCache();

            List<string> retVal = new List<string>();
            if (type != null)
            {
                string prefix = type.FullName;
                if (nameSpace == type.NameSpace && nameSpace != null)
                {
                    prefix = prefix.Substring(nameSpace.FullName.Length + 1);
                }
                OverallValueFinder.INSTANCE.findAllValueNames(prefix, type, false, retVal);
                retVal.Sort();
            }

            return new StandardValuesCollection(retVal);
        }
コード例 #51
0
        /// <summary>
        ///     Fills the given structure with the values provided from the database
        /// </summary>
        /// <param name="aNameSpace">Namespace of the structure</param>
        /// <param name="fields">Fields to be copied into the structure</param>
        /// <param name="index">Index (of fields list) from which we have to start copying</param>
        /// <param name="aStructure">The structure to be filled</param>
        private static void FillStructure(NameSpace aNameSpace, ArrayList fields, ref int currentIndex,
                                          StructureValue aStructure)
        {
            EfsSystem system = EfsSystem.Instance;

            int j = 0;

            while (currentIndex < fields.Count)
            {
                DBField field = fields[currentIndex] as DBField;

                KeyValuePair <string, IVariable> pair = aStructure.SubVariables.ElementAt(j);
                IVariable variable = pair.Value;

                // conditional variables can be missing in the database fields, but present in our structure => skip them
                while (!variable.Name.StartsWith(field.Variable) && j < aStructure.SubVariables.Count - 1)
                {
                    j++;
                    pair     = aStructure.SubVariables.ElementAt(j);
                    variable = pair.Value;
                }

                // We use StartsWith and not Equals because we can have N_ITER_1 and N_ITER
                if (variable.Name.StartsWith(field.Variable))
                {
                    if (variable.Type is Enum)
                    {
                        Enum type = variable.Type as Enum;
                        foreach (EnumValue enumValue in type.Values)
                        {
                            int value = int.Parse(enumValue.getValue());
                            int other = int.Parse(field.Value);
                            if (value == other)
                            {
                                variable.Value = enumValue;
                                j++;
                                break;
                            }
                        }
                    }
                    else if (variable.Type is Range)
                    {
                        Range  type = variable.Type as Range;
                        object v    = VariableConverter.INSTANCE.Convert(variable.Name, field.Value);

                        string stringValue = v as string;
                        if (stringValue != null)
                        {
                            int intValue;
                            if (int.TryParse(stringValue, out intValue))
                            {
                                v = intValue;
                            }
                        }
                        variable.Value = new IntValue(type, (int)v);
                        j++;
                    }
                    else if (variable.Type is StringType)
                    {
                        StringType type = variable.Type as StringType;
                        variable.Value = new StringValue(type, field.Value);
                        j++;
                    }
                    else
                    {
                        throw new Exception("Unhandled variable type");
                    }

                    if (variable.Name.StartsWith("N_ITER")) // we have to create a sequence
                    {
                        KeyValuePair <string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j);
                        IVariable  sequenceVariable = sequencePair.Value;
                        Collection collectionType   = (Collection)system.FindType(aNameSpace, sequenceVariable.TypeName);
                        ListValue  sequence         = new ListValue(collectionType, new List <IValue>());

                        int value = int.Parse(field.Value);
                        for (int k = 0; k < value; k++)
                        {
                            currentIndex++;
                            Structure structureType =
                                (Structure)system.FindType(aNameSpace, sequence.CollectionType.Type.FullName);
                            StructureValue structureValue = new StructureValue(structureType);
                            FillStructure(aNameSpace, fields, ref currentIndex, structureValue);
                            sequence.Val.Add(structureValue);
                        }
                        sequenceVariable.Value = sequence;
                        j++;
                    }
                }

                // Special case for X_TEXT
                if ("Sequence1".Equals(variable.Name) && "X_TEXT".Equals(field.Variable))
                {
                    KeyValuePair <string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j);
                    IVariable  sequenceVariable = sequencePair.Value;
                    Collection collectionType   = (Collection)system.FindType(aNameSpace, sequenceVariable.TypeName);
                    ListValue  sequence         = new ListValue(collectionType, new List <IValue>());
                    while (field != null && "X_TEXT".Equals(field.Variable))
                    {
                        if (string.IsNullOrEmpty(field.Value))
                        {
                            field.Value = " ";
                        }
                        Structure structureType =
                            (Structure)system.FindType(aNameSpace, sequence.CollectionType.Type.FullName);
                        StructureValue structureValue = new StructureValue(structureType);
                        FillStructure(aNameSpace, fields, ref currentIndex, structureValue);
                        sequence.Val.Add(structureValue);
                        currentIndex += 1;
                        if (currentIndex < fields.Count)
                        {
                            field = fields[currentIndex] as DBField;
                        }
                        else
                        {
                            field = null;
                        }
                    }
                    sequenceVariable.Value = sequence;
                    j++;
                }

                // if all the fields of the structue are filled, we terminated
                if (j == aStructure.SubVariables.Count)
                {
                    break;
                }
                else
                {
                    currentIndex += 1;
                }
            }
        }