public AzureEventStoreClient(AzureStoreConfiguration config, EventStoreId storeId, string serverEndpoint = null)
     : base(storeId, serverEndpoint)
 {
     Config = config;
     _blob = config.GetPageBlob(storeId.Name + "/stream.dat");
     _blob.Container.CreateIfNotExist();
 }
Esempio n. 2
0
        protected override object Run(ClientApi.WriteEvent request)
        {
            var token = new ManualResetEventSlim(false);
            var name  = EventStoreId.Parse(request.StoreId);

            _publisher.Publish(new ClientMessage.AppendEvents(
                                   name,
                                   request.StreamId,
                                   request.Data, s => token.Set()));

            return(Task.Factory.StartNew(() =>
            {
                try
                {
                    token.Wait();
                    return new ClientApi.WriteEventResponse()
                    {
                        Result = "Completed",
                        Success = true
                    };
                }
                finally
                {
                    token.Dispose();
                }
            }));
        }
Esempio n. 3
0
 public AzureEventStoreClient(AzureStoreConfiguration config, EventStoreId storeId, string serverEndpoint = null)
     : base(storeId, serverEndpoint)
 {
     Config = config;
     _blob  = config.GetPageBlob(storeId.Name + "/stream.dat");
     _blob.Container.CreateIfNotExist();
 }
Esempio n. 4
0
        protected override object Run(ClientApi.WriteBatch request)
        {
            var token = new ManualResetEventSlim(false);

            if (request.Length <= 0)
            {
                return(Error("WriteBatch request must have length more than 0 bytes"));
            }

            var container = EventStoreId.Parse(request.StoreId);

            _publisher.Publish(new ClientMessage.ImportEvents(container, request.StreamId, request.BatchLocation, request.Length, s => token.Set()));

            return(Task.Factory.StartNew(() =>
            {
                try
                {
                    token.Wait();
                    return new ClientApi.WriteBatchResponse()
                    {
                        Result = "Completed",
                        Success = true
                    };
                }
                finally
                {
                    token.Dispose();
                }
            }));
        }
Esempio n. 5
0
        public FileEventStoreManager(string rootDirectory)
        {
            if (null == rootDirectory)
            {
                throw new ArgumentNullException("rootDirectory");
            }

            _rootDirectory = rootDirectory;

            if (!Directory.Exists(rootDirectory))
            {
                Directory.CreateDirectory(rootDirectory);
            }

            var info = new DirectoryInfo(rootDirectory);

            foreach (var child in info.GetDirectories())
            {
                if (EventStoreId.IsValid(child.Name) != EventStoreId.Rule.Valid)
                {
                    Log.Info("Skipping invalid folder {0} (invalid name)", child.Name);
                    continue;
                }
                var container = EventStoreId.Parse(child.Name);
                if (FileEventStore.ExistsValid(rootDirectory, container))
                {
                    var writer = FileEventStore.OpenExistingForWriting(rootDirectory, container);
                    _stores.Add(container.Name, writer);
                }
                else
                {
                    Log.Info("Skipping invalid folder {0} (can't open)", child.Name);
                }
            }
        }
 protected JsonEventStoreClientBase(EventStoreId storeId, string uri)
 {
     StoreId = storeId;
     if (!string.IsNullOrWhiteSpace(uri))
     {
         WriteClient = new JsonServiceClient(uri);
     }
 }
Esempio n. 7
0
        public static FileEventStore OpenForReading(string root, EventStoreId storeId)
        {
            var folder = Path.Combine(root, storeId.Name);
            var check  = FileEventPointer.OpenOrCreateForReading(Path.Combine(folder, "stream.chk"));
            var store  = FileEventStoreChunk.OpenForReading(Path.Combine(folder, "stream.dat"));

            return(new FileEventStore(storeId, store, check));
        }
        public static FileEventStore OpenForReading(string root, EventStoreId storeId)
        {
            var folder = Path.Combine(root, storeId.Name);
            var check = FileEventPointer.OpenOrCreateForReading(Path.Combine(folder, "stream.chk"));
            var store = FileEventStoreChunk.OpenForReading(Path.Combine(folder, "stream.dat"));

            return new FileEventStore(storeId, store, check);
        }
 protected JsonEventStoreClientBase(EventStoreId storeId, string uri)
 {
     StoreId = storeId;
     if (!string.IsNullOrWhiteSpace(uri))
     {
         WriteClient = new JsonServiceClient(uri);
     }
 }
