Пример #1
0
        public StreamMetadata(long?maxCount         = null, TimeSpan?maxAge = null,
                              long?truncateBefore   = null, bool?tempStream = null,
                              TimeSpan?cacheControl = null, StreamAcl acl   = null)
        {
            if (maxCount <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          "maxCount", string.Format("{0} should be positive value.", SystemMetadata.MaxCount));
            }
            if (maxAge <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(
                          "maxAge", string.Format("{0} should be positive time span.", SystemMetadata.MaxAge));
            }
            if (truncateBefore < 0)
            {
                throw new ArgumentOutOfRangeException(
                          "truncateBefore",
                          string.Format("{0} should be non-negative value.", SystemMetadata.TruncateBefore));
            }
            if (cacheControl <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(
                          "cacheControl", string.Format("{0} should be positive time span.", SystemMetadata.CacheControl));
            }

            MaxCount       = maxCount;
            MaxAge         = maxAge;
            TruncateBefore = truncateBefore;
            TempStream     = tempStream;
            CacheControl   = cacheControl;
            Acl            = acl;
        }
Пример #2
0
 internal static void WriteAcl(JsonTextWriter jsonWriter, StreamAcl acl)
 {
     jsonWriter.WriteStartObject();
     WriteAclRoles(jsonWriter, SystemMetadata.AclRead, acl.ReadRoles);
     WriteAclRoles(jsonWriter, SystemMetadata.AclWrite, acl.WriteRoles);
     WriteAclRoles(jsonWriter, SystemMetadata.AclDelete, acl.DeleteRoles);
     WriteAclRoles(jsonWriter, SystemMetadata.AclMetaRead, acl.MetaReadRoles);
     WriteAclRoles(jsonWriter, SystemMetadata.AclMetaWrite, acl.MetaWriteRoles);
     jsonWriter.WriteEndObject();
 }
 private Event CreateStreamMetadataEvent()
 {
     var eventId = Guid.NewGuid();
     var acl = new StreamAcl(
         readRole: SystemRoles.Admins, writeRole: SystemRoles.Admins,
         deleteRole: SystemRoles.Admins, metaReadRole: SystemRoles.All,
         metaWriteRole: SystemRoles.Admins);
     var metadata = new StreamMetadata(maxCount: 2, maxAge: null, cacheControl: null, acl: acl);
     var dataBytes = metadata.ToJsonBytes();
     return new Event(eventId, SystemEventTypes.StreamMetadata, isJson: true, data: dataBytes, metadata: null);
 }
 private Event CreateStreamMetadataEvent(int? tb)
 {
     var eventId = Guid.NewGuid();
     var acl = new StreamAcl(
         readRole: SystemRoles.Admins, writeRole: SystemRoles.Admins,
         deleteRole: SystemRoles.Admins, metaReadRole: SystemRoles.Admins,
         metaWriteRole: SystemRoles.Admins);
     var metadata = new StreamMetadata(cacheControl: null, 
                                       truncateBefore: tb, 
                                       acl: acl);
     var dataBytes = metadata.ToJsonBytes();
     return new Event(eventId, SystemEventTypes.StreamMetadata, isJson: true, data: dataBytes, metadata: null);
 }
Пример #5
0
        public StreamMetadata(int? maxCount, TimeSpan? maxAge, TimeSpan? cacheControl, StreamAcl acl)
        {
            if (maxCount <= 0)
                throw new ArgumentOutOfRangeException(
                    "maxCount", string.Format("{0} should be positive value.", SystemMetadata.MaxCount));
            if (maxAge <= TimeSpan.Zero)
                throw new ArgumentOutOfRangeException(
                    "maxAge", string.Format("{0} should be positive time span.", SystemMetadata.MaxAge));
            if (cacheControl <= TimeSpan.Zero)
                throw new ArgumentOutOfRangeException(
                    "cacheControl", string.Format("{0} should be positive time span.", SystemMetadata.CacheControl));

            MaxCount = maxCount;
            MaxAge = maxAge;
            CacheControl = cacheControl;
            Acl = acl;
        }
