Example #1
0
 /// <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;
 }
Example #2
0
 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);
 }
Example #3
0
 /// <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);
 }
Example #4
0
 /// <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);
     }
 }
Example #5
0
 /// <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);
     }
 }
Example #6
0
 /// <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;
 }
Example #7
0
 internal void RemoveSimulatableChildWithoutDisposing(Simulatable child)
 {
     RemoveSimulatableChildWithoutDisposingHook(child);
 }
Example #8
0
 /// <summary>
 /// Handle removing a simulatable child without disposing it.
 /// </summary>
 protected abstract void RemoveSimulatableChildWithoutDisposingHook(Simulatable child);
Example #9
0
 /// <summary>
 /// Handle the fact that a simulatable child's name has changed.
 /// </summary>
 protected virtual void OnSimulatableChildNameChanged(Simulatable child, string oldName) { }
Example #10
0
 /// <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);
 }
Example #11
0
 public void RegisterMessage(Simulatable source, string messageName, Action correspondingEvent)
 {
     string messageSource = source.GetMessagePath(this, messageName);
     correspondingEvent += () => Message.InvokeMessage(source, messages[messageSource]);
 }
Example #12
0
 /// <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
 }
Example #13
0
 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); }
 }
Example #14
0
 private Simulatable ResolveDestination(Simulatable context)
 {
     return context.GetSimulatableRelative(destinationParts);
 }
Example #15
0
 public bool Contains(Simulatable item)
 {
     return GetItems().Contains(item);
 }
Example #16
0
 private TreeNode GetTreeNode(Simulatable item)
 {
     if (item == null) return null;
     TreeNode[] nodes = treeView.Nodes.Find(item.GetHashCode().ToString(), true);
     return nodes.FirstOrDefault();
 }