Ejemplo n.º 1
0
 private EntityContextFactory CreateEntityContextFactory()
 {
     return(EntityContextFactory
            .FromConfiguration(DescriptionConfigurationSection.Default.DefaultStoreFactoryName)
            .WithDefaultOntologies()
            .WithDotNetRDF(_tripleStore.Value));
 }
Ejemplo n.º 2
0
        private IEntityContext CreateEntityContext(IKernel kernel, CreationContext context)
        {
            IEntityContext result = null;

            lock (_lock)
            {
                EntityContextFactory entityContextFactory = _entityContextFactory.Value;
                if (!_isNamedGraphSelectorInitialized)
                {
                    entityContextFactory             = entityContextFactory.WithNamedGraphSelector(kernel.Resolve <INamedGraphSelector>());
                    _isNamedGraphSelectorInitialized = true;
                }

                if (!_isBaseUriInitialized)
                {
                    var baseUri = kernel.Resolve <IHttpServerConfiguration>().BaseUri;
                    if (baseUri != null)
                    {
                        _isBaseUriInitialized = true;
                        result = entityContextFactory.WithBaseUri(policy => policy.Default.Is(baseUri)).CreateContext();
                    }
                }

                if (result == null)
                {
                    result = entityContextFactory.CreateContext();
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        protected virtual void MoveItem(PlatformItem item, IPlatformModule targetModule)
        {
            if (item == null)
            {
                return;
            }

            var c = EntityContextFactory.CreateContext();

            c.Attach(Entities);

            ReleaseLinks(item);
            c.SaveEntityStateAsyncAndDispose();

            var context = EntityContextFactory.CreateContext();

            context.Attach(((PlatformModule)targetModule).Entities);
            context.Attach(item);
            item.AssociatedPlatformModuleEntity = ((PlatformModule)targetModule).Entities;
            context.SaveEntityStateAsyncAndDispose();
            Entities.PlatformItems.Remove(item);
            targetModule.AddItem(item);

            ItemRoutings.Remove(item);

            CurrentItemCountChangedEvent(this, new ItemCountChangedEventArgs(CurrentItemCount));
        }
Ejemplo n.º 4
0
        public void GivenTwoLinkedItems_WhenMoveOne_ShouldReleaseLinks()
        {
            var logger = new Mock <ILogger>();
            var entityContextFactory = new EntityContextFactory(logger.Object);
            var dummy = new PlatformModule
            {
                EntityContextFactory = entityContextFactory,
                Logger = logger.Object,
                CompositeAlarmManager = new CompositeAlarmManager(logger.Object),
                Name = string.Empty
            };

            dummy.Construct();
            var item1 = new PlatformItem {
                ItemId = 1
            };
            var item2 = new PlatformItem {
                ItemId = 2
            };

            item1.ItemBehind  = item2;
            item2.ItemInFront = item1;
            _testee.AddItem(item1);
            _testee.AddItem(item2);

            _testee.MoveItem(item1.ItemId, dummy);

            item1.ItemInFront.Should().BeNull();
            item1.ItemBehind.Should().BeNull();
            item2.ItemInFront.Should().BeNull();
            item2.ItemBehind.Should().BeNull();
        }
Ejemplo n.º 5
0
 public EntityRepository(
     EntityContextFactory entityContextFactory,
     Deserializer deserializer)
 {
     _entityContextFactory = entityContextFactory;
     _deserializer         = deserializer;
 }
        /// <summary>Sets up the factory to use <see cref="BaseUriResolutionStrategyComposition" /> for resolving external resources.</summary>
        /// <remarks>
        /// This implementation checks if a resource's identifier matches given <paramref name="baseUris" />
        /// and then resolves by making a <see cref="WebRequest" /> to resource's identifier.
        /// </remarks>
        /// <param name="factory">Target factory to be configured.</param>
        /// <param name="baseUris">Base Uris to match for external resources.</param>
        /// <returns>Given <paramref name="factory" />.</returns>
        public static EntityContextFactory WithUriMatchingResourceResulutionStrategy(this EntityContextFactory factory, IEnumerable <Uri> baseUris)
        {
            factory.WithDependencies <BaseUriResolutionStrategyComposition>();
            var resolutionStrategy = new UrlMatchingResourceResolutionStrategy(
                factory.Ontologies,
                factory.MappingModelVisitors.OfType <BaseUriMappingModelVisitor>().First().MappingAssemblies,
                baseUris);

            return(factory.WithResourceResolutionStrategy(resolutionStrategy));
        }
Ejemplo n.º 7
0
        public static void InitContext()
        {
            var contextFactory = new EntityContextFactory();

            contextFactory.WithMappings((MappingBuilder builder) =>
            {
                builder.FromAssemblyOf <INode>();
            });

            store = new TripleStore();
            contextFactory.WithDotNetRDF(store);
            contextFactory.WithMetaGraphUri(new Uri(clientURI));
            context = contextFactory.CreateContext();
        }
Ejemplo n.º 8
0
        public void Setup()
        {
            var container = new ServiceContainer();
            var logger = new Mock<ILogger>();
            logger.Setup(instance => instance.Log(It.IsAny<LogLevel>(), It.IsAny<string>(), It.IsAny<object[]>()));
            logger.Setup(instance => instance.Log(It.IsAny<LogLevel>(), It.IsAny<Exception>(), It.IsAny<string>(), It.IsAny<object[]>()));
            container.RegisterInstance(logger.Object);
            container.Register<MappingFromAttributes>();
            container.Register<MappingFromFluent>();
            IEntityContextFactory factory = new EntityContextFactory(container)
               .WithDefaultOntologies()
               .WithMetaGraphUri(new Uri("http://app.magi/graphs"))
               .WithDependenciesInternal<Dependencies>();

            _entityContext = factory.CreateContext();
        }
Ejemplo n.º 9
0
        private IEntityContext CreateEntityContext(IOntologyProvider ontologyProvider, IEnumerable <Assembly> mappingAssemblies)
        {
            var factory = new EntityContextFactory()
                          .WithMappings(builder => BuildMappingAssemblies(builder, mappingAssemblies))
                          .WithDefaultOntologies()
                          .WithMetaGraphUri(_metaGraph.BaseUri)
                          .WithNamedGraphSelector(_namedGraphSelector)
                          .WithDotNetRDF(_tripleStore);

            if (ontologyProvider != null)
            {
                factory = factory.WithOntology(ontologyProvider);
            }

            return(factory.CreateContext());
        }
Ejemplo n.º 10
0
        public void SetUp()
        {
            var entityContextFactory = new EntityContextFactory(new Mock <ILogger>().Object);

            _eventAggregator = new Mock <IEventAggregator>();
            _logger          = new Mock <ILogger>();
            _fileSystem      = new Mock <IPathExists>();
            _jobContainer    = new JobContainer(_logger.Object, entityContextFactory, new Mock <IPlatformModuleEntities>().Object);

            _testee = new JobManager();

            var setupTestee = new PrivateObject(_testee);

            setupTestee.SetFieldOrProperty("Logger", _logger.Object);
            setupTestee.SetFieldOrProperty("EventAggregator", _eventAggregator.Object);
            setupTestee.SetFieldOrProperty("Jobs", _jobContainer);
        }
Ejemplo n.º 11
0
        protected virtual void RemoveItem(PlatformItem item)
        {
            if (item == null)
            {
                return;
            }

            Entities.PlatformItems.Remove(item);

            var context = EntityContextFactory.CreateContext();

            context.Delete(item);
            context.SaveEntityStateAsyncAndDispose();

            ItemRoutings.Remove(item);

            CurrentItemCountChangedEvent(this, new ItemCountChangedEventArgs(CurrentItemCount));
        }
Ejemplo n.º 12
0
        public void Setup()
        {
            _store = new TripleStore();
            _store.LoadTestFile("TriplesWithLiteralSubjects.trig");

            var container = new ServiceContainer();

            container.RegisterInstance <ITripleStore>(_store);

            IEntityContextFactory factory = new EntityContextFactory(container)
                                            .WithDefaultOntologies()
                                            .WithEntitySource <TripleStoreAdapter>()
                                            .WithMetaGraphUri(new Uri("http://app.magi/graphs"))
                                            .WithDependenciesInternal <Dependencies>();

            _typeCache = (TestCache)container.GetInstance <IRdfTypeCache>();

            _entityContext = factory.CreateContext();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Raises an event to notify LineControl that an item was discovered (independently whether it's a new or old item).
        /// </summary>
        protected void RaisePlatformItemDetected(long itemId)
        {
            var item = GetItem(itemId);

            if (item != null)
            {
                item.LastDetectionTime = DateTime.Now;
                item.DetectedInModuleCount++;
                item.DetectedCount++;

                using (var context = EntityContextFactory.CreateContext())
                {
                    context.UpdateField(item, a => a.DetectedCount);
                    context.UpdateField(item, a => a.DetectedInModuleCount);
                    context.UpdateField(item, a => a.LastDetectionTime);
                }
            }

            EventAggregator.Publish(new PlatformItemEvent(itemId, this, PlatformItemEventType.ItemDetected));
        }
Ejemplo n.º 14
0
        public void Setup()
        {
            Mappings = SetupMappings();

            _container = new ServiceContainer();
            _store     = CreateTripleStore();
            EntityContextFactory factory = new EntityContextFactory(_container)
                                           .WithOntology(new DefaultOntologiesProvider())
                                           .WithOntology(new LifeOntology())
                                           .WithOntology(new TestOntologyProvider(IncludeFoaf))
                                           .WithOntology(new ChemOntology())
                                           .WithMappings(BuildMappings)
                                           .WithMetaGraphUri(MetaGraphUri)
                                           .WithDotNetRDF(_store)
                                           .WithBaseUri(b => b.Default.Is(new Uri("http://example.com/")));

            factory.ThreadSafe   = ThreadSafe;
            factory.TrackChanges = TrackChanges;
            _factory             = factory;
            ChildSetup();
        }
Ejemplo n.º 15
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Initialises this object.
        /// </summary>
        ///-------------------------------------------------------------------------------------------------

        public static void Init()
        {
            EntityContextFactory.Initalize();
            Container.Bind <IUnitOfWork>().ToMethod(
                () =>
            {
                string nameOrConnectionString  = null;
                var overriddenConnectionString = WebConfigurationManager.AppSettings["Framework.RepositoryContext"];
                if (!string.IsNullOrWhiteSpace(overriddenConnectionString))
                {
                    nameOrConnectionString = overriddenConnectionString;
                }

                if (string.IsNullOrWhiteSpace(nameOrConnectionString))
                {
                    nameOrConnectionString = "AppContext";
                }

                return(new UnitOfWork(nameOrConnectionString));
            }).InRequestScope();
        }
Ejemplo n.º 16
0
        private static IEntityContext CreateEntityContext()
        {
            var entityContextFactory = new EntityContextFactory()
                                       .WithMetaGraphUri(MetaGraphUri)
                                       .WithMappings(builder => builder.FromAssemblyOf <IKnowSomething>())
                                       .WithDefaultOntologies()
                                       .WithOntology(new IntegrationTestsBase.ChemOntology())
                                       .WithOntology(new IntegrationTestsBase.LifeOntology())
                                       .WithOntology(new TestOntologyProvider(false))
                                       .WithNamedGraphSelector(new NamedGraphSelector())
                                       .WithDependenciesInternal <BaseUriResolutionStrategyComposition>()
                                       .WithDotNetRDF(CreateTripleStore());
            var resolutionStrategy = new UrlMatchingResourceResolutionStrategy(
                entityContextFactory.Ontologies,
                entityContextFactory.MappingModelVisitors.OfType <BaseUriMappingModelVisitor>().First().MappingAssemblies,
                BaseUris,
                CreateWebRequest);

            return(entityContextFactory
                   .WithResourceResolutionStrategy(resolutionStrategy)
                   .CreateContext());
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Adds item to the module and schedules a persistance action to store the data in the db.
        /// The contract is that each item with Id = 0 is a new item to be created unless there is an item with the
        /// same ItemId already read from the database. In that case the database object is used. Otherwise
        /// a new platfrom item is created in the database.
        /// </summary>
        /// <param name="item"></param>
        public virtual void AddItem(PlatformItem item)
        {
            if (item == null)
            {
                return;
            }

            var context = EntityContextFactory.CreateContext();

            context.Attach(Entities);
            if (item.Id == 0)
            {
                var previouslyAddedItem = PlatformModuleEntities.GetAll().SelectMany(a => a.PlatformItems).FirstOrDefault(b => b.ItemId == item.ItemId);
                if (previouslyAddedItem != null)
                {
                    context.Detach(previouslyAddedItem);
                    Entities.PlatformItems.Remove(previouslyAddedItem);
                    item.Id = item.ItemId;
                    context.Update(item);
                }
                else
                {
                    item.Id = item.ItemId;
                    context.Add(item);
                }
            }
            else
            {
                context.Attach(item);
            }

            item.AssociatedPlatformModuleEntity = Entities;
            context.SaveEntityStateAsyncAndDispose();
            Entities.PlatformItems.Add(item);

            OverallItemCount++;
            CurrentItemCountChangedEvent(this, new ItemCountChangedEventArgs(CurrentItemCount));
        }
Ejemplo n.º 18
0
    static void Main()
    {
        ITripleStore store = new TripleStore();

        store.LoadFromFile("input.trig");
        var factory = new EntityContextFactory();

        // it is also possible to add fluent/attribute mappings separately
        factory.WithMappings(mb => mb.FromAssemblyOf <IPerson>());

        // this is necessary to tell where entities' data is stored in named graphs
        // see the input.trig file to find out how it does that
        factory.WithMetaGraphUri(new Uri("http://romanticweb.net/samples"));

        // this API bound to change in the future so that custom
        // namespaces can be added easily
        factory.WithOntology(new DefaultOntologiesProvider(BuiltInOntologies.DCTerms |
                                                           BuiltInOntologies.FOAF));

        factory.WithDotNetRDF(store);

        var context = factory.CreateContext();

        foreach (var person in context.AsQueryable <IPerson>().Where(p => p.Name != "Karol"))
        {
            var pubId = "http://romanticweb.net/samples/publication/" + Guid.NewGuid();
            var pub   = context.Create <IPublication>(pubId);
            pub.Title = string.Format("Publication about RDF by {0} {1}",
                                      person.Name, person.LastName);
            pub.DatePublished = DateTime.Now;

            person.Publications.Add(pub);
        }

        context.Commit();

        store.SaveToFile("output.trig", new TriGWriter());
    }
 /// <summary>
 /// Sets up the <paramref name="factory"/> with components required to use dotNetRDF
 /// and supplies a triple store name configured in app.config/web.config
 /// </summary>
 public static EntityContextFactory WithDotNetRDF(this EntityContextFactory factory, string storeName)
 {
     ((IComponentRegistryFacade)factory).Register(Configuration.StoresConfigurationSection.Default.CreateStore(storeName));
     return(WithDotNetRDF(factory));
 }
 /// <summary>Sets up the <paramref name="factory"/> with components required to use dotNetRDF and supplies a triple store instance.</summary>
 public static EntityContextFactory WithDotNetRDF(this EntityContextFactory factory, ITripleStore store)
 {
     ((IComponentRegistryFacade)factory).Register(store);
     return(WithDotNetRDF(factory));
 }
 /// <summary>Sets up the <paramref name="factory"/> with components required to use dotNetRDF.</summary>
 public static EntityContextFactory WithDotNetRDF(this EntityContextFactory factory)
 {
     return(factory.WithDependencies <Components>()
            .WithEntitySource <TripleStoreAdapter>());
 }
 public void Setup()
 {
     _ontology = new Mock<IOntologyProvider>();
     _ontology.Setup(provider => provider.ResolveUri(It.IsAny<string>(), It.IsAny<string>())).Returns((string prefix, string name) => new Uri(new Uri("http://base/"), name));
     _entityContextFactory = new EntityContextFactory().WithOntology(_ontology.Object);
 }
Ejemplo n.º 23
0
        /// <inheritdoc />
        public virtual IUnitOfWorkContext BeginContext()
        {
            var entityContext = EntityContextFactory.Create();

            return(new UnitOfWorkContext(entityContext, RepoProvider));
        }
 public void Should_include_pointed_mapping_assemblies()
 {
     EntityContextFactory.FromConfiguration("test").Mappings.FindEntityMappingFor <IProduct>(null).Should().NotBeNull();
 }
 public void Setup()
 {
     _ontology = new Mock <IOntologyProvider>();
     _ontology.Setup(provider => provider.ResolveUri(It.IsAny <string>(), It.IsAny <string>())).Returns((string prefix, string name) => new Uri(new Uri("http://base/"), name));
     _entityContextFactory = new EntityContextFactory().WithOntology(_ontology.Object);
 }