private void AddRole_Click(object sender, RoutedEventArgs e) { Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>(); input["name"] = new UserInputWindow.Input() { Label = "Name", DefaultValue = "" }; input["hasStreams"] = new UserInputWindow.Input() { Label = "Has streams", DefaultValue = "true" }; UserInputWindow dialog = new UserInputWindow("Add new role", input); dialog.ShowDialog(); if (dialog.DialogResult == true) { string name = dialog.Result("name"); bool hasStreams = true; bool.TryParse(dialog.Result("hasStreams"), out hasStreams); DatabaseRole role = new DatabaseRole() { Name = name, HasStreams = hasStreams }; if (DatabaseHandler.AddRole(role)) { GetRoles(dialog.Result("name")); } } }
public RoleViewModel(DatabaseRole databaseRole) { Name = databaseRole.Name; Value = databaseRole.Value; RawSqlRoleName = databaseRole.RawSqlRoleName; _originalValue = databaseRole.Value; }
/// <summary> /// Initializes a new instance of the <see cref="ScriptableObject"/> class. /// </summary> /// <param name="databaseRole">Object that can be scripted.</param> public ScriptableObject(DatabaseRole databaseRole) { new { databaseRole }.AsArg().Must().NotBeNull(); this.Name = databaseRole.Name; this.ObjectToScript = databaseRole; this.DatabaseObjectType = ScriptableObjectType.DatabaseRole; }
/// <summary>Конструктор с указанной сессией, используемый для загрузки привилегий роли</summary> /// <param name="session">Сессия для загрузки и сохранения объектов в базе данных</param> /// <param name="role">Роль пользователя в базе данных</param> /// <param name="targetType">Тип объектов, к которым относится разрешение на операции</param> /// <param name="allowSelect">Разрешение на выборку данных</param> /// <param name="allowInsert">Разрешение на добавление данных</param> /// <param name="allowUpdate">Разрешение на изменение данных</param> /// <param name="allowDelete">Разрешение на удаление данных</param> /// <remarks>Конструктор используется для загрузки привилегий роли и не вызывает обновления соответствующего свойства</remarks> public DatabasePrivilege(Session session, DatabaseRole role, Type targetType, bool allowSelect, bool allowInsert, bool allowUpdate, bool allowDelete) : base(session) { this.role = role; this.targetType = targetType; this.allowSelect = allowSelect; this.allowInsert = allowInsert; this.allowUpdate = allowUpdate; this.allowDelete = allowDelete; }
private static Type GetContextTypeOfRole(DatabaseRole role) { return(role switch { DatabaseRole.Account => typeof(AccountContext), DatabaseRole.Admin => typeof(EntityDataContext), DatabaseRole.Configuration => typeof(ConfigurationContext), DatabaseRole.Guild => typeof(GuildContext), DatabaseRole.Friend => typeof(FriendContext), _ => throw new ArgumentException($"Role {role} unknown.") });
private string GenerateGrant(DatabaseRole role) { return($@" GRANT SELECT ON SCHEMA:: [{_schema}] TO [{role.Name}] GRANT INSERT ON SCHEMA:: [{_schema}] TO [{role.Name}] GRANT DELETE ON SCHEMA:: [{_schema}] TO [{role.Name}] GRANT UPDATE ON SCHEMA:: [{_schema}] TO [{role.Name}] GRANT EXECUTE ON SCHEMA:: [{_schema}] TO [{role.Name}] GO "); }
public static void DropDBUser(Database sourcedb, Database destdb, string dbusername) { foreach (DatabaseRole destrole in destdb.Roles) { string destrolename = destrole.Name; DatabaseRole sourcerole = sourcedb.Roles[destrolename]; if (!DBChecks.DBRoleExists(sourcedb, destrolename) && !sourcerole.EnumMembers().Contains(dbusername) && destrole.EnumMembers().Contains(dbusername)) { destrole.DropMember(dbusername); } } destdb.Users[dbusername].Drop(); }
public void Document(DatabaseRole databaseRole) { new { databaseRole }.AsArg().Must().NotBeNull(); string[,] values = new string[1, 2]; int rowIndexer = 0; values[rowIndexer++, 0] = "[[BOLD]]Description"; rowIndexer = 0; values[rowIndexer++, 1] = string.Empty; // TODO: get rol.Description? if possible; int[,] merges = new int[0, 0]; this.documentGenerator.AddTable(databaseRole.Name, values, merges); }
private static Type GetContextTypeOfRole(DatabaseRole role) { switch (role) { case DatabaseRole.Account: return(typeof(AccountContext)); case DatabaseRole.Admin: return(typeof(EntityDataContext)); case DatabaseRole.Configuration: return(typeof(ConfigurationContext)); } throw new ArgumentException($"Role {role} unknown."); }
public static void AddUserToDBRoles(Database sourcedb, Database destdb, string dbusername) { foreach (DatabaseRole role in sourcedb.Roles) { if (role.EnumMembers().Contains(dbusername)) { string rolename = role.Name; DatabaseRole destdbrole = destdb.Roles[rolename]; if (DBChecks.DBRoleExists(destdb, rolename) && dbusername != "dbo" && !destdbrole.EnumMembers().Contains(dbusername)) { destdbrole.AddMember(dbusername); destdbrole.Alter(); } } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { switchMode(); GetDatabases(DatabaseHandler.DatabaseName); if (mode == Mode.COMPLETE) { AnnoList annoList = AnnoTierStatic.Selected.AnnoList; DatabaseScheme scheme = ((List <DatabaseScheme>)SchemesBox.ItemsSource).Find(s => s.Name == annoList.Scheme.Name); if (scheme != null) { SchemesBox.SelectedItem = scheme; SchemesBox.ScrollIntoView(scheme); } DatabaseRole role = ((List <DatabaseRole>)RolesBox.ItemsSource).Find(r => r.Name == annoList.Meta.Role); if (role != null) { RolesBox.SelectedItem = role; RolesBox.ScrollIntoView(role); } DatabaseAnnotator annotator = ((List <DatabaseAnnotator>)AnnotatorsBox.ItemsSource).Find(a => a.Name == Properties.Settings.Default.MongoDBUser); if (annotator != null) { AnnotatorsBox.SelectedItem = annotator; AnnotatorsBox.ScrollIntoView(annotator); } DatabaseSession session = ((List <DatabaseSession>)SessionsBox.ItemsSource).Find(s => s.Name == DatabaseHandler.SessionName); if (session != null) { SessionsBox.SelectedItem = session; SessionsBox.ScrollIntoView(session); } Update(); } ApplyButton.Focus(); handleSelectionChanged = true; }
private void EditRole_Click(object sender, RoutedEventArgs e) { if (RolesBox.SelectedItem != null) { string old_name = (string)RolesBox.SelectedItem; DatabaseRole old_role = DatabaseHandler.Roles.Find(r => r.Name == old_name); Dictionary <string, UserInputWindow.Input> input = new Dictionary <string, UserInputWindow.Input>(); input["name"] = new UserInputWindow.Input() { Label = "Name", DefaultValue = old_name }; input["hasStreams"] = new UserInputWindow.Input() { Label = "Has streams", DefaultValue = (old_role == null ? "true" : old_role.HasStreams.ToString()) }; UserInputWindow dialog = new UserInputWindow("Edit role", input); dialog.ShowDialog(); if (dialog.DialogResult == true) { string name = dialog.Result("name"); bool hasStreams = true; bool.TryParse(dialog.Result("hasStreams"), out hasStreams); DatabaseRole role = new DatabaseRole() { Name = name, HasStreams = hasStreams }; if (DatabaseHandler.UpdateRole(old_name, role)) { GetRoles(name); } } } }
public void GetRoles() { RolesBox.ItemsSource = DatabaseHandler.Roles; if (RolesBox.Items.Count > 0) { string[] items = Properties.Settings.Default.CMLDefaultRole.Split(';'); foreach (string item in items) { DatabaseRole role = ((List <DatabaseRole>)RolesBox.ItemsSource).Find(r => r.Name == item); if (role != null) { RolesBox.SelectedItems.Add(role); } } if (RolesBox.SelectedItem == null) { RolesBox.SelectAll(); } RolesBox.ScrollIntoView(RolesBox.SelectedItem); } }
public static string GetDescription(this DatabaseRole source) { string description; try { FieldInfo fi = source.GetType().GetField(source.ToString()); var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attributes.Length > 0) { return(attributes[0].Description); } description = source.ToString(); } catch (Exception) { return(""); } return(description); }
public SqlRoleGenerator(DatabaseRole databaseRole) { _databaseRole = databaseRole; }
// Обновление привилегий роли в базе данных private void UpdatePrivileges(DatabaseRole role) { if (role != null) role.UpdatePrivileges(); }
private void ScriptDBRoles(Database db, Scripter scr) { DatabaseRole[] dbRoles = new DatabaseRole[db.Roles.Count]; db.Roles.CopyTo(dbRoles, 0); scr.Script(dbRoles); }
/// <summary> /// Gets the password password of the role from the configured connection string. /// </summary> /// <param name="role">The role.</param> /// <returns>The password password of the role from the configured connection string.</returns> public static string GetRolePassword(DatabaseRole role) { var settings = Settings[GetContextTypeOfRole(role)]; return(Regex.Match(settings.ConnectionString, "Password=([^;]+?);").Groups[1].Value); }
private void Apply_Click(object sender, RoutedEventArgs e) { Properties.Settings.Default.SettingCMLDefaultBN = NetworkSelectionBox.SelectedItem.ToString(); Properties.Settings.Default.CMLDefaultAnnotator = AnnotatorsBox.SelectedItem.ToString(); Properties.Settings.Default.CMLDefaultRole = RolesBox.SelectedItem.ToString(); Properties.Settings.Default.CMLDefaultScheme = SchemesBox.SelectedItem.ToString(); Properties.Settings.Default.CMLDefaultTrainer = NetworkSelectionBox.SelectedItem.ToString(); Properties.Settings.Default.Save(); bool force = ForceCheckBox.IsChecked.Value; string database = DatabaseHandler.DatabaseName; var sessions = SessionsBox.SelectedItems; logTextBox.Text = ""; string networkrDir = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.FusionFolderName + "\\" + Defaults.CML.FusionBayesianNetworkFolderName + "\\" + NetworkSelectionBox.SelectedItem + ".xdsl"; string datasetDir = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.FusionFolderName + "\\" + Defaults.CML.FusionBayesianNetworkFolderName + "\\" + namebox.Text; double chunksizeinMS; double.TryParse(chunksizebox.Text, out chunksizeinMS); int tempsteps; int.TryParse(timestepsbox.Text, out tempsteps); bool isdynamic = tempsteps > 0 ? true : false; if (File.Exists(datasetDir) && ForceCheckBox.IsChecked == false) { // logTextBox.Text = "dataset exists, skip.\n"; logTextBox.Text += "\nData sheet exits, check force to overwrite"; // logTextBox.Text += handler.CMLTrainBayesianNetwork(networkrDir, datasetDir, isdynamic); return; } File.Delete(datasetDir); bool ishead = true; foreach (DatabaseSession session in SessionsBox.SelectedItems) { List <AnnoList> annoLists = new List <AnnoList>(); foreach (SchemeRoleAnnotator item in AnnotationSelectionBox.Items) { DatabaseRole role = DatabaseHandler.Roles.Find(r => r.Name == item.Role); DatabaseScheme scheme = DatabaseHandler.Schemes.Find(m => m.Name == item.Name); ObjectId annotatorID = DatabaseHandler.Annotators.Find(a => a.FullName == item.Annotator).Id; var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("scheme_id", scheme.Id) & builder.Eq("annotator_id", annotatorID) & builder.Eq("role_id", role.Id) & builder.Eq("session_id", session.Id); List <DatabaseAnnotation> list = DatabaseHandler.GetAnnotations(filter); foreach (DatabaseAnnotation anno in list) { AnnoList annolist = DatabaseHandler.LoadAnnoList(anno.Id); if (annolist.Scheme.Type == AnnoScheme.TYPE.CONTINUOUS) { for (int i = 0; i < item.Classes; i++) { annolist.Scheme.Labels.Add(new AnnoScheme.Label("s" + (i + 1).ToString(), System.Windows.Media.Colors.Black)) ; } } annoLists.Add(annolist); logTextBox.Text = logTextBox.Text + "Session: " + session.Name + " Role: " + annolist.Meta.Role + " Scheme: " + annolist.Scheme.Name + "\n"; logTextBox.Focus(); logTextBox.CaretIndex = logTextBox.Text.Length; logTextBox.ScrollToEnd(); } } logTextBox.Text = logTextBox.Text + "----------------------------------\n"; if (rolecheckbox.IsChecked == true) { ExportFrameWiseAnnotations(chunksizeinMS, ';', "REST", datasetDir, annoLists, ishead, session.Name, tempsteps); } else { ExportFrameWiseAnnotationsRolesSeperated(chunksizeinMS, ';', "REST", datasetDir, annoLists, ishead, session.Name, tempsteps); } if (ishead) { ishead = false; } } string[] pairs = new string[AnnotationSelectionBox.Items.Count]; int s = 0; foreach (SchemeRoleAnnotator item in AnnotationSelectionBox.Items) { pairs[s] = item.Name + ":" + item.Annotator + ":" + item.Role + ":" + item.Classes; s++; } string cmlfolderpath = Properties.Settings.Default.CMLDirectory + "\\" + Defaults.CML.FusionFolderName + "\\" + Defaults.CML.FusionBayesianNetworkFolderName + "\\"; string trainingsetpath = cmlfolderpath + "training.set"; System.IO.File.WriteAllLines(trainingsetpath, pairs); logTextBox.Text += "\nCreating Data sheet successful\nHit train to train the network or use it in GenIE"; }