Esempio n. 10
0
 public static AzureEventStore OpenExistingForReading(AzureStoreConfiguration config, EventStoreId container)
 {
     var blob = config.GetPageBlob(container.Name + "/stream.dat");
     var check = AzureEventPointer.OpenReadable(blob);
     blob.FetchAttributes();
     var store = AzureEventStoreChunk.OpenExistingForReading(blob, blob.Properties.Length);
     return new AzureEventStore(container, store, check);
 }
 public AppendEvents(EventStoreId storeId,
                     string streamId, byte[] eventData, Action <AppendEventsCompleted> envelope)
 {
     StoreId   = storeId;
     StreamId  = streamId;
     EventData = eventData;
     Envelope  = envelope;
 }
Esempio n. 12
0
 public AppendEvents(EventStoreId storeId, 
     string streamId, byte[] eventData,  Action<AppendEventsCompleted> envelope)
 {
     StoreId = storeId;
     StreamId = streamId;
     EventData = eventData;
     Envelope = envelope;
 }
Esempio n. 13
0
 public static AzureEventStore OpenExistingForWriting(AzureStoreConfiguration config, EventStoreId container)
 {
     var blob = config.GetPageBlob(container.Name + "/stream.dat");
     var check = AzureEventPointer.OpenWriteable(blob);
     var offset = check.Read();
     var length = blob.Properties.Length;
     var store = AzureEventStoreChunk.OpenExistingForWriting(blob, offset, length);
     return new AzureEventStore(container, store, check);
 }
Esempio n. 14
0
 public ImportEvents(EventStoreId storeId, 
     string streamId, string stagingLocation, long size, Action<ImportEventsCompleted> envelope)
 {
     StoreId = storeId;
     StreamId = streamId;
     StagingLocation = stagingLocation;
     Envelope = envelope;
     Size = size;
 }
 public ImportEvents(EventStoreId storeId,
                     string streamId, string stagingLocation, long size, Action <ImportEventsCompleted> envelope)
 {
     StoreId         = storeId;
     StreamId        = streamId;
     StagingLocation = stagingLocation;
     Envelope        = envelope;
     Size            = size;
 }
Esempio n. 16
0
        public static FileEventStore CreateNew(string root, EventStoreId storeId)
        {
            var folder = Path.Combine(root, storeId.Name);
            if (!Directory.Exists(folder))
                Directory.CreateDirectory(folder);

            var check = FileEventPointer.OpenOrCreateForWriting((Path.Combine(folder, "stream.chk")));
            var store = FileEventStoreChunk.CreateNew(Path.Combine(folder, "stream.dat"));
            return new FileEventStore(storeId,store,check);
        }
Esempio n. 17
0
        public static bool ExistsValid(string root, EventStoreId storeId)
        {
            var folder = Path.Combine(root, storeId.Name);
            if (!Directory.Exists(folder))
                return false;

            var check = Path.Combine(folder, "stream.chk");
            var store = Path.Combine(folder, "stream.dat");
            return (System.IO.File.Exists(check) && System.IO.File.Exists(store));
        }
 public void AppendEventsToStore(EventStoreId storeId, string streamId, IEnumerable<byte[]> eventData)
 {
     AzureEventStore store;
     if (!_stores.TryGetValue(storeId.Name, out store))
     {
         store = AzureEventStore.CreateNewForWriting(_config, storeId);
         _stores.Add(storeId.Name, store);
     }
     store.Write(streamId, eventData);
 }
