public Task StartParseWikiJob(GrainCancellationToken cancellationToken)
        {
            var saveDir = GetCloneDirectory();

            //TODO Parseflow

            return(Task.CompletedTask);
        }
Esempio n. 2
0
        public Task CancellationTokenCallbackThrow(GrainCancellationToken tc)
        {
            tc.CancellationToken.Register(() =>
            {
                throw new InvalidOperationException("From cancellation token callback");
            });

            return(Task.CompletedTask);
        }
Esempio n. 3
0
        public Task <string> SayHello(string name, GrainCancellationToken grainCancellationToken)
        {
            if (!grainCancellationToken.CancellationToken.IsCancellationRequested)
            {
                return(Task.FromResult(Say.hello(name)));
            }

            return(null);
        }
Esempio n. 4
0
 public Task AcceptMessageAsync(AnonymousMessage message, GrainCancellationToken cancellationToken)
 {
     return(Task.WhenAll(
                State.ConnectionIds
                .Where(connId => !message.Excluding.Contains(connId))
                .Select(connId => GrainFactory.GetGrain <IClientGrain>(connId))
                .Select(client => client.AcceptMessageAsync(message.Payload, cancellationToken))
                ).WithCancellation(cancellationToken.CancellationToken));
 }
        public Task StartExecutingAsync(GrainCancellationToken cancellation)
        {
            var waitHandle = new ManualResetEventSlim(false);

            RunPollLoopOnThreadpool(cancellation.CancellationToken, waitHandle);
            RunMessageProcessingLoop(cancellation.CancellationToken, waitHandle);

            return(Task.CompletedTask);
        }
        public Task CancelRemoteToken(GrainCancellationToken token)
        {
            GrainCancellationToken gct;
            if (!_cancellationTokens.TryFind(token.Id, out gct))
            {
                _logger.Value.Error(ErrorCode.CancellationTokenCancelFailed,  $"Remote token cancellation failed: token with id {token.Id} was not found");
                return TaskDone.Done;
            }

            return gct.Cancel();
        }
Esempio n. 7
0
        public async Task <string> SayHello(string name, GrainCancellationToken grainCancellationToken)
        {
            string result = null;

            if (!grainCancellationToken.CancellationToken.IsCancellationRequested &&
                await _featureManagerSnapshot.IsEnabledAsync("FeatureA"))
            {
                result = Say.hello(name) + $" Grain reference - {IdentityString}";
            }

            return(result);
        }
Esempio n. 8
0
        public Task CancelRemoteToken(GrainCancellationToken token)
        {
            GrainCancellationToken gct;

            if (!_cancellationTokens.TryFind(token.Id, out gct))
            {
                _logger.Value.Error(ErrorCode.CancellationTokenCancelFailed, $"Remote token cancellation failed: token with id {token.Id} was not found");
                return(Task.CompletedTask);
            }

            return(gct.Cancel());
        }
Esempio n. 9
0
        public async Task <DotNetRuProfiles.Models.Profile.Profile> GetProfile(GrainCancellationToken grainCancellationToken)
        {
            var path = Path.Combine(
                Directory.GetCurrentDirectory(),
                "AnatolyKulakov\\SpbDotNet.wiki.git\\",
                $"{this.GetPrimaryKeyString()}.md"
                );

            var file = await File.ReadAllTextAsync(path);

            return(await _markdownParser.Extract <DotNetRuProfiles.Models.Profile.Profile>(file));
        }
        public async Task <string> GetAllSerialized(GrainCancellationToken cancellationToken = null)
        {
            _logger.Info($"{GetType().Name}.{nameof(GetAllSerialized)}() started...");

            var collection = await _tarantoolUtils.GetIndex <T>();

            if (cancellationToken == null)
            {
                return(JsonConvert.SerializeObject(collection));
            }

            var serialized = JsonConvert.SerializeObject(collection);

            return(serialized);
        }
