示例#1
0
        public void SimpleInterface()
        {
            var body = new Source(
                @"
interface Hello {
  world: String
}".ToLF());
            var doc      = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create <SchemaDefinition>(
                    new InterfaceDefinition
                {
                    Name   = new Name("Hello", new Location(11, 16, body)),
                    Fields = ImmutableArray.Create(
                        new FieldDefinition
                    {
                        Name     = new Name("world", new Location(21, 26, body)),
                        Type     = new NamedType("String", 28, 34, body),
                        Location = new Location(21, 34, body),
                    }),
                    Location = new Location(1, 36, body),
                }),
                Location = new Location(1, 36, body),
            };

            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#2
0
        static void UpdateMetaModel(string commandsFilePath)
        {
            LogFile.WriteLine("Updating metamodel...");

            SchemaDocument schema = new SchemaDocument();

            schema.Load(Path.Combine(Settings.InstallDir, @"Code\_Source\Tools\metamodelSchema.xml"));

            SyncCommand[] commands = McXmlSerializer.GetObjectFromFile <SyncCommand[]>(commandsFilePath);

            using (DataContext dataContext = new DataContext(string.Empty))
            {
                DataContext.Current = dataContext;
                dataContext.SqlContext.CommandTimeout = CommandTimeout;
                SqlTransaction previousTransaction = DataContext.Current.SqlContext.Transaction;
                using (DBTransaction tran = DBHelper2.DBHelper.BeginTransaction())
                {
                    DataContext.Current.SqlContext.Transaction = tran.SqlTran;
                    try
                    {
                        MetaModelSync.Execute(schema, commands);
                        tran.Commit();
                        LogWriteOk();
                    }
                    finally
                    {
                        DataContext.Current.SqlContext.Transaction = previousTransaction;
                    }
                }
            }
        }
示例#3
0
        public void SimpleNonNullType()
        {
            var body = new Source(
                @"
type Hello {
  world: String!
}".ToLF());
            var doc      = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create <SchemaDefinition>(
                    new TypeDefinition
                {
                    Name   = new Name("Hello", new Location(6, 11, body)),
                    Fields = ImmutableArray.Create(
                        new FieldDefinition
                    {
                        Name = new Name("world", new Location(16, 21, body)),
                        Type = new NonNullType
                        {
                            Type     = new NamedType("String", 23, 29, body),
                            Location = new Location(23, 30, body),
                        },
                        Location = new Location(16, 30, body),
                    }),
                    Location = new Location(1, 32, body),
                }),
                Location = new Location(1, 32, body),
            };

            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
 public void Close()
 {
     SelectedPhase = null;
     Phases.Clear();
     _doc?.Dispose();
     _doc = null;
 }
示例#5
0
        public void SimpleNonNullType()
        {
            var body = new Source(
                @"
type Hello {
  world: String!
}".ToLF());
            var doc = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create<SchemaDefinition>(
                    new TypeDefinition
                    {
                        Name = new Name("Hello", new Location(6, 11, body)),
                        Fields = ImmutableArray.Create(
                            new FieldDefinition
                            {
                                Name = new Name("world", new Location(16, 21, body)),
                                Type = new NonNullType
                                {
                                    Type = new NamedType("String", 23, 29, body),
                                    Location = new Location(23, 30, body),
                                },
                                Location = new Location(16, 30, body),
                            }),
                        Location = new Location(1, 32, body),
                    }),
                Location = new Location(1, 32, body),
            };
            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#6
0
        public void SimpleInputObject()
        {
            var body = new Source(
                @"
input Hello {
  world: String
}".ToLF());
            var doc      = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create <SchemaDefinition>(
                    new InputObjectDefinition
                {
                    Name   = new Name("Hello", new Location(7, 12, body)),
                    Fields = ImmutableArray.Create(
                        new InputValueDefinition
                    {
                        Name     = new Name("world", new Location(17, 22, body)),
                        Type     = new NamedType("String", 24, 30, body),
                        Location = new Location(17, 30, body),
                    }),
                    Location = new Location(1, 32, body),
                }),
                Location = new Location(1, 32, body),
            };

            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#7
0
        public void SimpleFieldWithArg()
        {
            var body = new Source(
                @"
type Hello {
  world(flag: Boolean): String
}".ToLF());
            var doc      = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create <SchemaDefinition>(
                    new TypeDefinition
                {
                    Name   = new Name("Hello", new Location(6, 11, body)),
                    Fields = ImmutableArray.Create(
                        new FieldDefinition
                    {
                        Name      = new Name("world", new Location(16, 21, body)),
                        Type      = new NamedType("String", 38, 44, body),
                        Arguments = ImmutableArray.Create(
                            new InputValueDefinition
                        {
                            Name     = new Name("flag", new Location(22, 26, body)),
                            Type     = new NamedType("Boolean", 28, 35, body),
                            Location = new Location(22, 35, body),
                        }),
                        Location = new Location(16, 44, body),
                    }),
                    Location = new Location(1, 46, body),
                }),
                Location = new Location(1, 46, body),
            };

            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#8
0
        EnumBuilder BuildEnumType(ModuleBuilder moduleBuilder, EnumSchema schema, SchemaDocument document)
        {
            var name = schema.Name.ToPascalCase();
            var attr = TypeAttributes.Public;
            var underlyingTypeDescription = BasicTypeDescriptions
                                            .BasicDescriptions[document.Basics[schema.Storage]];
            var underlingType = underlyingTypeDescription.UnderlyingType;
            var enumBuilder   = moduleBuilder.DefineEnum(name, attr, underlingType);

            return(enumBuilder);
        }
示例#9
0
        public DataReader(SchemaDocument document,
                          ReadBasicData readBasicFunc,
                          TryReadCompoundData readCompoundFunc = null)
        {
            Document              = document;
            ReadBasicFunc         = readBasicFunc;
            ReadExtraCompoundFunc = readCompoundFunc;

            Inheritance = document.InheritanceLookup;
            Expressions = document.ExpressionLookup;
        }
示例#10
0
        public SchemaView()
        {
            Document = new SchemaDocument();

            InitializeComponent();

            DocumentCommands.Add(new CommandInfo(new NullCommand((int)CommandManager.Priorities.ViewCommands), CommandManager.viewContext));                // Separator
            DocumentCommands.Add(new CommandInfo(new ZoomLevelCommand(), CommandManager.viewContext));
            DocumentCommands.Add(new CommandInfo(new ZoomOutCommand(), CommandManager.viewContext));
            DocumentCommands.Add(new CommandInfo(new ZoomInCommand(), CommandManager.viewContext));
        }
示例#11
0
        public SchemaBasicReaderBuilder(ModuleBuilder module, SchemaDocument document, Dictionary <string, Type> basicTypeMap)
        {
            BasicDescriptions = basicTypeMap
                                .Select(kvp => new BasicTypeDescription(kvp.Value, document.Basics[kvp.Key]))
                                .ToDictionary(desc => desc.Schema);

            var builder = CreateBasicReaderInterface(module, BasicDescriptions);

            IBasicReaderMethods = BasicDescriptions
                                  .ToDictionary(desc => desc.Key,
                                                desc => WriteBasicReaderMethod(builder, desc.Value));

            IBasicReaderType = builder.CreateType();
        }
示例#12
0
        public void Scalar()
        {
            var body     = new Source("scalar Hello");
            var doc      = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create <SchemaDefinition>(
                    new ScalarDefinition
                {
                    Name     = new Name("Hello", new Location(7, 12, body)),
                    Location = new Location(0, 12, body),
                }),
                Location = new Location(0, 12, body),
            };

            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#13
0
        public void SimpleTypeInheritingInterface()
        {
            var body     = new Source("type Hello implements World { }");
            var doc      = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create <SchemaDefinition>(
                    new TypeDefinition
                {
                    Name       = new Name("Hello", new Location(5, 10, body)),
                    Interfaces = ImmutableArray.Create(new NamedType("World", 22, 27, body)),
                    Location   = new Location(0, 31, body),
                }),
                Location = new Location(0, 31, body),
            };

            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#14
0
        public void SimpleUnion()
        {
            var body     = new Source("union Hello = World");
            var doc      = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create <SchemaDefinition>(
                    new UnionDefinition
                {
                    Name  = new Name("Hello", new Location(6, 11, body)),
                    Types = ImmutableArray.Create(
                        new NamedType("World", 14, 19, body)),
                    Location = new Location(0, 19, body),
                }),
                Location = new Location(0, 19, body),
            };

            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#15
0
        public void SimpleFieldWithTwoArgs()
        {
            var body = new Source(
                @"
type Hello {
  world(argOne: Boolean, argTwo: Int): String
}".ToLF());
            var doc      = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create <SchemaDefinition>(
                    new TypeDefinition
                {
                    Name   = new Name("Hello", new Location(6, 11, body)),
                    Fields = ImmutableArray.Create(
                        new FieldDefinition
                    {
                        Name      = new Name("world", new Location(16, 21, body)),
                        Type      = new NamedType("String", 53, 59, body),
                        Arguments = ImmutableArray.Create(
                            new InputValueDefinition
                        {
                            Name         = new Name("argOne", new Location(22, 28, body)),
                            Type         = new NamedType("Boolean", 30, 37, body),
                            DefaultValue = null,
                            Location     = new Location(22, 37, body),
                        },
                            new InputValueDefinition
                        {
                            Name         = new Name("argTwo", new Location(39, 45, body)),
                            Type         = new NamedType("Int", 47, 50, body),
                            DefaultValue = null,
                            Location     = new Location(39, 50, body),
                        }),
                        Location = new Location(16, 59, body),
                    }),
                    Location = new Location(1, 61, body),
                }),
                Location = new Location(1, 61, body),
            };

            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#16
0
        public void SingleValueEnum()
        {
            var body     = new Source("enum Hello { WORLD }");
            var doc      = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create <SchemaDefinition>(
                    new EnumDefinition
                {
                    Name   = new Name("Hello", new Location(5, 10, body)),
                    Values = ImmutableArray.Create(
                        new EnumValueDefinition("WORLD", new Location(13, 18, body))),
                    Location = new Location(0, 20, body),
                }),
                Location = new Location(0, 20, body),
            };

            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#17
0
        public SchemaConstructorBuilder(SchemaDocument doc,
                                        SchemaTypeBuilder types,
                                        SchemaFieldBuilder fields,
                                        SchemaBasicReaderBuilder basic)
        {
            Doc    = doc;
            Types  = types;
            Fields = fields;
            Basic  = basic;

            CompoundConstructors = Types.CompoundTypes
                                   .ToDictionary(
                kvp => kvp.Key,
                kvp => WriteCompoundConstructor(kvp.Value)
                );
            //NiObjectConstructors = Types.NiObjectTypes
            //    .ToDictionary(
            //        kvp => kvp.Key,
            //        kvp => kvp.Value.DefineDefaultConstructor(MethodAttributes.Public)
            //    );
        }
示例#18
0
        public void SimpleFieldWithListArg()
        {
            var body = new Source(
                @"
type Hello {
  world(things: [String]): String
}".ToLF());
            var doc      = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create <SchemaDefinition>(
                    new TypeDefinition
                {
                    Name   = new Name("Hello", new Location(6, 11, body)),
                    Fields = ImmutableArray.Create(
                        new FieldDefinition
                    {
                        Name      = new Name("world", new Location(16, 21, body)),
                        Type      = new NamedType("String", 41, 47, body),
                        Arguments = ImmutableArray.Create(
                            new InputValueDefinition
                        {
                            Name = new Name("things", new Location(22, 28, body)),
                            Type = new ListType
                            {
                                Type     = new NamedType("String", 31, 37, body),
                                Location = new Location(30, 38, body),
                            },
                            DefaultValue = null,
                            Location     = new Location(22, 38, body),
                        }),
                        Location = new Location(16, 47, body),
                    }),
                    Location = new Location(1, 49, body),
                }),
                Location = new Location(1, 49, body),
            };

            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
        private async void Loading()
        {
            if (File.Exists(FullPath))
            {
                if (_doc != null)
                {
                    Close();
                }

                await Task.Run(() =>
                {
                    Status = DocumentStatus.Loading;
                    try
                    {
                        _doc = new SchemaDocument();
                        _doc.Open(FullPath);
                        Phases.Add(new Phase()
                        {
                            Id = "ALL"
                        });
                        foreach (Phase phase in _doc.Phases)
                        {
                            Phases.Add(phase);
                        }
                        //Phases = new ObservableCollection<Phase>(_doc.Phases);
                        //Phases.Insert(0, new Phase() { Id = "ALL" });

                        Status = DocumentStatus.LoadedCorrectly;
                    }
                    catch (Exception ex)
                    {
                        Status  = DocumentStatus.LoadedFailure;
                        Message = ex.Message;
                    }
                });
            }
        }
示例#20
0
        /// <summary>
        /// Writes types for each niObject, compound, enum, bitflag and bitfield
        /// into a reflection module, as well as building constructors for each
        /// type.
        /// </summary>
        /// <param name="moduleBuilder">The module to write the types to</param>
        /// <param name="document">The base schema document that described the types in NIF.xml/BlockStructure format</param>
        /// <param name="basics">A map of basic type names to their primitive values</param>
        /// <param name="version">The specific version of the document to use</param>
        public SchemaDocumentBuilder(ModuleBuilder moduleBuilder,
                                     SchemaDocument document,
                                     Dictionary <string, Type> basics,
                                     VersionKey version)
        {
            Document          = document;
            SchemaBasicReader = new SchemaBasicReaderBuilder(moduleBuilder, document, basics);

            SchemaTypes        = new SchemaTypeBuilder(document, moduleBuilder, SchemaBasicReader);
            SchemaFields       = new SchemaFieldBuilder(this, version);
            SchemaInheritance  = new SchemaInheritanceBuilder(SchemaTypes);
            SchemaEnum         = new SchemaEnumBuilder(SchemaTypes);
            SchemaConstructors = new SchemaConstructorBuilder(document, SchemaTypes, SchemaFields, SchemaBasicReader);
            SchemaILBuilder    = new SchemaConstructorILBuilder(this);

            foreach (var enumBuilder in SchemaTypes.BuiltEnumsByName.Values)
            {
                enumBuilder.CreateTypeInfo();
            }
            foreach (var typeBuilder in SchemaTypes.BuiltTypesByName.Values)
            {
                typeBuilder.CreateTypeInfo();
            }
        }
示例#21
0
        public SchemaTypeBuilder(SchemaDocument document,
                                 ModuleBuilder moduleBuilder,
                                 SchemaBasicReaderBuilder basicBuilder)
        {
            Document = document;
            BasicTypeDescriptions = basicBuilder;

            CompoundTypes = document.Compounds
                            .ToDictionary(kvp => kvp.Value, kvp => BuildCompoundType(moduleBuilder, kvp.Value));
            NiObjectTypes = document.NiObjects
                            .ToDictionary(kvp => kvp.Value, kvp => BuildNiObjectType(moduleBuilder, kvp.Value));
            EnumTypes = document.Enums
                        .ToDictionary(kvp => kvp.Value, kvp => BuildEnumType(moduleBuilder, kvp.Value, document));
            BitFieldTypes = document.Bitfields
                            .ToDictionary(kvp => kvp.Value, kvp => BuildBitfieldType(moduleBuilder, kvp.Value));
            BitflagsTypes = document.Bitflags
                            .ToDictionary(kvp => kvp.Value, kvp => BuildBitflagType(moduleBuilder, kvp.Value, document));

            BuiltTypesByName = new List <(string, TypeBuilder)>()
                               .Concat(CompoundTypes.Select(kvp => (kvp.Key.Name, kvp.Value)))
                               .Concat(NiObjectTypes.Select(kvp => (kvp.Key.Name, kvp.Value)))
                               .Concat(BitFieldTypes.Select(kvp => (kvp.Key.Name, kvp.Value)))
                               .ToDictionary(pair => pair.Item1, pair => pair.Item2);
            BuiltEnumsByName = new List <(string, EnumBuilder)>()
                               .Concat(EnumTypes.Select(kvp => (kvp.Key.Name, kvp.Value)))
                               .Concat(BitflagsTypes.Select(kvp => (kvp.Key.Name, kvp.Value)))
                               .ToDictionary(pair => pair.Item1, pair => pair.Item2);

            SchemaTypesByName = new List <(string, Type)>()
                                .Concat(BasicTypeDescriptions.BasicDescriptions.Select(kvp => (kvp.Key.Name, kvp.Value.UnderlyingType)))
                                .Concat(BuiltTypesByName.Select(kvp => (kvp.Key, kvp.Value as Type)))
                                .Concat(BuiltEnumsByName.Select(kvp => (kvp.Key, kvp.Value as Type)))
                                .ToDictionary(pair => pair.Item1, pair => pair.Item2);
            TemplateTypeByName = CompoundTypes
                                 .ToDictionary(c => c.Key.Name, c => BuildTemplateType(c.Value, c.Key));
        }
示例#22
0
        public void SimpleInputObject()
        {
            var body = new Source(
@"
input Hello {
  world: String
}".ToLF());
            var doc = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create<SchemaDefinition>(
                    new InputObjectDefinition
                    {
                        Name = new Name("Hello", new Location(7, 12, body)),
                        Fields = ImmutableArray.Create(
                            new InputValueDefinition
                            {
                                Name = new Name("world", new Location(17, 22, body)),
                                Type = new NamedType("String", 24, 30, body),
                                Location = new Location(17, 30, body),
                            }),
                        Location = new Location(1, 32, body),
                    }),
                Location = new Location(1, 32, body),
            };
            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#23
0
        private void CreateMetadata()
        {
            SchemaDocument schema = new SchemaDocument();
            schema.Load(string.Concat(_toolsDir, "metamodelSchema.xml"));

            SyncCommand[] commands = McXmlSerializer.GetObjectFromFile<SyncCommand[]>(string.Concat(_toolsDir, "metamodelCommands.xml"));
            MetaModelSync.Execute(schema, commands);

            // Fill tables
            XmlDocument doc = new XmlDocument();
            doc.Load(Path.Combine(_toolsDir, "metamodelData.xml"));
            WriteTables(doc.SelectNodes("/dictionaries/dictionary"), _dbHelper, 0, 0, null, true, null);
        }
示例#24
0
 public void Scalar()
 {
     var body = new Source("scalar Hello");
     var doc = SchemaParser.ParseSchema(body);
     var expected = new SchemaDocument
     {
         Definitions = ImmutableArray.Create<SchemaDefinition>(
             new ScalarDefinition
             {
                 Name = new Name("Hello", new Location(7, 12, body)),
                 Location = new Location(0, 12, body),
             }),
         Location = new Location(0, 12, body),
     };
     doc.ShouldBeEquivalentToDeepDynamic(expected);
 }
示例#25
0
 public void UnionWithTwoTypes()
 {
     var body = new Source("union Hello = Wo | Rld");
     var doc = SchemaParser.ParseSchema(body);
     var expected = new SchemaDocument
     {
         Definitions = ImmutableArray.Create<SchemaDefinition>(
             new UnionDefinition
             {
                 Name = new Name("Hello", new Location(6, 11, body)),
                 Types = ImmutableArray.Create(
                     new NamedType("Wo", 14, 16, body),
                     new NamedType("Rld", 19, 22, body)),
                 Location = new Location(0, 22, body),
             }),
         Location = new Location(0, 22, body),
     };
     doc.ShouldBeEquivalentToDeepDynamic(expected);
 }
示例#26
0
        public void SimpleFieldWithTwoArgs()
        {
            var body = new Source(
                @"
type Hello {
  world(argOne: Boolean, argTwo: Int): String
}".ToLF());
            var doc = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create<SchemaDefinition>(
                    new TypeDefinition
                    {
                        Name = new Name("Hello", new Location(6, 11, body)),
                        Fields = ImmutableArray.Create(
                            new FieldDefinition
                            {
                                Name = new Name("world", new Location(16, 21, body)),
                                Type = new NamedType("String", 53, 59, body),
                                Arguments = ImmutableArray.Create(
                                    new InputValueDefinition
                                    {
                                        Name = new Name("argOne", new Location(22, 28, body)),
                                        Type = new NamedType("Boolean", 30, 37, body),
                                        DefaultValue = null,
                                        Location = new Location(22, 37, body),
                                    },
                                    new InputValueDefinition
                                    {
                                        Name = new Name("argTwo", new Location(39, 45, body)),
                                        Type = new NamedType("Int", 47, 50, body),
                                        DefaultValue = null,
                                        Location = new Location(39, 50, body),
                                    }),
                                Location = new Location(16, 59, body),
                            }),
                        Location = new Location(1, 61, body),
                    }),
                Location = new Location(1, 61, body),
            };
            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#27
0
        public void SimpleFieldWithListArg()
        {
            var body = new Source(
                @"
type Hello {
  world(things: [String]): String
}".ToLF());
            var doc = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create<SchemaDefinition>(
                    new TypeDefinition
                    {
                        Name = new Name("Hello", new Location(6, 11, body)),
                        Fields = ImmutableArray.Create(
                            new FieldDefinition
                            {
                                Name = new Name("world", new Location(16, 21, body)),
                                Type = new NamedType("String", 41, 47, body),
                                Arguments = ImmutableArray.Create(
                                    new InputValueDefinition
                                    {
                                        Name = new Name("things", new Location(22, 28, body)),
                                        Type = new ListType
                                        {
                                            Type = new NamedType("String", 31, 37, body),
                                            Location = new Location(30, 38, body),
                                        },
                                        DefaultValue = null,
                                        Location = new Location(22, 38, body),
                                    }),
                                Location = new Location(16, 47, body),
                            }),
                        Location = new Location(1, 49, body),
                    }),
                Location = new Location(1, 49, body),
            };
            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#28
0
        public void SchemaDocumentTest()
        {
            string        dir   = @"../../../../../testdata/";
            List <string> tests = new List <string>()
            {
                "mimetype",
                "cultures",
                "calendar-2017"
            };

            SchemaDocument        doc      = null;
            Reporter              report   = new Reporter();
            Func <string, string> replacer = new Func <string, string>((str) =>
            {
                return(Regex.Replace(str, "<div class=\"dateinfo\">(.+?)</div>", ""));
            });

            try
            {
                Stopwatch sw = Stopwatch.StartNew();

                PrintWorkingSet($"start of processing: ({DateTime.Now.ToShortTimeString()})");

                foreach (string test in tests)
                {
                    PrintWorkingSet($"pre processing of {test}");

                    string testsch = Path.Combine(dir, $"{test}.sch");
                    string testxml = Path.Combine(dir, $"{test}.xml");
                    string dstfile = Path.Combine(dir, $"{test}-result.json");
                    if (!File.Exists(testsch))
                    {
                        throw new FileNotFoundException();
                    }
                    if (!File.Exists(testxml))
                    {
                        throw new FileNotFoundException();
                    }

                    doc = new SchemaDocument();

                    doc.Open(testsch);
                    doc.Compile(Phase.ALL);

                    report.Results = doc.Validation(testxml);

#if true
                    report.Write(dstfile, new ReportJsonStrategy());
#else
                    // test result
                    string result = report.ToString(ExportFormats.Html);
                    // trusted result
                    string expected = File.ReadAllText(dstfile, Encoding.UTF8);

                    result   = replacer(result);
                    expected = replacer(expected);

                    Assert.AreEqual(result, expected, $"{test} not equals.");
#endif

                    doc?.Dispose();

                    PrintWorkingSet($"post processing of {test}");
                }

                sw.Stop();
                PrintWorkingSet($"end of processing: ({DateTime.Now.ToShortTimeString()}, {sw.ElapsedMilliseconds} ms)");
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
            }
        }
示例#29
0
        static void Execute(ArgumentInfo arginfo)
        {
            string disp_se      = ResultStatus.SyntaxError.DisplayName();
            string disp_fa      = ResultStatus.Assert.DisplayName();
            string disp_sr      = ResultStatus.Report.DisplayName();
            string reportheader = $"{disp_se} | {disp_fa} | {disp_sr}";
            string reportborder = new string('-', reportheader.Length);

            Console.ForegroundColor = ConsoleColor.Gray;

            SchemaDocument doc = null;

            try
            {
                doc = new SchemaDocument();

                doc.Open(arginfo.SchFile.FullName);
                doc.Compile(arginfo.Phase);

                ResultCollection results = new ResultCollection();
                foreach (FileInfo xmlfile in arginfo.XmlFiles)
                {
                    Console.WriteLine("");
                    Console.WriteLine($"> Validation Start of '{xmlfile.Name}' by '{doc.SchemaTmp.Name}'");

                    ResultCollection file_results = doc.Validation(xmlfile.FullName);

                    string se = String.Format("{0, " + disp_se.Length + "}", file_results.TotalSyntaxError);
                    string fa = String.Format("{0, " + disp_fa.Length + "}", file_results.TotalAssert);
                    string sr = String.Format("{0, " + disp_sr.Length + "}", file_results.TotalReport);
                    Console.WriteLine("  " + reportborder);
                    Console.WriteLine("  " + reportheader);
                    Console.WriteLine($"  {se} | {fa} | {sr}");
                    Console.WriteLine("  " + reportborder);

                    Console.WriteLine("> End of Validation");

                    results.AddRange(file_results);
                }
                if (results.Count > 0 && arginfo.OutFile != null)
                {
                    Reporter report = new Reporter();
                    report.Results = results;
                    IReportStrategy strategy = EmbeddReportStrategies.Find(arginfo.OutFormat);
                    if (strategy == null)
                    {
                        strategy = new ReportDefaultStrategy();
                    }

                    report.Write(arginfo.OutFile.FullName, strategy);
                }
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("");
                Console.WriteLine("COMPLETE!");
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("");
                Console.WriteLine("ERROR!");
                Console.WriteLine(ex.Message);
            }
            finally
            {
                doc?.Dispose();
            }
        }
示例#30
0
 public void DoubleValueEnum()
 {
     var body = new Source("enum Hello { WO, RLD }");
     var doc = SchemaParser.ParseSchema(body);
     var expected = new SchemaDocument
     {
         Definitions = ImmutableArray.Create<SchemaDefinition>(
             new EnumDefinition
             {
                 Name = new Name("Hello", new Location(5, 10, body)),
                 Values = ImmutableArray.Create(
                     new EnumValueDefinition("WO", new Location(13, 15, body)),
                     new EnumValueDefinition("RLD", new Location(17, 20, body))),
                 Location = new Location(0, 22, body),
             }),
         Location = new Location(0, 22, body),
     };
     doc.ShouldBeEquivalentToDeepDynamic(expected);
 }
示例#31
0
文件: Program.cs 项目: 0anion0/IBN
        static void UpdateMetaModel(string companyRoot, string commandsFilePath)
        {
            LogFile.WriteLine("Updating metamodel...");

            SchemaDocument schema = new SchemaDocument();
            schema.Load(Path.Combine(companyRoot, @"Tools\metamodelSchema.xml"));

            SyncCommand[] commands = McXmlSerializer.GetObjectFromFile<SyncCommand[]>(commandsFilePath);

            MetaModelSync.Execute(schema, commands);

            LogWriteOk();
        }
示例#32
0
        EnumBuilder BuildBitflagType(ModuleBuilder moduleBuilder, BitflagsSchema schema, SchemaDocument document)
        {
            var name = schema.Name.ToPascalCase();
            var attr = TypeAttributes.Public;
            var underlyingTypeDescription = BasicTypeDescriptions
                                            .BasicDescriptions[document.Basics[schema.Storage]];

            Type            flagsAttributeType   = typeof(FlagsAttribute);
            ConstructorInfo attributeConstructor = flagsAttributeType.GetConstructor(new Type[] { });

            var underlingType  = underlyingTypeDescription.UnderlyingType;
            var bitflagBuilder = moduleBuilder.DefineEnum(name, attr, underlingType);

            //bitflagBuilder.SetCustomAttribute(attributeConstructor, new byte[] { 01, 00, 01 });
            return(bitflagBuilder);
        }
示例#33
0
 public void SimpleTypeInheritingMultipleInterfaces()
 {
     var body = new Source("type Hello implements Wo, rld { }");
     var doc = SchemaParser.ParseSchema(body);
     var expected = new SchemaDocument
     {
         Definitions = ImmutableArray.Create<SchemaDefinition>(
             new TypeDefinition
             {
                 Name = new Name("Hello", new Location(5, 10, body)),
                 Interfaces = ImmutableArray.Create(
                     new NamedType("Wo", 22, 24, body),
                     new NamedType("rld", 26, 29, body)),
                 Location = new Location(0, 33, body),
             }),
         Location = new Location(0, 33, body),
     };
     doc.ShouldBeEquivalentToDeepDynamic(expected);
 }
示例#34
0
        public void SimpleInterface()
        {
            var body = new Source(
                @"
interface Hello {
  world: String
}".ToLF());
            var doc = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create<SchemaDefinition>(
                    new InterfaceDefinition
                    {
                        Name = new Name("Hello", new Location(11, 16, body)),
                        Fields = ImmutableArray.Create(
                            new FieldDefinition
                            {
                                Name = new Name("world", new Location(21, 26, body)),
                                Type = new NamedType("String", 28, 34, body),
                                Location = new Location(21, 34, body),
                            }),
                        Location = new Location(1, 36, body),
                    }),
                Location = new Location(1, 36, body),
            };
            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#35
0
 public virtual TResult VisitSchemaDocument(SchemaDocument node)
 {
     return(DefaultVisit(node));
 }
示例#36
0
        public void SimpleFieldWithArgWithDefaultValue()
        {
            var body = new Source(
                @"
type Hello {
  world(flag: Boolean = true): String
}".ToLF());
            var doc = SchemaParser.ParseSchema(body);
            var expected = new SchemaDocument
            {
                Definitions = ImmutableArray.Create<SchemaDefinition>(
                    new TypeDefinition
                    {
                        Name = new Name("Hello", new Location(6, 11, body)),
                        Fields = ImmutableArray.Create(
                            new FieldDefinition
                            {
                                Name = new Name("world", new Location(16, 21, body)),
                                Type = new NamedType("String", 45, 51, body),
                                Arguments = ImmutableArray.Create(
                                    new InputValueDefinition
                                    {
                                        Name = new Name("flag", new Location(22, 26, body)),
                                        Type = new NamedType("Boolean", 28, 35, body),
                                        DefaultValue = new BooleanValue
                                        {
                                            Value = true,
                                            Location = new Location(38, 42, body),
                                        },
                                        Location = new Location(22, 42, body),
                                    }),
                                Location = new Location(16, 51, body),
                            }),
                        Location = new Location(1, 53, body),
                    }),
                Location = new Location(1, 53, body),
            };
            doc.ShouldBeEquivalentToDeepDynamic(expected);
        }
示例#37
0
文件: Program.cs 项目: 0anion0/IBN
        static void UpdateMetaModel(string commandsFilePath)
        {
            LogFile.WriteLine("Updating metamodel...");

            SchemaDocument schema = new SchemaDocument();
            schema.Load(Path.Combine(Settings.InstallDir, @"Code\_Source\Tools\metamodelSchema.xml"));

            SyncCommand[] commands = McXmlSerializer.GetObjectFromFile<SyncCommand[]>(commandsFilePath);

            using (DataContext dataContext = new DataContext(string.Empty))
            {
                DataContext.Current = dataContext;
                dataContext.SqlContext.CommandTimeout = CommandTimeout;
                SqlTransaction previousTransaction = DataContext.Current.SqlContext.Transaction;
                using (DBTransaction tran = DBHelper2.DBHelper.BeginTransaction())
                {
                    DataContext.Current.SqlContext.Transaction = tran.SqlTran;
                    try
                    {
                        MetaModelSync.Execute(schema, commands);
                        tran.Commit();
                        LogWriteOk();
                    }
                    finally
                    {
                        DataContext.Current.SqlContext.Transaction = previousTransaction;
                    }
                }
            }
        }