Esempio n. 1
0
 public void ExportData(Stream stream, string graphUri)
 {
     try
     {
         var triples = ReadStore.Match(null, null, null, graph: graphUri);
         using (var sw = new StreamWriter(stream))
         {
             var nw = new BrightstarTripleSinkAdapter(new NTriplesWriter(sw));
             foreach (var triple in triples)
             {
                 nw.Triple(triple);
             }
             sw.Flush();
         }
     }
     catch (ReadWriteStoreModifiedException)
     {
         Logging.LogError(BrightstarEventId.ExportDataError, "Store was modified while export was running.");
     }
     catch (Exception ex)
     {
         Logging.LogError(BrightstarEventId.ExportDataError, "Error Exporting Data {0} {1}", ex.Message,
                          ex.StackTrace);
     }
 }
 public static async Task <AuctionItemReadModel> GetAuctionItemAsync(this ReadStore store,
                                                                     string auctionId, string name)
 {
     return(await store.GetAll <AuctionItemReadModel>()
            .Where(i => i.AuctionId == auctionId)
            .SingleAsync(i => i.Name == name));
 }
Esempio n. 3
0
        /// <summary>
        /// Setup the dependency injection
        /// </summary>
        /// <returns>Initialised dependency injection container</returns>
        /// <param name="persistedApplicationStateRepository">Application state repository for access to the persisted application state</param>
        /// <param name="applicationStateFactory">Factory for the current application state</param>
        private IContainer CreateContainer(
            IPersistedApplicationStateRepository persistedApplicationStateRepository,
            ICurrentApplicationStateFactory applicationStateFactory)
        {
            var simpleInjector = new Container();

            // Application state repository is required when we want to save current the application state
            simpleInjector.RegisterSingleton <IPersistedApplicationStateRepository>(persistedApplicationStateRepository);
            simpleInjector.RegisterSingleton <ICurrentApplicationStateFactory>(applicationStateFactory);

            // Event store only exists once (the state can be exchanged at runtime though)
            this.EventStore = new EventStore();
            simpleInjector.RegisterSingleton <IEventStore>(this.EventStore);
            simpleInjector.RegisterSingleton <IReadOnlyEventStore>(this.EventStore);

            // Device Id
            var deviceId = new DeviceId();

            this.DeviceId = deviceId;
            simpleInjector.RegisterSingleton <IDeviceId>(this.DeviceId);
            simpleInjector.RegisterSingleton <IReadOnlyDeviceId>(this.DeviceId);

            // Vector clock
            this.VectorClock = new MasterVectorClock(deviceId);
            simpleInjector.RegisterSingleton <IVectorClock>(this.VectorClock);

            // Core messaging infrastructure
            this.EventBus = new EventBus();
            simpleInjector.RegisterSingleton <IEventBus>(this.EventBus);

            // Initialise the command bus last because it depends on many other objects
            this.CommandBus = new CommandBus(
                simpleInjector,
                this.EventBus,
                this.DeviceId,
                this.VectorClock,
                this.EventStore);
            simpleInjector.RegisterSingleton <ICommandBus>(this.CommandBus);

            // Read store (for read side repositories)
            // same singleton for read and reset
            var readStore = new ReadStore();

            simpleInjector.RegisterSingleton <IReadStore>(readStore);
            simpleInjector.RegisterSingleton <IResetableReadStore>(readStore);
            simpleInjector.RegisterSingleton <IReadStoreResetBroadcast>(readStore);

            // Must also register container itself because infrastructure needs it
            simpleInjector.RegisterSingleton <IContainer>(simpleInjector);

            // Sub-registrations (must not depend on each other)
            this.RegisterCommandHandlers(simpleInjector);
            this.RegisterProjectionRepositories(simpleInjector);
            this.RegisterProjections(simpleInjector, this.EventBus);

            simpleInjector.Verify();
            return(simpleInjector);
        }
