Esempio n. 1
0
        public IEnumerable <Task> Initialize(IAsyncDocumentSession session)
        {
            // those are no longer needed, when we request the
            // Silverlight UI from the server, those indexes will
            // be created automatically

            //yield return session.Advanced.AsyncDatabaseCommands
            //    .PutIndexAsync<RavenDocumentsByEntityName>(true);

            //yield return session.Advanced.AsyncDatabaseCommands
            //    .PutIndexAsync<RavenCollections>(true);

            SimpleLogger.Start("preloading collection templates");
            var templateProvider = IoC.Get <IDocumentTemplateProvider>();
            var collections      = session.Advanced.AsyncDatabaseCommands.GetCollectionsAsync(0, 25);

            yield return(collections);

            var preloading = collections.Result
                             .Select(x => x.Name)
                             .Union(Enumeration.All <BuiltinCollectionName>().Select(x => x.Value))
                             .Select(templateProvider.GetTemplateFor);

            foreach (var task in preloading)
            {
                yield return(task);
            }

            SimpleLogger.End("preloading collection templates");
        }
        public IEnumerable <Task> Initialize(IAsyncDocumentSession session)
        {
            yield return(session.Advanced.AsyncDatabaseCommands
                         .PutIndexAsync(@"Studio/DocumentCollections",
                                        new IndexDefinition
            {
                Map =
                    @"from doc in docs
let Name = doc[""@metadata""][""Raven-Entity-Name""]
where Name != null
select new { Name , Count = 1}
",
                Reduce =
                    @"from result in results
group result by result.Name into g
select new { Name = g.Key, Count = g.Sum(x=>x.Count) }"
            }, true));


            // preload collection templates
            var templateProvider = IoC.Get <IDocumentTemplateProvider>();
            var collections      = session.Advanced.AsyncDatabaseCommands.GetCollectionsAsync(0, 25);

            yield return(collections);

            var preloading = collections.Result
                             .Select(x => x.Name)
                             .Union(Enumeration.All <BuiltinCollectionName>().Select(x => x.Value))
                             .Select(templateProvider.GetTemplateFor);

            foreach (var task in preloading)
            {
                yield return(task);
            }
        }