Пример #1
0
            public override UpgradeEngine Given()
            {
                scriptProvider = Substitute.For <IScriptProvider>();
                scriptProvider.GetScripts(Arg.Any <IConnectionManager>()).Returns(new List <SqlScript>
                {
                    new SqlScript("#1", "Content of #1"),
                    new SqlScript("#3", "Content of #3"),
                });
                versionTracker = Substitute.For <IJournal>();
                versionTracker.GetExecutedScripts().Returns(new[] { "#1", "#2", "#3" });
                scriptExecutor = Substitute.For <IScriptExecutor>();

                var config = new UpgradeConfiguration
                {
                    ConnectionManager = new TestConnectionManager(Substitute.For <IDbConnection>())
                };

                config.ScriptProviders.Add(scriptProvider);
                config.ScriptExecutor = scriptExecutor;
                config.Journal        = versionTracker;

                var upgrader = new UpgradeEngine(config);

                return(upgrader);
            }
Пример #2
0
            public override UpgradeEngine Given()
            {
                scriptProvider = Substitute.For <IScriptProvider>();
                versionTracker = Substitute.For <IJournal>();
                versionTracker.GetExecutedScripts().Returns(new List <ExecutedSqlScript>
                {
                    new ExecutedSqlScript {
                        Hash = "a", Name = "#1"
                    },
                    new ExecutedSqlScript {
                        Hash = "b", Name = "#2"
                    },
                    new ExecutedSqlScript {
                        Hash = "c", Name = "#3"
                    }
                });
                scriptExecutor = Substitute.For <IScriptExecutor>();

                var config = new UpgradeConfiguration
                {
                    ConnectionManager = new TestConnectionManager(Substitute.For <IDbConnection>())
                };

                config.ScriptProviders.Add(scriptProvider);
                config.ScriptExecutor = scriptExecutor;
                config.Journal        = versionTracker;

                var upgrader = new UpgradeEngine(config);

                return(upgrader);
            }
Пример #3
0
        private void Window_Initialized(object sender, EventArgs e)
        {
            UpgradeConfiguration = new UpgradeConfiguration();
            var cfg = UpgradeConfiguration;

            cfg.UpdateByCommandLine();
            bool extractOptions = cfg.Options.ExtractOptions && cfg.SourcePath != null;

            if (extractOptions)
            {
                ExtractOptions();
                cfg.UpdateByCommandLine();
            }
            if (cfg.Options.Auto)
            {
                var upgrader = new Upgrader(cfg);
                upgrader.Process();
                Close();
//        if (Debugger.IsAttached)
//          Console.ReadLine();
            }
            else if (!extractOptions)
            {
                // Let's suggest these options by default in UI
                cfg.Options.AddImports    = true;
                cfg.Options.AddReferences = true;
            }
            Refresh();
        }
Пример #4
0
        public void WhenASingleLoggerIsAddedThenItselfShouldBeReturned()
        {
            var config   = new UpgradeConfiguration();
            var addedLog = new NoOpUpgradeLog();

            config.AddLog(addedLog);
            config.Log.ShouldBe(addedLog);
        }
Пример #5
0
        public void WhenTheLoggerIsClearedThenTheDefaultLoggerReturns()
        {
            var config     = new UpgradeConfiguration();
            var defaultLog = config.Log;

            config.AddLog(new NoOpUpgradeLog());
            config.Log.ShouldNotBe(defaultLog);

            config.Log = null;
            config.Log.ShouldBe(defaultLog);
        }
Пример #6
0
        public void WhenMultipleLoggersAreAddedThenAMultipleLoggerShouldBeReturnedAndLogsGoToAllDestinations()
        {
            var log1 = new TestLog();
            var log2 = new TestLog();
            var log3 = new TestLog();

            var config = new UpgradeConfiguration();

            config.AddLog(log1);
            config.AddLog(log2);
            config.AddLog(log3);
            config.Log.WriteInformation("Test");

            config.Log.ShouldBeOfType <MultipleUpgradeLog>();
            log1.WasWritten.ShouldBe(true);
            log2.WasWritten.ShouldBe(true);
            log3.WasWritten.ShouldBe(true);
        }
