/// <summary> /// Create a Navigator. /// </summary> /// <param name="destinationParts">The destination split into string parts. May not be null.</param> /// <param name="context">The navigation context. May not be null.</param> public Navigator(string[] destinationParts, Simulatable context) { XiHelper.ArgumentNullCheck(destinationParts, context); this.destinationParts = destinationParts; this.destinationPartIndex = -1; this.context = context; }
private void BuildTreeNode(Simulatable item, TreeNode parentNode) { TreeNode node = new TreeNode(item.NameOrDefault); node.Name = item.GetHashCode().ToString(); if (parentNode == null) treeView.Nodes.Add(node); else parentNode.Nodes.Add(node); foreach (Simulatable child in item.PersistentSimulatableChildren) BuildTreeNode(child, node); }
/// <summary> /// Invoke a message in the given context. /// Message definition may be an empty string for no message. /// </summary> public static void InvokeMessage(Simulatable context, string messageDefinition, object eventArgument) { XiHelper.ArgumentNullCheck(context, messageDefinition); if (messageDefinition.Length == 0) return; Message message; if (!messageDictionary.TryGetValue(messageDefinition, out message)) messageDictionary.Add(messageDefinition, message = new Message(messageDefinition)); message.Invoke(context, eventArgument); }
/// <summary> /// Invoke messages in the given context. /// Message definition may be an empty string for no messages. /// Message definitions are separated by a '@' with no white space. /// </summary> public static void InvokeMessages(Simulatable context, string messageDefinitions, object eventArgument) { XiHelper.ArgumentNullCheck(context, messageDefinitions); if (messageDefinitions.Length == 0) return; // OPTIMIZATION if (!HasMultipleMessageDefinitions(messageDefinitions)) InvokeMessage(context, messageDefinitions, eventArgument); // OPTIMIZATION else { string[] messageDefinitionArray = ToMessageDefinitionArray(messageDefinitions); foreach (string messageDefinition in messageDefinitionArray) InvokeMessage(context, messageDefinition, eventArgument); } }
/// <summary> /// Try to invoke a message in the given context. /// Message definition may be an empty string for no message. /// </summary> public static void TryInvokeMessage(Simulatable context, string messageDefinition, object eventArgument) { XiHelper.ArgumentNullCheck(context, messageDefinition); try { InvokeMessage(context, messageDefinition, eventArgument); } catch (Exception e) { Trace.Fail(e.Message); } }
/// <summary> /// Clear the calling context. /// Important to do to avoid keeping around stale object references. /// </summary> public void ClearContext(Simulatable context) { for (int i = 0; i < argumentValues.Length; ++i) if (argumentValues[i] == context) argumentValues[i] = ArgumentSymbol.Context; }
internal void RemoveSimulatableChildWithoutDisposing(Simulatable child) { RemoveSimulatableChildWithoutDisposingHook(child); }
/// <summary> /// Handle removing a simulatable child without disposing it. /// </summary> protected abstract void RemoveSimulatableChildWithoutDisposingHook(Simulatable child);
/// <summary> /// Handle the fact that a simulatable child's name has changed. /// </summary> protected virtual void OnSimulatableChildNameChanged(Simulatable child, string oldName) { }
/// <summary> /// Notify that a simulatable child's name has changed. /// </summary> public void NotifySimulatableChildNameChanged(Simulatable child, string oldName) { XiHelper.ArgumentNullCheck(child, oldName); OnSimulatableChildNameChanged(child, oldName); }
public void RegisterMessage(Simulatable source, string messageName, Action correspondingEvent) { string messageSource = source.GetMessagePath(this, messageName); correspondingEvent += () => Message.InvokeMessage(source, messages[messageSource]); }
/// <summary> /// Invoke the message in the given invocation context. /// </summary> public void Invoke(Simulatable context, object eventArgument) { XiHelper.ArgumentNullCheck(context); Simulatable destination = ResolveDestination(context); if (destination != null) InvokeOn(context, destination, eventArgument); // TODO: consider logging if the destination isn't found }
private void InvokeOn(Simulatable context, object instance, object eventArgument) { MethodInfo method = ResolveMethod(instance); if (method == null) return; arguments.PopulateContext(context); arguments.PopulateEventArgument(eventArgument); try { method.Invoke(instance, arguments.ArgumentValues); } finally { arguments.ClearContext(context); } }
private Simulatable ResolveDestination(Simulatable context) { return context.GetSimulatableRelative(destinationParts); }
public bool Contains(Simulatable item) { return GetItems().Contains(item); }
private TreeNode GetTreeNode(Simulatable item) { if (item == null) return null; TreeNode[] nodes = treeView.Nodes.Find(item.GetHashCode().ToString(), true); return nodes.FirstOrDefault(); }