Ejemplo n.º 1
0
        private void Publish(TodoListEvent todoListEvent, TodoItem item)
        {
            ITodoListEvents callback = OperationContext.Current.GetCallbackChannel <ITodoListEvents>();

            Thread t = new Thread(x =>
            {
                List <ITodoListEvents> toremove = new List <ITodoListEvents>();

                lock (_SubscriberLock)
                {
                    foreach (ITodoListEvents cb in _TodoListEventSubscribers)
                    {
                        if (cb.GetHashCode() != x.GetHashCode())
                        {
                            Console.WriteLine("Sending event to {0}", cb.GetHashCode());
                            try
                            {
                                if (todoListEvent == TodoListEvent.ItemAdded)
                                {
                                    cb.ItemAdded(item);
                                }
                                else if (todoListEvent == TodoListEvent.ItemChanged)
                                {
                                    cb.ItemChanged(item);
                                }
                                else if (todoListEvent == TodoListEvent.ItemDeleted)
                                {
                                    cb.ItemDeleted(item.ID);
                                }
                            }
                            catch (Exception ex)
                            {
                                FaultException faultex = ex as FaultException;
                                if (faultex == null)
                                {
                                    Console.WriteLine("Callback failed, removing {0}", cb.GetHashCode());
                                    toremove.Add(cb);
                                }
                            }
                        }
                    }
                    if (toremove.Count > 0)
                    {
                        foreach (ITodoListEvents cb in toremove)
                        {
                            _TodoListEventSubscribers.Remove(cb);
                        }
                    }
                }
            });

            t.Start(callback);
        }
Ejemplo n.º 2
0
        private void Publish(TodoListEvent todoListEvent, TodoItem item)
        {
            ITodoListEvents callback = OperationContext.Current.GetCallbackChannel<ITodoListEvents>();

            Thread t = new Thread(x =>
            {
                List<ITodoListEvents> toremove = new List<ITodoListEvents>();

                lock (_SubscriberLock)
                {
                    foreach (ITodoListEvents cb in _TodoListEventSubscribers)
                    {
                        if (cb.GetHashCode() != x.GetHashCode())
                        {
                            Console.WriteLine("Sending event to {0}", cb.GetHashCode());
                            try
                            {
                                if (todoListEvent == TodoListEvent.ItemAdded)
                                    cb.ItemAdded(item);
                                else if (todoListEvent == TodoListEvent.ItemChanged)
                                    cb.ItemChanged(item);
                                else if (todoListEvent == TodoListEvent.ItemDeleted)
                                    cb.ItemDeleted(item.ID);
                            }
                            catch (Exception ex)
                            {
                                FaultException faultex = ex as FaultException;
                                if (faultex == null)
                                {
                                    Console.WriteLine("Callback failed, removing {0}", cb.GetHashCode());
                                    toremove.Add(cb);
                                }
                            }
                        }
                    }
                    if (toremove.Count > 0)
                    {
                        foreach (ITodoListEvents cb in toremove)
                        {
                            _TodoListEventSubscribers.Remove(cb);
                        }
                    }
                }

            });
            t.Start(callback);

        }