Ejemplo n.º 1
0
        private bool OnThumbnailReady(IThumbnailProvider dw, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > callback, ISurface <ColorBgra> thumb)
        {
            ValueEventArgs <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > args = ValueEventArgs <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > .Get(Tuple.Create <IThumbnailProvider, ISurface <ColorBgra> >(dw, thumb));

            List <Tuple <ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, object, ValueEventArgs <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > > > thumbnailReadyInvokeList = this.thumbnailReadyInvokeList;

            lock (thumbnailReadyInvokeList)
            {
                this.thumbnailReadyInvokeList.Add(new Tuple <ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, object, ValueEventArgs <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > >(callback, this, args));
            }
            try
            {
                this.syncContext.Post(delegate(object _) {
                    this.DrainThumbnailReadyInvokeList();
                }, null);
                return(true);
            }
            catch (Exception exception)
            {
                if (!(exception is ObjectDisposedException) && !(exception is InvalidOperationException))
                {
                    throw;
                }
                return(false);
            }
        }
 public static void Raise <T>(this ValueEventHandler <T> handler, object sender, ValueEventArgs <T> e)
 {
     if (handler != null)
     {
         handler(sender, e);
     }
 }
Ejemplo n.º 3
0
 private void HookUpEvents()
 {
     using (Dictionary <string, Property> .ValueCollection.Enumerator enumerator = this.properties.Values.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             ValueEventHandler <object> handler;
             ValueEventHandler <bool>   handler3;
             Property property = enumerator.Current;
             if (this.valueChangedHandlers.TryGetValue(property, out handler))
             {
                 property.ValueChanged -= handler;
             }
             ValueEventHandler <object> handler2 = (s, e) => this.OnPropertyValueChanged(property, e.Value);
             property.ValueChanged += handler2;
             this.valueChangedHandlers.Add(property, handler2);
             if (this.readOnlyChangedHandlers.TryGetValue(property, out handler3))
             {
                 property.ReadOnlyChanged -= handler3;
             }
             ValueEventHandler <bool> handler4 = (s, e) => this.OnPropertyReadOnlyChanged(property, e.Value);
             property.ReadOnlyChanged += handler4;
             this.readOnlyChangedHandlers.Add(property, handler4);
         }
     }
 }
        public async Task CanGetEventSubscriptions_WhenTheyHaveBeenSubscribedBefore()
        {
            Action <Type> register = t => { };

            var expectedValue        = 0;
            var @event               = new ValueEvent(Value);
            var eventHandlerInstance = new ValueEventHandler();
            var eventHandler         = new Func <ValueEvent, Task>(e =>
            {
                expectedValue = e.Value;
                return(Task.CompletedTask);
            });

            A.CallTo(() => this.handlerRegistry.GetEventHandlers(@event)).Returns(new[] { eventHandlerInstance });

            this.testee.AddEventHandler(eventHandler);
            this.testee.ScanAssemblyForMessageHandlers(Assembly.GetExecutingAssembly(), register);

            var subscriptions = this.testee.GetEventSubscriptions(@event);
            var tasks         = subscriptions.Select(s => s.HandleAsync(@event));

            await Task.WhenAll(tasks).ConfigureAwait(false);

            expectedValue.Should().Be(Value);
            eventHandlerInstance.Value.Should().Be(Value);
        }
        public void CanSubscribeEventHandler()
        {
            var handler = new ValueEventHandler();

            this.testee.SubscribeEventHandler <ValueEvent>(handler.HandleAsync);

            var subscriptions = this.testee.Subscriptions.GetEventSubscriptions(new ValueEvent(11));

            subscriptions.Single().Should().BeAssignableTo <EventSubscription <ValueEvent> >();
        }
        public static void Raise <T>(this ValueEventHandler <T> handler, object sender, T value)
        {
            if (handler != null)
            {
                ValueEventArgs <T> e = ValueEventArgs <T> .Get(value);

                handler(sender, e);
                e.Return();
            }
        }
Ejemplo n.º 7
0
        private void StateMachineThread()
        {
            this.threadException = null;
            ValueEventHandler <PaintDotNet.Updates.State> handler = delegate(object sender, ValueEventArgs <PaintDotNet.Updates.State> e) {
                this.stateMachineInitialized.Set();
                this.OnStateBegin(e.Value);
            };
            ProgressEventHandler handler2 = (sender, e) => this.OnStateProgress(e.Percent);

            try
            {
                this.stateMachineNotBusy.Set();
                this.OnStateMachineBegin();
                this.stateMachineNotBusy.Reset();
                this.stateMachine.NewState      += handler;
                this.stateMachine.StateProgress += handler2;
                this.stateMachine.Start();
                do
                {
                    this.stateMachineNotBusy.Set();
                    this.OnStateWaitingForInput(this.stateMachine.CurrentState);
                    this.inputAvailable.WaitOne();
                    this.inputAvailable.Reset();
                    if (this.pleaseAbort)
                    {
                        break;
                    }
                    this.stateMachine.ProcessInput(this.queuedInput);
                }while (!this.stateMachine.IsInFinalState);
                this.stateMachineNotBusy.Set();
            }
            catch (Exception exception)
            {
                this.threadException = exception;
            }
            finally
            {
                this.stateMachineNotBusy.Set();
                this.stateMachineInitialized.Set();
                this.stateMachine.NewState      -= handler;
                this.stateMachine.StateProgress -= handler2;
                this.OnStateMachineFinished();
            }
        }
