public void TestClassNameRefactoring()
        {
            CataloguePatcher p = new CataloguePatcher();

            var patch = p.GetAllPatchesInAssembly(null).Single(kvp => kvp.Key == "068_FixNamespaces.sql").Value;

            Regex findSubsRegex = new Regex(@"REPLACE\(.*,'(.*)','(.*)'\)");

            Dictionary <string, string> substitutions = new Dictionary <string, string>();

            foreach (Match match in findSubsRegex.Matches(patch.EntireScript))
            {
                if (substitutions.ContainsKey(match.Groups[1].Value))
                {
                    continue;
                }

                substitutions.Add(match.Groups[1].Value, match.Groups[2].Value);
            }

            SetupMEF();

            MEF.SafeDirectoryCatalog.AddType(typeof(FAnsi.DatabaseType));

            foreach (var oldClass in ExpectedClasses)
            {
                string newClass = oldClass;

                foreach (KeyValuePair <string, string> kvp in substitutions)
                {
                    newClass = newClass.Replace(kvp.Key, kvp.Value);
                }

                Type foundNow = MEF.GetType(newClass);

                Assert.IsNotNull(foundNow, "Patch did not work correctly for Type '" + oldClass + "' which after renaming became '" + newClass + "'");
            }
        }
示例#2
0
        public void DoStartup(ICheckNotifier notifier)
        {
            bool foundCatalogue = false;

            notifier.OnCheckPerformed(new CheckEventArgs("Loading core assemblies", CheckResult.Success));

            DiscoveredServerHelper.CreateDatabaseTimeoutInSeconds = UserSettings.CreateDatabaseTimeout;

            var cataloguePatcher = new CataloguePatcher();

            try
            {
                foundCatalogue = Find((ITableRepository)RepositoryLocator.CatalogueRepository, cataloguePatcher, notifier);
            }
            catch (Exception e)
            {
                DatabaseFound(this, new PlatformDatabaseFoundEventArgs(null, cataloguePatcher, RDMPPlatformDatabaseStatus.Broken, e));
            }

            if (foundCatalogue)
            {
                try
                {
                    //setup connection string keywords
                    foreach (ConnectionStringKeyword keyword in RepositoryLocator.CatalogueRepository.GetAllObjects <ConnectionStringKeyword>())
                    {
                        var tomem = new ToMemoryCheckNotifier(notifier);
                        keyword.Check(tomem);

                        //don't add broken keywords!
                        if (tomem.GetWorst() >= CheckResult.Fail)
                        {
                            continue;
                        }

                        //pass it into the system wide static keyword collection for use with all databases of this type all the time (that includes Microsoft Sql Server btw which means those options will happen for DataExport too!)
                        DiscoveredServerHelper.AddConnectionStringKeyword(keyword.DatabaseType, keyword.Name, keyword.Value, ConnectionStringKeywordPriority.SystemDefaultMedium);
                    }
                }
                catch (Exception ex)
                {
                    notifier.OnCheckPerformed(new CheckEventArgs("Could not apply ConnectionStringKeywords", CheckResult.Fail, ex));
                }
            }


            //only load data export manager if catalogue worked
            if (foundCatalogue)
            {
                LoadMEF(RepositoryLocator.CatalogueRepository, notifier);

                //find tier 2 databases
                foreach (var patcher in _patcherManager.Tier2Patchers)
                {
                    FindWithPatcher(patcher, notifier);
                }

                try
                {
                    var dataExportRepository = RepositoryLocator.DataExportRepository;

                    //not configured
                    if (dataExportRepository == null)
                    {
                        return;
                    }

                    Find((ITableRepository)dataExportRepository, new DataExportPatcher(), notifier);
                }
                catch (Exception e)
                {
                    DatabaseFound(this, new PlatformDatabaseFoundEventArgs(null, new DataExportPatcher(), RDMPPlatformDatabaseStatus.Broken, e));
                }

                FindTier3Databases(RepositoryLocator.CatalogueRepository, notifier);
            }

            if (MEFSafeDirectoryCatalog != null)
            {
                Validator.RefreshExtraTypes(MEFSafeDirectoryCatalog, notifier);
            }
        }