Пример #7
0
            public override UpgradeEngine Given()
            {
                scriptProvider = Substitute.For <IScriptProvider>();
                scriptProvider.GetScripts(Arg.Any <Func <IDbConnection> >()).Returns(new List <SqlScript> {
                    new SqlScript("1234", "foo")
                });
                versionTracker = Substitute.For <IJournal>();
                scriptExecutor = Substitute.For <IScriptExecutor>();

                var config = new UpgradeConfiguration();

                config.ScriptProviders.Add(scriptProvider);
                config.ScriptExecutor = scriptExecutor;
                config.Journal        = versionTracker;

                var upgrader = new UpgradeEngine(config);

                return(upgrader);
            }
Пример #8
0
        public virtual void BeforeEach()
        {
            ScriptProvider     = Substitute.For <IScriptProvider> ();
            VersionTracker     = Substitute.For <IJournal> ();
            ScriptExecutor     = Substitute.For <IScriptExecutor> ();
            ScriptPreprocessor = Substitute.For <IScriptPreprocessor>();

            Log = Substitute.For <IUpgradeLog> ();

            var config = new UpgradeConfiguration();

            config.ScriptPreprocessors.Add(ScriptPreprocessor);
            config.ScriptProviders.Add(ScriptProvider);
            config.ScriptExecutor = ScriptExecutor;
            config.Journal        = VersionTracker;
            config.Log            = Log;

            DbUpgrader = new UpgradeEngine(config);
        }