Ejemplo n.º 8
0
        public void EnsureInitialize(Assembly assembly)
        {
            foreach (var type in assembly.GetTypes())
            {
                ExecutionContainerAttribute containerAttr =
                    type.GetCustomAttributes(typeof(ExecutionContainerAttribute), false)
                    .Cast <ExecutionContainerAttribute>()
                    .FirstOrDefault();
                if (containerAttr == null)
                {
                    continue;
                }
                LogErrorAttribute classErrorAttr = type.GetCustomAttributes(typeof(LogErrorAttribute), false).Cast <LogErrorAttribute>().FirstOrDefault();
                var factory = _factories[containerAttr.FactoryType];
                var methods = type.GetMethods(  );
                foreach (var method in methods)
                {
                    ExecutionAttribute executionAttr = method.GetCustomAttributes(typeof(ExecutionAttribute), false).Cast <ExecutionAttribute>().FirstOrDefault();
                    LogErrorAttribute  logErrorAttr  = method.GetCustomAttributes(typeof(LogErrorAttribute), false).Cast <LogErrorAttribute>().FirstOrDefault();
                    if (executionAttr != null)
                    {
                        var handle = method.MethodHandle;

                        ValueEventHandler handler = (object sender, ValueEventArgs e) => MethodBase.GetMethodFromHandle(handle).Invoke(null, new object[] { sender, e });
                        var execution             = new FuncExecution(handler);
                        if (logErrorAttr != null)
                        {
                            execution.SwallowError = logErrorAttr.Swallow;
                            execution.LogError     = true;
                        }
                        else if (classErrorAttr != null)
                        {
                            execution.SwallowError = classErrorAttr.Swallow;
                            execution.LogError     = true;
                        }
                        factory.Add(executionAttr.Key, execution);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public static void Main(String[] args)
        {
            ThreadPool.SetMaxThreads(2, 256);
            //Executor executor = Executors.newFixedThreadPool(2);
            //EventFactory<ValueEvent<String>> factory = ValueEventHandler.factory();

            Disruptor <ValueEvent <String> > disruptorA =
                new Disruptor <ValueEvent <String> >(
                    () => new ValueEvent <string>(),
                    1024,
                    TaskScheduler.Default,
                    ProducerType.MULTI,
                    new BlockingWaitStrategy());

            Disruptor <ValueEvent <String> > disruptorB =
                new Disruptor <ValueEvent <String> >(
                    () => new ValueEvent <string>(),
                    1024,
                    TaskScheduler.Default,
                    ProducerType.SINGLE,
                    new BlockingWaitStrategy());

            ValueEventHandler <String> handlerA = new ValueEventHandler <String>(
                disruptorB.GetRingBuffer);

            disruptorA.HandleEventsWith(handlerA);

            ValueEventHandler <String> handlerB = new ValueEventHandler <String>(
                disruptorA.GetRingBuffer);

            disruptorB.HandleEventsWith(handlerB);

            disruptorA.Start();
            disruptorB.Start();

            Console.Read();
        }
Ejemplo n.º 10
0
        public void QueueThumbnailUpdate(IThumbnailProvider updateMe, int thumbSideLength, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > callback)
        {
            if (thumbSideLength < 1)
            {
                throw new ArgumentOutOfRangeException("thumbSideLength", "must be greater than or equal to 1");
            }
            object updateLock = this.updateLock;

            lock (updateLock)
            {
                this.RemoveFromQueue(updateMe);
                Tuple <IThumbnailProvider, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, int> item = new Tuple <IThumbnailProvider, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, int>(updateMe, callback, thumbSideLength);
                if (this.renderQueue.Any <Tuple <IThumbnailProvider, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, int> >())
                {
                    Tuple <IThumbnailProvider, ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >, int> tuple2 = this.renderQueue.PeekBack();
                    if (item.Equals(tuple2))
                    {
                        this.renderQueue.DequeueBack();
                    }
                }
                this.renderQueue.Enqueue(item);
                Monitor.Pulse(this.updateLock);
            }
        }
Ejemplo n.º 11
0
        //delegate void( object , ValueEventArgs ) ValueEventHandler;
        //public EventHandler/*<TArgs>*/ EventHandler;

        public FuncExecution(ValueEventHandler /*<TArgs>*/ func)
        {
            EventHandler += func;
        }