/// <summary> /// /// </summary> /// <param name="database"></param> /// <param name="model"></param> /// <returns></returns> /// <exception cref="Exception">Database already exists</exception> /// <exception cref="ArgumentNullException"><paramref name="database"/> is <see langword="null" />.</exception> public bool CreateDatabase(string database) { //to check in processes var dataDir = Path.Combine(_serverConfiguration.DbFarmDir, database); var model = new MonetServerOptionsModel(); if (DiagnosticHelper.IsRunningApplication(MSERVER_PROCESS_NAME, String.Format("--dbpath=\"{0}\"", dataDir))) { throw new MonetDbException("Database already created"); } try { //database var serverFileName = string.Format("{0}\\bin\\mserver5.exe", _serverConfiguration.DbInstallerDir); var serverFileArgs = string.Format("--set \"prefix={0}\" " + "--set \"exec_prefix={0}\" " + "--set \"mapi_port={1}\" " + "--dbpath=\"{2}\" " + "--set \"gdk_nr_threads={3}\" " + "--set \"max_clients={4}\"", _serverConfiguration.DbInstallerDir, model.Port, dataDir, model.Threads, model.MaxClients); model.ServerArguments = serverFileArgs; model.ServerFileName = serverFileName; //environment EnvironmentHelper.SetVariables("PATH", string.Format("{0}\\bin;{0}\\lib;{0}\\lib\\MonetDB5;", _serverConfiguration.DbInstallerDir)); if (DiagnosticHelper.AutoLaunchApplicationToSleep(serverFileName, serverFileArgs)) { //server options BinaryFormatterHelper.Serialize(model, Path.Combine(dataDir, SERVER_OPTIONS_FILE)); //startup ShellHelper.AddToStartup(ToTitle(database), Path.Combine(IoHelper.CurrentRoot, STARTUP_PROCESS_NAME), $"\"{Path.Combine(dataDir, SERVER_OPTIONS_FILE)}\""); //logging LoggerHelper.Write(LoggerOption.Info, "Client#{0} -> Created '{1}' database", CurrentClient.ClientId, database); return(true); } } catch (Exception exception) { LoggerHelper.Write(LoggerOption.Error, exception.Message); throw; } return(false); }