Ejemplo n.º 1
0
        private async Task RebuildAppIndexes()
        {
            var appsByName = new Dictionary <string, Guid>();
            var appsByUser = new Dictionary <string, HashSet <Guid> >();

            await statesForApps.ReadAllAsync((app, version) =>
            {
                if (!app.IsArchived)
                {
                    appsByName[app.Name] = app.Id;

                    foreach (var contributor in app.Contributors.Keys)
                    {
                        appsByUser.GetOrAddNew(contributor).Add(app.Id);
                    }
                }

                return(TaskHelper.Done);
            });

            await grainFactory.GetGrain <IAppsByNameIndex>(SingleGrain.Id).RebuildAsync(appsByName);

            foreach (var kvp in appsByUser)
            {
                await grainFactory.GetGrain <IAppsByUserIndex>(kvp.Key).RebuildAsync(kvp.Value);
            }
        }
Ejemplo n.º 2
0
        public Task UpdateAsync()
        {
            return(stateForAssets.ReadAllAsync(async(state, version) =>
            {
                state.Slug = state.FileName.ToAssetSlug();

                await stateForAssets.WriteAsync(state.Id, state, version, version);
            }));
        }
Ejemplo n.º 3
0
        public Task UpdateAsync()
        {
            return(stateForAssets.ReadAllAsync(async(state, version) =>
            {
                state.Slug = state.FileName.ToAssetSlug();

                var key = DomainId.Combine(state.AppId.Id, state.Id).ToString();

                await stateForAssets.WriteAsync(key, state, version, version);
            }));
        }
Ejemplo n.º 4
0
        public async Task UpdateAsync(
            CancellationToken ct)
        {
            await foreach (var(state, version) in stateForAssets.ReadAllAsync(ct))
            {
                state.Slug = state.FileName.ToAssetSlug();

                var key = DomainId.Combine(state.AppId.Id, state.Id);

                await stateForAssets.WriteAsync(key, state, version, version, ct);
            }
        }
Ejemplo n.º 5
0
        public IReadOnlyCollection <XElement> GetAllElements()
        {
            var result = new List <XElement>();

            store.ReadAllAsync((state, version) =>
            {
                result.Add(XElement.Parse(state.Xml));

                return(Task.CompletedTask);
            }).Wait();

            return(result);
        }
Ejemplo n.º 6
0
        private async Task RebuildRuleIndexes()
        {
            var rulesByApp = new Dictionary <Guid, HashSet <Guid> >();

            await statesForRules.ReadAllAsync((schema, version) =>
            {
                if (!schema.IsDeleted)
                {
                    rulesByApp.GetOrAddNew(schema.AppId.Id).Add(schema.Id);
                }

                return(TaskHelper.Done);
            });

            foreach (var kvp in rulesByApp)
            {
                await grainFactory.GetGrain <IRulesByAppIndex>(kvp.Key).RebuildAsync(kvp.Value);
            }
        }
Ejemplo n.º 7
0
        private async Task RebuildSchemaIndexes()
        {
            var schemasByApp = new Dictionary <Guid, Dictionary <string, Guid> >();

            await statesForSchemas.ReadAllAsync((schema, version) =>
            {
                if (!schema.IsDeleted)
                {
                    schemasByApp.GetOrAddNew(schema.AppId.Id)[schema.Name] = schema.Id;
                }

                return(TaskHelper.Done);
            });

            foreach (var kvp in schemasByApp)
            {
                await grainFactory.GetGrain <ISchemasByAppIndex>(kvp.Key).RebuildAsync(kvp.Value);
            }
        }
Ejemplo n.º 8
0
        public void Should_read_from_store()
        {
            A.CallTo(() => store.ReadAllAsync(A <Func <DefaultXmlRepository.State, long, Task> > ._, A <CancellationToken> ._))
            .Invokes((Func <DefaultXmlRepository.State, long, Task> callback, CancellationToken _) =>
            {
                callback(new DefaultXmlRepository.State
                {
                    Xml = new XElement("xml").ToString()
                }, 0);

                callback(new DefaultXmlRepository.State
                {
                    Xml = new XElement("xml").ToString()
                }, 0);
            });

            var xml = sut.GetAllElements();

            Assert.Equal(2, xml.Count);
        }
        public void Should_return_items_from_store()
        {
            A.CallTo(() => store.ReadAllAsync(A <Func <DefaultXmlRepository.State, long, Task> > .Ignored))
            .Invokes((Func <DefaultXmlRepository.State, long, Task> callback) =>
            {
                callback(new DefaultXmlRepository.State {
                    Xml = "<a />"
                }, EtagVersion.Any);
                callback(new DefaultXmlRepository.State {
                    Xml = "<b />"
                }, EtagVersion.Any);
                callback(new DefaultXmlRepository.State {
                    Xml = "<c />"
                }, EtagVersion.Any);
            });

            var result = sut.GetAllElements().ToList();

            Assert.Equal("<a />", result[0].ToString());
            Assert.Equal("<b />", result[1].ToString());
            Assert.Equal("<c />", result[2].ToString());
        }
Ejemplo n.º 10
0
 private async Task <IReadOnlyCollection <XElement> > GetAllElementsAsync()
 {
     return(await store.ReadAllAsync().Select(x => x.State.ToXml()).ToListAsync());
 }