Esempio n. 19
0
        public static AzureEventStore CreateNewForWriting(AzureStoreConfiguration config, EventStoreId container)
        {
            var blob = config.GetPageBlob(container.Name + "/stream.dat");
            blob.Container.CreateIfNotExist();

            var store = AzureEventStoreChunk.CreateNewForWriting(blob);
            var check = AzureEventPointer.OpenWriteable(blob);

            return new AzureEventStore(container, store, check);
        }
 public void AppendEventsToStore(EventStoreId storeId, string streamId, IEnumerable<byte[]> eventData)
 {
     FileEventStore value;
     if (!_stores.TryGetValue(storeId.Name, out value))
     {
         value = FileEventStore.CreateNew(_rootDirectory, storeId);
         _stores.Add(storeId.Name, value);
     }
     value.Write(streamId, eventData);
 }
Esempio n. 21
0
        public void AppendEventsToStore(EventStoreId storeId, string streamId, IEnumerable <byte[]> eventData)
        {
            FileEventStore value;

            if (!_stores.TryGetValue(storeId.Name, out value))
            {
                value = FileEventStore.CreateNew(_rootDirectory, storeId);
                _stores.Add(storeId.Name, value);
            }
            value.Write(streamId, eventData);
        }
        public FileEventStoreClient(string serverFolder, EventStoreId storeId, string serverEndpoint = null)
            : base(storeId, serverEndpoint)
        {
            // open for reading or new
            _serverFolder = serverFolder;

            var path = Path.Combine(Path.GetFullPath(serverFolder ?? ""), storeId.Name);

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
        }
        public void AppendEventsToStore(EventStoreId storeId, string streamId, IEnumerable <byte[]> eventData)
        {
            AzureEventStore store;

            if (!_stores.TryGetValue(storeId.Name, out store))
            {
                store = AzureEventStore.CreateNewForWriting(_config, storeId);
                _stores.Add(storeId.Name, store);
            }
            store.Write(streamId, eventData);
        }
