/// <summary> /// Copies the LM. /// </summary> /// <returns></returns> /// <remarks>Documented by Dev07, 2009-05-20</remarks> public static bool CopyLM(string source, string destination) { try { string filename = destination; if (File.Exists(filename)) { int i = 0; while (File.Exists(filename.Replace(".mlm", "_" + i + ".mlm"))) { i++; } filename = filename.Replace(".mlm", "_" + i + ".mlm"); } string sourceConString = MSSQLCEConn.GetFullConnectionString(source); string desConString = MSSQLCEConn.GetFullConnectionString(filename); SqlCeEngine engine = new SqlCeEngine(sourceConString); engine.Compact(desConString); engine.Dispose(); } catch (Exception e) { Trace.WriteLine(e.ToString()); return(false); } return(true); }
private int FindAC_ID_Type(string type, string permissionName, string roleId, bool bIsGroup) { string XXX_AccessControlList; string XXX_RoleId; int ac_id; if (bIsGroup) { XXX_AccessControlList = "UserGroups_AccessControlList"; XXX_RoleId = "groups_id"; } else { XXX_AccessControlList = "UserProfiles_AccessControlList"; XXX_RoleId = "users_id"; } //Suche entsprechende ac_id using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = string.Format("SELECT al.id FROM \"AccessControlList\" AS al INNER JOIN \"{0}\" AS ua ON ua.acl_id = al.id ", XXX_AccessControlList) + "INNER JOIN \"Permissions\" AS pe ON al.permissions_id = pe.id INNER JOIN \"TypeDefinitions\" AS td ON pe.types_id = td.id INNER JOIN \"ObjectList\" AS ol ON ol.id=al.object_id " + string.Format("WHERE ua.{0} = {1} AND pe.name = '{2}' AND td.clr_name='{3}' AND ol.locator='DUMMYOBJECT'", XXX_RoleId, roleId, permissionName, type); object result = cmd.ExecuteScalar(); ac_id = (result == null || result is System.DBNull) ? -1 : (int)result; //ac_id = (int)cmd.ExecuteScalar(); } return(ac_id); }
/// <summary> /// Gets the default permission for a type. /// </summary> /// <param name="type">The type.</param> /// <param name="permissionName">Name of the permission.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2009-02-27</remarks> public bool _GetDefaultPermissionOfType(string type, string permissionName) { using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = "SELECT pe.\"default\" FROM Permissions AS pe INNER JOIN TypeDefinitions AS td ON pe.types_id = td.id WHERE td.clr_name = @clr_name AND pe.name = @permission"; cmd.Parameters.Add("@clr_name", type); cmd.Parameters.Add("@permission", permissionName); object result = cmd.ExecuteScalar(); return((result == null || result is System.DBNull) ? false : (bool)result); } }
/// <summary> /// Gets the users permission for an object. /// </summary> /// <param name="locator">The locator.</param> /// <param name="type">The type.</param> /// <param name="permissionName">Name of the permission.</param> /// <param name="userId">The user id.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2009-02-27</remarks> public bool?_GetPermissionOfUserObjectPermissionList(string locator, string type, string permissionName, string userId) { using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = "SELECT al.access FROM \"AccessControlList\" AS al INNER JOIN \"UserProfiles_AccessControlList\" AS ua ON ua.acl_id = al.id " + "INNER JOIN \"Permissions\" AS pe ON al.permissions_id = pe.id INNER JOIN \"TypeDefinitions\" AS td ON pe.types_id = td.id INNER JOIN \"ObjectList\" AS ol ON ol.id=al.object_id " + string.Format("WHERE ua.users_id = {0} AND pe.name = '{1}' AND ol.locator = '{2}' AND td.clr_name='{3}'", userId, permissionName, locator, type); object result = cmd.ExecuteScalar(); return((result == null || result is System.DBNull) ? (bool?)null : (bool?)result); } }
/// <summary> /// Gets the users permission for a type. /// </summary> /// <param name="type">The type.</param> /// <param name="permissionName">Name of the permission.</param> /// <param name="userId">The user id.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2009-02-27</remarks> public bool?_GetPermissionOfUserTypePermissionList(string type, string permissionName, string userId) { using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = "SELECT al.access FROM \"AccessControlList\" AS al INNER JOIN \"UserProfiles_AccessControlList\" AS ua ON ua.acl_id = al.id " + "INNER JOIN \"Permissions\" AS pe ON al.permissions_id = pe.id INNER JOIN \"TypeDefinitions\" AS td ON pe.types_id = td.id INNER JOIN \"ObjectList\" AS ol ON ol.id=al.object_id " + "WHERE ua.users_id = @user_id AND pe.name = @permission AND ol.locator = 'DUMMYOBJECT' AND td.clr_name = @clr_name"; cmd.Parameters.Add("@user_id", userId); cmd.Parameters.Add("@permission", permissionName); cmd.Parameters.Add("@clr_name", type); object result = cmd.ExecuteScalar(); return((result == null || result is System.DBNull) ? (bool?)null : (bool?)result); } }
public int GetIdByLocator(string locator) { //Lösche nun noch in der UserGroups_AccessControlList using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = string.Format("SELECT id FROM ObjectList WHERE locator='{0}'", locator); object result = null; using (SqlCeDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { result = reader["id"]; } } return((result == null || result is System.DBNull) ? -1 : (int)result); } }
public void Refresh() { this.Clear(); using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = "SELECT users_id,groups_id FROM UserProfiles_UserGroups"; SqlCeDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { UserProfile_UserGroups entry = new UserProfile_UserGroups(); entry.UserId = Convert.ToInt32(reader["users_id"]); entry.GroupId = Convert.ToInt32(reader["groups_id"]); this.Add(entry); } } }
public void Refresh() { this.Clear(); using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = "SELECT id, name FROM UserGroups"; SqlCeDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { UserGroup userGroup = new UserGroup(); userGroup.Id = Convert.ToInt32(reader["id"]); userGroup.Name = reader["name"].ToString(); this.Add(userGroup.Id, userGroup); } } }
public void Refresh() { this.Clear(); using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = "SELECT id,name, types_id,\"default\" FROM Permissions"; SqlCeDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Permission info = new Permission(); info.Id = Convert.ToInt32(reader["id"]); info.PermissionName = reader["name"].ToString(); info.TypeId = Convert.ToInt32(reader["types_id"]); info.DefaultAccess = Convert.ToBoolean(reader["default"]); this.Add(info.Id, info); } } }
/// <summary> /// Resets the users permission for an object. /// </summary> /// <param name="locator">The locator.</param> /// <param name="type">The type.</param> /// <param name="userId">The user id.</param> /// <remarks>Documented by Dev03, 2009-02-27</remarks> public void _ResetUserObjectPermission(string locator, string type, string userId) { int type_id = Adapters.TypeDefinitionsAdapter.GetIdByTypeName(type); //suche alle acl_id Einträge in UserGroups_AccessControlList mit groups_id //lösche alle Einträge in der AccessControlList mit id == acl_id eines Typs int user_id = int.Parse(userId); List <int> acl_ids = new List <int>(); List <int> object_ids = new List <int>(); using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = "SELECT upacl.acl_id,acl.object_id FROM \"UserProfiles_AccessControlList\" as upacl " + "INNER JOIN \"AccessControlList\" AS acl ON acl.id=upacl.acl_id " + "INNER JOIN \"Permissions\" AS pe ON pe.id=acl.permissions_id " + "INNER JOIN \"ObjectList\" AS ol ON ol.id=acl.object_id " + "WHERE upacl.users_id=@users_id AND pe.types_id=@type_id AND ol.locator=@locator"; cmd.Parameters.Add("@users_id", user_id); cmd.Parameters.Add("@type_id", type_id); cmd.Parameters.Add("@locator", locator); using (SqlCeDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { acl_ids.Add((int)dr["acl_id"]); object_ids.Add((int)dr["object_id"]); } } } foreach (int object_id in object_ids) { Adapters.ObjectListAdapter.RemoveEntry(object_id); } foreach (int acl_id in acl_ids) { Adapters.UserProfiles_AccessControlListAdapter.RemoveEntry(user_id, acl_id); } foreach (int acl_id in acl_ids) { Adapters.AccessControlListAdapter.RemoveEntryById(acl_id); } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <remarks>Documented by Dev03, 2009-01-13</remarks> public void Dispose() { if (DbMediaServer.DbMediaServer.Instance(parent).IsAlive) { DbMediaServer.DbMediaServer.Instance(parent).Stop(); } if (Parent != null) { Parent.OnDictionaryClosed(this, EventArgs.Empty); } if (Parent.CurrentUser.ConnectionString.Typ == DatabaseType.MsSqlCe) { MSSQLCEConn.CloseMyConnection(this.Connection); } //MSSQLCEConn.CloseAllConnections(); FileCleanupQueue.DoCleanup(); }
/// <summary> /// Creates a new extension file. /// </summary> /// <remarks>Documented by Dev07, 2009-07-06</remarks> public void Create() { if (!Directory.Exists(Path.GetDirectoryName(User.ConnectionString.ConnectionString))) { Directory.CreateDirectory(Path.GetDirectoryName(User.ConnectionString.ConnectionString)); } if (!File.Exists(User.ConnectionString.ConnectionString)) { using (SqlCeEngine clientEngine = new SqlCeEngine("Data Source=" + User.ConnectionString.ConnectionString)) { clientEngine.CreateDatabase(); clientEngine.Dispose(); } } using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(User)) { cmd.CommandText = Resources.MsSqlCeDbCreateScript; MSSQLCEConn.ExecuteNonQuery(cmd); } }
public void Refresh() { this.Clear(); using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = "SELECT id, username, enabled FROM UserProfiles"; SqlCeDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { UserProfile userProfile = new UserProfile(); userProfile.Id = Convert.ToInt32(reader["id"]); userProfile.UserName = reader["username"].ToString(); userProfile.Enabled = Convert.ToBoolean(reader["enabled"]); this.Add(userProfile.Id, userProfile); } } }
public void Refresh() { this.Clear(); using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(m_User)) { cmd.CommandText = "SELECT id, clr_name, parent_id FROM TypeDefinitions"; SqlCeDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { TypeDefinition info = new TypeDefinition(); info.Id = Convert.ToInt32(reader["id"]); info.ClrName = reader["clr_name"].ToString(); object result = reader["parent_id"]; info.ParentId = (result is DBNull || result == null) ? -1 : Convert.ToInt32(result); this.Add(info.Id, info); } } }
/// <summary> /// Deletes a specific LM. /// </summary> /// <param name="css">The connection string struct.</param> /// <remarks>Documented by Dev02, 2008-07-28</remarks> /// <remarks>Documented by Dev08, 2008-12-09</remarks> /// <remarks>Documented by Dev08, 2008-12-09</remarks> public void Delete(ConnectionStringStruct css) { if (!this.HasPermission(PermissionTypes.CanModify)) { throw new PermissionException(); } switch (css.Typ) { case DatabaseType.PostgreSQL: parent.CurrentUser.CheckConnection(parent.CurrentUser.ConnectionString); connector.DeleteLM(css.LmId); break; case DatabaseType.MsSqlCe: //MSSQLCEConn.CloseAllConnections(); MSSQLCEConn.CloseMyConnection(css.ConnectionString); //[ML-1939] "Delete" of EDB needs very long time File.Delete(css.ConnectionString); break; default: throw new UnsupportedDatabaseTypeException(css.Typ); } }
private static SqlCeConnection GetConnection(string path) { return(new SqlCeConnection(MSSQLCEConn.GetFullConnectionString(path))); }
/// <summary> /// Checks the connection. /// </summary> /// <param name="connectionString">The connection string.</param> /// <remarks>Documented by Dev03, 2008-11-27</remarks> public void CheckConnection(ConnectionStringStruct connectionString) { if (!dbConnectionValid && connectionString.Typ != DatabaseType.Xml) { DummyUser user = new DummyUser(connectionString); DbConnection con = connectionString.Typ == DatabaseType.PostgreSQL ? PostgreSQLConn.CreateConnection(user) as DbConnection : MSSQLCEConn.GetConnection(user) as DbConnection; if (con.State == System.Data.ConnectionState.Open) { dbConnectionValid = true; } else { throw new ConnectionInvalidException(); } if (connectionString.Typ == DatabaseType.PostgreSQL) { con.Close(); } DbDatabase.GetInstance(new ParentClass(new DummyUser(connectionString), this)).CheckIfDatabaseVersionSupported(); } }