protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["EntityToken"] == null) { RelationshipGraphHolder.Controls.Add(new LiteralControl("No entity token.... nothing to do....")); return; } string serializedEntityToken = Request.QueryString["EntityToken"]; EntityToken entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); //Composite.Core.WebClient.ElementInformation elementInformation = ElementInformationSerializer.Deserialize(serializedEntityToken); RelationshipGraph graph = new RelationshipGraph(entityToken, RelationshipGraphSearchOption.Both); foreach (RelationshipGraphLevel level in graph.Levels) { if (level.AllEntities.Count() != 0) { RelationshipGraphHolder.Controls.Add(new LiteralControl(new XElement("h2", string.Format("Level {0}", level.Level)).ToString())); } foreach (EntityToken token in level.Entities) { PrettyPrintEntityToken(token, "red"); } foreach (EntityToken token in level.HookedEntities) { PrettyPrintEntityToken(token, "green"); } } }
/// <summary> /// Posts refresh messages to the ancestors of the specified entityToken /// </summary> /// <param name="childEntityToken"></param> /// <param name="parentLevel">1 means the first parent, 2 means the second, etc.</param> public void PostRefreshMessages(EntityToken childEntityToken, int parentLevel = 1) { Verify.ArgumentNotNull(childEntityToken, "childEntityToken"); if (_postRefreshMessagesCalled) { throw new InvalidOperationException("Only one PostRefreshMessages call is allowed"); } _postRefreshMessagesCalled = true; RelationshipGraph relationshipGraph = new RelationshipGraph(childEntityToken, RelationshipGraphSearchOption.Both); var levels = relationshipGraph.Levels.Evaluate(); if (levels.Count <= parentLevel) { return; } RelationshipGraphLevel relationshipGraphLevel = levels.ElementAt(parentLevel); IManagementConsoleMessageService messageService = _flowControllerServicesContainer.GetService <IManagementConsoleMessageService>(); foreach (EntityToken entityToken in relationshipGraphLevel.AllEntities) { messageService.RefreshTreeSection(entityToken); Log.LogVerbose(this.GetType().Name, "Refreshing EntityToken: Type = {0}, Source = {1}, Id = {2}, EntityTokenType = {3}", entityToken.Type, entityToken.Source, entityToken.Id, entityToken.GetType()); } }
/// <exclude /> public AddNewTreeRefresher(EntityToken parentEntityToken, FlowControllerServicesContainer flowControllerServicesContainer) { Verify.ArgumentNotNull(parentEntityToken, "parentEntityToken"); Verify.ArgumentNotNull(flowControllerServicesContainer, "flowControllerServicesContainer"); _beforeGraph = new RelationshipGraph(parentEntityToken, RelationshipGraphSearchOption.Both, false, false); _flowControllerServicesContainer = flowControllerServicesContainer; }
/// <exclude /> public DeleteTreeRefresher(EntityToken beforeDeleteEntityToken, FlowControllerServicesContainer flowControllerServicesContainer) { Verify.ArgumentNotNull(beforeDeleteEntityToken, "beforeDeleteEntityToken"); Verify.ArgumentNotNull(flowControllerServicesContainer, "flowControllerServicesContainer"); _beforeGraph = new RelationshipGraph(beforeDeleteEntityToken, RelationshipGraphSearchOption.Both); _flowControllerServicesContainer = flowControllerServicesContainer; }
/// <exclude /> public void PostRefreshMesseges(EntityToken newChildEntityToken) { Verify.ArgumentNotNull(newChildEntityToken, "newChildEntityToken"); Verify.That(!_postRefreshMessegesCalled, "Only one PostRefreshMesseges call is allowed"); _postRefreshMessegesCalled = true; _afterGraph = new RelationshipGraph(newChildEntityToken, RelationshipGraphSearchOption.Both, false, false); IManagementConsoleMessageService messageService = _flowControllerServicesContainer.GetService <IManagementConsoleMessageService>(); foreach (EntityToken entityToken in RefreshBeforeAfterEntityTokenFinder.FindEntityTokens(_beforeGraph, _afterGraph)) { messageService.RefreshTreeSection(entityToken); Log.LogVerbose("AddNewTreeRefresher", string.Format("Refreshing EntityToken: Type = {0}, Source = {1}, Id = {2}, EntityTokenType = {3}", entityToken.Type, entityToken.Source, entityToken.Id, entityToken.GetType())); } }
/// <exclude /> public void PostRefreshMessages(EntityToken afterUpdateEntityToken) { if (_postRefreshMessagesCalled) { throw new InvalidOperationException("Only one PostRefreshMessages call is allowed"); } _postRefreshMessagesCalled = true; _afterGraph = new RelationshipGraph(afterUpdateEntityToken, RelationshipGraphSearchOption.Both, false, false); IManagementConsoleMessageService messageService = _flowControllerServicesContainer.GetService <IManagementConsoleMessageService>(); foreach (EntityToken entityToken in RefreshBeforeAfterEntityTokenFinder.FindEntityTokens(_beforeGraph, _afterGraph)) { messageService.RefreshTreeSection(entityToken); Log.LogVerbose(this.GetType().Name, "Refreshing EntityToken: Type = {0}, Source = {1}, Id = {2}, EntityTokenType = {3}", entityToken.Type, entityToken.Source, entityToken.Id, entityToken.GetType()); } }
protected static void UpdateParents(string seralizedEntityToken, string consoleId) { var entityToken = EntityTokenSerializer.Deserialize(seralizedEntityToken); var graph = new RelationshipGraph(entityToken, RelationshipGraphSearchOption.Both); if (graph.Levels.Count() <= 1) { return; } var level = graph.Levels.ElementAt(1); foreach (var token in level.AllEntities) { var consoleMessageQueueItem = new RefreshTreeMessageQueueItem { EntityToken = token }; ConsoleMessageQueueFacade.Enqueue(consoleMessageQueueItem, consoleId); } }
internal RelationshipGraphLevelEnumerable(RelationshipGraph relationshipGraph) { _relationshipGraph = relationshipGraph; }
protected override bool RunCore(Program program, IList<string> arguments) { // Read RelationshipGraph whose filename is passed in as a parameter. // Build a RelationshipGraph in RelationshipGraph rg var filename = arguments[0]; // create a new RelationshipGraph object var rg = new RelationshipGraph(); // name of person currently being read string name = ""; int numPeople = 0; string[] values; Console.Write("Reading file " + filename + "\n"); try { string input = System.IO.File.ReadAllText(filename);// read file input = input.Replace("\r", ";"); // get rid of nasty carriage returns input = input.Replace("\n", ";"); // get rid of nasty new lines string[] inputItems = Regex.Split(input, @";\s*"); // parse out the relationships (separated by ;) foreach (string item in inputItems) { if (item.Length > 2) // don't bother with empty relationships { values = Regex.Split(item, @"\s*:\s*"); // parse out relationship:name if (values[0] == "name") // name:[personname] indicates start of new person { name = values[1]; // remember name for future relationships rg.AddNode(name); // create the node numPeople++; } // Keys defining relationships start with “has” followed // by a relationship name. else if (values[0].StartsWith("has")) { // Extract relationship name from after “has”. E.g., // hasFriend. var relationship = values[0].Substring("has".Length); // PascalCase -> camelCase. E.g., Friend -> friend. if (relationship.Length > 0) relationship = char.ToLowerInvariant(relationship[0]) + relationship.Substring(1); rg.AddEdge(name, values[1], relationship); // add relationship (name1, name2, relationship) // handle symmetric relationships -- add the other way if (relationship == "spouse" || relationship == "friend") rg.AddEdge(values[1], name, relationship); // for parent relationships add child as well else if (relationship == "parent") rg.AddEdge(values[1], name, "child"); else if (relationship == "child") rg.AddEdge(values[1], name, "parent"); } } } } catch (Exception e) { Console.Write("Unable to read file {0}: {1}\n", filename, e.ToString()); } Console.WriteLine(numPeople + " people read"); program.RelationshipGraph = rg; return true; }