Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddOptions();

            // Configure RavenDB options and store holder
            services.Configure <RavenSettings>(Configuration.GetSection("Raven"));
            services.AddSingleton <IDocumentStoreHolder, DocumentStoreHolder>();

            // Configure talk data services
            services.AddSingleton <InMemoryTalkService, InMemoryTalkService>();
            services.AddTransient <RavenTalkService, RavenTalkService>();
            services.AddTransient <TalkServiceProvider, TalkServiceProvider>();

            // Static load
            // InMemoryTalkService.Load(CsvData.LoadTalks(), CsvData.LoadSpeakers());
            InMemoryTalkService.Load(CsvData.LoadSpeakers());


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Esempio n. 2
0
        private void CreateDatabaseIfNotExists()
        {
            var database = Store.Database;
            var dbRecord = Store.Maintenance.Server.Send(new GetDatabaseRecordOperation(database));

            if (dbRecord == null)
            {
                this._logger.LogInformation("RavenDB database does not exist, creating and seeding with initial data");

                // Create database
                var newDatabase = new DatabaseRecord(database);

                var createResult = Store.Maintenance.Server.Send(new CreateDatabaseOperation(newDatabase));

                if (createResult.Name != null)
                {
                    // Seed database
                    var talks    = CsvData.LoadTalks();
                    var speakers = CsvData.LoadSpeakers();

                    // old => new speaker ID map
                    var speakerIdMap = new Dictionary <string, string>();

                    using (var session = Store.OpenSession())
                    {
                        foreach (var speaker in speakers)
                        {
                            var oldId = speaker.Id;
                            speaker.Id = null;
                            session.Store(speaker);
                            speakerIdMap.Add(oldId, speaker.Id);
                        }

                        foreach (var talk in talks)
                        {
                            talk.Id      = null;
                            talk.Speaker = speakerIdMap[talk.Speaker];
                            session.Store(talk);
                        }
                        session.SaveChanges();
                    }

                    this._logger.LogInformation("Seeded database with {0} talks", talks.Count);
                    this._logger.LogInformation("Seeded database with {0} speakers", speakers.Count);
                }
            }
        }