public void Intercept(IInvocation invocation)
        {
            var method = invocation.Method;

            var td = method.ReturnType.GetTaskType();

            switch (td.MethodType)
            {
            case TaskType.None:
                throw new NotSupportedException("Actor method should only return Task or Task<T>");

            case TaskType.Task:
                invocation.ReturnValue = _Queue.Enqueue(() =>
                {
                    return(invocation.Call <Task>());
                });

                break;

            case TaskType.GenericTask:
                var mi = _Proceed.MakeGenericMethod(td.Type);
                mi.Invoke(this, new[] { invocation });
                break;
            }
        }
Exemple #2
0
            public Task <T> Enqueue <T>(Func <Task <T> > function)
            {
                var task = _origin.Enqueue(function);

                _lastTask = task;
                return(task);
            }
Exemple #3
0
        private IEnumerator LoadAsyncCachedBinary(DownloadLicense license)
        {
            byte[]    binary    = new byte[] { };
            Exception exception = null;

            _taskQueue.Enqueue(() =>
            {
                try
                {
                    binary = _modelLoadModule.Load(license);
                }
                catch (Exception ex)
                {
                    exception = ex;
                }
            });

            yield return(WaitFor());

            if (OnProgress != null)
            {
                OnProgress(1.0f);
            }

            if (exception == null)
            {
                LoadVRMFromBinary(binary);
            }
            else if (OnError != null)
            {
                OnError(exception);
            }
        }
Exemple #4
0
        private void FileRegistrationTrackerOnProjectListChanged(object sender, ProjectsEventArgs e)
        {
            Logger.LogInfo("List of projects has changed: Enqueuing a partial file system scan");

            // If we are queuing a task that requires rescanning the entire file system,
            // cancel existing tasks (should be only one really) to avoid wasting time
            _longRunningFileSystemTaskQueue.CancelCurrentTask();

            _longRunningFileSystemTaskQueue.Enqueue(ProjectListChangedTaskId, cancellationToken => {
                // Pass empty changes, as we don't know of any file system changes for
                // existing entries. For new entries, they don't exist in the snapshot,
                // so they will be read form disk
                var emptyChanges = new FullPathChanges(ArrayUtilities.EmptyList <PathChangeEntry> .Instance);
                RescanFileSystem(e.Projects, emptyChanges, cancellationToken);
            });
        }
 public static Task Enqueue(this ITaskQueue queue, Action action)
 {
     return(queue.Enqueue(() =>
     {
         action();
         return Task.FromResult <object>(null);
     }));
 }
Exemple #6
0
 void EnqueueEvent <TEventArgs>(EventHandler <TEventArgs> handler, TEventArgs args)
     where TEventArgs : EventArgs
 {
     if (handler != null)
     {
         EventsQueue.Enqueue(() => handler(this, args));
     }
 }
 public static Task Enqueue(this ITaskQueue queue, Func <Task> action)
 {
     return(queue.Enqueue <object>(async() =>
     {
         await action();
         return null;
     }));
 }
Exemple #8
0
        public Task RepeatState()
        {
            _taskQueue.Enqueue(() =>
            {
                CallbackStateChanged(_state);
            });

            return(Task.CompletedTask);
        }
 private void DirectoryChangeWatcherOnPathsChanged(IList <PathChangeEntry> changes)
 {
     _taskExecutor.ExecuteAsync(token => {
         if (!_isPaused)
         {
             _pathsChangedQueue.Enqueue(changes);
             _flushPathChangesTaskQueue.Enqueue(FlushPathsChangedQueueTaskId, FlushPathsChangedQueueTask);
         }
     });
 }
Exemple #10
0
 public void ProcessRequestAsync(IpcRequest request)
 {
     if (request.RunOnSequentialQueue)
     {
         // Run on queue, with a unique ID since each request is unique
         _sequentialTaskQueue.Enqueue(new TaskId(String.Format("RequestId={0}", request.RequestId)), t => ProcessRequestWorker(request));
     }
     else
     {
         _customThreadPool.RunAsync(() => ProcessRequestWorker(request));
     }
 }
