示例#1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            var commandLine = new CommandLine(args);

            if (commandLine.RunAsService)
            {
                ServiceBase[] servicesToRun = new ServiceBase[] { new ShredHostService() };
                ServiceBase.Run(servicesToRun);
            }
            else if (!String.IsNullOrEmpty(commandLine.PreviousExeConfigurationFilename))
            {
                var groups = SettingsGroupDescriptor.ListInstalledSettingsGroups(SettingsGroupFilter.LocalStorage);
                foreach (var group in groups)
                {
                    SettingsMigrator.MigrateSharedSettings(group, commandLine.PreviousExeConfigurationFilename);
                }

                ShredSettingsMigrator.MigrateAll(commandLine.PreviousExeConfigurationFilename);
            }
            else
            {
                Thread.CurrentThread.Name = "Main thread";
                if (!ManifestVerification.Valid)
                {
                    Console.WriteLine("The manifest detected an invalid installation.");
                }
                ShredHostService.InternalStart();
                Console.WriteLine("Press <Enter> to terminate the ShredHost.");
                Console.WriteLine();
                Console.ReadLine();
                ShredHostService.InternalStop();
            }
        }
        private static void TestLocalSharedSettingsMigration(Type mixedScopeSettingsClass)
        {
            if (!mixedScopeSettingsClass.IsSubclassOf(typeof(MixedScopeSettingsBase)))
            {
                throw new ArgumentException();
            }

            var configuration = SystemConfigurationHelper.GetExeConfiguration();
            var values        = CreateSettingsValues(mixedScopeSettingsClass, MigrationScope.Shared, SettingValue.Current);

            configuration.PutSettingsValues(mixedScopeSettingsClass, values);

            string directory           = Path.GetDirectoryName(configuration.FilePath);
            string previousExeFilename = String.Format("{0}{1}Previous.exe.config", directory, Path.DirectorySeparatorChar);

            try
            {
                TestConfigResourceToFile(previousExeFilename);

                ValidateLocalMixedScopeSettingsValuesInConfig(mixedScopeSettingsClass, configuration, SettingValue.Current);
                SettingsMigrator.MigrateSharedSettings(mixedScopeSettingsClass, previousExeFilename);
                configuration = SystemConfigurationHelper.GetExeConfiguration();
                ValidateLocalMixedScopeSettingsValuesInConfig(mixedScopeSettingsClass, configuration, SettingValue.Previous);
            }
            finally
            {
                File.Delete(previousExeFilename);
                configuration.RemoveSettingsValues(mixedScopeSettingsClass);
            }
        }
示例#3
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            var commandLine = new CommandLine(args);

            if (commandLine.RunAsService)
            {
                var ServicesToRun = new ServiceBase[] { new ShredHostService() };
                ServiceBase.Run(ServicesToRun);
            }
            else if (!String.IsNullOrEmpty(commandLine.PreviousExeConfigurationFilename))
            {
                var groups = SettingsGroupDescriptor.ListInstalledLocalSettingsGroups();
                groups.Add(new SettingsGroupDescriptor(typeof(ShredSettingsMigrator).Assembly.GetType("ClearCanvas.Server.ShredHost.ShredHostServiceSettings")));
                foreach (var group in groups)
                {
                    SettingsMigrator.MigrateSharedSettings(group, commandLine.PreviousExeConfigurationFilename);
                }

                ShredSettingsMigrator.MigrateAll(commandLine.PreviousExeConfigurationFilename);
            }
            else
            {
                ShredHostService.InternalStart();
                Console.WriteLine("Press <Enter> to terminate the ShredHost.");
                Console.WriteLine();
                Console.ReadLine();
                ShredHostService.InternalStop();
            }
        }
示例#4
0
        public void TestLocalSharedSettingsMigration()
        {
            Type settingsClass = typeof(LocalMixedScopeSettings);
            var  configuration = SystemConfigurationHelper.GetExeConfiguration();
            var  values        = CreateSettingsValues(settingsClass, MigrationScope.Shared, SettingValue.Current);

            SystemConfigurationHelper.PutSettingsValues(configuration, settingsClass, values);

            string directory           = Path.GetDirectoryName(configuration.FilePath);
            string previousExeFilename = String.Format("{0}{1}Previous.exe.config", directory, Path.DirectorySeparatorChar);

            try
            {
                TestConfigResourceToFile(previousExeFilename);

                ValidateLocalMixedScopeSettingsValuesInConfig(configuration, SettingValue.Current);
                SettingsMigrator.MigrateSharedSettings(settingsClass, previousExeFilename);
                configuration = SystemConfigurationHelper.GetExeConfiguration();
                ValidateLocalMixedScopeSettingsValuesInConfig(configuration, SettingValue.Previous);
            }
            finally
            {
                File.Delete(previousExeFilename);
                SystemConfigurationHelper.RemoveSettingsValues(configuration, settingsClass);
            }
        }
