public void TestMultiServersGetConnectionString()
        {
            MongoConfiguration config = new MongoConfiguration { Username = string.Empty, Password = string.Empty };

            config.Host = "127.0.0.1";
            config.Port = 22;
            config.Database = "Test";
            Assert.AreEqual("mongodb://127.0.0.1:22/Test", config.ToConnectionString());

            config.Username = "******";
            config.Password = "******";
            Assert.AreEqual("mongodb://*****:*****@127.0.0.1:22/Test", config.ToConnectionString());

            config.Servers = new Server[1];
            config.Servers[0] = new Server() { Host = "localhost", Port = 1000 };
            Assert.AreEqual("mongodb://*****:*****@localhost:1000/Test", config.ToConnectionString());

            config.Servers = new Server[2];
            config.Servers[0] = new Server() { Host = "localhost", Port = 1000 };
            config.Servers[1] = new Server() { Host = "100.10.1.1", Port = 5000 };
            Assert.AreEqual("mongodb://*****:*****@localhost:1000,100.10.1.1:5000/Test", config.ToConnectionString());

            config.ReplicaSet = "iApplyReplicaSet";
            Assert.AreEqual("mongodb://*****:*****@localhost:1000,100.10.1.1:5000/Test?replicaSet=iApplyReplicaSet", config.ToConnectionString());

            config.ReplicaSet = string.Empty;
            config.Username = string.Empty;
            Assert.AreEqual("mongodb://localhost:1000,100.10.1.1:5000/Test", config.ToConnectionString());
        }
        public void TestGetClientSettings()
        {
            MongoConfiguration config = new MongoConfiguration
                                        {
                                            Username = string.Empty,
                                            Password = string.Empty
                                        };

            Assert.AreEqual(0, config.ToMongoClientSettings().Credentials.Count());
            Assert.AreEqual(config.Host, config.ToMongoClientSettings().Server.Host);
            Assert.AreEqual(config.Port, config.ToMongoClientSettings().Server.Port);

            config.Username = "******";
            config.Password = "******";

            const int somePort = 8080;
            const string someHost = "ISOLUTIONS-AMAZINGDB";

            config.Port = somePort;
            config.Host = someHost;

            Assert.AreEqual(1, config.ToMongoClientSettings().Credentials.Count());
            Assert.AreEqual(someHost, config.ToMongoClientSettings().Server.Host);
            Assert.AreEqual(somePort, config.ToMongoClientSettings().Server.Port);
        }
        public void TestGetConnectionString()
        {
            MongoConfiguration config = new MongoConfiguration { Username = string.Empty, Password = string.Empty };

            Assert.IsFalse(config.ToConnectionString().Contains("@"));

            config.Username = "******";
            config.Password = "******";

            Assert.IsTrue(config.ToConnectionString().Contains(config.Username));
            Assert.IsTrue(config.ToConnectionString().Contains("@"));
            Assert.IsTrue(config.ToConnectionString().Contains(config.Password));
        }
        /// <summary>
        /// Updates the global database configuration file.
        /// </summary>
        public void WriteDbConfig()
        {
            MongoConfiguration mongoConfiguration = new MongoConfiguration
                                                    {
                Host = this.installOptions.MongoHost,
                Port = this.installOptions.MongoPort.Value,
                Database = this.installOptions.MongoDatabase,
                Username = !string.IsNullOrWhiteSpace(this.installOptions.MongoUsername) ? this.installOptions.MongoUsername : null,
                Password = !string.IsNullOrWhiteSpace(this.installOptions.MongoPassword) ? this.installOptions.MongoPassword : null
            };

            using (Stream stream = new FileStream(this.installVariables.ServerDatabaseConfigPath, FileMode.Create, FileAccess.Write))
            using (XmlWriter writer = XmlWriter.Create(stream, new XmlWriterSettings { Indent = true, IndentChars = "    " }))
            {
                new XmlSerializer(mongoConfiguration.GetType()).Serialize(writer, mongoConfiguration);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Run the installation / uninstallation process.
        /// </summary>
        /// <param name="options">The install options.</param>
        private void Run(InstallOptions options)
        {
            int exitCode = 0;
            this.installOptions = options;

            try
            {
                if (string.IsNullOrEmpty(this.installOptions.LogFileRelative))
                {
                    this.installOptions.LogFileAbsolute = this.installOptions.Mode + ".log";
                }

                installLogger.SetLogFile(options.LogFileAbsolute);
                if (!this.IsUserAdministrator())
                {
                    throw new UnauthorizedAccessException(Messages.MAIN_AdminRequired);
                }

                this.installVariables.BasePath = this.FindBasePath();
                this.CheckParameters(options);

                this.webManager = new WebManager(this.installOptions, this.installVariables, installLogger);
                this.taskManager = new ScheduledTaskManager(this.installOptions, this.installVariables, installLogger);

                if (options.Mode != InstallerMode.Uninstall)
                {
                    IMongoConfiguration mongoConfiguration = new MongoConfiguration
                                                             {
                        Host = this.installOptions.MongoHost,
                        Port = this.installOptions.MongoPort.Value,
                        Database = this.installOptions.MongoDatabase,
                        Username = this.installOptions.MongoUsername,
                        Password = this.installOptions.MongoPassword
                    };

                    var websiteName = this.installOptions.WebsiteName;

                    if (this.installOptions.RootSite != null)
                    {
                        websiteName = string.Format("{0}/{1}", this.installOptions.HostName, this.installOptions.WebsiteName);
                    }

                    DatabaseInitialiserOptions dbInitOptions = new DatabaseInitialiserOptions
                    {
                        WebsiteName = websiteName,
                        OrgName = this.installOptions.OrgName,
                        AdminEmail = this.installOptions.AdminEmail,
                        AdminPassword = this.installOptions.AdminPassword
                    };

                    this.dbManager = new DatabaseInitialiser(mongoConfiguration, dbInitOptions, this.installVariables, installLogger)
                                     {
                                         ReadInput = this.ReadInput,
                                         ReadPassword = this.ReadInput
                                     };
                }

                if (options.Mode == InstallerMode.Install)
                {
                    this.RunInstall(options.Type);
                }

                if (options.Mode == InstallerMode.Repair)
                {
                    this.dbManager.Run();
                }

                if (options.Mode != InstallerMode.Uninstall)
                {
                    if (options.Api && !string.IsNullOrEmpty(this.installOptions.IapplyWebsiteName))
                    {
                        this.installOptions.WebsiteName = this.installOptions.IapplyWebsiteName;
                    }

                    ConfigurationUpdater updater = new ConfigurationUpdater(this.installOptions, this.installVariables);
                    updater.UpdateXmlConfig(options.Type);
                    updater.UpdateJsConfig(options.Type);
                    updater.WriteDbConfig();

                    if (options.Mode != InstallerMode.Repair)
                    {
                        updater.GenerateNewCryptoKeys();
                    }

                    installLogger.LogLine(Messages.MAIN_InstallationComplete);
                }

                if (options.Mode == InstallerMode.Uninstall)
                {
                    this.RunUninstall(options.Type);
                }
            }
            catch (Exception e)
            {
                installLogger.LogError(e);
                exitCode = 1;
            }

            if (!this.installOptions.Quiet)
            {
                Console.Write(Environment.NewLine + Strings.PressAnyKey);
                Console.ReadKey();
            }

            Environment.Exit(exitCode);
        }