Пример #6
0
        public static SystemSettings FromJsonBytes(ReadOnlyMemory <byte> json)
        {
            using (var reader = new JsonTextReader(new StreamReader(new MemoryStream(json.ToArray())))) {
                Check(reader.Read(), reader);
                Check(JsonToken.StartObject, reader);

                StreamAcl userStreamAcl   = null;
                StreamAcl systemStreamAcl = null;

                while (true)
                {
                    Check(reader.Read(), reader);
                    if (reader.TokenType == JsonToken.EndObject)
                    {
                        break;
                    }
                    Check(JsonToken.PropertyName, reader);
                    var name = (string)reader.Value;
                    switch (name)
                    {
                    case SystemMetadata.UserStreamAcl:
                        userStreamAcl = StreamMetadata.ReadAcl(reader);
                        break;

                    case SystemMetadata.SystemStreamAcl:
                        systemStreamAcl = StreamMetadata.ReadAcl(reader);
                        break;

                    default: {
                        Check(reader.Read(), reader);
                        // skip
                        JToken.ReadFrom(reader);
                        break;
                    }
                    }
                }

                return(new SystemSettings(userStreamAcl, systemStreamAcl));
            }
        }
Пример #7
0
        public StreamMetadata(int?maxCount, TimeSpan?maxAge, TimeSpan?cacheControl, StreamAcl acl)
        {
            if (maxCount <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          "maxCount", string.Format("{0} should be positive value.", SystemMetadata.MaxCount));
            }
            if (maxAge <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(
                          "maxAge", string.Format("{0} should be positive time span.", SystemMetadata.MaxAge));
            }
            if (cacheControl <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(
                          "cacheControl", string.Format("{0} should be positive time span.", SystemMetadata.CacheControl));
            }

            MaxCount     = maxCount;
            MaxAge       = maxAge;
            CacheControl = cacheControl;
            Acl          = acl;
        }
        public StreamMetadata(int? maxCount = null, TimeSpan? maxAge = null,
                              int? truncateBefore = null, bool? tempStream = null,
                              TimeSpan? cacheControl = null, StreamAcl acl = null)
        {
            if (maxCount <= 0)
                throw new ArgumentOutOfRangeException(
                    "maxCount", string.Format("{0} should be positive value.", SystemMetadata.MaxCount));
            if (maxAge <= TimeSpan.Zero)
                throw new ArgumentOutOfRangeException(
                    "maxAge", string.Format("{0} should be positive time span.", SystemMetadata.MaxAge));
            if (truncateBefore < 0)
                throw new ArgumentOutOfRangeException(
                    "truncateBefore", string.Format("{0} should be non negative value.", SystemMetadata.TruncateBefore));
            if (cacheControl <= TimeSpan.Zero)
                throw new ArgumentOutOfRangeException(
                    "cacheControl", string.Format("{0} should be positive time span.", SystemMetadata.CacheControl));

            MaxCount = maxCount;
            MaxAge = maxAge;
            TruncateBefore = truncateBefore;
            TempStream = tempStream;
            CacheControl = cacheControl;
            Acl = acl;
        }
 internal static void WriteAcl(JsonTextWriter jsonWriter, StreamAcl acl)
 {
     jsonWriter.WriteStartObject();
     WriteAclRoles(jsonWriter, SystemMetadata.AclRead, acl.ReadRoles);
     WriteAclRoles(jsonWriter, SystemMetadata.AclWrite, acl.WriteRoles);
     WriteAclRoles(jsonWriter, SystemMetadata.AclDelete, acl.DeleteRoles);
     WriteAclRoles(jsonWriter, SystemMetadata.AclMetaRead, acl.MetaReadRoles);
     WriteAclRoles(jsonWriter, SystemMetadata.AclMetaWrite, acl.MetaWriteRoles);
     jsonWriter.WriteEndObject();
 }