Esempio n. 4
0
        /// <summary>
        /// Preload index and resource pages for this store
        /// </summary>
        /// <param name="pageCacheRatio">The fractional amount of the number of available cache pages to use in the preload</param>
        public void WarmupStore(decimal pageCacheRatio)
        {
            if (pageCacheRatio > 1.0m)
            {
                pageCacheRatio = 1.0m;
            }
#if PORTABLE || WINDOWS_PHONE
            var pagesToPreload = (int)Math.Floor(PageCache.Instance.FreePages * (float)pageCacheRatio);
#else
            var pagesToPreload = (int)Math.Floor(PageCache.Instance.FreePages * pageCacheRatio);
#endif
            ReadStore.WarmupPageCache(pagesToPreload);
        }
Esempio n. 5
0
 public IEnumerable <Triple> GetResourceStatements(string resourceUri)
 {
     Logging.LogDebug("GetResourceStatements {0}", resourceUri);
     try
     {
         return(ReadStore.GetResourceStatements(resourceUri));
     }
     catch (ReadWriteStoreModifiedException)
     {
         Logging.LogDebug("Read/Write store was concurrently modified. Attempting retry.");
         InvalidateReadStore();
         return(GetResourceStatements(resourceUri));
     }
 }
Esempio n. 6
0
 public BrightstarSparqlResultsType Query(SparqlQuery query, ISerializationFormat targetFormat, Stream resultsStream, string[] defaultGraphUris)
 {
     Logging.LogDebug("Query {0}", query);
     try
     {
         return(ReadStore.ExecuteSparqlQuery(query, targetFormat, resultsStream, defaultGraphUris));
     }
     catch (ReadWriteStoreModifiedException)
     {
         Logging.LogDebug("Read/Write store was concurrently modified. Attempting a retry");
         InvalidateReadStore();
         return(Query(query, targetFormat, resultsStream, defaultGraphUris));
     }
 }
Esempio n. 7
0
 public string Query(string queryExpression, SparqlResultsFormat resultsFormat)
 {
     Logging.LogDebug("Query {0}", queryExpression);
     try
     {
         return(ReadStore.ExecuteSparqlQuery(queryExpression, resultsFormat));
     }
     catch (ReadWriteStoreModifiedException)
     {
         Logging.LogDebug("Read/Write store was concurrently modified. Attempting a retry");
         InvalidateReadStore();
         return(Query(queryExpression, resultsFormat));
     }
 }
Esempio n. 8
0
 public void Query(string queryExpression, SparqlResultsFormat resultsFormat, Stream resultsStream)
 {
     Logging.LogDebug("Query {0}", queryExpression);
     try
     {
         BrightstarSparqlResultsType resultsType;
         ReadStore.ExecuteSparqlQuery(queryExpression, resultsFormat, resultsStream, out resultsType);
     }
     catch (ReadWriteStoreModifiedException)
     {
         Logging.LogDebug("Read/Write store was concurrently modified. Attempting a retry");
         InvalidateReadStore();
         Query(queryExpression, resultsFormat, resultsStream);
     }
 }
