示例#1
0
            private void Create(ContentEvent @event, ContentData data)
            {
                var uniqueId = DomainId.Combine(@event.AppId, @event.ContentId);

                var state = new TextContentState
                {
                    UniqueContentId = uniqueId
                };

                state.GenerateDocIdCurrent();

                Index(@event,
                      new UpsertIndexEntry
                {
                    ContentId      = @event.ContentId,
                    DocId          = state.DocIdCurrent,
                    GeoObjects     = data.ToGeo(jsonSerializer),
                    ServeAll       = true,
                    ServePublished = false,
                    Texts          = data.ToTexts(),
                    IsNew          = true
                });

                states[state.UniqueContentId] = state;

                updates[state.UniqueContentId] = state;
            }
        private Envelope <IEvent> E(ContentEvent contentEvent)
        {
            contentEvent.ContentId = contentId;
            contentEvent.SchemaId  = schemaId;

            return(new Envelope <IEvent>(contentEvent));
        }
示例#3
0
        private Envelope <IEvent> E(ContentEvent contentEvent)
        {
            contentEvent.ContentId = contentId;
            contentEvent.SchemaId  = NamedId.Of(schemaId, "my-schema");

            return(new Envelope <IEvent>(contentEvent));
        }
示例#4
0
            private void DeleteDraft(ContentEvent @event)
            {
                var uniqueId = DomainId.Combine(@event.AppId, @event.ContentId);

                if (states.TryGetValue(uniqueId, out var state) && state.DocIdNew != null)
                {
                    Index(@event,
                          new UpdateIndexEntry
                    {
                        DocId          = state.DocIdCurrent,
                        ServeAll       = true,
                        ServePublished = true
                    });

                    Index(@event,
                          new DeleteIndexEntry
                    {
                        DocId = state.DocIdNew
                    });

                    state.DocIdNew = null;

                    updates[state.UniqueContentId] = state;
                }
            }
示例#5
0
        #pragma warning restore S4144

        private async Task PublishContentEvent(
            IOrchestrationContext context,
            ContentEventType eventType)
        {
            if (!_eventGridConfiguration.CurrentValue.PublishEvents)
            {
                _logger.LogInformation("Event grid publishing is disabled. No events will be published.");
                return;
            }

            try
            {
                IContentItemVersion contentItemVersion = eventType switch
                {
                    ContentEventType.Published => _publishedContentItemVersion,
                    ContentEventType.Draft => _previewContentItemVersion,
                    _ => _neutralEventContentItemVersion
                };

                string userId = _syncNameProvider.GetEventIdPropertyValue(
                    context.ContentItem.Content.GraphSyncPart,
                    contentItemVersion);

                ContentEvent contentEvent = new ContentEvent(context.ContentItem, userId, eventType);
                await _eventGridContentClient.Publish(contentEvent);
            }
            catch (Exception publishException)
            {
                _logger.LogError(publishException, "The event grid event could not be published.");
                await context.Notifier.Add("Warning: the event grid event could not be published. Composite apps might not show your changes.",
                                           "Exception", publishException, type : NotifyType.Warning);
            }
        }