Esempio n. 11
0
        public async Task <string> GetAllSerialized(GrainCancellationToken cancellationToken = null)
        {
            _logger.Info($"{GetType().Name}.{nameof(GetAllSerialized)}() started...");

            var collection = await _mongoUtils.GetCollection <T>();

            if (cancellationToken == null)
            {
                return(JsonConvert.SerializeObject(await collection.AsQueryable().ToListAsync()));
            }

            var serialized = JsonConvert.SerializeObject(await collection.AsQueryable().ToListAsync(cancellationToken.CancellationToken));

            return(serialized);
        }
        public Task StartFetchWikiJob(GrainCancellationToken cancellationToken)
        {
            var repolink = this.GetPrimaryKeyString();
            var saveDir  = GetCloneDirectory();

            if (Directory.Exists(saveDir))
            {
                FetchRepo(repolink);
            }
            else
            {
                CloneRepo(repolink, saveDir);
            }

            return(Task.CompletedTask);
        }
        public async Task LongIoWork(GrainCancellationToken tc, TimeSpan delay)
        {
            logger.LogInformation("LongIoWork");
            var timesamp = DateTimeOffset.UtcNow;

            while (!tc.CancellationToken.IsCancellationRequested && (DateTimeOffset.UtcNow - timesamp) < delay)
            {
                await IoOperation(tc.CancellationToken);
            }
            if (tc.CancellationToken.IsCancellationRequested)
            {
                logger.LogInformation("Cancel");
            }
            else
            {
                logger.LogInformation("timeout");
            }
        }
Esempio n. 14
0
        public Task <bool> CancellationTokenCallbackResolve(GrainCancellationToken tc)
        {
            var tcs       = new TaskCompletionSource <bool>();
            var orleansTs = TaskScheduler.Current;

            tc.CancellationToken.Register(() =>
            {
                if (TaskScheduler.Current != orleansTs)
                {
                    tcs.SetException(new Exception("Callback executed on wrong thread"));
                }
                else
                {
                    tcs.SetResult(true);
                }
            });

            return(tcs.Task);
        }
Esempio n. 15
0
 public async Task LongWait(GrainCancellationToken tc, TimeSpan delay)
 {
     await Task.Delay(delay, tc.CancellationToken);
 }
Esempio n. 16
0
        public async Task <Immutable <Map2D <TExport>[]> > Render(RenderingOptions options, Complex center, double scale, double scaleMultiplier, int frames, GrainCancellationToken cancellationToken = null)
        {
            var rendererTasks = new Task <Immutable <Map2D <TExport> > > [frames];
            var currentScale  = scale;

            // Render all frames
            for (int i = 0; i < frames; i++)
            {
                var renderer = GrainFactory.GetGrain <IFrameRenderer <TExport> >(Guid.NewGuid());

                rendererTasks[i] = renderer.RenderFrame(options, center, currentScale, cancellationToken);
                currentScale    *= scaleMultiplier;
            }

            // Wait for the rendering to finish
            var   combinedTask = Task.WhenAll(rendererTasks);
            await combinedTask; // TODO: exception handling

            cancellationToken?.CancellationToken.ThrowIfCancellationRequested();

            var readyFrames = new Map2D <TExport> [frames];

            for (int i = 0; i < frames; i++)
            {
                readyFrames[i] = rendererTasks[i].Result.Value;
            }

            return(new Immutable <Map2D <TExport>[]>(readyFrames));
        }
Esempio n. 17
0
        public async Task AcceptMessageAsync(HubInvocationMessage message, GrainCancellationToken cancellationToken)
        {
            var handle = await rewoundMessagesGrain.PushMessageAsync(message);

            observers.Notify(x => x.ReceiveMessage(message, handle));
        }
Esempio n. 18
0
 public async Task <string> GetAllSerialized(GrainCancellationToken cancellationToken = null)
 => await(await GetGrain()).GetAllSerialized();
 public Entry(GrainCancellationToken token)
 {
     Token        = token;
     _createdTime = Stopwatch.GetTimestamp();
 }
Esempio n. 20
0
        private async Task DispatchRenderMovie(Guid requestIdentifier, Complex center, double scale, double scaleMultiplier, int frames, GrainCancellationToken cancellationToken = null)
        {
            var movieRenderer = GrainFactory.GetGrain <IMovieRenderer <TExport> >(Guid.NewGuid());

            var rendered = await movieRenderer.Render(State, center, scale, scaleMultiplier, frames, cancellationToken);

            _observerManager.Notify(o => o.ReceiveRenderedMovie(requestIdentifier, rendered));
        }
Esempio n. 21
0
        public Task <bool> BeginRenderMovie(Guid requestIdentifier, Complex center, double scale, double scaleMultiplier, int frames, GrainCancellationToken cancellationToken = null)
        {
            DispatchRenderMovie(requestIdentifier, center, scale, scaleMultiplier, frames, cancellationToken);

            return(Task.FromResult(true));
        }
