コード例 #1
0
        public static async Task <ContentOperationContext> CreateAsync(
            Guid appId,
            Guid schemaId,
            ContentCommand command,
            IAppProvider appProvider,
            IAssetRepository assetRepository,
            IContentRepository contentRepository,
            IScriptEngine scriptEngine,
            Func <string> message)
        {
            var(appEntity, schemaEntity) = await appProvider.GetAppWithSchemaAsync(appId, schemaId);

            var context = new ContentOperationContext
            {
                appEntity         = appEntity,
                assetRepository   = assetRepository,
                command           = command,
                contentRepository = contentRepository,
                message           = message,
                schemaId          = schemaId,
                schemaEntity      = schemaEntity,
                scriptEngine      = scriptEngine
            };

            return(context);
        }
コード例 #2
0
        public static async Task <ContentOperationContext> CreateAsync(
            IContentRepository contentRepository,
            ContentDomainObject content,
            ContentCommand command,
            IAppProvider appProvider,
            IAssetRepository assetRepository,
            IScriptEngine scriptEngine,
            Func <string> message)
        {
            var a = content.Snapshot.AppId;
            var s = content.Snapshot.SchemaId;

            if (command is CreateContent createContent)
            {
                a = a ?? createContent.AppId;
                s = s ?? createContent.SchemaId;
            }

            var(appEntity, schemaEntity) = await appProvider.GetAppWithSchemaAsync(a.Id, s.Id);

            var context = new ContentOperationContext
            {
                appEntity         = appEntity,
                assetRepository   = assetRepository,
                contentRepository = contentRepository,
                content           = content,
                command           = command,
                message           = message,
                schemaEntity      = schemaEntity,
                scriptEngine      = scriptEngine
            };

            return(context);
        }
コード例 #3
0
        public ContentDomainObject(IStore <DomainId> store, ISemanticLog log,
                                   ContentOperationContext context)
            : base(store, log)
        {
            Guard.NotNull(context, nameof(context));

            this.context = context;
        }
コード例 #4
0
ファイル: ContentGrain.cs プロジェクト: xixaoly/squidex
        private async Task <ContentOperationContext> CreateContext(Guid appId, Guid schemaId, Guid contentId, Func <string> message)
        {
            var operationContext =
                await ContentOperationContext.CreateAsync(appId, schemaId, contentId,
                                                          appProvider, assetRepository, contentRepository, scriptEngine, message);

            return(operationContext);
        }
コード例 #5
0
        public ContentDomainObject(IStore <Guid> store, IContentWorkflow contentWorkflow, ContentOperationContext context, ISemanticLog log)
            : base(store, log)
        {
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(contentWorkflow, nameof(contentWorkflow));

            this.contentWorkflow = contentWorkflow;
            this.context         = context;
        }
コード例 #6
0
        private async Task <ContentOperationContext> CreateContext(ContentCommand command, Func <string> message)
        {
            var operationContext =
                await ContentOperationContext.CreateAsync(command, Snapshot,
                                                          contentRepository,
                                                          appProvider,
                                                          assetRepository,
                                                          scriptEngine,
                                                          message);

            return(operationContext);
        }
コード例 #7
0
        public ContentDomainObject(IStore <DomainId> store, ISemanticLog log,
                                   IContentWorkflow contentWorkflow,
                                   IContentRepository contentRepository,
                                   ContentOperationContext context)
            : base(store, log)
        {
            Guard.NotNull(contentRepository, nameof(contentRepository));
            Guard.NotNull(contentWorkflow, nameof(contentWorkflow));
            Guard.NotNull(context, nameof(context));

            this.contentWorkflow   = contentWorkflow;
            this.contentRepository = contentRepository;
            this.context           = context;
        }
コード例 #8
0
        public ContentDomainObjectTests()
        {
            app = Mocks.App(AppNamedId, Language.DE);

            var scripts = new SchemaScripts
            {
                Change = "<change-script>",
                Create = "<create-script>",
                Delete = "<delete-script>",
                Update = "<update-script>"
            };

            var schemaDef =
                new Schema("my-schema")
                .AddNumber(1, "my-field1", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsRequired = true
            })
                .AddNumber(2, "my-field2", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsRequired = false
            })
                .SetScripts(scripts);

            schema = Mocks.Schema(AppNamedId, SchemaNamedId, schemaDef);

            A.CallTo(() => appProvider.GetAppAsync(AppName, false))
            .Returns(app);

            A.CallTo(() => appProvider.GetAppWithSchemaAsync(AppId, SchemaId, false))
            .Returns((app, schema));

            A.CallTo(() => scriptEngine.TransformAsync(A <ScriptVars> ._, A <string> ._, ScriptOptions()))
            .ReturnsLazily(x => Task.FromResult(x.GetArgument <ScriptVars>(0) !.Data !));

            patched = patch.MergeInto(data);

            var validators = Enumerable.Repeat(new DefaultValidatorsFactory(), 1);

            var context = new ContentOperationContext(appProvider,
                                                      validators,
                                                      contentWorkflow,
                                                      contentRepository,
                                                      scriptEngine, A.Fake <ISemanticLog>());

            sut = new ContentDomainObject(Store, A.Dummy <ISemanticLog>(), context);
            sut.Setup(Id);
        }
コード例 #9
0
        public static async Task <ContentOperationContext> CreateAsync(
            Guid appId,
            Guid schemaId,
            ContentCommand command,
            IAppProvider appProvider,
            IAssetRepository assetRepository,
            IContentRepository contentRepository,
            IScriptEngine scriptEngine,
            Func <string> message)
        {
            var(appEntity, schemaEntity) = await appProvider.GetAppWithSchemaAsync(appId, schemaId);

            if (appEntity == null)
            {
                throw new InvalidOperationException("Cannot resolve app.");
            }

            if (schemaEntity == null)
            {
                throw new InvalidOperationException("Cannot resolve schema.");
            }

            var context = new ContentOperationContext
            {
                appEntity         = appEntity,
                assetRepository   = assetRepository,
                command           = command,
                contentRepository = contentRepository,
                message           = message,
                schemaId          = schemaId,
                schemaEntity      = schemaEntity,
                scriptEngine      = scriptEngine
            };

            return(context);
        }