Пример #1
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);
        }
Пример #2
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));
        }
Пример #3
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();
        }
Пример #4
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();
        }
Пример #5
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());
        }
Пример #6
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));
        }
Пример #7
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();
        }
Пример #8
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));
        }
Пример #9
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));
        }
Пример #10
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());
    }