Пример #1
0
        public CloudState RegisterCrdtEntity(
            ICrdtEntityHandlerFactory factory,
            ServiceDescriptor descriptor,
            params FileDescriptor[] additionalDescriptors)
        {
            var anySupport = NewAnySupport(additionalDescriptors);

            StatefulServices.Add(
                descriptor.FullName,
                new CrdtStatefulService(
                    factory,
                    descriptor,
                    anySupport));

            return(this);
        }
Пример #2
0
        /// <summary>
        /// Register an event sourced entity to be used when starting the CloudState worker.
        /// </summary>
        /// <param name="descriptor">gRPC service descriptor for the given entity</param>
        /// <param name="additionalDescriptors">Additional Protobuf file descriptors to support
        /// gRPC calls and event store persistence</param>
        /// <typeparam name="TEntity">Entity type</typeparam>
        /// <returns>CloudState</returns>
        public CloudState RegisterEventSourcedEntity <TEntity>(
            ServiceDescriptor descriptor,
            params FileDescriptor[] additionalDescriptors
            )
        {
            var entity = typeof(TEntity).GetCustomAttribute <EventSourcedEntityAttribute>(true);

            if (entity == null)
            {
                throw new InvalidOperationException(
                          $"{typeof(TEntity)} does not declare a(n) {typeof(EventSourcedEntityAttribute).Name} attribute!"
                          );
            }

            string persistenceId;
            int    snapshotEvery;

            if (string.IsNullOrEmpty(entity.PersistenceId))
            {
                persistenceId = typeof(TEntity).Name;
                snapshotEvery = 0;
            }
            else
            {
                persistenceId = entity.PersistenceId;
                snapshotEvery = entity.SnapshotEvery;
            }

            var anySupport = NewAnySupport(additionalDescriptors);

            StatefulServices.Add(
                descriptor.FullName,
                new EventSourcedStatefulService(
                    new AttributeBasedEntityHandlerFactory(
                        typeof(TEntity),
                        anySupport,
                        descriptor
                        ),
                    descriptor,
                    anySupport,
                    persistenceId,
                    snapshotEvery
                    )
                );

            return(this);
        }
Пример #3
0
        public CloudState RegisterEventSourcedEntity(
            IEventSourcedEntityHandlerFactory factory,
            ServiceDescriptor descriptor,
            string persistenceId,
            int snapshotEvery,
            params FileDescriptor[] additionalDescriptors
            )
        {
            StatefulServices.Add(
                descriptor.FullName,
                new EventSourcedStatefulService(
                    factory,
                    descriptor,
                    NewAnySupport(additionalDescriptors),
                    persistenceId,
                    snapshotEvery
                    )
                );

            return(this);
        }
Пример #4
0
        public CloudState RegisterCrdtEntity <T>(
            ServiceDescriptor descriptor,
            params FileDescriptor[] additionalDescriptors)
        {
            var entityClass = typeof(T);
            var entity      = entityClass.GetCustomAttribute <CrdtEntityAttribute>();

            if (entity == null)
            {
                throw new InvalidOperationException(
                          entityClass + " does not declare an " + nameof(CrdtEntityAttribute) + " attribute");
            }

            var anySupport = NewAnySupport(additionalDescriptors);

            StatefulServices.Add(
                descriptor.FullName,
                new CrdtStatefulService(
                    new AttributeBasedCrdtHandlerFactory(entityClass, anySupport, descriptor),
                    descriptor,
                    anySupport));

            return(this);
        }
Пример #5
0
 private void AddService(ServiceDescriptor serviceDescriptor)
 {
     foreach (var method in serviceDescriptor.Methods)
     {
         filesBySymbol[method.FullName] = method.File;
     }
     filesBySymbol[serviceDescriptor.FullName] = serviceDescriptor.File;
 }