Esempio n. 1
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. 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 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);
                }
            }
        }
Esempio n. 4
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));
        }