コード例 #1
0
ファイル: Tester.cs プロジェクト: antonnovik/knowledge-net
        public static void Main(String[] args)
        {
            Console.WriteLine("start");
            ExpComp.Clear();
            Scanner scanner = new Scanner("D:\\temp\\1.exp");

            ExpComp.parser = new Parser(scanner);
            ExpComp.parser.Parse();

//            foreach (DataFrame frame in ExpComp.dataFrames.Values) {
//                Console.WriteLine(frame.ToString());
//            }
            IModelBuilder modelBuilder = ModelBuilderFactory.getInstance().createBuilder(ModelBuilderFactory.KIF);

            converters.Converter converter = new converters.Converter(modelBuilder);
            IModel             model       = converter.convert(ExpComp.dataFrames.Values);
            SimpleKifFormatter formatter   = new SimpleKifFormatter();

            formatter.write(model, Console.Out);

            //           model.store(Console.Out);


/*
 *          string text = IOUtils.readText("d:\\test\\t.txt");
 *          Console.WriteLine(text);
 *          DependenciesManager dependenciesManager = new DependenciesManager("d:\\test\\t.txt");
 *          dependenciesManager.print();
 */

            Console.ReadKey();
        }
コード例 #2
0
        public SqlServerDataStoreServices(
            [NotNull] SqlServerDataStore store,
            [NotNull] SqlServerDataStoreCreator creator,
            [NotNull] SqlServerConnection connection,
            [NotNull] SqlServerValueGeneratorCache valueGeneratorCache,
            [NotNull] SqlServerDatabase database,
            [NotNull] ModelBuilderFactory modelBuilderFactory,
            [NotNull] SqlServerMigrator migrator)
        {
            Check.NotNull(store, "store");
            Check.NotNull(creator, "creator");
            Check.NotNull(connection, "connection");
            Check.NotNull(valueGeneratorCache, "valueGeneratorCache");
            Check.NotNull(database, "database");
            Check.NotNull(modelBuilderFactory, "modelBuilderFactory");
            Check.NotNull(migrator, "migrator");

            _store               = store;
            _creator             = creator;
            _connection          = connection;
            _valueGeneratorCache = valueGeneratorCache;
            _database            = database;
            _modelBuilderFactory = modelBuilderFactory;
            _migrator            = migrator;
        }
コード例 #3
0
        private static IModel BuildModel()
        {
            var builder = new ModelBuilderFactory().CreateConventionBuilder();

            builder.Entity <Product>(b =>
            {
                b.Reference(e => e.AlternateProduct).InverseReference(e => e.OriginalProduct)
                .ForeignKey <Product>(e => e.AlternateProductId);

                b.Reference(e => e.Detail).InverseReference(e => e.Product)
                .ForeignKey <ProductDetail>(e => e.Id);
            });

            builder.Entity <Category>().Collection(e => e.Products).InverseReference(e => e.Category);

            builder.Entity <ProductDetail>();

            builder.Entity <ProductPhoto>(b =>
            {
                b.Key(e => new { e.ProductId, e.PhotoId });
                b.Collection(e => e.ProductTags).InverseReference(e => e.Photo)
                .ForeignKey(e => new { e.ProductId, e.PhotoId });
            });

            builder.Entity <ProductReview>(b =>
            {
                b.Key(e => new { e.ProductId, e.ReviewId });
                b.Collection(e => e.ProductTags).InverseReference(e => e.Review)
                .ForeignKey(e => new { e.ProductId, e.ReviewId });
            });

            builder.Entity <ProductTag>();

            return(builder.Model);
        }