示例#5
0
 private static void MigrateSharedSettings(string previousExeConfigFilename)
 {
     foreach (var group in SettingsGroupDescriptor.ListInstalledSettingsGroups(false))
     {
         SettingsMigrator.MigrateSharedSettings(group, previousExeConfigFilename);
     }
 }
        public void TestNeverMigrateProductSettings()
        {
            ResetUpgradeSettings();
            ResetAllSettingsClasses();
            Type settingsClass = typeof(ProductSettings);

            Assert.IsFalse(SettingsMigrator.MigrateUserSettings(settingsClass));
            Assert.IsFalse(SettingsMigrator.MigrateSharedSettings(settingsClass, null));
        }
        public void RunApplication(string[] args)
        {
            var commandLine = new CommandLine(args);

            var groups = SettingsGroupDescriptor.ListInstalledSettingsGroups(SettingsGroupFilter.LocalStorage);

            foreach (var group in groups)
            {
                SettingsMigrator.MigrateSharedSettings(group, commandLine.PreviousExeConfigurationFilename);
            }
        }
        private static void TestMultipleSharedSettingsMigrated(Type mixedScopeSettingsClass)
        {
            if (!mixedScopeSettingsClass.IsSubclassOf(typeof(MixedScopeSettingsBase)))
            {
                throw new ArgumentException();
            }

            ResetSimpleStore();
            ResetAllSettingsClasses();

            PopulateSimpleStore(mixedScopeSettingsClass);

            SettingsMigrator.MigrateSharedSettings(mixedScopeSettingsClass, null);
            var settings = ApplicationSettingsHelper.GetSettingsClassInstance(mixedScopeSettingsClass);

            SettingsProperty property = settings.Properties[MixedScopeSettingsBase.PropertyUser1];
            string           expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current);
            var actual = (string)settings[property.Name];

            Assert.AreEqual(expected, actual);

            property = settings.Properties[MixedScopeSettingsBase.PropertyUser2];
            expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current);
            actual   = (string)settings[property.Name];
            Assert.AreEqual(expected, actual);

            property = settings.Properties[MixedScopeSettingsBase.PropertyApp1];
            expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous);
            actual   = (string)settings.GetSharedPropertyValue(property.Name);
            Assert.AreEqual(expected, actual);
            actual = (string)settings[property.Name];
            Assert.AreEqual(expected, actual);

            property = settings.Properties[MixedScopeSettingsBase.PropertyApp2];
            expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous);
            actual   = (string)settings.GetSharedPropertyValue(property.Name);
            Assert.AreEqual(expected, actual);
            actual = (string)settings[property.Name];
            Assert.AreEqual(expected, actual);

            property = settings.Properties[MixedScopeSettingsBase.PropertyUser1];
            expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous);
            actual   = (string)settings.GetSharedPropertyValue(property.Name);
            Assert.AreEqual(expected, actual);

            property = settings.Properties[MixedScopeSettingsBase.PropertyUser2];
            expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous);
            actual   = (string)settings.GetSharedPropertyValue(property.Name);
            Assert.AreEqual(expected, actual);
        }
示例#9
0
        public void MigrateSettingsNoChanges()
        {
            TestSettingsStore.Instance.Reset();

            var settings = new MigrationAppSettings();


            SettingsMigrator.MigrateSharedSettings(typeof(MigrationAppSettings), null);

            var settings3 = new MigrationAppSettings();

            Assert.AreEqual(settings3.App1, MigrationAppSettings.DefaultValueApp);
            Assert.AreEqual(settings3.App2, MigrationAppSettings.DefaultValueApp);
            Assert.AreEqual(settings3.App3, MigrationAppSettings.DefaultValueApp);
        }