Esempio n. 24
0
        public FileEventStoreClient(string serverFolder, EventStoreId storeId, string serverEndpoint = null) : base(storeId, serverEndpoint)
        {
            // open for reading or new
            _serverFolder = serverFolder;

            var path = Path.Combine(Path.GetFullPath(serverFolder ?? ""), storeId.Name);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
Esempio n. 25
0
        public static bool TryGetContainerName(
            AzureStoreConfiguration config, 
            CloudBlobDirectory dir,
            out EventStoreId container)
        {
            var topic = dir.Uri.ToString().Remove(0, dir.Container.Uri.ToString().Length).Trim('/');

            container = null;
            if (EventStoreId.IsValid(topic)!= EventStoreId.Rule.Valid)
                return false;
            container = EventStoreId.Parse(topic);
            return IsValid(config, container);
        }
Esempio n. 26
0
        public static bool ExistsValid(string root, EventStoreId storeId)
        {
            var folder = Path.Combine(root, storeId.Name);

            if (!Directory.Exists(folder))
            {
                return(false);
            }

            var check = Path.Combine(folder, "stream.chk");
            var store = Path.Combine(folder, "stream.dat");

            return(System.IO.File.Exists(check) && System.IO.File.Exists(store));
        }
Esempio n. 27
0
        public static FileEventStore CreateNew(string root, EventStoreId storeId)
        {
            var folder = Path.Combine(root, storeId.Name);

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            var check = FileEventPointer.OpenOrCreateForWriting((Path.Combine(folder, "stream.chk")));
            var store = FileEventStoreChunk.CreateNew(Path.Combine(folder, "stream.dat"));

            return(new FileEventStore(storeId, store, check));
        }
Esempio n. 28
0
        public static bool TryGetContainerName
        (
            AzureStoreConfiguration config,
            CloudBlobDirectory dir,
            out EventStoreId container)
        {
            var topic = dir.Uri.ToString().Remove(0, dir.Container.Uri.ToString().Length).Trim('/');

            container = null;
            if (EventStoreId.IsValid(topic) != EventStoreId.Rule.Valid)
            {
                return(false);
            }
            container = EventStoreId.Parse(topic);
            return(IsValid(config, container));
        }
Esempio n. 29
0
        public bool Execute(CommandProcessorContext context, CancellationToken token, string[] args)
        {
            if (args.Length != 1)
            {
                context.Log.Error("Container name expected");
                return(false);
            }

            var isValid = EventStoreId.IsValid(args[0]);

            if (isValid != EventStoreId.Rule.Valid)
            {
                context.Log.Error("Container name is invalid: {0}", isValid);
                return(false);
            }

            context.Log.Info("Switching to container '{0}'", args[0]);
            context.Client.UseEventStore(args[0]);

            return(true);
        }
Esempio n. 30
0
 public FileEventStore(EventStoreId storeId, FileEventStoreChunk store, FileEventPointer checkpoint)
 {
     StoreId = storeId;
     _store = store;
     _checkpoint = checkpoint;
 }
Esempio n. 31
0
 public static bool IsValid(AzureStoreConfiguration config, EventStoreId container)
 {
     var store = config.GetPageBlob(container.Name + "/stream.dat");
     return Exists(store);
 }
Esempio n. 32
0
 public AzureEventStore(EventStoreId container, AzureEventStoreChunk store, AzureEventPointer checkpoint)
 {
     Container   = container;
     _store      = store;
     _checkpoint = checkpoint;
 }
Esempio n. 33
0
 public AzureEventStore(EventStoreId container, AzureEventStoreChunk store, AzureEventPointer checkpoint)
 {
     Container = container;
     _store = store;
     _checkpoint = checkpoint;
 }
Esempio n. 34
0
        public static AzureEventStore OpenExistingForReading(AzureStoreConfiguration config, EventStoreId container)
        {
            var blob  = config.GetPageBlob(container.Name + "/stream.dat");
            var check = AzureEventPointer.OpenReadable(blob);

            blob.FetchAttributes();
            var store = AzureEventStoreChunk.OpenExistingForReading(blob, blob.Properties.Length);

            return(new AzureEventStore(container, store, check));
        }
Esempio n. 35
0
 public FileEventStore(EventStoreId storeId, FileEventStoreChunk store, FileEventPointer checkpoint)
 {
     StoreId     = storeId;
     _store      = store;
     _checkpoint = checkpoint;
 }
Esempio n. 36
0
        public static bool IsValid(AzureStoreConfiguration config, EventStoreId container)
        {
            var store = config.GetPageBlob(container.Name + "/stream.dat");

            return(Exists(store));
        }
Esempio n. 37
0
        public static AzureEventStore OpenExistingForWriting(AzureStoreConfiguration config, EventStoreId container)
        {
            var blob   = config.GetPageBlob(container.Name + "/stream.dat");
            var check  = AzureEventPointer.OpenWriteable(blob);
            var offset = check.Read();
            var length = blob.Properties.Length;
            var store  = AzureEventStoreChunk.OpenExistingForWriting(blob, offset, length);

            return(new AzureEventStore(container, store, check));
        }
Esempio n. 38
0
        public static AzureEventStore CreateNewForWriting(AzureStoreConfiguration config, EventStoreId container)
        {
            var blob = config.GetPageBlob(container.Name + "/stream.dat");

            blob.Container.CreateIfNotExist();

            var store = AzureEventStoreChunk.CreateNewForWriting(blob);
            var check = AzureEventPointer.OpenWriteable(blob);

            return(new AzureEventStore(container, store, check));
        }
 void Should(EventStoreId.Rule validity, string asdAsd)
 {
     Assert.AreEqual(validity, EventStoreId.IsValid(asdAsd), asdAsd);
 }
 void Should(EventStoreId.Rule validity, string asdAsd)
 {
     Assert.AreEqual(validity, EventStoreId.IsValid(asdAsd), asdAsd);
 }