public static void MigrateLocaleResources(this SmartObjectContext ctx, Action<LocaleResourcesBuilder> fn, bool updateTouchedResources = false)
		{
			Guard.ArgumentNotNull(() => ctx);
			Guard.ArgumentNotNull(() => fn);

			var builder = new LocaleResourcesBuilder();
			fn(builder);
			var entries = builder.Build();
			 
			var migrator = new LocaleResourcesMigrator(ctx);
			migrator.Migrate(entries, updateTouchedResources);
		}
Exemple #2
0
        public static void MigrateLocaleResources(this SmartObjectContext ctx, Action <LocaleResourcesBuilder> fn, bool updateTouchedResources = false)
        {
            Guard.NotNull(ctx, nameof(ctx));
            Guard.NotNull(fn, nameof(fn));

            var builder = new LocaleResourcesBuilder();

            fn(builder);
            var entries = builder.Build();

            var migrator = new LocaleResourcesMigrator(ctx);

            migrator.Migrate(entries, updateTouchedResources);
        }
Exemple #3
0
        public static void ExecutePendingResourceMigrations(string resPath, SmartObjectContext dbContext)
        {
            Guard.ArgumentNotNull(() => dbContext);

            string headPath = Path.Combine(resPath, "head.txt");

            if (!File.Exists(headPath))
            {
                return;
            }

            string resHead = File.ReadAllText(headPath).Trim();

            if (!MigratorUtils.IsValidMigrationId(resHead))
            {
                return;
            }

            var migrator   = new DbMigrator(new MigrationsConfiguration());
            var migrations = GetPendingResourceMigrations(migrator, resHead);

            foreach (var id in migrations)
            {
                if (IsAutomaticMigration(id))
                {
                    continue;
                }

                if (!IsValidMigrationId(id))
                {
                    continue;
                }

                // Resolve and instantiate the DbMigration instance from the assembly
                var migration = CreateMigrationInstanceByMigrationId(id, migrator.Configuration);

                var provider = migration as ILocaleResourcesProvider;
                if (provider == null)
                {
                    continue;
                }

                var builder = new LocaleResourcesBuilder();
                provider.MigrateLocaleResources(builder);

                var resEntries  = builder.Build();
                var resMigrator = new LocaleResourcesMigrator(dbContext);
                resMigrator.Migrate(resEntries);
            }
        }
		public void Can_add_resource_entries()
		{
			var resources = context.Set<LocaleStringResource>();
			resources.Any().ShouldBeFalse();

			var entries = GetDefaultResourceEntries();
			var migrator = new LocaleResourcesMigrator(context);
			migrator.Migrate(entries);

			ReloadContext();
			resources = context.Set<LocaleStringResource>();

			resources.ToList().Count.ShouldEqual(6);
		}
		public void Can_update_resource_entries()
		{
			var resources = context.Set<LocaleStringResource>();
			resources.Any().ShouldBeFalse();

			var entries = GetDefaultResourceEntries();
			var migrator = new LocaleResourcesMigrator(context);
			migrator.Migrate(entries);

			var builder = new LocaleResourcesBuilder();
			builder.AddOrUpdate("Res1").Value("NewValue1");
			migrator.Migrate(builder.Build());

			resources.ToList().Count.ShouldEqual(6);

			var updated = resources.Where(x => x.ResourceName == "Res1").ToList();
			updated.Count.ShouldEqual(2);
			updated.Each(x => x.ResourceValue.ShouldEqual("NewValue1"));
		}
		public void Can_delete_resource_entries()
		{
			var resources = context.Set<LocaleStringResource>();
			resources.Any().ShouldBeFalse();

			var entries = GetDefaultResourceEntries();
			var migrator = new LocaleResourcesMigrator(context);
			migrator.Migrate(entries);

			var builder = new LocaleResourcesBuilder();
			builder.DeleteFor("de", "Res1", "Res2", "Res3");
			builder.DeleteFor("en", "Res1");
			migrator.Migrate(builder.Build());

			resources.ToList().Count.ShouldEqual(2);

			builder.Reset();
			builder.DeleteFor("en", "Res2");
			migrator.Migrate(builder.Build());
			resources.ToList().Count.ShouldEqual(1);
		}