示例#10
0
        public void TestCustomSharedSettingsMigration()
        {
            ResetSimpleStore();
            ResetAllSettingsClasses();

            Type settingsClass = typeof(CustomMigrationMixedScopeSettings);

            PopulateSimpleStore(settingsClass);

            SettingsMigrator.MigrateSharedSettings(settingsClass, null);
            var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass);

            SettingsProperty property = settings.Properties[MixedScopeSettingsBase.PropertyUser1];
            string           expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current);
            var actual = (string)settings[property.Name];

            Assert.AreEqual(expected, actual);

            property = settings.Properties[MixedScopeSettingsBase.PropertyUser2];
            expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current);
            actual   = (string)settings[property.Name];
            Assert.AreEqual(expected, actual);

            property = settings.Properties[MixedScopeSettingsBase.PropertyApp1];
            expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current);
            actual   = (string)settings.GetSharedPropertyValue(property.Name);
            Assert.AreEqual(expected, actual);
            actual = (string)settings[property.Name];
            Assert.AreEqual(expected, actual);

            property = settings.Properties[MixedScopeSettingsBase.PropertyApp2];
            expected = "CustomApp2";
            actual   = (string)settings.GetSharedPropertyValue(property.Name);
            Assert.AreEqual(expected, actual);
            actual = (string)settings[property.Name];
            Assert.AreEqual(expected, actual);

            property = settings.Properties[MixedScopeSettingsBase.PropertyUser1];
            expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous);
            actual   = (string)settings.GetSharedPropertyValue(property.Name);
            Assert.AreEqual(expected, actual);

            property = settings.Properties[MixedScopeSettingsBase.PropertyUser2];
            expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current);
            actual   = (string)settings.GetSharedPropertyValue(property.Name);
            Assert.AreEqual(expected, actual);
        }
示例#11
0
 private static void MigrateSharedSettings(string previousExeConfigFilename)
 {
     foreach (var group in SettingsGroupDescriptor.ListInstalledSettingsGroups())
     {
         try
         {
             SettingsMigrator.MigrateSharedSettings(group, previousExeConfigFilename);
         }
         catch (Exception e)
         {
             //Failure to migrate a settings is not good enough reason to cause the whole app to fail.
             //Some of the viewer settings classes SHOULD actually fail to migrate in the context of the ImageServer.
             //
             Platform.Log(LogLevel.Warn, e, "Failed to migrate settings '{0}'", group.AssemblyQualifiedTypeName);
         }
     }
 }
示例#12
0
        private static void TestMigrateXmlSettings(Type xmlSettingsClass)
        {
            if (!xmlSettingsClass.IsSubclassOf(typeof(LocalXmlSettingsBase)))
            {
                throw new ArgumentException();
            }

            var configuration = SystemConfigurationHelper.GetExeConfiguration();

            var settings = (LocalXmlSettingsBase)ApplicationSettingsHelper.GetSettingsClassInstance(xmlSettingsClass);
            var document = new XmlDocument();

            document.LoadXml((string)settings.Properties[LocalXmlSettingsBase.PropertyApp].DefaultValue);
            var node = document.SelectSingleNode("//test");

            node.InnerText = "CurrentApp";
            var values = new Dictionary <string, string>();

            values[LocalXmlSettingsBase.PropertyApp] = document.InnerXml;
            configuration.PutSettingsValues(xmlSettingsClass, values);

            string directory           = Path.GetDirectoryName(configuration.FilePath);
            string previousExeFilename = String.Format("{0}{1}Previous.exe.config", directory, Path.DirectorySeparatorChar);

            try
            {
                TestConfigResourceToFile(previousExeFilename);
                SettingsMigrator.MigrateSharedSettings(xmlSettingsClass, previousExeFilename);
                configuration = SystemConfigurationHelper.GetExeConfiguration();
                settings      = (LocalXmlSettingsBase)ApplicationSettingsHelper.GetSettingsClassInstance(xmlSettingsClass);
                settings.Reload();
                document = (XmlDocument)settings.GetSharedPropertyValue(LocalXmlSettingsBase.PropertyApp);
                Assert.AreEqual("PreviousApp", document.SelectSingleNode("//test").InnerXml);
                document = settings.App;
                Assert.AreEqual("PreviousApp", document.SelectSingleNode("//test").InnerXml);
            }
            finally
            {
                File.Delete(previousExeFilename);
                configuration.RemoveSettingsValues(xmlSettingsClass);
            }
        }
        public void TestNonMigratableSharedSettings()
        {
            ResetUpgradeSettings();

            Type settingsClass = typeof(NonMigratableSharedSettings);

            PopulateSimpleStore(settingsClass);

            Assert.IsFalse(SettingsMigrator.MigrateSharedSettings(settingsClass, null));
            var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass);

            SettingsProperty property = settings.Properties[NonMigratableSharedSettings.PropertyApp];
            string           expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current);

            Assert.AreEqual(expected, settings[property.Name]);

            string current = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name);

            Assert.AreEqual(expected, current);
        }
        public void RunApplication(string[] args)
        {
            var cmd = new CommandLine();

            try
            {
                cmd.Parse(args);
            }
            catch (Exception)
            {
                cmd.PrintUsage(Console.Out);
                Environment.Exit(-1);
            }

            //Hack to redirect local shared settings to a different exe's config file.
            ExtendedLocalFileSettingsProvider.ExeConfigFileName = cmd.Target;
            foreach (var settingsClass in _applicationSettingsClasses)
            {
                var settingsType = Type.GetType(settingsClass);
                SettingsMigrator.MigrateSharedSettings(settingsType, cmd.Source);
            }

            try
            {
                if (!String.IsNullOrEmpty(cmd.DicomServersFileName) && File.Exists(cmd.DicomServersFileName))
                {
                    var existingServerTree = new ServerTree.ServerTree();
                    if (existingServerTree.RootServerGroup.GetAllServers().Count == 0)
                    {
                        //Settings NOT from an old xml file were just migrated, so
                        //if there's still no servers defined, import from old xml file.
                        var serverTree = new ServerTree.ServerTree(cmd.DicomServersFileName);
                        serverTree.Save();
                    }
                }
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Warn, e, "Failed to import legacy server tree '{0}'.", cmd.DicomServersFileName);
            }
        }
