public async void CreateUpdateDelete() { // Ensure there is no existing UserGroup called "Test" var existingUserGroup = (await PortalClient .GetAllAsync(new Filter <UserGroup> { FilterItems = new List <FilterItem <UserGroup> > { new Eq <UserGroup>(nameof(UserGroup.Name), Value) } }) .ConfigureAwait(false)) .SingleOrDefault(); if (existingUserGroup != null) { await PortalClient.DeleteAsync(existingUserGroup).ConfigureAwait(false); } var userGroup = await PortalClient.CreateAsync(new UserGroupCreationDto { Name = Value, Description = "Desc", }).ConfigureAwait(false); // Refetch var refetch = await PortalClient.GetAsync <UserGroup>(userGroup.Id).ConfigureAwait(false); Assert.NotNull(refetch); // Delete await PortalClient.DeleteAsync(userGroup).ConfigureAwait(false); }
public async void CanCreateAndDeleteNetscanGroups() { var allNetscanGroups = await PortalClient.GetAllAsync <NetscanGroup>().ConfigureAwait(false); const string name = "API Unit Test CanCreateAndDeleteNetscanGroups"; const string description = "API Unit Test CanCreateAndDeleteNetscanGroups Description"; var existingTestNetscanGroup = allNetscanGroups.SingleOrDefault(group => group.Name == name); if (existingTestNetscanGroup != null) { await PortalClient.DeleteAsync <NetscanGroup>(existingTestNetscanGroup.Id).ConfigureAwait(false); } Assert.DoesNotContain(await PortalClient.GetAllAsync <NetscanGroup>().ConfigureAwait(false), group => group.Name == name); // Definitely not there now // Create one var netscanGroupCreationDto = new NetscanGroupCreationDto { Name = name, Description = description }; var newNetscanGroup = await PortalClient.CreateAsync(netscanGroupCreationDto).ConfigureAwait(false); Assert.Contains(await PortalClient.GetAllAsync <NetscanGroup>().ConfigureAwait(false), group => group.Name == name); await PortalClient.DeleteAsync(newNetscanGroup).ConfigureAwait(false); Assert.DoesNotContain(await PortalClient.GetAllAsync <NetscanGroup>().ConfigureAwait(false), group => group.Name == name); }
public async void CreateUser() { // Delete it if it already exists foreach (var existingUser in await PortalClient.GetAllAsync(new Filter <User> { FilterItems = new List <FilterItem <User> > { new Eq <User>(nameof(User.UserName), "test") } }).ConfigureAwait(false)) { await PortalClient.DeleteAsync(existingUser).ConfigureAwait(false); } var userCreationDto = new UserCreationDto { ViewPermission = new ViewPermission { Alerts = true, Dashboards = true, Devices = true, Reports = true, Websites = true, Settings = true }, Username = "******", FirstName = "first", LastName = "last", Email = "*****@*****.**", #pragma warning disable SCS0015 // Hardcoded password Password = "******", #pragma warning restore SCS0015 // Hardcoded password Password1 = "Abc123!!!", ForcePasswordChange = true, TwoFAEnabled = false, SmsEmail = "", SmsEmailFormat = "sms", Timezone = "", ViewPermissions = new List <bool> { true, true, true, true, true, true }, Status = "active", Note = "note", Roles = new List <Role> { new Role { Id = 1 } }, ApiTokens = new List <object>(), Phone = "+447761503941", ApiOnly = false }; var user = await PortalClient.CreateAsync(userCreationDto).ConfigureAwait(false); // Delete again await PortalClient.DeleteAsync(user).ConfigureAwait(false); }
public async void CrudCollectorGroup() { // Try to get this item var collectorGroups = await PortalClient.GetAllAsync(new Filter <CollectorGroup> { FilterItems = new List <FilterItem <CollectorGroup> > { new Eq <CollectorGroup>(nameof(CollectorGroup.Name), TestName) } }).ConfigureAwait(false); foreach (var priorCollectorGroup in collectorGroups) { await PortalClient.DeleteAsync(priorCollectorGroup).ConfigureAwait(false); } // There are now none with this name // Create one var newCollectorGroup = await PortalClient.CreateAsync(new CollectorGroupCreationDto { Name = TestName, Description = TestDescription, CustomProperties = new List <Property> { new Property { Name = "a", Value = "b" } } }).ConfigureAwait(false); Assert.NotNull(newCollectorGroup); Assert.NotEqual(0, newCollectorGroup.Id); var newCollectorGroupRefetch = await PortalClient.GetAsync <CollectorGroup>(newCollectorGroup.Id).ConfigureAwait(false); Assert.NotNull(newCollectorGroupRefetch); Assert.NotNull(newCollectorGroupRefetch.Name); Assert.NotNull(newCollectorGroupRefetch.Description); Assert.NotNull(newCollectorGroupRefetch.CustomProperties); Assert.NotEmpty(newCollectorGroupRefetch.CustomProperties); Assert.Single(newCollectorGroupRefetch.CustomProperties); Assert.Equal("a", newCollectorGroupRefetch.CustomProperties[0].Name); Assert.Equal("b", newCollectorGroupRefetch.CustomProperties[0].Value); // Put await PortalClient.PutAsync(newCollectorGroupRefetch).ConfigureAwait(false); // Delete await PortalClient.DeleteAsync(newCollectorGroupRefetch).ConfigureAwait(false); }
public async void CreateUpdateAndDelete() { const string testAppliesToFunctionName = "XxxUnitTest"; var testAppliesToFunctionDescription = $"{testAppliesToFunctionName} - Description"; var testAppliesToFunctionCode = $"displayname == \"{testAppliesToFunctionName}\""; // Delete if already present var existingAppliesToFunction = await PortalClient.GetByNameAsync <AppliesToFunction>(testAppliesToFunctionName).ConfigureAwait(false); if (existingAppliesToFunction != null) { await PortalClient.DeleteAsync(existingAppliesToFunction).ConfigureAwait(false); } // Create var createdAppliesToFunction = await PortalClient.CreateAsync(new AppliesToFunctionCreationDto { Name = testAppliesToFunctionName, Description = testAppliesToFunctionDescription, Code = testAppliesToFunctionCode }).ConfigureAwait(false); // Refetch and check existingAppliesToFunction = await PortalClient.GetByNameAsync <AppliesToFunction>(testAppliesToFunctionName).ConfigureAwait(false); Assert.NotNull(existingAppliesToFunction); Assert.Equal(createdAppliesToFunction.Id, existingAppliesToFunction.Id); // Update var newDescription = testAppliesToFunctionDescription + "2"; existingAppliesToFunction.Description = newDescription; await PortalClient.PutAsync(existingAppliesToFunction).ConfigureAwait(false); // Refetch and check existingAppliesToFunction = await PortalClient.GetByNameAsync <AppliesToFunction>(testAppliesToFunctionName).ConfigureAwait(false); Assert.Equal(newDescription, existingAppliesToFunction.Description); // Delete await PortalClient.DeleteAsync(existingAppliesToFunction).ConfigureAwait(false); // Refetch and check existingAppliesToFunction = await PortalClient.GetByNameAsync <AppliesToFunction>(testAppliesToFunctionName).ConfigureAwait(false); Assert.Null(existingAppliesToFunction); }
public async void CreateCollectorDownloadAndDelete() { // Determine the latest supported version var collectorVersionInts = (await PortalClient.GetAllCollectorVersionsAsync( new Filter <CollectorVersion> { FilterItems = new List <FilterItem <CollectorVersion> > { new Eq <CollectorVersion>(nameof(CollectorVersion.IsStable), true), } } ).ConfigureAwait(false)) .Select(cv => (cv.MajorVersion * 1000) + cv.MinorVersion) .OrderByDescending(v => v) .ToList(); Assert.NotNull(collectorVersionInts); Assert.NotEmpty(collectorVersionInts); var collectorVersionInt = collectorVersionInts[0]; // Create the collector var collector = await PortalClient.CreateAsync(new CollectorCreationDto { Description = "UNIT TEST" }).ConfigureAwait(false); var tempFileInfo = new FileInfo(Path.GetTempPath() + Guid.NewGuid().ToString()); try { await PortalClient.DownloadCollector( collector.Id, tempFileInfo, CollectorPlatformAndArchitecture.Win64, CollectorDownloadType.Bootstrap, CollectorSize.Medium, collectorVersionInt).ConfigureAwait(false); } finally { // No need to do this as the collector has not been registered // await DefaultPortalClient.DeleteAsync(collector).ConfigureAwait(false); tempFileInfo.Delete(); // Remove the collector from the API await PortalClient.DeleteAsync(collector).ConfigureAwait(false); } }
public async void GetOpsNotes() { // Create an ops note var newOpsNote = await PortalClient.CreateAsync(new OpsNoteCreationDto { DateTimeUtcSeconds = DateTime.UtcNow.SecondsSinceTheEpoch(), Note = $"LogicMonitor.Api.Test run on {DateTime.UtcNow}", Tags = new List <OpsNoteTagCreationDto> { new OpsNoteTagCreationDto { Name = "LogicMonitor.Api" } } }) .ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); var allOpsNotes = await PortalClient.GetAllAsync <OpsNote>().ConfigureAwait(false); // Make sure that some are returned Assert.True(allOpsNotes.Count > 0); Assert.Contains(newOpsNote.Id, allOpsNotes.Select(o => o.Id)); }
public async void CrudReportGroups() { // Delete it if it already exists foreach (var existingReportGroup in await PortalClient.GetAllAsync(new Filter <ReportGroup> { FilterItems = new List <FilterItem <ReportGroup> > { new Eq <ReportGroup>(nameof(ReportGroup.Name), "Test Name") } }).ConfigureAwait(false)) { await PortalClient.DeleteAsync(existingReportGroup).ConfigureAwait(false); } // Create it var reportGroup = await PortalClient.CreateAsync(new ReportGroupCreationDto { Name = "Test Name", Description = "Test Description" }).ConfigureAwait(false); // Delete it again await PortalClient.DeleteAsync(reportGroup).ConfigureAwait(false); }
public async void CreatePingDataSourceSdtOnEmptyDeviceGroup() { const string deviceGroupName = "CreatePingDataSourceSdtOnEmptyDeviceGroupUnitTest"; // Ensure DeviceGroup is NOT present var deviceGroup = await PortalClient .GetDeviceGroupByFullPathAsync(deviceGroupName) .ConfigureAwait(false); if (deviceGroup != null) { await PortalClient .DeleteAsync(deviceGroup) .ConfigureAwait(false); } // Create DeviceGroup deviceGroup = await PortalClient .CreateAsync(new DeviceGroupCreationDto { ParentId = "1", Name = deviceGroupName }) .ConfigureAwait(false); // Get ping DataSource var dataSource = (await PortalClient .GetAllAsync(new Filter <DataSource> { FilterItems = new List <FilterItem <DataSource> > { new Eq <DataSource>(nameof(DataSource.Name), "Ping") } }) .ConfigureAwait(false)) .SingleOrDefault(); // Create Scheduled Downtime var sdtCreationDto = new DeviceGroupScheduledDownTimeCreationDto(deviceGroup.Id) { Comment = "Created by Unit Test", StartDateTimeEpochMs = DateTime.UtcNow.MillisecondsSinceTheEpoch(), EndDateTimeEpochMs = DateTime.UtcNow.AddDays(7).MillisecondsSinceTheEpoch(), RecurrenceType = ScheduledDownTimeRecurrenceType.OneTime, DataSourceId = dataSource.Id, DataSourceName = dataSource.Name }; // Check the created SDT looks right var createdSdt = await PortalClient .CreateAsync(sdtCreationDto) .ConfigureAwait(false); Assert.NotNull(createdSdt); // Clean up await PortalClient .DeleteAsync <ScheduledDownTime>(createdSdt.Id) .ConfigureAwait(false); // Remove the device group await PortalClient .DeleteAsync(deviceGroup) .ConfigureAwait(false); }
public async void CreateUpdateDelete() { // Ensure there is no existing role called "Test" var existingRole = (await PortalClient .GetAllAsync(new Filter <Role> { FilterItems = new List <FilterItem <Role> > { new Eq <Role>(nameof(Role.Name), Value) } }) .ConfigureAwait(false)) .SingleOrDefault(); if (existingRole != null) { await PortalClient.DeleteAsync(existingRole).ConfigureAwait(false); } var dashboardGroup = (await PortalClient.GetAllAsync(new Filter <DashboardGroup> { Take = 1 }).ConfigureAwait(false)).SingleOrDefault(); var deviceGroup = (await PortalClient.GetAllAsync(new Filter <DeviceGroup> { Take = 1 }).ConfigureAwait(false)).SingleOrDefault(); var websiteGroup = (await PortalClient.GetAllAsync(new Filter <WebsiteGroup> { Take = 1 }).ConfigureAwait(false)).SingleOrDefault(); var reportGroup = (await PortalClient.GetAllAsync(new Filter <ReportGroup> { Take = 1 }).ConfigureAwait(false)).SingleOrDefault(); var role = await PortalClient.CreateAsync(new RoleCreationDto { CustomHelpLabel = "", CustomHelpUrl = "", Description = "Desc", Name = Value, RequireEULA = false, TwoFactorAuthenticationRequired = false, Privileges = new List <RolePrivilege> { new RolePrivilege { ObjectType = PrivilegeObjectType.DashboardGroup, ObjectId = dashboardGroup.Id.ToString(), Operation = RolePrivilegeOperation.Read }, new RolePrivilege { ObjectType = PrivilegeObjectType.DeviceGroup, ObjectId = deviceGroup.Id.ToString(), Operation = RolePrivilegeOperation.Read }, new RolePrivilege { ObjectType = PrivilegeObjectType.WebsiteGroup, ObjectId = websiteGroup.Id.ToString(), Operation = RolePrivilegeOperation.Read }, new RolePrivilege { ObjectType = PrivilegeObjectType.ReportGroup, ObjectId = reportGroup.Id.ToString(), Operation = RolePrivilegeOperation.Read }, new RolePrivilege { ObjectType = PrivilegeObjectType.Help, ObjectId = "*", Operation = RolePrivilegeOperation.Read }, new RolePrivilege { ObjectType = PrivilegeObjectType.DeviceDashboard, Operation = RolePrivilegeOperation.Read }, new RolePrivilege { ObjectType = PrivilegeObjectType.ConfigNeedDeviceManagePermission, ObjectId = "", Operation = RolePrivilegeOperation.Write }, new RolePrivilege { ObjectType = PrivilegeObjectType.ReportGroup, ObjectId = reportGroup.Id.ToString(), Operation = RolePrivilegeOperation.Read }, } }).ConfigureAwait(false); // Refetch var refetch = await PortalClient.GetAsync <Role>(role.Id).ConfigureAwait(false); Assert.NotNull(refetch); // Delete await PortalClient.DeleteAsync(role).ConfigureAwait(false); }
public async void SetDeviceGroupCustomProperty() { // Create a device group for testing purposes const string testDeviceGroupName = "Property Test Device Group"; var existingDeviceGroup = await PortalClient .GetDeviceGroupByFullPathAsync(testDeviceGroupName) .ConfigureAwait(false); if (existingDeviceGroup != null) { await PortalClient .DeleteAsync(existingDeviceGroup) .ConfigureAwait(false); } var deviceGroup = await PortalClient.CreateAsync(new DeviceGroupCreationDto { ParentId = "1", Name = testDeviceGroupName }).ConfigureAwait(false); const string propertyName = "blah"; const string value1 = "test1"; const string value2 = "test2"; // Set it to an expected value await PortalClient.SetDeviceGroupCustomPropertyAsync(deviceGroup.Id, propertyName, value1).ConfigureAwait(false); var deviceProperties = await PortalClient.GetDeviceGroupPropertiesAsync(deviceGroup.Id).ConfigureAwait(false); var actual = deviceProperties.Count(dp => dp.Name == propertyName && dp.Value == value1); Assert.Equal(1, actual); // Set it to a different value await PortalClient.SetDeviceGroupCustomPropertyAsync(deviceGroup.Id, propertyName, value2).ConfigureAwait(false); deviceProperties = await PortalClient.GetDeviceGroupPropertiesAsync(deviceGroup.Id).ConfigureAwait(false); actual = deviceProperties.Count(dp => dp.Name == propertyName && dp.Value == value2); Assert.Equal(1, actual); // Set it to null (delete it) await PortalClient.SetDeviceGroupCustomPropertyAsync(deviceGroup.Id, propertyName, null).ConfigureAwait(false); deviceProperties = await PortalClient.GetDeviceGroupPropertiesAsync(deviceGroup.Id).ConfigureAwait(false); actual = deviceProperties.Count(dp => dp.Name == propertyName); Assert.Equal(0, actual); // This should fail as there is nothing to delete var deletionException = await Record.ExceptionAsync(async() => await PortalClient.SetDeviceGroupCustomPropertyAsync(deviceGroup.Id, propertyName, null, SetPropertyMode.Delete).ConfigureAwait(false)).ConfigureAwait(false); Assert.IsType <LogicMonitorApiException>(deletionException); var updateException = await Record.ExceptionAsync(async() => await PortalClient.SetDeviceGroupCustomPropertyAsync(deviceGroup.Id, propertyName, null, SetPropertyMode.Update).ConfigureAwait(false)).ConfigureAwait(false); Assert.IsType <InvalidOperationException>(updateException); var createNullException = await Record.ExceptionAsync(async() => await PortalClient.SetDeviceGroupCustomPropertyAsync(deviceGroup.Id, propertyName, null, SetPropertyMode.Create).ConfigureAwait(false)).ConfigureAwait(false); Assert.IsType <InvalidOperationException>(createNullException); // Create one without checking await PortalClient.SetDeviceGroupCustomPropertyAsync(deviceGroup.Id, propertyName, value1, SetPropertyMode.Create).ConfigureAwait(false); deviceProperties = await PortalClient.GetDeviceGroupPropertiesAsync(deviceGroup.Id).ConfigureAwait(false); actual = deviceProperties.Count(dp => dp.Name == propertyName && dp.Value == value1); Assert.Equal(1, actual); // Update one without checking await PortalClient.SetDeviceGroupCustomPropertyAsync(deviceGroup.Id, propertyName, value2, SetPropertyMode.Update).ConfigureAwait(false); deviceProperties = await PortalClient.GetDeviceGroupPropertiesAsync(deviceGroup.Id).ConfigureAwait(false); actual = deviceProperties.Count(dp => dp.Name == propertyName && dp.Value == value2); Assert.Equal(1, actual); // Delete one without checking await PortalClient.SetDeviceGroupCustomPropertyAsync(deviceGroup.Id, propertyName, null, SetPropertyMode.Delete).ConfigureAwait(false); deviceProperties = await PortalClient.GetDeviceGroupPropertiesAsync(deviceGroup.Id).ConfigureAwait(false); actual = deviceProperties.Count(dp => dp.Name == propertyName); Assert.Equal(0, actual); }
public async void SetWebsiteCustomProperty() { var website = await PortalClient.GetByNameAsync <Website>(nameof(SetWebsiteCustomProperty)).ConfigureAwait(false) ?? await PortalClient.CreateAsync(GetWebsiteCreationDto(1, nameof(SetWebsiteCustomProperty))).ConfigureAwait(false); const string propertyName = "blah"; const string value1 = "test1"; const string value2 = "test2"; // Set it to an expected value await PortalClient.SetWebsiteCustomPropertyAsync(website.Id, propertyName, value1).ConfigureAwait(false); var deviceProperties = await PortalClient.GetWebsitePropertiesAsync(website.Id).ConfigureAwait(false); var actual = deviceProperties.Count(dp => dp.Name == propertyName && dp.Value == value1); Assert.Equal(1, actual); // Set it to a different value await PortalClient.SetWebsiteCustomPropertyAsync(website.Id, propertyName, value2).ConfigureAwait(false); deviceProperties = await PortalClient.GetWebsitePropertiesAsync(website.Id).ConfigureAwait(false); actual = deviceProperties.Count(dp => dp.Name == propertyName && dp.Value == value2); Assert.Equal(1, actual); // Set it to null (delete it) await PortalClient.SetWebsiteCustomPropertyAsync(website.Id, propertyName, null).ConfigureAwait(false); deviceProperties = await PortalClient.GetWebsitePropertiesAsync(website.Id).ConfigureAwait(false); actual = deviceProperties.Count(dp => dp.Name == propertyName); Assert.Equal(0, actual); // This should fail as there is nothing to delete var deletionException = await Record.ExceptionAsync(async() => await PortalClient.SetWebsiteCustomPropertyAsync(website.Id, propertyName, null, SetPropertyMode.Delete).ConfigureAwait(false)).ConfigureAwait(false); Assert.IsType <LogicMonitorApiException>(deletionException); var updateException = await Record.ExceptionAsync(async() => await PortalClient.SetWebsiteCustomPropertyAsync(website.Id, propertyName, null, SetPropertyMode.Update).ConfigureAwait(false)).ConfigureAwait(false); Assert.IsType <InvalidOperationException>(updateException); var createNullException = await Record.ExceptionAsync(async() => await PortalClient.SetWebsiteCustomPropertyAsync(website.Id, propertyName, null, SetPropertyMode.Create).ConfigureAwait(false)).ConfigureAwait(false); Assert.IsType <InvalidOperationException>(createNullException); // Create one without checking await PortalClient.SetWebsiteCustomPropertyAsync(website.Id, propertyName, value1, SetPropertyMode.Create).ConfigureAwait(false); deviceProperties = await PortalClient.GetWebsitePropertiesAsync(website.Id).ConfigureAwait(false); actual = deviceProperties.Count(dp => dp.Name == propertyName && dp.Value == value1); Assert.Equal(1, actual); // Update one without checking await PortalClient.SetWebsiteCustomPropertyAsync(website.Id, propertyName, value2, SetPropertyMode.Update).ConfigureAwait(false); deviceProperties = await PortalClient.GetWebsitePropertiesAsync(website.Id).ConfigureAwait(false); actual = deviceProperties.Count(dp => dp.Name == propertyName && dp.Value == value2); Assert.Equal(1, actual); // Delete one without checking await PortalClient.SetWebsiteCustomPropertyAsync(website.Id, propertyName, null, SetPropertyMode.Delete).ConfigureAwait(false); deviceProperties = await PortalClient.GetWebsitePropertiesAsync(website.Id).ConfigureAwait(false); actual = deviceProperties.Count(dp => dp.Name == propertyName); Assert.Equal(0, actual); await PortalClient.DeleteAsync(website).ConfigureAwait(false); }
public async void CrudWebsiteGroupsAndWebsites() { // Ensure the website group doesn't exist var oldWebsiteGroup = await PortalClient.GetWebsiteGroupByFullPathAsync("Test Name").ConfigureAwait(false); if (oldWebsiteGroup != null) { await PortalClient.DeleteAsync <WebsiteGroup>(oldWebsiteGroup.Id).ConfigureAwait(false); } // Ensure the website doesn't exist var oldWebsites = await PortalClient.GetAllAsync(new Filter <Website> { FilterItems = new List <FilterItem <Website> > { new Eq <Website>(nameof(Website.Name), nameof(CrudWebsiteGroupsAndWebsites)) } }).ConfigureAwait(false); foreach (var oldWebsite in oldWebsites) { await PortalClient.DeleteAsync <Website>(oldWebsite.Id).ConfigureAwait(false); } // Create it var websiteGroup = await PortalClient.CreateAsync(new WebsiteGroupCreationDto { Name = "Test Name", Description = "Test Description", IsAlertingDisabled = false, IsMonitoringDisabled = false, ParentGroupFullPath = "", ParentId = "1", Properties = new List <Property> { new Property { Name = "name", Value = "value" } }, TestLocation = new TestLocation { All = true, SmgIds = new List <int> { 1, 2, 4, 3, 5, 6 } } }).ConfigureAwait(false); try { // Create the website var website = await PortalClient .CreateAsync(GetWebsiteCreationDto(websiteGroup.Id, nameof(CrudWebsiteGroupsAndWebsites))) .ConfigureAwait(false); Assert.NotNull(website); Assert.Equal(websiteGroup.Id, website.WebsiteGroupId); Assert.True(website.TriggerSslExpirationAlerts); Assert.Equal(ExpectedAlertExpression, website.AlertExpression); // Wait to ensure that it was created await Task.Delay(1000) .ConfigureAwait(false); // Delete it await PortalClient .DeleteAsync <Website>(website.Id) .ConfigureAwait(false); } finally { // Delete it again await PortalClient.DeleteAsync(websiteGroup).ConfigureAwait(false); } }
private static async Task <TGroup> CreateGroupAsync <TGroup, TItem>( PortalClient portalClient, TGroup parentGroup, Structure <TGroup, TItem> structure, List <Property> variables, List <Property> originalProperties) where TGroup : IdentifiedItem, IHasEndpoint, new() where TItem : IdentifiedItem, IHasEndpoint, new() { var name = Substitute(structure.Name, variables); var properties = structure.ApplyProperties ? originalProperties .Select(p => new Property { Name = p.Name, Value = Substitute(p.Value, variables) }) .ToList() : null; var groupTypeName = typeof(TGroup).Name; CreationDto <TGroup> creationDto; switch (groupTypeName) { case nameof(CollectorGroup): creationDto = new CollectorGroupCreationDto { Name = name } as CreationDto <TGroup>; break; case nameof(DashboardGroup): creationDto = new DashboardGroupCreationDto { ParentId = parentGroup?.Id.ToString() ?? "1", Name = name } as CreationDto <TGroup>; break; case nameof(DeviceGroup): creationDto = new DeviceGroupCreationDto { ParentId = parentGroup?.Id.ToString() ?? "1", Name = name, AppliesTo = Substitute(structure.AppliesTo, variables), CustomProperties = properties } as CreationDto <TGroup>; break; case nameof(NetscanGroup): creationDto = new NetscanGroupCreationDto { Name = name } as CreationDto <TGroup>; break; case nameof(ReportGroup): creationDto = new ReportGroupCreationDto { Name = name } as CreationDto <TGroup>; break; case nameof(WebsiteGroup): creationDto = new WebsiteGroupCreationDto { ParentId = parentGroup?.Id.ToString() ?? "1", Name = name, Properties = properties } as CreationDto <TGroup>; break; default: throw new NotSupportedException($"Creating {groupTypeName}s not supported."); } return(await portalClient .CreateAsync(creationDto) .ConfigureAwait(false)); }