Esempio n. 22
0
 public async Task <ICollection <T> > GetAllCollection(GrainCancellationToken cancellationToken = null)
 => JsonConvert.DeserializeObject <ICollection <T> >(await GetAllSerialized(cancellationToken));
Esempio n. 23
0
 public async Task DoAsyncWork(TimeSpan waitTime, GrainCancellationToken gct)
 {
     await Task.Delay(waitTime, gct.CancellationToken);
 }
Esempio n. 24
0
        public async Task <Immutable <Map2D <TExport> > > RenderFrame(RenderingOptions options, Complex center, double scale, GrainCancellationToken cancellationToken = null)
        {
            // Prepare a frame to return
            var frame = new Map2D <TExport>(options.FrameWidth, options.FrameHeight);

            // Load initial values
            var initialSet = PrepareInitialValues(options.FrameWidth, options.FrameHeight, center, scale);

            // Compute in batches
            var batchCount = (int)Math.Ceiling(frame.Raw.Length / (double)options.BatchSize);
            var batchTasks = new Task <Immutable <TExport[]> > [batchCount];

            for (int i = 0; i < batchCount; i++)
            {
                var newBatch = GrainFactory.GetGrain <IRenderBatch <TExport> >(Guid.NewGuid());

                var startPoint = i * options.BatchSize;
                var count      = Math.Min(options.BatchSize, frame.Raw.Length - startPoint);

                var buffer = new Span <Complex>(initialSet, startPoint, count).ToArray();

                batchTasks[i] = newBatch.Compute(options, buffer, cancellationToken);
            }

            // Wait for the workers to finish
            var   combinedTask = Task.WhenAll(batchTasks); // TODO: exception handling
            await combinedTask;

            cancellationToken?.CancellationToken.ThrowIfCancellationRequested();

            // Import the results...
            for (int i = 0; i < batchCount; i++)
            {
                var startPoint = i * options.BatchSize;

                batchTasks[i].Result.Value.CopyTo(frame.Raw, startPoint);
            }

            // ... and send them back to the requestor.
            return(new Immutable <Map2D <TExport> >(frame));
        }
Esempio n. 25
0
 public Task RemoveFromGroupAsync(string connectionId, GrainCancellationToken cancellationToken)
 {
     dirty = State.ConnectionIds.Remove(connectionId) || dirty;
     return(Task.CompletedTask);
 }
Esempio n. 26
0
 public Task <bool> StartAsync(TRequest request, GrainCancellationToken cancellationToken)
 {
     return(StartAsync(request, cancellationToken.CancellationToken));
 }
Esempio n. 27
0
 public async Task CallOtherLongRunningTask(ILongRunningTaskGrain <T> target, GrainCancellationToken tc, TimeSpan delay)
 {
     await target.LongWait(tc, delay);
 }
Esempio n. 28
0
        public Task <Immutable <TExport[]> > Compute(RenderingOptions options, Complex[] coordinates, GrainCancellationToken cancellationToken = null)
        {
            var bailout      = options.BailoutValue * options.BailoutValue;
            var maxIteration = options.MaxIteration;

            var values = new TExport[coordinates.Length];

            for (int n = 0; n < coordinates.Length; n++)
            {
                // Kill on request
                cancellationToken?.CancellationToken.ThrowIfCancellationRequested();

                var i = 0;

                var newVal = Complex.Zero;

                while (newVal.Real * newVal.Real + newVal.Imaginary * newVal.Imaginary <= bailout && i < maxIteration)
                {
                    var tempVal = newVal * newVal + coordinates[n];

                    // Local periodicity checking
                    if (tempVal == newVal)
                    {
                        i = maxIteration - 1;
                    }

                    newVal = tempVal;

                    ++i;
                }

                values[n] = (TExport)Convert.ChangeType(i, typeof(TExport));
            }

            return(Task.FromResult(new Immutable <TExport[]>(values)));
        }
Esempio n. 29
0
 public Task SendAsync(T t, GrainCancellationToken gct)
 {
     throw new NotImplementedException();
 }
Esempio n. 30
0
 public Task AddToUserAsync(string connectionId, GrainCancellationToken cancellationToken)
 {
     dirty = State.ConnectionIds.Add(connectionId) || dirty;
     return(Task.CompletedTask);
 }