/// <summary> /// This method demonstrates how to create monitoring account for those with permissions. /// </summary> public static void CreateMonitoringAccount() { var connectionInfo = new ConnectionInfo(MdmEnvironment.Int); var manager = new MonitoringAccountConfigurationManager(connectionInfo); var newAccountToCreate = "NewAccount"; Console.WriteLine($"Create a new monitoring account '{newAccountToCreate}' from scratch..."); var permissions = new IPermissionV2[] { new UserPermissionV2("my-alias", RoleConfiguration.Administrator) }; var monitoringAccount = new MonitoringAccount(newAccountToCreate, "test account creation", permissions); try { manager.CreateAsync(monitoringAccount, "int2.metrics.nsatc.net").Wait(); Console.WriteLine($"{newAccountToCreate} is successfully created."); } catch (AggregateException e) { var inner = e.InnerException as ConfigurationValidationException; if (inner?.Message?.IndexOf($"{newAccountToCreate} is already in use", StringComparison.Ordinal) >= 0) { Console.WriteLine($"{newAccountToCreate} is already in use."); } else { throw; } } newAccountToCreate = "NewAccount2"; var monitoringAccountToCopyFrom = "NewAccount"; Console.WriteLine($"Create a new monitoring account named '{newAccountToCreate}' by copying the common settings from '{monitoringAccountToCopyFrom}'..."); try { manager.CreateAsync(newAccountToCreate, monitoringAccountToCopyFrom, "int2.metrics.nsatc.net").Wait(); Console.WriteLine($"{newAccountToCreate} is successfully created."); } catch (AggregateException e) { var inner = e.InnerException as ConfigurationValidationException; if (inner?.Message?.IndexOf($"{newAccountToCreate} is already in use", StringComparison.Ordinal) >= 0) { Console.WriteLine($"{newAccountToCreate} is already in use."); } else { throw; } } }
/// <summary> /// Remove permission from the account. /// </summary> /// <param name="permission">Permission to remove.</param> public void RemovePermission(IPermissionV2 permission) { this.permissions.Remove(permission); }
/// <summary> /// Adds a permission to the account. /// </summary> /// <param name="permission">Permission to add.</param> public void AddPermission(IPermissionV2 permission) { this.permissions.Add(permission); }