public static void Create(ProjectionsManager manager, string[] commandArgs) { if (commandArgs.Length < 2) { Log("Invalid argument value (projection type)"); return; } var type = commandArgs[0].Trim().ToLower(); var queryInfo = GetQueryAndCredentials(commandArgs.Skip(1).ToArray()); if (queryInfo == null || (type != "onetime" && string.IsNullOrEmpty(queryInfo.Item1))) { Log("Invalid arguments"); return; } var pname = queryInfo.Item1; var query = queryInfo.Item2; var userCredentials = queryInfo.Item3; switch (type) { case "onetime": Log("Creating onetime projection..."); manager.CreateOneTimeAsync(query, userCredentials).Wait(); Log("Created"); break; case "continuous": Log("Creating continuous projection {0}...", pname); manager.CreateContinuousAsync(pname, query, userCredentials).Wait(); Log("Created"); break; default: Log("projection type not recognized"); break; } }
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(); } }