Exemple #1
0
        private void OnDoWork(IThreadInvoker invoker, CancellationToken token)
        {
            _updater.CheckForUpdate(_currentVersion);

            if (!_updater.IsUpdateAvailable)
            {
                return;
            }

            invoker.InvokeOnUIThreadSync(OnUpdateReadyToDownload);

            if (!AllowDownload)
            {
                return;
            }

            invoker.InvokeOnUIThreadSync(OnBeforeDownload);

            _updater.DownloadProgressChanged += delegate(FileDownloadProgress progress)
            {
                invoker.InvokeOnUIThreadSync(cancellationToken => ProgressChanged(progress));
            };

            token.Register(_updater.CancelDownload);

            _updater.DownloadUpdate();
        }
Exemple #2
0
        private static void TestConnection(IThreadInvoker threadInvoker, CancellationToken cancellationToken)
        {
            // ReSharper disable once UnusedVariable
            using (var client = new WebClient())
                using (var stream = client.OpenRead("http://www.google.com/"))
                {
                }

            // ReSharper disable once UnusedVariable
            using (var client = new WebClient())
                using (var stream = client.OpenRead("http://www.microsoft.com/"))
                {
                }
        }
        private static void TestConnection(IThreadInvoker threadInvoker, CancellationToken cancellationToken)
        {
            // ReSharper disable once UnusedVariable
            using (var client = new WebClient())
            using (var stream = client.OpenRead("http://www.google.com/"))
            {
            }

            // ReSharper disable once UnusedVariable
            using (var client = new WebClient())
            using (var stream = client.OpenRead("http://www.microsoft.com/"))
            {
            }
        }
Exemple #4
0
        public Subscriber(
            SubscribeAttribute subscribeAttribute,
            MethodInfo subscriberMethodInfo,
            IThreadInvoker threadInvoker,
            object container,
            MessageChecker messageChecker)
        {
            _subscribeAttribute   = subscribeAttribute;
            _subscriberMethodInfo = subscriberMethodInfo;
            _threadInvoker        = threadInvoker;
            Container             = container;
            _messageChecker       = messageChecker;

            var parameters = _subscriberMethodInfo.GetParameters();

            if (parameters.Length != 1)
            {
                throw new ArgumentException("Subscriber method must have only one parameter.");
            }
            _subscribeType = parameters[0].ParameterType;
        }
Exemple #5
0
        /// <summary>
        /// Builds a <see cref="Task{TResult}"/> object whose <see cref="Task{TResult}.Result"/> property returns
        /// <code>true</code> if the task's <see cref="DoWork"/> action completed without throwing an exception or
        /// <code>false</code> if it threw an exception.
        /// </summary>
        /// <returns>
        /// Task that may be run asynchronously or synchronously on the thread specified by
        /// <see cref="OnThread"/> or <see cref="OnCurrentThread"/>.
        /// </returns>
        public Task <bool> Build()
        {
            var scheduler = _callbackThread;
            var token     = _cancellationToken;

            if (scheduler == null)
            {
                throw new InvalidOperationException("Missing TaskScheduler");
            }

            if (token == null)
            {
                throw new InvalidOperationException("Missing CancellationToken");
            }

            _invoker = new ThreadInvoker(scheduler, token);

            var task = new Task <bool>(delegate
            {
                try
                {
                    if (InvokeBeforeStart() && InvokeDoWork())
                    {
                        InvokeSucceed();
                        return(true);
                    }
                }
                finally
                {
                    // TODO: Log uncaught exceptions?
                    // TODO: Where to handle uncaught exceptions?
                    InvokeFinally();
                }
                return(false);
            }, token, TaskCreationOptions.None);

            return(task);
        }
Exemple #6
0
        /// <summary>
        /// Builds a <see cref="Task{TResult}"/> object whose <see cref="Task{TResult}.Result"/> property returns
        /// <code>true</code> if the task's <see cref="DoWork"/> action completed without throwing an exception or
        /// <code>false</code> if it threw an exception.
        /// </summary>
        /// <returns>
        /// Task that may be run asynchronously or synchronously on the thread specified by
        /// <see cref="OnThread"/> or <see cref="OnCurrentThread"/>.
        /// </returns>
        public Task<bool> Build()
        {
            var scheduler = _callbackThread;
            var token = _cancellationToken;

            if (scheduler == null)
            {
                throw new InvalidOperationException("Missing TaskScheduler");
            }

            if (token == null)
            {
                throw new InvalidOperationException("Missing CancellationToken");
            }

            _invoker = new ThreadInvoker(scheduler, token);

            var task = new Task<bool>(delegate
                {
                    try
                    {
                        if (InvokeBeforeStart() && InvokeDoWork())
                        {
                            InvokeSucceed();
                            return true;
                        }
                    }
                    finally
                    {
                        // TODO: Log uncaught exceptions?
                        // TODO: Where to handle uncaught exceptions?
                        InvokeFinally();
                    }
                    return false;
                }, token, TaskCreationOptions.None);

            return task;
        }
 public IRemotingTestServices GetServices(IThreadInvoker invoker)
 {
     return _queue.CreateProxy<IRemotingTestServices>(invoker, this);
 }
 public InvokeReactorQueueProxyHandler(InvokeReactorQueue queue, object implementation, IThreadInvoker invoker)
 {
     _queue = queue;
     _implementation = implementation;
     _invoker = invoker;
 }
Exemple #9
0
        private void OnDoWork(IThreadInvoker invoker, CancellationToken token)
        {
            _updater.CheckForUpdate(_currentVersion);

            if (!_updater.IsUpdateAvailable)
                return;

            invoker.InvokeOnUIThreadSync(OnUpdateReadyToDownload);

            if (!AllowDownload)
                return;

            invoker.InvokeOnUIThreadSync(OnBeforeDownload);

            _updater.DownloadProgressChanged += delegate(FileDownloadProgress progress)
                {
                    invoker.InvokeOnUIThreadSync(cancellationToken => ProgressChanged(progress));
                };

            token.Register(_updater.CancelDownload);

            _updater.DownloadUpdate();
        }
 private void DoNothing(IThreadInvoker threadinvoker, CancellationToken cancellationtoken)
 {
 }
 private void DoNothing(IThreadInvoker threadinvoker, CancellationToken cancellationtoken)
 {
 }
 private void Work(IThreadInvoker threadInvoker, CancellationToken cancellationToken)
 {
     TestIsOnline();
 }
 public IInvokeQueueTestInterface GetTestInterface(IThreadInvoker invoker)
 {
     return _queue.CreateProxy<IInvokeQueueTestInterface>(invoker, this);
 }