Esempio n. 9
0
        public override async Task <bool> Save(AggregateRootWithEvents aggregateRoot)
        {
            if (aggregateRoot is DHCPv4RootScope == false)
            {
                return(await base.Save(aggregateRoot));
            }

            PseudoDHCPv4RootScope pseudoRootScope = new();

            var events = aggregateRoot.GetChanges();

            List <AggregateRootWithEvents> aggregatesToSave = new();

            aggregatesToSave.Add(pseudoRootScope);

            HashSet <Guid> scopesToDelete = new();
            HashSet <Guid> leasesToDelete = new();

            foreach (var item in events)
            {
                switch (item)
                {
                case DHCPv4ScopeAddedEvent e:
                {
                    pseudoRootScope.AddScope(e.Instructions.Id);
                    var pseudoScope = new PseudoDHCPv4Scope(e.Instructions.Id);
                    pseudoScope.AddChange(e);
                    aggregatesToSave.Add(pseudoScope);
                }
                break;

                case DHCPv4ScopeDeletedEvent e:
                {
                    pseudoRootScope.RemoveScope(e.EntityId);
                    scopesToDelete.Add(e.EntityId);
                }
                break;

                case EntityBasedDomainEvent e when
                    item is DHCPv4ScopePropertiesUpdatedEvent ||
                    item is DHCPv4ScopeNameUpdatedEvent ||
                    item is DHCPv4ScopeDescriptionUpdatedEvent ||
                    item is DHCPv4ScopeResolverUpdatedEvent ||
                    item is DHCPv4ScopeAddressPropertiesUpdatedEvent ||
                    item is DHCPv4ScopeParentUpdatedEvent ||
                    item is DHCPv4ScopeAddressesAreExhaustedEvent ||
                    item is DHCPv4ScopeSuspendedEvent ||
                    item is DHCPv4ScopeReactivedEvent:
                {
                    var pseudoScope = new PseudoDHCPv4Scope(e.EntityId);
                    pseudoScope.AddChange(e);
                    aggregatesToSave.Add(pseudoScope);
                }
                break;

                case DHCPv4LeaseCreatedEvent e:
                {
                    pseudoRootScope.AddLease(e.EntityId);
                    var pseudoScope = new PseudoDHCPv4Lease(e.EntityId);
                    pseudoScope.AddChange(e);
                    aggregatesToSave.Add(pseudoScope);
                }
                break;

                case DHCPv4LeaseRemovedEvent e:
                {
                    pseudoRootScope.RemoveLease(e.EntityId);
                    leasesToDelete.Add(e.EntityId);
                }
                break;

                case DHCPv4ScopeRelatedEvent e:
                {
                    var pseudoLease = new PseudoDHCPv4Lease(e.EntityId);
                    pseudoLease.AddChange(e);
                    aggregatesToSave.Add(pseudoLease);
                }
                break;

                default:
                    break;
                }
            }

            foreach (var item in aggregatesToSave)
            {
                await EventStore.Save(item, 20);

                if (item is PseudoDHCPv4Lease)
                {
                    var propertyResolver = Provider.GetService <IDHCPv6ServerPropertiesResolver>();

                    await EventStore.ApplyMetaValuesForStream <PseudoDHCPv4Lease>(
                        item.Id,
                        new EventStoreStreamMetaValues(EventStoreStreamMetaValues.DoNotTruncate, propertyResolver.GetLeaseLifeTime()));
                }
            }

            foreach (var item in scopesToDelete)
            {
                await EventStore.DeleteAggregateRoot <PseudoDHCPv4Scope>(item);
            }

            foreach (var item in leasesToDelete)
            {
                await EventStore.DeleteAggregateRoot <PseudoDHCPv4Lease>(item);
            }

            aggregateRoot.ClearChanges();

            Boolean projectResult = await ReadStore.Project(events);

            return(projectResult);
        }
Esempio n. 10
0
 public Task <Boolean> LogFilteredDHCPv4Packet(DHCPv4Packet packet, String filterName) => ReadStore.LogFilteredDHCPv4Packet(packet, filterName);
Esempio n. 11
0
 public Task <Boolean> LogInvalidDHCPv4Packet(DHCPv4Packet packet) => ReadStore.LogInvalidDHCPv4Packet(packet);
Esempio n. 12
0
 public Task <IEnumerable <DHCPv4Listener> > GetDHCPv4Listener() => ReadStore.GetDHCPv4Listener();
 public static async Task <AuctionReadModel> GetAuctionAsync(this ReadStore store, string auctionId)
 {
     return(await store.GetAll <AuctionReadModel>()
            .SingleAsync(a => a.Id == auctionId));
 }
 public AuctionItemAddedEventHandler(ReadStore readStore)
 {
     _readStore = readStore;
 }
Esempio n. 15
0
 public GetAuctionsListQueryHandler(ReadStore readStore)
 {
     _readStore = readStore;
 }
Esempio n. 16
0
 /// <summary>
 /// Get the identifiers of the named graphs in the store
 /// </summary>
 /// <returns>An enumeration of the identifiers of the named graphs in the store</returns>
 public IEnumerable <string> ListNamedGraphs()
 {
     return(ReadStore.GetGraphUris().Where(x => x != Constants.DefaultGraphUri));
 }
 public AuctionCreatedEventHandler(ReadStore readStore)
 {
     _readStore = readStore;
 }