コード例 #4
0
        private void Test(Action <ModelBuilder> buildModel, string expectedCode, Action <IModel> assert)
        {
            var modelBuilder = new ModelBuilderFactory().CreateConventionBuilder();

            buildModel(modelBuilder);
            var model = modelBuilder.Model;

            var generator = new CSharpModelGenerator(new CSharpHelper());

            var builder = new IndentedStringBuilder();

            generator.Generate(model, builder);
            var code = builder.ToString();

            Assert.Equal(expectedCode, code);

            var build = new BuildSource
            {
                References =
                {
                    BuildReference.ByName("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"),
                    BuildReference.ByName("System.Linq.Expressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
                    BuildReference.ByName("System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
                    BuildReference.ByName("EntityFramework.Core"),
                    BuildReference.ByName("EntityFramework.Relational"),
                },
                Sources = { @"
                    using System;
                    using Microsoft.Data.Entity;
                    using Microsoft.Data.Entity.Metadata;
                    using Microsoft.Data.Entity.Metadata.ModelConventions;
                    using Microsoft.Data.Entity.Relational.Migrations.Infrastructure;

                    
                    public static class ModelSnapshot
                    {
                        public static IModel Model
                        {
                            get
                            {
                                var builder = new ModelBuilder(new ConventionSet());
                                " + code + @"

                                return builder.Model;
                            }
                        }
                   }
                " }
            };

            var assembly    = build.BuildInMemory();
            var factoryType = assembly.GetType("ModelSnapshot");
            var property    = factoryType.GetProperty("Model");
            var value       = (IModel)property.GetValue(null);

            Assert.NotNull(value);
            assert(value);
        }
コード例 #5
0
        private static Model CreateModel()
        {
            var model        = new Model();
            var modelBuilder = new ModelBuilderFactory().CreateConventionBuilder(model);

            modelBuilder.Entity <Customer>();

            return(model);
        }
コード例 #6
0
 public FakeDataStoreServices(
     FakeDataStore store,
     RecordingDataStoreCreator creator,
     FakeRelationalConnection connection,
     FakeValueGeneratorCache valueGeneratorCache,
     FakeDatabase database,
     ModelBuilderFactory modelBuilderFactory,
     TestMigrator migrator)
 {
     _store               = store;
     _creator             = creator;
     _connection          = connection;
     _valueGeneratorCache = valueGeneratorCache;
     _database            = database;
     _modelBuilderFactory = modelBuilderFactory;
     _migrator            = migrator;
 }
コード例 #7
0
        private string[] CONVERTER_TYPES = { ModelBuilderFactory.KIF, ModelBuilderFactory.ONTOLINGUA };//TODO:

        private void okButtonClick(object sender, EventArgs e)
        {
            //TODO: validate();
            string fileName = _outputPathField.Text;

            string converterType = CONVERTER_TYPES[_outputFormatBox.SelectedIndex];

//            IConverter converter = ConverterFactory.getInstance().getConverter(converterType);

            //TODO: ask rewrite if exists
            IOUtils.createOrRewriteFile(fileName);

            /*          IWriter writer = WriterFactory.createFileWriter(fileName);
             *        writer.open();*/
            StreamWriter writer = new StreamWriter(fileName);

            IModelBuilder modelBuilder = ModelBuilderFactory.getInstance().createBuilder(converterType);

            converters.Converter converter = new converters.Converter(modelBuilder);
            IModel             model       = converter.convert(ExpComp.dataFrames.Values);
            SimpleKifFormatter formatter   = new SimpleKifFormatter();

            formatter.write(model, writer);


//            ICollection<Object> convertedItems = converter.convert(getSourceModel());

//            writer.write(convertedItems);
            writer.Flush();
            writer.Close();
            Close();
            //ACTION

            DialogResult reply = MessageBox.Show("Would you like to view generated file?",
                                                 "Transformation finished", MessageBoxButtons.YesNo, MessageBoxIcon.Question);//TODO:

            if (reply == DialogResult.Yes)
            {
                Window textEditor = _environment.OpenFile(Constants.vsViewKindCode, fileName);
                textEditor.Visible = true;
                textEditor.Activate();
            }
        }
コード例 #8
0
        protected static Model CreateModel()
        {
            var model        = new Model();
            var modelBuilder = new ModelBuilderFactory().CreateConventionBuilder(model);

            modelBuilder
            .Entity <Address>(e => e.HasOne(a => a.Resident).WithOne(p => p.Address));

            // TODO: Bug #1116
            modelBuilder.Entity <Address>().Property(a => a.Id).GenerateValueOnAdd(false);

            modelBuilder.Entity <Address2>().Property <int>("PersonId");

            modelBuilder
            .Entity <Person2>(
                e => e.HasOne(p => p.Address).WithOne(a => a.Resident)
                .ForeignKey(typeof(Address2), "PersonId"));

            return(model);
        }
コード例 #9
0
ファイル: CoreModule.cs プロジェクト: BennyJ1982/SAPI
        /// <summary>
        /// This Operation is called, when the module shall initialize itself.
        /// </summary>
        /// <param name="typeRegistry">The type registry for service requests or registrations.</param>
        /// <inheritdoc/>
        public void Initialize(ITypeRegistry typeRegistry)
        {
            var odataObjectFactory = new ODataObjectFactory();

            var pathService                      = new ODataPathService();
            var modelItemNamingService           = new ModelItemNamingService();
            var navigationPropertyBuilderFactory = new NavigationPropertyBuilderFactory(modelItemNamingService);

            var modelBuilderFactory     = new ModelBuilderFactory(pathService, navigationPropertyBuilderFactory);
            var queryBuilderFactory     = new QueryBuilderFactory();
            var operationContextFactory = new OperationContextFactory(pathService);
            var dataTypeRegistry        = new DataTypeRegistry(new DefaultDataTypeKeyLookupStrategy());

            typeRegistry.RegisterInstance <IModelBuilderFactory>(modelBuilderFactory);
            typeRegistry.RegisterInstance <IDataTypeRegistry>(dataTypeRegistry);
            typeRegistry.RegisterInstance <IODataObjectFactory>(odataObjectFactory);
            typeRegistry.RegisterInstance <IODataPathService>(pathService);
            typeRegistry.RegisterInstance <IOperationContextFactory>(operationContextFactory);
            typeRegistry.RegisterInstance <IModelItemNamingService>(modelItemNamingService);
            typeRegistry.RegisterInstance <IQueryBuilderFactory>(queryBuilderFactory);
        }
コード例 #10
0
        public SQLiteDataStoreServices(
            [NotNull] SQLiteDataStore store,
            [NotNull] SQLiteDataStoreCreator creator,
            [NotNull] SQLiteConnection connection,
            [NotNull] SQLiteValueGeneratorCache valueGeneratorCache,
            [NotNull] RelationalDatabase database,
            [NotNull] ModelBuilderFactory modelBuilderFactory)
        {
            Check.NotNull(store, "store");
            Check.NotNull(creator, "creator");
            Check.NotNull(connection, "connection");
            Check.NotNull(valueGeneratorCache, "valueGeneratorCache");
            Check.NotNull(database, "database");
            Check.NotNull(modelBuilderFactory, "modelBuilderFactory");

            _store               = store;
            _creator             = creator;
            _connection          = connection;
            _valueGeneratorCache = valueGeneratorCache;
            _database            = database;
            _modelBuilderFactory = modelBuilderFactory;
        }
コード例 #11
0
        private static IModel BuildModel()
        {
            var model   = new Model();
            var builder = new ModelBuilderFactory().CreateConventionBuilder(model);

            builder.Entity <Product>(b =>
            {
                b.HasOne(e => e.AlternateProduct).WithOne(e => e.OriginalProduct)
                .ForeignKey <Product>(e => e.AlternateProductId);

                b.HasOne(e => e.Detail).WithOne(e => e.Product)
                .ForeignKey <ProductDetail>(e => e.Id);
            });

            builder.Entity <Category>().HasMany(e => e.Products).WithOne(e => e.Category);

            builder.Entity <ProductDetail>();

            builder.Entity <ProductPhoto>(b =>
            {
                b.Key(e => new { e.ProductId, e.PhotoId });
                b.HasMany(e => e.ProductTags).WithOne(e => e.Photo)
                .ForeignKey(e => new { e.ProductId, e.PhotoId });
            });

            builder.Entity <ProductReview>(b =>
            {
                b.Key(e => new { e.ProductId, e.ReviewId });
                b.HasMany(e => e.ProductTags).WithOne(e => e.Review)
                .ForeignKey(e => new { e.ProductId, e.ReviewId });
            });

            builder.Entity <ProductTag>();

            return(model);
        }
コード例 #12
0
        private void Test(Action<ModelBuilder> buildModel, string expectedCode, Action<IModel> assert)
        {
            var modelBuilder = new ModelBuilderFactory().CreateConventionBuilder();
            buildModel(modelBuilder);
            var model = modelBuilder.Model;

            var generator = new CSharpModelGenerator(new CSharpHelper());

            var builder = new IndentedStringBuilder();
            generator.Generate(model, builder);
            var code = builder.ToString();

            Assert.Equal(expectedCode, code);

            var build = new BuildSource
            {
                References =
                {
                    BuildReference.ByName("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"),
                    BuildReference.ByName("System.Linq.Expressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
                    BuildReference.ByName("System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
                    BuildReference.ByName("EntityFramework.Core"),
                    BuildReference.ByName("EntityFramework.Relational"),
                },
                Sources = { @"
                    using System;
                    using Microsoft.Data.Entity;
                    using Microsoft.Data.Entity.Metadata;
                    using Microsoft.Data.Entity.Metadata.ModelConventions;
                    using Microsoft.Data.Entity.Relational.Migrations.Infrastructure;

                    
                    public static class ModelSnapshot
                    {
                        public static IModel Model
                        {
                            get
                            {
                                var builder = new ModelBuilder(new ConventionSet());
                                " + code + @"

                                return builder.Model;
                            }
                        }
                   }
                " }
            };

            var assembly = build.BuildInMemory();
            var factoryType = assembly.GetType("ModelSnapshot");
            var property = factoryType.GetProperty("Model");
            var value = (IModel)property.GetValue(null);

            Assert.NotNull(value);
            assert(value);
        }