Exemple #11
0
        void EnqueueServiceResolution <TService>(System.Action <TService> setter, bool blocking)
            where TService : class, IService
        {
            if (blocking)
            {
                _taskQueue.Enqueue(() => {
                    TService service = _serviceResolver.Get <TService>();
                    setter(service);
                });
                return;
            }

            bool     found        = false;
            TService foundService = null;

            _taskQueue.Enqueue(() => {
                _serviceResolver.Get <TService>((result, service) => {
                    foundService = service;
                    setter(service);
                    found = true;
                });
            });

            _taskQueue.Parallelize(() => found, -1, string.Format("find service {0}", typeof(TService).Name)).Done += result => {
                CoreLogger.LogDebug(LoggerModules.GameApplication, string.Format("done preparing service {0}: {1}; provider is: {2}", typeof(TService).Name, result,
                                                                                 foundService == null ? "null" : foundService.GetType().Name));
            };
        }
Exemple #12
0
        public void Send(ReportBody body)
        {
            var content = GetJsonContent(body);

            _taskQueue.Enqueue(() =>
            {
                try
                {
                    _httpClient.PostAsync(_uri, content);
                }
                catch (HttpRequestException)
                {
                    //ignore
                }
            });
        }
Exemple #13
0
        private async Task <VpnEndpoint> EnqueueAsync(Func <Task <VpnEndpoint> > func, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(VpnEndpoint.Empty);
            }

            return(await _taskQueue.Enqueue(async() =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return VpnEndpoint.Empty;
                }

                return await func();
            }));
        }
Exemple #14
0
        private void Queued(Action <CancellationToken> action, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            _taskQueue.Enqueue(() =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                action(cancellationToken);
            });
        }
Exemple #15
0
        /// <summary> Fill queue with tasks </summary>
        /// <param name="pathParams"> Paths for input and output files </param>
        /// <param name="operation"> Process operation type </param>
        public void CreateTasks(FilePaths pathParams, IOperation operation)
        {
            Guard.NotNull(pathParams, $"{nameof(pathParams)}");
            Guard.NotNull(operation, $"{nameof(operation)}");

            var fileChunks = operation.SplitFile(pathParams.InputFilePath)
                             .OrderBy(x => x.StartPosition);

            // Each task has it's number for operations which could required sequential processing
            var taskNumber = 0;

            foreach (var chunk in fileChunks)
            {
                var syncParams = _taskSyncParamsFactory.Create(taskNumber, ResetEvent, CanProceed);
                var task       = _gzipTaskFactory.Create(pathParams, syncParams, chunk, operation);

                _taskQueue.Enqueue(task);
                taskNumber++;
            }
        }
        /// <summary>
        /// Changes the current language.
        /// </summary>
        /// <param name="language">The language.</param>
        public void ChangeCurrentLanguage(LanguageInfo language)
        {
            language.Culture.DateTimeFormat = _systemFormat;

            var localizationChangingArgs = new LocalizationChangingEventArgs(language);

            _localizationChangingEvent.Publish(localizationChangingArgs);

            if (localizationChangingArgs.WaitingFor.IsEmpty())
            {
                SetCurrentLanguage(language);
            }
            else
            {
                var waitTask = new WaitTask(Logger)
                {
                    Handlers = localizationChangingArgs.WaitingFor.ToArray(),
                    OnResult = result => { SetCurrentLanguage(language); }
                };

                _taskQueue.Enqueue(waitTask);
            }
        }
 public void RegisterFileAsync(FullPath path)
 {
     Logger.LogInfo("Register path \"{0}\"", path);
     _pendingFileRegistrations.Enqueue(FileRegistrationKind.Register, path);
     _taskQueue.Enqueue(FlushFileRegistrationQueueTaskId, FlushFileRegistrationQueueTask);
 }
Exemple #18
0
 public void Enqueue(TaskId id, Action <CancellationToken> task)
 {
     _taskQueue.Enqueue(id, task);
 }
