Ejemplo n.º 1
0
        public FilteredPoliciesRM(IConfiguredConnection conn, List <string> policyFilter = null)
            : base(nameof(FilteredPoliciesRM), () => conn.GetListener(nameof(FilteredPoliciesRM)))
        {
            if (policyFilter != null)
            {
                AllowedApplications = new HashSet <string>(policyFilter);
            }

            //set handlers
            EventStream.Subscribe <ApplicationMsgs.ApplicationCreated>(this);
            EventStream.Subscribe <ApplicationMsgs.PolicyCreated>(this);
            EventStream.Subscribe <ApplicationMsgs.RoleCreated>(this);
            EventStream.Subscribe <PolicyUserMsgs.PolicyUserAdded>(this);
            EventStream.Subscribe <PolicyUserMsgs.RoleAdded>(this);
            EventStream.Subscribe <PolicyUserMsgs.RoleRemoved>(this);
            EventStream.Subscribe <PolicyUserMsgs.UserDeactivated>(this);
            EventStream.Subscribe <PolicyUserMsgs.UserReactivated>(this);

            //read
            long?appCheckpoint;
            long?userCheckpoint;

            using (var reader = conn.GetReader(nameof(FilteredPoliciesRM), Handle))
            {
                reader.Read <Domain.SecuredApplication>(() => Idle);
                appCheckpoint = reader.Position;
                reader.Read <Domain.PolicyUser>(() => Idle);
                userCheckpoint = reader.Position;
            }
            //subscribe
            Start <Domain.SecuredApplication>(appCheckpoint);
            Start <Domain.PolicyUser>(userCheckpoint);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a read model using the provided stream store connection. Reads existing events using a
 /// reader, then transitions to a listener for live events.
 /// </summary>
 /// <param name="name">The name of the read model. Also used as the name of the listener and reader.</param>
 /// <param name="connection">A connection to a stream store.</param>
 protected ReadModelBase(string name, IConfiguredConnection connection)
 {
     Ensure.NotNull(connection, nameof(connection));
     _getListener = () => connection.GetListener(name);
     _getReader   = () => connection.GetReader(name, Handle);
     _listeners   = new List <IListener>();
     _bus         = new InMemoryBus($"{nameof(ReadModelBase)}:{name} bus", false);
     _queue       = new QueuedHandler(_bus, $"{nameof(ReadModelBase)}:{name} queue");
     _queue.Start();
 }
Ejemplo n.º 3
0
        public UsersRm(IConfiguredConnection conn) : base(nameof(UsersRm), () => conn.GetListener(nameof(UsersRm)))
        {
            long?position;

            EventStream.Subscribe <UserMsgs.UserEvent>(this);
            using (var reader = conn.GetReader(nameof(UsersRm), Handle))
            {
                reader.Read <User>(() => Idle);
                position = reader.Position;
            }

            Start <User>(checkpoint: position, blockUntilLive: true);
        }
Ejemplo n.º 4
0
        public SubjectsRm(IConfiguredConnection conn)
            : base(nameof(SubjectsRm), () => conn.GetListener(nameof(SubjectsRm)))
        {
            //set handlers
            EventStream.Subscribe <SubjectMsgs.SubjectCreated>(this);

            //read
            long?checkpoint;

            using (var reader = conn.GetReader(nameof(SubjectsRm), Handle))
            {
                reader.Read <Subject>(() => Idle);
                checkpoint = reader.Position;
            }

            //subscribe
            Start <Subject>(checkpoint, true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a read model for getting information about Policy Users.
        /// </summary>
        public PolicyUserRm(IConfiguredConnection conn)
            : base(nameof(PolicyUserRm), () => conn.GetListener(nameof(PolicyUserRm)))
        {
            //set handlers
            EventStream.Subscribe <PolicyUserMsgs.PolicyUserAdded>(this);
            EventStream.Subscribe <PolicyUserMsgs.RoleAdded>(this);
            EventStream.Subscribe <PolicyUserMsgs.RoleRemoved>(this);
            EventStream.Subscribe <PolicyUserMsgs.UserDeactivated>(this);
            EventStream.Subscribe <PolicyUserMsgs.UserReactivated>(this);

            //read
            long?checkpoint;

            using (var reader = conn.GetReader(nameof(PolicyUserRm), Handle))
            {
                reader.Read <Domain.PolicyUser>(() => Idle);
                checkpoint = reader.Position;
            }
            //subscribe
            Start <Domain.PolicyUser>(checkpoint);
        }
Ejemplo n.º 6
0
        public ClientStore(IConfiguredConnection conn) : base(nameof(ClientStore), () => conn.GetListener(nameof(ClientStore)))
        {
            long checkpoint;

            EventStream.Subscribe <ClientMsgs.ClientCreated>(this);
            EventStream.Subscribe <ClientMsgs.ClientSecretAdded>(this);
            EventStream.Subscribe <ClientMsgs.ClientSecretRemoved>(this);

            using (var reader = conn.GetReader(nameof(ClientStore), Handle))
            {
                reader.Read <IdentityStorage.Domain.Client>(() => Idle);
                checkpoint = reader.Position ?? StreamPosition.Start;
            }
            Start <IdentityStorage.Domain.Client>(checkpoint);
        }