Esempio n. 1
0
        public void EmptyTest()
        {
            IEnumerable <AliasInfo> emptyResult = AliasesParser.Parse(string.Empty);

            Assert.NotNull(emptyResult);
            Assert.Empty(emptyResult);
        }
Esempio n. 2
0
        public void IsolatedTypesTest(string input, AliasInfo expected)
        {
            IEnumerable <AliasInfo> executionResult = AliasesParser.Parse(input);

            Assert.Single(executionResult);
            Assert.Equal(expected, executionResult.Single(), new AliasInfoValueEqualityComparer());
        }
Esempio n. 3
0
        public void ExampleMibsAliasesParseTest(string input, List <AliasInfo> expectedResult)
        {
            IEnumerable <AliasInfo> executionResult = AliasesParser.Parse(input);

            Assert.Equal(expectedResult, executionResult, new AliasInfoValueEqualityComparer());
        }
Esempio n. 4
0
        public static MibData Parse(string fileName)
        {
            MibData result = InitMibData();

            string mibFileTxt = SmiParser.Utils.FileUtils.ReadFileFromOutputDirectory(MibFilesFolder, fileName);
            IEnumerable <ImportInfo> importsByFiles = ImportsParser.ParseImportInfo(mibFileTxt);

            foreach (ImportInfo singleFileImports in importsByFiles)
            {
                try
                {
                    MibData imported = Parse(singleFileImports.Filename);
                    result = Merge(result, imported);
                }
                catch (FileNotFoundException e)
                {
                    Debug.WriteLine(string.Format("File {0} has not been found", e.Message));
                }
            }

            IEnumerable <CustomDataType> dataTypes = DataTypesParser.ParseAllDataTypes(mibFileTxt);

            foreach (CustomDataType type in dataTypes)
            {
                result.DataTypes.Add(type.Name, type);
            }

            IEnumerable <AliasInfo>     parsedAliases = AliasesParser.Parse(mibFileTxt);
            IEnumerable <DataTypeAlias> aliases       = parsedAliases
                                                        .Select(
                ai =>
                GetAliasTypeFromInfo(result.DataTypes, ai))
                                                        .Where(alias => alias != null)
                                                        .ToList();

            foreach (DataTypeAlias alias in aliases)
            {
                result.DataTypes.Add(alias.Alias, alias);
            }

            IEnumerable <OidInfo> oids = OidsParser.ParseAllOids(mibFileTxt);

            foreach (OidInfo oi in oids)
            {
                var oidNode = new TreeNode()
                {
                    Children     = new List <TreeNode>(),
                    Name         = oi.Name,
                    SiblingIndex = oi.SiblingNo
                };
                TreeBuilder.InsertIntoTree(oidNode, oi.ParentExpression, result.FlatMibTree);
            }

            IDictionary <OidInfo, ObjectTypeInfo> objectTypes = ObjectTypesParser.ParseAllObjectTypes(mibFileTxt);;

            foreach (var objTypeInfoKV in objectTypes)
            {
                ObjectType objType = GetObjectTypeFromInfo(result.DataTypes, objTypeInfoKV.Value);
                if (objType == null)
                {
                    continue;
                }

                var otNode = new TreeNode()
                {
                    Children     = new List <TreeNode>(),
                    Name         = objTypeInfoKV.Key.Name,
                    SiblingIndex = objTypeInfoKV.Key.SiblingNo,
                    ObjectType   = objType
                };
                TreeBuilder.InsertIntoTree(otNode, objTypeInfoKV.Key.ParentExpression, result.FlatMibTree);
            }

            return(result);
        }