Exemple #19
0
        public IEnumerator Init(bool block)
        {
            if (s_initInProgress)
            {
                CoreLogger.LogError(LoggerModules.GameApplication, "attempt to initialize kernel while already doing so!");
                yield break;
            }

            Application.targetFrameRate = this.targetFrameRate;

            s_instance = this;

            s_initInProgress = true;

            _taskQueue        = gameObject.AddMissingComponent <TaskQueue>();
            _taskQueue.Active = false;

            EnqueueCreateResolvers();

            EnqueueAddProviders();

            EnqueuePreStageServiceResolution(block);
            _taskQueue.Enqueue(() => {
                LoadLoggerConfig();
            });
            EnqueueInitModules(int.MinValue, -1, block);

            EnqueueServiceResolution(block);
            EnqueueInitModules(0, 0, block);

            EnqueuePostStageServiceResolution(block);
            EnqueueInitModules(1, int.MaxValue, block);

            _taskQueue.Enqueue(() => {
                LoadLoggerConfig();
            });

            //register to the event that tells us when the queue is empty,
            //which implies we have finished initializing
            bool initDone = false;

            //when the task queue empties, we will know we are done
            _taskQueue.Enqueue(() => {
                //at this point we can set the static instance safely
                s_earlyAccess = false;

                //init is done
                s_initInProgress = false;
                initDone         = true;
            });

            //now start the actual initialization, by activating the queue
            float initStart = Time.time;

            //start running the init tasks
            _taskQueue.Active = true;

            if (block)
            {
                //the synchronous version:
                _taskQueue.HandleAll();

                //at this point in time, the singleton is ready for use
                _gameModules.Start();

                yield break;
            }
            else
            {
                //the async. version:

                //while(Time.time - initStart < initTimeout)
                while (true)
                {
                    if (Time.time - initStart > initTimeout)
                    {
                        CoreLogger.LogWarning(LoggerModules.GameApplication, "timeout in creating GameApplication object");
                    }

                    if (initDone)
                    {
                        //at this point in time, the singleton is ready for use
                        _gameModules.Start();

                        yield return(StartCoroutine(WaitForStrangeServiceProviderInit()));

                        InitDone();
                        CoreLogger.LogDebug(LoggerModules.GameApplication, "GameApplication succesfully finished Init!");
                        yield break;
                    }

                    yield return(null);
                }
            }
        }
Exemple #20
0
 private void FileSystemProcessorOnFilesChanged(object sender, FilesChangedEventArgs filesChangedEventArgs)
 {
     _taskQueue.Enqueue(UpdateFileContentsTaskId, cancellationToken => {
         UpdateFileContents(filesChangedEventArgs.ChangedFiles);
     });
 }
Exemple #21
0
 private Task Queued(Func <Task> function)
 {
     return(_taskQueue.Enqueue(function));
 }
Exemple #22
0
 public static void ExecuteAsync(this ITaskQueue queue, Action <CancellationToken> task)
 {
     queue.Enqueue(new TaskId("Unique"), task);
 }
Exemple #23
0
 private void Queued(Action action)
 {
     _taskQueue.Enqueue(action);
 }
Exemple #24
0
 private void FileSystemProcessorOnFilesChanged(object sender, FilesChangedEventArgs filesChangedEventArgs)
 {
     _taskQueue.Enqueue(
         new TaskId("FileSystemProcessorOnFilesChanged"),
         () => UpdateFileContents(filesChangedEventArgs.ChangedFiles));
 }
 public void NotifyEventCreation(EventSlim evt)
 {
     _taskQueue.Enqueue(new
     {
         RegistrationIds = evt.UserList.Where(user =>
                                              !_isRequester(user.UserId, evt.InitiatorId.ToString()) &&
                                              _isValidGCMId(user.GCMClientId)).Select(user => user.GCMClientId),
         NotificationData = PushMessageComposer.GetMessage(evt, "EventInvite")
     });
 }
 public void Refresh()
 {
     _taskQueue.Enqueue(RefreshTaskId, RefreshTask);
 }
 public void AddFile(string filename)
 {
     _taskQueue.Enqueue(string.Format("AddFile(\"{0}\")", filename), () => AddFileTask(filename));
 }
 public static Task <T> Enqueue <T>(this ITaskQueue queue, Func <T> function)
 {
     return(queue.Enqueue(() => Task.FromResult(function())));
 }
Exemple #29
0
 private void Origin_StateChanged(object sender, EventArgs <VpnState> e)
 {
     _taskQueue.Enqueue(() => OnStateChanged(e.Data));
 }
Exemple #30
0
 private void DirectoryChangeWatcherOnPathsChanged(IList <PathChangeEntry> changes)
 {
     Logger.LogInfo("File change events: enqueuing an incremental file system rescan");
     _pathsChangedQueue.Enqueue(changes);
     _flushPathChangesTaskQueue.Enqueue(FlushPathsChangedQueueTaskId, FlushPathsChangedQueueTask);
 }