示例#6
0
        private async Task DeleteDraftAsync(ContentEvent @event)
        {
            var appId = @event.AppId.Id;

            var state = await textIndexerState.GetAsync(appId, @event.ContentId);

            if (state?.DocIdNew != null)
            {
                await IndexAsync(@event,
                                 new UpdateIndexEntry
                {
                    DocId          = state.DocIdCurrent,
                    ServeAll       = true,
                    ServePublished = true
                },
                                 new DeleteIndexEntry
                {
                    DocId = state.DocIdNew
                });

                state.DocIdNew = null;

                await textIndexerState.SetAsync(appId, state);
            }
        }
        private void  MockEvent(string reference, string uri, string expectedType, bool pass = true)
        {
            ContentEvent mockItem = new ContentEvent();

            mockItem.eventType        = expectedType;
            mockItem.id               = Guid.NewGuid().ToString();
            mockItem.subject          = "/content/sharedcontent/29849536-f716-468d-bf49-41446cb68284";
            mockItem.eventTime        = "";
            mockItem.dataVersion      = "";
            mockItem.metadataVersion  = "";
            mockItem.topic            = "";
            mockItem.data.itemId      = reference;
            mockItem.data.api         = uri;
            mockItem.data.versionId   = Guid.NewGuid().ToString();
            mockItem.data.displayText = "some content";
            mockItem.data.author      = "Fred";

            string response;

            CosmosHelper.Initialise(_scenarioContext.GetEnv().eventStoreEndPoint, _scenarioContext.GetEnv().eventStoreKey);

            CosmosHelper.InsertDocumentFromJson <ContentEvent>("EventStore",
                                                               "events",
                                                               mockItem,
                                                               out response);
        }
        public Task Publish(ContentEvent contentEvent, CancellationToken cancellationToken = default)
        {
            //todo: log topic
            _logger.LogInformation("Publishing single event {ContentEvent}", contentEvent);

            return(_eventGridContentRestHttpClientFactory.CreateClient(contentEvent.Data.ContentType)
                   .PostAsJson("", new[] { contentEvent }, cancellationToken));
        }
示例#9
0
        private IndexOperation Op(DomainId id, ContentEvent contentEvent)
        {
            contentEvent.ContentId = id;
            contentEvent.AppId     = appId;
            contentEvent.SchemaId  = schemaId;

            return(p => p.On(Enumerable.Repeat(Envelope.Create <IEvent>(contentEvent), 1)));
        }
        private async Task UpdateAsync(DomainId id, ContentEvent contentEvent)
        {
            contentEvent.ContentId = id;
            contentEvent.AppId     = appId;
            contentEvent.SchemaId  = schemaId;

            await Sut.On(Enumerable.Repeat(Envelope.Create <IEvent>(contentEvent), 1));

            await Task.Delay(WaitAfterUpdate);
        }
示例#11
0
        private async Task CreateDraftAsync(ContentEvent @event)
        {
            var state = await textIndexerState.GetAsync(@event.ContentId);

            if (state != null)
            {
                state.GenerateDocIdNew();

                await textIndexerState.SetAsync(state);
            }
        }
示例#12
0
        public virtual TEntity Update(TEntity entity, TextFolder folder)
        {
            entity.Repository = Repository.Name;
            entity.FolderName = folder.FullName;
            entity.SchemaName = folder.SchemaName;
            ContentEvent.Fire(ContentAction.PreUpdate, entity);
            TextContentProvider.Update(entity, entity);
            ContentEvent.Fire(ContentAction.Update, entity);

            return(entity);
        }
示例#13
0
            private void CreateDraft(ContentEvent @event)
            {
                var uniqueId = DomainId.Combine(@event.AppId, @event.ContentId);

                if (states.TryGetValue(uniqueId, out var state))
                {
                    state.GenerateDocIdNew();

                    updates[state.UniqueContentId] = state;
                }
            }
