コード例 #1
0
        private void IncrementV2(ScriptExecutionContext context, DomainId appId, string name, Action <JsValue> callback)
        {
            context.Schedule(async(scheduler, ct) =>
            {
                var grain = grainFactory.GetGrain <ICounterGrain>(appId.ToString());

                var result = await grain.IncrementAsync(name);

                if (callback != null)
                {
                    scheduler.Run(callback, JsValue.FromObject(context.Engine, result));
                }
            });
        }
コード例 #2
0
        private void GetReferences(ScriptExecutionContext context, DomainId appId, ClaimsPrincipal user, JsValue references, Action <JsValue> callback)
        {
            Guard.NotNull(callback);

            context.Schedule(async(scheduler, ct) =>
            {
                var ids = references.ToIds();

                if (ids.Count == 0)
                {
                    var emptyContents = Array.Empty <IEnrichedContentEntity>();

                    scheduler.Run(callback, JsValue.FromObject(context.Engine, emptyContents));
                    return;
                }

                var app = await GetAppAsync(appId);

                if (app == null)
                {
                    var emptyContents = Array.Empty <IEnrichedContentEntity>();

                    scheduler.Run(callback, JsValue.FromObject(context.Engine, emptyContents));
                    return;
                }

                var contentQuery = serviceProvider.GetRequiredService <IContentQueryService>();

                var requestContext =
                    new Context(user, app).Clone(b => b
                                                 .WithoutContentEnrichment()
                                                 .WithUnpublished()
                                                 .WithoutTotal());

                var contents = await contentQuery.QueryAsync(requestContext, Q.Empty.WithIds(ids), ct);

                scheduler.Run(callback, JsValue.FromObject(context.Engine, contents.ToArray()));
            });
        }