public static void Configure(ProjectionGatewayConfiguration projectionGatewayConfiguration, IPEndPoint httpEndPoint, UserCredentials credentials)
            {
                var projectionManager = new ProjectionsManager(new ConsoleLogger(), httpEndPoint, new TimeSpan(1, 0, 0, 0));
                var byCategoryProjectionStatus = ((JObject)JsonConvert.DeserializeObject(projectionManager.GetStatusAsync("$by_category", credentials).Result))["status"].ToString();
                var streamByCategoryProjectionStatus = ((JObject)JsonConvert.DeserializeObject(projectionManager.GetStatusAsync("$stream_by_category", credentials).Result))["status"].ToString();

                if (byCategoryProjectionStatus == "Stopped")
                {
                    projectionManager.EnableAsync("$by_category", credentials).Wait();
                }

                if (streamByCategoryProjectionStatus == "Stopped")
                {
                    projectionManager.EnableAsync("$stream_by_category", credentials).Wait();
                }
                const string projectionPattern = @"fromCategory('{0}')
                .foreachStream()
                .whenAny(function(state, event){{
                    linkTo('{1}', event);
                }})";

                foreach (var aggregateRootName in projectionGatewayConfiguration.Subscriptions.Keys)
                {
                    projectionManager.CreateContinuousAsync(
                        string.Format("{0}Projection", aggregateRootName),
                        string.Format(projectionPattern, aggregateRootName, aggregateRootName + "View"), credentials).Wait();
                }
            }
Ejemplo n.º 2
0
 public static void Enable(ProjectionsManager manager, string[] commandArgs)
 {
     var nameAndCredentials = GetProjectionNameAndCredentials(commandArgs);
     var name = nameAndCredentials.Item1;
     Log("Enabling {0}...", name);
     manager.EnableAsync(name, nameAndCredentials.Item2).Wait();
     Log("{0} enabled", name);
 }
        public static void SetupEventStore(StartConflictOption opt = StartConflictOption.Connect)
        {

            //TODO: Convert to Embedded when I can figure out loading the miniWeb component
            var runningEventStores = Process.GetProcessesByName("EventStore.ClusterNode");
            if (runningEventStores.Length != 0)
            {
                switch (opt)
                {
                    case StartConflictOption.Connect:
                        _process = runningEventStores[0];
                        break;
                    case StartConflictOption.Kill:
                        foreach (var es in runningEventStores)
                        {
                            es.Kill();
                        }
                        break;
                    case StartConflictOption.Error:
                        throw new Exception("Conflicting EventStore running.");
                    default:
                        throw new ArgumentOutOfRangeException(nameof(opt), opt, null);
                }
            }
            if (_process == null)
            {
                _process = new Process
                {
                    StartInfo =
                    {
                        UseShellExecute = false, CreateNoWindow = true, FileName = Path, Arguments = Args, Verb = "runas"
                    }
                };
                _process.Start();
            }
            var tcp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113);
            var http = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2113);
            Connection = EventStoreConnection.Create(tcp);
            Connection.ConnectAsync().Wait();
            var pManager = new ProjectionsManager(new NullLogger(), http, TimeSpan.FromSeconds(5));
            var creds = new UserCredentials("admin", "changeit");
            bool ready = false;
            int retry = 0;
            while (!ready)
            {
                try
                {
                    pManager.EnableAsync("$streams", creds).Wait();
                    pManager.EnableAsync("$by_event_type", creds).Wait();
                    pManager.EnableAsync("$by_category", creds).Wait();
                    pManager.EnableAsync("$stream_by_category", creds).Wait();
                    ready = true;
                }
                catch
                {
                    retry++;
                    if (retry > 8)
                        throw new Exception("EventStore Projection Start Error.");
                    System.Threading.Thread.Sleep(250);
                }
            }
        }