Пример #10
0
        public static StreamMetadata FromJsonReader(JsonTextReader reader)
        {
            Check(reader.Read(), reader);
            Check(JsonToken.StartObject, reader);

            long?     maxCount       = null;
            TimeSpan? maxAge         = null;
            long?     truncateBefore = null;
            bool?     tempStream     = null;
            TimeSpan? cacheControl   = null;
            StreamAcl acl            = null;

            while (true)
            {
                Check(reader.Read(), reader);
                if (reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }
                Check(JsonToken.PropertyName, reader);
                var name = (string)reader.Value;
                switch (name)
                {
                case SystemMetadata.MaxCount: {
                    Check(reader.Read(), reader);
                    Check(JsonToken.Integer, reader);
                    maxCount = (long)reader.Value;
                    break;
                }

                case SystemMetadata.MaxAge: {
                    Check(reader.Read(), reader);
                    Check(JsonToken.Integer, reader);
                    maxAge = TimeSpan.FromSeconds((long)reader.Value);
                    break;
                }

                case SystemMetadata.TruncateBefore: {
                    Check(reader.Read(), reader);
                    Check(JsonToken.Integer, reader);
                    truncateBefore = (long)reader.Value;
                    break;
                }

                case SystemMetadata.TempStream: {
                    Check(reader.Read(), reader);
                    Check(JsonToken.Boolean, reader);
                    tempStream = (bool)reader.Value;
                    break;
                }

                case SystemMetadata.CacheControl: {
                    Check(reader.Read(), reader);
                    Check(JsonToken.Integer, reader);
                    cacheControl = TimeSpan.FromSeconds((long)reader.Value);
                    break;
                }

                case SystemMetadata.Acl: {
                    acl = ReadAcl(reader);
                    break;
                }

                default: {
                    Check(reader.Read(), reader);
                    // skip
                    JToken.ReadFrom(reader);
                    break;
                }
                }
            }

            return(new StreamMetadata(
                       maxCount > 0 ? maxCount : null, maxAge > TimeSpan.Zero ? maxAge : null,
                       truncateBefore >= 0 ? truncateBefore : null, tempStream,
                       cacheControl > TimeSpan.Zero ? cacheControl : null, acl));
        }
Пример #11
0
        public static StreamMetadata FromJsonBytes(byte[] json)
        {
            using (var reader = new JsonTextReader(new StreamReader(new MemoryStream(json))))
            {
                Check(reader.Read(), reader);
                Check(JsonToken.StartObject, reader);

                int?      maxCount     = null;
                TimeSpan? maxAge       = null;
                TimeSpan? cacheControl = null;
                StreamAcl acl          = null;

                while (true)
                {
                    Check(reader.Read(), reader);
                    if (reader.TokenType == JsonToken.EndObject)
                    {
                        break;
                    }
                    Check(JsonToken.PropertyName, reader);
                    var name = (string)reader.Value;
                    switch (name)
                    {
                    case SystemMetadata.MaxCount:
                    {
                        Check(reader.Read(), reader);
                        Check(JsonToken.Integer, reader);
                        maxCount = (int)(long)reader.Value;
                        break;
                    }

                    case SystemMetadata.MaxAge:
                    {
                        Check(reader.Read(), reader);
                        Check(JsonToken.Integer, reader);
                        maxAge = TimeSpan.FromSeconds((long)reader.Value);
                        break;
                    }

                    case SystemMetadata.CacheControl:
                    {
                        Check(reader.Read(), reader);
                        Check(JsonToken.Integer, reader);
                        cacheControl = TimeSpan.FromSeconds((long)reader.Value);
                        break;
                    }

                    case SystemMetadata.Acl:
                    {
                        acl = ReadAcl(reader);
                        break;
                    }

                    default:
                    {
                        Check(reader.Read(), reader);
                        // skip
                        JToken.ReadFrom(reader);
                        break;
                    }
                    }
                }
                return(new StreamMetadata(maxCount > 0 ? maxCount : null,
                                          maxAge > TimeSpan.Zero ? maxAge : null,
                                          cacheControl > TimeSpan.Zero ? cacheControl : null,
                                          acl));
            }
        }
Пример #12
0
 public SystemSettings(StreamAcl userStreamAcl, StreamAcl systemStreamAcl)
 {
     UserStreamAcl = userStreamAcl;
     SystemStreamAcl = systemStreamAcl;
 }
Пример #13
0
 public SystemSettings(StreamAcl userStreamAcl, StreamAcl systemStreamAcl)
 {
     UserStreamAcl   = userStreamAcl;
     SystemStreamAcl = systemStreamAcl;
 }