示例#14
0
            private void Index(ContentEvent @event, IndexCommand command)
            {
                command.AppId    = @event.AppId;
                command.SchemaId = @event.SchemaId;

                if (command is UpdateIndexEntry update &&
                    commands.TryGetValue(command.DocId, out var existing) &&
                    existing is UpsertIndexEntry upsert)
                {
                    upsert.ServeAll       = update.ServeAll;
                    upsert.ServePublished = update.ServePublished;
                }
        public async Task Should_enrich_events(ContentEvent @event, EnrichedContentEventType type)
        {
            var envelope = Envelope.Create <AppEvent>(@event).SetEventStreamNumber(12);

            A.CallTo(() => contentLoader.GetAsync(@event.ContentId, 12))
            .Returns(new ContentEntity {
                SchemaId = SchemaMatch
            });

            var result = await sut.CreateEnrichedEventAsync(envelope) as EnrichedContentEvent;

            Assert.Equal(type, result !.Type);
        }
示例#16
0
        private async Task EnrichContentAsync(EnrichedContentEvent result, ContentEvent contentEvent, Envelope <AppEvent> @event)
        {
            var content =
                (await grainFactory
                 .GetGrain <IContentGrain>(contentEvent.ContentId)
                 .GetStateAsync(@event.Headers.EventStreamNumber())).Value;

            SimpleMapper.Map(content, result);

            result.Data = content.Data ?? content.DataDraft;

            switch (contentEvent)
            {
            case ContentCreated _:
                result.Type = EnrichedContentEventType.Created;
                break;

            case ContentDeleted _:
                result.Type = EnrichedContentEventType.Deleted;
                break;

            case ContentChangesPublished _:
            case ContentUpdated _:
                result.Type = EnrichedContentEventType.Updated;
                break;

            case ContentStatusChanged contentStatusChanged:
                switch (contentStatusChanged.Change)
                {
                case StatusChange.Published:
                    result.Type = EnrichedContentEventType.Published;
                    break;

                case StatusChange.Unpublished:
                    result.Type = EnrichedContentEventType.Unpublished;
                    break;

                case StatusChange.Archived:
                    result.Type = EnrichedContentEventType.Archived;
                    break;

                case StatusChange.Restored:
                    result.Type = EnrichedContentEventType.Restored;
                    break;
                }

                break;
            }

            result.Name = $"{content.SchemaId.Name.ToPascalCase()}{result.Type}";
        }
示例#17
0
        public virtual TEntity AddSubContent(TEntity entity, TextFolder folder, string parentFolderName, string parentUUID)
        {
            entity.Repository   = Repository.Name;
            entity.FolderName   = folder.FullName;
            entity.SchemaName   = folder.SchemaName;
            entity.ParentFolder = parentFolderName;
            entity.ParentUUID   = parentUUID;

            ContentEvent.Fire(ContentAction.PreAdd, entity);
            TextContentProvider.Add(entity);
            ContentEvent.Fire(ContentAction.Add, entity);

            return(entity);
        }
示例#18
0
        public SongInfo GetRandom()
        {
            List <IBeatmapSet> beatmapSetList = BeatmapDb.BeatmapSets.Values.ToList();
            List <IBeatmap>    beatmapList;

            if (CollectionMode)
            {
                beatmapList = PlayCollection;
            }
            else
            {
                IBeatmapSet mapSet = beatmapSetList[(int)(new Random().NextDouble() * (beatmapSetList.Count - 1))];

                beatmapList = mapSet.Beatmaps.Values.ToList();
            }


            IBeatmap map = beatmapList[(int)(new Random().NextDouble() * (beatmapList.Count - 1))];

            DirectoryInfo beatmapFolder = new DirectoryInfo(SongsFolder.FullName + Path.DirectorySeparatorChar + map.SongFolderName);

            Beatmap bm = new Beatmap(beatmapFolder.FullName + Path.DirectorySeparatorChar + map.OsuFileName);

            ContentEvent backgroundEvent = null;

            foreach (EventBase e in bm.Events)
            {
                if (e is ContentEvent contentEvent)
                {
                    if (contentEvent.Type == ContentType.Image)
                    {
                        backgroundEvent = contentEvent;
                        break;
                    }
                }
            }

            return(new SongInfo
            {
                Title = bm.Title,
                TitleUnicode = bm.TitleUnicode,

                ArtistName = bm.Artist,
                ArtistNameUnicode = bm.ArtistUnicode,

                Song = beatmapFolder.FullName + Path.DirectorySeparatorChar + bm.AudioFilename,
                Background = backgroundEvent == null ? null : beatmapFolder.FullName + Path.DirectorySeparatorChar + backgroundEvent.Filename
            });
        }
        public async Task Should_create_enriched_events(ContentEvent @event, EnrichedContentEventType type)
        {
            @event.AppId = appId;

            var envelope = Envelope.Create <AppEvent>(@event).SetEventStreamNumber(12);

            A.CallTo(() => contentLoader.GetAsync(appId.Id, @event.ContentId, 12))
            .Returns(new ContentEntity {
                AppId = appId, SchemaId = schemaMatch
            });

            var result = await sut.CreateEnrichedEventsAsync(envelope);

            var enrichedEvent = result.Single() as EnrichedContentEvent;

            Assert.Equal(type, enrichedEvent !.Type);
        }
示例#20
0
        private async Task UpdateAsync(ContentEvent @event, NamedContentData data)
        {
            var state = await textIndexerState.GetAsync(@event.ContentId);

            if (state != null)
            {
                if (state.DocIdNew != null)
                {
                    await IndexAsync(@event,
                                     new UpsertIndexEntry
                    {
                        ContentId      = @event.ContentId,
                        DocId          = state.DocIdNew,
                        ServeAll       = true,
                        ServePublished = false,
                        Texts          = data.ToTexts()
                    },
                                     new UpdateIndexEntry
                    {
                        DocId          = state.DocIdCurrent,
                        ServeAll       = false,
                        ServePublished = true
                    });

                    state.DocIdForPublished = state.DocIdCurrent;
                }
                else
                {
                    var isPublished = state.DocIdCurrent == state.DocIdForPublished;

                    await IndexAsync(@event,
                                     new UpsertIndexEntry
                    {
                        ContentId      = @event.ContentId,
                        DocId          = state.DocIdCurrent,
                        ServeAll       = true,
                        ServePublished = isPublished,
                        Texts          = data.ToTexts()
                    });

                    state.DocIdForPublished = state.DocIdNew;
                }

                await textIndexerState.SetAsync(state);
            }
        }
示例#21
0
            private void Update(ContentEvent @event, ContentData data)
            {
                var uniqueId = DomainId.Combine(@event.AppId, @event.ContentId);

                if (states.TryGetValue(uniqueId, out var state))
                {
                    if (state.DocIdNew != null)
                    {
                        Index(@event,
                              new UpsertIndexEntry
                        {
                            ContentId      = @event.ContentId,
                            DocId          = state.DocIdNew,
                            GeoObjects     = data.ToGeo(jsonSerializer),
                            ServeAll       = true,
                            ServePublished = false,
                            Texts          = data.ToTexts()
                        });

                        Index(@event,
                              new UpdateIndexEntry
                        {
                            DocId          = state.DocIdCurrent,
                            ServeAll       = false,
                            ServePublished = true
                        });
                    }
                    else
                    {
                        var isPublished = state.DocIdCurrent == state.DocIdForPublished;

                        Index(@event,
                              new UpsertIndexEntry
                        {
                            ContentId      = @event.ContentId,
                            DocId          = state.DocIdCurrent,
                            GeoObjects     = data.ToGeo(jsonSerializer),
                            ServeAll       = true,
                            ServePublished = isPublished,
                            Texts          = data.ToTexts()
                        });
                    }
                }
            }
示例#22
0
            private void Unpublish(ContentEvent @event)
            {
                var uniqueId = DomainId.Combine(@event.AppId, @event.ContentId);

                if (states.TryGetValue(uniqueId, out var state) && state.DocIdForPublished != null)
                {
                    Index(@event,
                          new UpdateIndexEntry
                    {
                        DocId          = state.DocIdForPublished,
                        ServeAll       = true,
                        ServePublished = false
                    });

                    state.DocIdForPublished = null;

                    updates[state.UniqueContentId] = state;
                }
            }
示例#23
0
        private async Task UnpublishAsync(ContentEvent @event)
        {
            var state = await textIndexerState.GetAsync(@event.ContentId);

            if (state != null && state.DocIdForPublished != null)
            {
                await IndexAsync(@event,
                                 new UpdateIndexEntry
                {
                    DocId          = state.DocIdForPublished,
                    ServeAll       = true,
                    ServePublished = false
                });

                state.DocIdForPublished = null;

                await textIndexerState.SetAsync(state);
            }
        }
示例#24
0
        private async Task DeleteAsync(ContentEvent @event)
        {
            var state = await textIndexerState.GetAsync(@event.ContentId);

            if (state != null)
            {
                await IndexAsync(@event,
                                 new DeleteIndexEntry
                {
                    DocId = state.DocIdCurrent
                },
                                 new DeleteIndexEntry
                {
                    DocId = state.DocIdNew ?? NotFound,
                });

                await textIndexerState.RemoveAsync(state.ContentId);
            }
        }
示例#25
0
        private async Task PublishAsync(ContentEvent @event)
        {
            var state = await textIndexerState.GetAsync(@event.ContentId);

            if (state != null)
            {
                if (state.DocIdNew != null)
                {
                    await IndexAsync(@event,
                                     new UpdateIndexEntry
                    {
                        DocId          = state.DocIdNew,
                        ServeAll       = true,
                        ServePublished = true
                    },
                                     new DeleteIndexEntry
                    {
                        DocId = state.DocIdCurrent
                    });

                    state.DocIdForPublished = state.DocIdNew;
                    state.DocIdCurrent      = state.DocIdNew;
                }
                else
                {
                    await IndexAsync(@event,
                                     new UpdateIndexEntry
                    {
                        DocId          = state.DocIdCurrent,
                        ServeAll       = true,
                        ServePublished = true
                    });

                    state.DocIdForPublished = state.DocIdCurrent;
                }

                state.DocIdNew = null;

                await textIndexerState.SetAsync(state);
            }
        }
示例#26
0
        private async Task CreateAsync(ContentEvent @event, NamedContentData data)
        {
            var state = new TextContentState
            {
                ContentId = @event.ContentId
            };

            state.GenerateDocIdCurrent();

            await IndexAsync(@event,
                             new UpsertIndexEntry
            {
                ContentId      = @event.ContentId,
                DocId          = state.DocIdCurrent,
                ServeAll       = true,
                ServePublished = false,
                Texts          = data.ToTexts(),
            });

            await textIndexerState.SetAsync(state);
        }
示例#27
0
        public void TearDownDataItems()
        {
            // clear down based on stored uri
            foreach (var item in _scenarioContext.GetDataItems().Where(x => x.TearDownGraph))
            {
                //clear graph based on URI
                bool result = _scenarioContext.DeleteGraphNodesWithUri(item.Uri);
                Console.WriteLine($"CLEANUP: Succesfully deleted GRAPH items with uri {item.Uri}");
            }
            foreach (var item in _scenarioContext.GetDataItems().Where(x => x.TearDownSql))
            {
                //clear SQL based on URI
                Console.WriteLine("CLEANUP: Sql clear down based on URI not yet implemented");
            }
            var env       = _scenarioContext.GetEnv();
            var dataItems = _scenarioContext.GetContentItemIndexList();

            if (env.sendEvents && env.sqlServerChecksEnabled && dataItems.Count > 0)
            {
                foreach (var item in dataItems)
                {
                    ContentItem contentItem = new ContentItem();
                    contentItem.Author               = item.Author;
                    contentItem.ContentItemId        = item.ContentItemId;
                    contentItem.ContentItemVersionId = item.ContentItemVersionId;
                    contentItem.ContentType          = item.ContentType;
                    contentItem.CreatedUtc           = DateTime.Parse(item.CreatedUtc);
                    contentItem.DisplayText          = item.DisplayText;
                    var          uri          = _scenarioContext.GetLatestUri().Replace("<<contentapiprefix>>", _scenarioContext.GetEnv().contentApiBaseUrl);
                    ContentEvent contentEvent = new ContentEvent(contentItem, uri, DFC.ServiceTaxonomy.Events.Models.ContentEventType.Deleted);
                    string       json         = $"[{JsonConvert.SerializeObject(contentEvent)}]";
                    var          response     = RestHelper.Post(env.eventTopicUrl, json, new Dictionary <string, string>()
                    {
                        { "Aeg-sas-key", env.AegSasKey }
                    });
                    Console.WriteLine($"CLEANUP: send delete event for {uri} - Response Code:{response.StatusCode}");
                }
            }
        }