示例#15
0
        public void MigrateSettings()
        {
            TestSettingsStore.Instance.Reset();

            var settings = new MigrationAppSettings();

            const string testVal1 = "A man, a plan, a canal, panama";
            const string testVal2 = "Now is the time for all good men to come to the aide of their country";

            settings.App1 = testVal1;
            settings.App2 = testVal2;
            settings.Save();

            Assert.IsTrue(SettingsMigrator.MigrateSharedSettings(typeof(MigrationAppSettings), null));

            var settings1a = new MigrationAppSettings();

            Assert.AreEqual(settings1a.App1, testVal1);
            Assert.AreEqual(settings1a.App2, testVal2);
            Assert.AreEqual(settings1a.App3, MigrationAppSettings.DefaultValueApp);

            var group = new SettingsGroupDescriptor(typeof(MigrationAppSettings));

            TestSettingsStore.Instance.GetPreviousSettingsGroup(group);
            TestSettingsStore.Instance.RemoveSettingsGroup(group);

            var settings2 = new MigrationAppSettings();

            Assert.AreEqual(settings2.App1, MigrationAppSettings.DefaultValueApp);
            Assert.AreEqual(settings2.App2, MigrationAppSettings.DefaultValueApp);
            Assert.AreEqual(settings2.App3, MigrationAppSettings.DefaultValueApp);

            Assert.IsTrue(SettingsMigrator.MigrateSharedSettings(typeof(MigrationAppSettings), null));

            var settings3 = new MigrationAppSettings();

            Assert.AreEqual(settings3.App1, testVal1 + TestSettingsStore.TestString);
            Assert.AreEqual(settings3.App2, testVal2 + TestSettingsStore.TestString);
            Assert.AreEqual(settings3.App3, MigrationAppSettings.DefaultValueApp);
        }
示例#16
0
        public void TestUserDefaultSettingsMigrated()
        {
            ResetUpgradeSettings();

            Type settingsClass = typeof(SimpleUserSettings);

            PopulateSimpleStore(settingsClass);

            Assert.IsTrue(SettingsMigrator.MigrateSharedSettings(settingsClass, null));

            var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass);

            SettingsProperty property = settings.Properties[SimpleUserSettings.PropertyUser];
            string           expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current);

            Assert.AreEqual(expected, settings[property.Name]);

            expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous);
            string current = (string)settings.GetSharedPropertyValue(property.Name);

            Assert.AreEqual(expected, current);
        }