예제 #1
0
 /// <summary>
 /// This method removes a callback to the list of callbacks.
 /// </summary>
 /// <remarks>
 /// It is not checked if the callback has actually been added before and
 /// no exception will be thrown if it had not been present.
 /// </remarks>
 /// <param name="callback">The callback to remove.</param>
 public virtual void RemoveCallback(Action <Event> callback)
 {
     if (IsProcessed)
     {
         throw new InvalidOperationException("Event is already processed.");
     }
     CallbackList.Remove(callback);
 }
예제 #2
0
        public static void BroadcastRemoteCallback(Action <IServiceRemotingCallback> actionDelegate, bool newThread = false)
        {
            if (CallbackList != null && CallbackList.Count > 0)
            {
                if (newThread)
                {
                    Task.Factory.StartNew(() =>
                    {
                        BroadcastRemoteCallback(actionDelegate, false);
                    });
                }
                else
                {
                    Action <IServiceRemotingCallback> invoke =
                        (IServiceRemotingCallback x) =>
                    {
                        try
                        {
                            actionDelegate(x);
                        }
                        catch (CommunicationObjectAbortedException)
                        {
                            CallbackList.Remove(x);
                        }
                    };

                    try
                    {
                        CallbackList.ForEach(invoke);
                    }
                    catch (CommunicationObjectAbortedException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
예제 #3
0
        private SimpleUndoPair InnerAddNodes(IEnumerable <ConversationNode> nodes, IEnumerable <NodeGroup> groups, ILocalizationEngine localization)
        {
            List <Action> undoActions = new List <Action>();
            List <Action> redoActions = new List <Action>();

            //Set up actions for adding/removing the nodes
            foreach (var node in nodes)
            {
                var            n       = node;
                SimpleUndoPair actions = n.GetNodeRemoveActions();

                //Ensure that the localization engine is up to date in terms of usage of localized data
                foreach (var parameter in n.Data.Parameters.OfType <ILocalizedStringParameter>())
                {
                    if (parameter.Value != null)
                    {
                        SimpleUndoPair clearLocalization = localization.ClearLocalizationAction(Id <LocalizedStringType> .ConvertFrom(parameter.TypeId), parameter.Value);
                        undoActions.Add(clearLocalization.Redo);
                        redoActions.Add(clearLocalization.Undo);
                    }
                }

                var containingGroups = m_groups.Where(g => g.Contents.Contains(n.Data.NodeId)).Evaluate();
                redoActions.Add(() =>
                {
                    m_nodes.Add(n);
                    m_audioProvider.UpdateUsage(n);
                    foreach (var group in containingGroups)
                    {
                        group.Contents.Add(n.Data.NodeId);
                    }
                    actions.Undo(); //Undo the node removal
                });
                undoActions.Add(() =>
                {
                    if (CanRemoveFromData(n, PromptNodeDeletion))
                    {
                        m_nodes.Remove(n);
                    }
                    foreach (var group in containingGroups)
                    {
                        group.Contents.Remove(n.Data.NodeId);
                    }
                    actions.Redo(); //Redo the node removal
                    NodesDeleted.Execute();
                });
            }

            //Set up actions for adding/removing nodes from other groups that are gaining/losing their grouping due to removing/adding new groups
            foreach (var group in groups)
            {
                foreach (var node in group.Contents)
                {
                    var n   = node;
                    var old = m_groups.SingleOrDefault(g => g.Contents.Contains(n));
                    if (old != null)
                    {
                        undoActions.Add(() => old.Contents.Add(n));
                        redoActions.Add(() => old.Contents.Remove(n));
                    }
                }
            }

            //Set up actions for adding/removing the groups
            undoActions.Add(() =>
            {
                foreach (var group in groups.Reverse())
                {
                    m_groups.Remove(group);
                }
            });
            redoActions.Add(() =>
            {
                m_groups.AddRange(groups);
            });

            return(new SimpleUndoPair
            {
                Undo = () => { using (m_audioProvider.SuppressUpdates()) foreach (Action action in undoActions)
                                   {
                                       action();
                                   }
                },
                Redo = () => { using (m_audioProvider.SuppressUpdates()) foreach (Action action in redoActions)
                                   {
                                       action();
                                   }
                },
            });
        }