private void MoveClientDefinition( string instanceNameSource, string instanceNameTarget, string clientName ) { ClientManager clientManagerSource = new ClientManager(Path.Combine( ConfigurationManager.AppSettings["InstanceRoot"], instanceNameSource, "App_Data", "Clients.xml" )); ClientManager clientManagerTarget = new ClientManager(Path.Combine( ConfigurationManager.AppSettings["InstanceRoot"], instanceNameTarget, "App_Data", "Clients.xml" )); if (clientManagerTarget.GetSingle(clientName) != null) { clientManagerTarget.Remove(clientName); } Client client = clientManagerSource.GetSingle(clientName); clientManagerTarget.Append( client.Name, client.Database, client.Host, client.Color1, client.Color2, client.XmlNode.Attributes["CreatedDate"].Value, string.Join(",", client.SynchServers) ); clientManagerSource.Remove(clientName); }
private void CreateClient(HttpContext context) { // Get the client name from // the http request's parameters. string clientName = context.Request.Params["Client"]; // Get the source instance name from // the http request's parameters. string instanceName = context.Request.Params["Instance"]; string hostname = string.Format( ConfigurationManager.AppSettings["Hostname"], clientName ); InstanceCollection instances = new InstanceCollection( ConfigurationManager.AppSettings["InstanceRoot"] ); if (!instances.Instances.ContainsKey(instanceName)) { context.Response.Write("__ERROR__Instance does not exist on the server."); return; } Instance instance = instances.Instances[instanceName]; ClientManager clientManager = new ClientManager(Path.Combine( ConfigurationManager.AppSettings["InstanceRoot"], instanceName, "App_Data", "Clients.xml" )); clientManager.Append( clientName.ToLower(), clientName, hostname, "#6CAEE0", "#FCB040", DateTime.Today.ToString("dd-MM-yyyy"), context.Request.Params["Servers"] ); InstanceVersion version = new InstanceVersion(instance.Version); string databaseScriptsDirectory = Path.Combine( context.Request.PhysicalApplicationPath, "App_Data", "ClientCreation", version.ToString(), "DATABASE" ); while (!Directory.Exists(databaseScriptsDirectory)) { version -= 1; if (version.ToString() == "0.0.0.0") { return; } databaseScriptsDirectory = Path.Combine( context.Request.PhysicalApplicationPath, "App_Data", "ClientCreation", version.ToString(), "DATABASE" ); } string databaseRoot = ConfigurationManager.AppSettings["DatabaseRoot"]; int i = 0; foreach (string scriptFile in Directory.GetFiles(databaseScriptsDirectory)) { string script = File.ReadAllText(scriptFile); script = script.Replace("###CLIENTNAME###", clientName); script = script.Replace("###DATABASEROOT###", databaseRoot); ExecuteQuery( i == 0 ? "master" : clientName, script ); i++; } string fileSystemRoot = Path.Combine( context.Request.PhysicalApplicationPath, "App_Data", "ClientCreation", version.ToString(), "FILESYSTEM" ); foreach (string directory in Directory.GetDirectories(fileSystemRoot)) { string target = directory.Replace( fileSystemRoot, Path.Combine( ConfigurationManager.AppSettings["InstanceRoot"], instanceName )); CopyDirectory( directory, target, clientName ); } try { IISBindings iisBindings = new IISBindings(); iisBindings.AddBindings(instanceName, hostname); } catch { } string caseDataDirectory = Path.Combine( ConfigurationManager.AppSettings["CaseDataPath"], clientName ); if (!Directory.Exists(caseDataDirectory)) { Directory.CreateDirectory(caseDataDirectory); } ExecuteQuery(clientName, "INSERT INTO [Roles] (Id, CreationDate, Name, Description) " + "VALUES ({0}, {1}, {2}, {3})", Guid.Parse("00000000-0000-0000-0000-000000000000"), DateTime.Now, "Administrators", "Blueocean administrators" ); XmlDocument document = new XmlDocument(); document.Load(Path.Combine( ConfigurationManager.AppSettings["InstanceRoot"], instanceName, "App_Data", "Permissions.xml" )); foreach (XmlNode xmlNodePermission in document.SelectNodes("//Permission")) { ExecuteQuery(clientName, "INSERT INTO [RolePermissions] (Id, IdRole, Permission, CreationDate) " + "VALUES (NEWID(), {0}, {1}, {2})", Guid.Parse("00000000-0000-0000-0000-000000000000"), int.Parse(xmlNodePermission.Attributes["Id"].Value), DateTime.Now ); } }