Пример #9
0
 public SqlTableJournal(UpgradeConfiguration upgradeConfig)
 {
     Config = upgradeConfig;
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UpgradeEngine"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 public UpgradeEngine(UpgradeConfiguration configuration)
 {
     this.configuration = configuration;
 }
Пример #11
0
 public SqlScriptExecutor(UpgradeConfiguration upgradeConfig)
 {
     Config = upgradeConfig;
 }
Пример #12
0
        private void InitializeServices(Type rootEntityType, Type[] entityTypes, UpgradeConfiguration upgradeConfiguration)
        {
            this.rootEntityType = rootEntityType;
            this.entityTypes    = entityTypes;

            typesService = new TypesService(provider);

            objectSerializationService.TypesService = typesService;

            var interfaceToTypeIdMapping = typesService.InitializeTypeSystem(entityTypes);

            var completeTypesList = interfaceToTypeIdMapping.Keys;

            generationService = new GenerationService(typesService);
            // TODO (nsabo) Optional loading of proxy types from the given assembly (we dont want always to generate on small devices, Silverlight...)
            // Note: Collection/Dictionary types are not saved in the assembly
            var interfaceToGeneratedMapping = generationService.GenerateProxyTypes(completeTypesList, Properties.Settings.Default.SaveGeneratedAssemblyToDisk, Properties.Settings.Default.GeneratedAssemblyFileName);

            proxyCreatorService = new ProxyCreatorService(completeTypesList, interfaceToTypeIdMapping, interfaceToGeneratedMapping);

            snapshotsService = new SnapshotsService(provider);

            #region Parent map provider setup
            if (Properties.Settings.Default.ParentMappingFileStorageUsed)
            {
                // Usage of file for caching parent information
                var indexedFile = new IndexedFileStorage(new FileStream(this.parentMappingFileName, FileMode.Create), Properties.Settings.Default.ParentMappingFileBlockSize, false);
                indexedFile.Serializer = this.objectSerializationService;
                disposables.Add(indexedFile);

                var parentProviderStorage = new CachedWriteNodeProviderUnsafe <Guid, object, EdgeData>(
                    new DirectNodeProviderUnsafe <Guid, object, EdgeData>(indexedFile, true),
                    new LimitedDirectNodeProviderUnsafe <Guid, object, EdgeData>(
                        new LimitedMemoryStorageUnsafe <Guid, object>(Properties.Settings.Default.ParentMappingMemoryMinimumCount, Properties.Settings.Default.ParentMappingMemoryMaximumCount), false)
                    );
                disposables.Add(parentProviderStorage);

                mutableParentProvider = new ParentMapProvider(parentProviderStorage, provider, null, true);
            }
            else
            {
                // Default parent information is stored in memory and has only the last snapshot available
                mutableParentProvider = new ParentMapProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false), provider, null, true);
            }
            #endregion

            #region Merge rule provider setup
            IMergeRuleProvider mergeRuleProvider = null;

            if (SnapshotIsolationEnabled)
            {
                if (Properties.Settings.Default.ConcurrencyAutoOverrideResolution)
                {
                    mergeRuleProvider = new AutoOverrideMergeRuleProvider();
                }
                else
                {
                    if (Properties.Settings.Default.ConcurrencyAttributesEnabled)
                    {
                        mergeRuleProvider = new AttributeBasedMergeRuleProvider(typesService);
                    }
                    else
                    {
                        throw new ArgumentException("No selected provider for merge rules in snapshot isolation conflicts. Check configuration of merge rule providers.");
                    }
                }
            }
            #endregion

            #region Setup change set provider
            // TODO (nsabo) Provide option for change set safety when context goes offline, OfflineWorkspaces should enable commits when context is back online

            if (Properties.Settings.Default.ChangeSetHistoryFileStorageUsed)
            {
                var indexedFile = new IndexedFileStorage(new FileStream(Properties.Settings.Default.ChangeSetHistoryFileStorageFileName, FileMode.Create), 256, false);
                indexedFile.Serializer = this.objectSerializationService;
                disposables.Add(indexedFile);

                var changeSetProviderStorage = new CachedWriteNodeProviderUnsafe <Guid, object, EdgeData>(
                    new DirectNodeProviderUnsafe <Guid, object, EdgeData>(indexedFile, true),
                    new LimitedDirectNodeProviderUnsafe <Guid, object, EdgeData>(
                        new LimitedMemoryStorageUnsafe <Guid, object>(Properties.Settings.Default.ChangeSetHistoryWriteCacheMinimumCount, Properties.Settings.Default.ChangeSetHistoryWriteCacheMaximumCount), false)
                    );
                disposables.Add(changeSetProviderStorage);

                changeSetProvider = new TrackingChangeSetProvider(changeSetProviderStorage);
            }
            else
            {
                changeSetProvider = new TrackingChangeSetProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false));
            }

            #endregion

            var immutableParentProvider = new ParentMapProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false), provider, null, false);
            collectedNodesProvider = new CollectedNodesProvider(new DirectNodeProviderUnsafe <Guid, object, EdgeData>(new MemoryStorageUnsafe <Guid, object>(), false), provider);

            commitDataService = new CommitDataService(provider, typesService, snapshotsService, mutableParentProvider, immutableParentProvider, changeSetProvider, new NodeMergeExecutor(mergeRuleProvider, typesService), collectedNodesProvider);

            workspaceExclusiveLockProvider = new WorkspaceExclusiveLockProvider();
            disposables.Add(workspaceExclusiveLockProvider);

            trackingWorkspaceStateProvider = new TrackingWorkspaceStateProvider(workspaceExclusiveLockProvider);

            objectInstancesService = new ObjectInstancesService(provider, typesService);

            subscriptionManagerService = new SubscriptionManagerService(typesService, objectInstancesService);

            workspaceFacade = new WorkspaceFacade(commitDataService, trackingWorkspaceStateProvider, subscriptionManagerService, snapshotsService, workspaceExclusiveLockProvider);

            backupService = new BackupService();

            bool firstRun = snapshotsService.InitializeSnapshots();

            if (firstRun)
            {
                InitializeDefaultSnapshot();
            }
            else
            {
                OptimizeData();
            }

            StaticProxyFacade.Initialize(typesService);
        }
Пример #13
0
 /// <summary>
 /// Creates new instance of Context type and upgrades the data from existing storage.
 /// </summary>
 /// <param name="rootEntityType">Type of root entity</param>
 /// <param name="entityTypes">Array of entity interface types to register. All reachable sub-types are registered automatically.</param>
 /// <param name="storage">Storage to be used</param>
 /// <param name="upgradeConfiguration">Upgrade configuration</param>
 public Context(Type rootEntityType, Type[] entityTypes, IKeyValueStorage <Guid, object> storage, UpgradeConfiguration upgradeConfiguration)
 {
     InitializeProvider(storage);
     if (entityTypes == null)
     {
         entityTypes = new Type[] { rootEntityType };
     }
     InitializeServices(rootEntityType, entityTypes, upgradeConfiguration);
 }
Пример #14
0
 public MySqlLockManager(UpgradeConfiguration upgradeConfiguration)
 {
     _UpgradeConfiguration = upgradeConfiguration;
 }