/// <summary> /// Execures the permissions procedure for each template entry /// </summary> private void ExecutePermissionsProcedures() { string commandLine = string.Empty; StringBuilder sb = new StringBuilder(); Utilities.Logger.LogInformation("Executing permissions procedures ..."); using (StreamReader sr = new StreamReader(this.extractCommands)) { PermissionPattern permissions = this.GetPermissions(); foreach (PermissionMap map in permissions.PermissionMaps) { string objectTypes = string.Concat("'", string.Join("'',''", map.ObjectTypes.Split(new char[] { ',' })), "'"); if (string.IsNullOrEmpty(map.SchemaName)) { commandLine = string.Format("exec spGeneratePermissions @Principal='{0}',@Permissions='{1}',@ObjectTypes=''{2}''", map.PrincipalName, map.GrantType, objectTypes); } else { commandLine = string.Format("exec spGeneratePermissions @Principal='{0}',@Permissions='{1}',@ObjectTypes=''{2}'',@SchemaName='{3}'", map.PrincipalName, map.GrantType, objectTypes, map.SchemaName); } if (!string.IsNullOrEmpty(commandLine.Trim())) { DataSet ds = this.database.ExecuteWithResults(commandLine); if (ds != null) { foreach (DataTable dt in ds.Tables) { foreach (DataRow dr in dt.Rows) { sb.AppendLine(dr[0].ToString()); } } } } } sr.Close(); } using (StreamWriter sw = new StreamWriter(this.permissionsTargetFile)) { sw.Write(sb.ToString()); sw.Flush(); sw.Close(); } }
/// <summary> /// Gets the permission pattern from the permissions Template /// </summary> /// <returns>The permissions pattern to apply when generating permissions</returns> private PermissionPattern GetPermissions() { PermissionPattern p = null; if (File.Exists(this.permissionsTemplate)) { using (StreamReader sr = new StreamReader(this.permissionsTemplate)) { XmlSerializer xs = new XmlSerializer(typeof(PermissionPattern)); p = (PermissionPattern)xs.Deserialize(sr.BaseStream); sr.Close(); } } return(p); }