/// <summary> /// Deletes all items (or all items of specified type) within all or specified tenant /// </summary> /// <param name="type">Item type to be deleted (optional)</param> /// <param name="tenantTitle">Tenant title (optional)</param> public static void DeleteItems(ItemType type = ItemType.Any, TenantTitle tenantTitle = TenantTitle.All) { var tenantList = tenantTitle == TenantTitle.All ? ActionManager.Tenants.ToArray() : ActionManager.Tenants .Where(x => x.Title == tenantTitle.ToString()) .ToArray(); foreach (var tenant in tenantList) { var response = RestController.HttpRequestJson( UriCxm.Items, Method.GET, tenantCode: tenant.Code, user: TestConfig.AdminUser); var items = JsonConvert.DeserializeObject <ItemFromList[]>(response.Content); if (type == ItemType.Any) { foreach (var item in items) { RestController.HttpRequestJson(string.Format(UriCxm.ItemById, item.Id), Method.DELETE, tenantCode: tenant.Code, user: TestConfig.AdminUser); } continue; } items = items.AsParallel().Where(x => x.ModelId == (int)type).ToArray(); foreach (var item in items) { RestController.HttpRequestJson(string.Format(UriCxm.ItemById, item.Id), Method.DELETE, tenantCode: tenant.Code, user: TestConfig.AdminUser); } } }
/// <summary> /// Deletes all places (or all of specified type) and their children within all tenants or /// specified one /// </summary> /// <param name="type">Place type (optional)</param> /// <param name="tenantTitle">Tenant title where places should be deleted (optional)</param> public static void DeletePlaces(PlaceType type = PlaceType.Any, TenantTitle tenantTitle = TenantTitle.All) { var tenantList = tenantTitle == TenantTitle.All ? ActionManager.Tenants.ToArray() : ActionManager.Tenants .Where(x => x.Title == tenantTitle.ToString()) .ToArray(); foreach (var tenant in tenantList) { var response = RestController.HttpRequestJson( UriCxm.Places, Method.GET, tenantCode: tenant.Code, user: TestConfig.AdminUser); var places = JsonConvert.DeserializeObject <List <Place> >(response.Content) .AsParallel() .Where(x => x.Status != (int)PlaceStatus.Deleted && x.ParentId == null) .ToArray(); foreach (var place in places) { place.PlaceModules = new List <PlaceModule>(); if (type == PlaceType.Any) { RestController.HttpRequestJson( string.Format(UriCxm.PlacesDelete, place.Id, "true"), Method.DELETE, tenantCode: tenant.Code, user: TestConfig.AdminUser); } else { if (place.DeviceTypeId == (type != 0 ? (int?)type : null)) { RestController.HttpRequestJson( string.Format(UriCxm.PlacesDelete, place.Id, "true"), Method.DELETE, tenantCode: tenant.Code, user: TestConfig.AdminUser); } } } } }
/// <summary> /// Deletes apps (or all of specified type(s)) within all or specified tenant /// </summary> /// <param name="deleteCompletely">Optional. If true, delete app(s) of the type(s) specified. /// If false, mark the app(s) version(s) as deleted.</param> /// <param name="appTypes">App types array (optional, use null to delete all app types) /// </param> /// <param name="tenantTitle">Tenant title (optional)</param> public static void DeleteApps(bool deleteCompletely = true, string[] appTypes = null, TenantTitle tenantTitle = TenantTitle.All) { var tenantList = tenantTitle == TenantTitle.All ? ActionManager.Tenants.ToArray() : ActionManager.Tenants .Where(x => x.Title == tenantTitle.ToString()) .ToArray(); if (appTypes == null || appTypes.Length == 0) { appTypes = new [] { AppTitle.Any }; } BackgroundTaskApi.DeleteAllTasksAsync(TestConfig.AdminUser) .ConfigureAwait(false) .GetAwaiter() .GetResult(); foreach (var tenant in tenantList) { var response = RestController.HttpRequestJson( UriCxm.Apps, Method.GET, tenantCode: tenant.Code, user: TestConfig.AdminUser); var apps = JsonConvert.DeserializeObject <AppResponse[]>(response.Content); foreach (var app in apps) { if (appTypes.All(x => x.ToString() != AppTitle.Any) && appTypes.All(x => x.ToString() != app.ActualAppVersion.Title) && appTypes.All(x => x.ToString() != app.Key) && !app.ActualAppVersion.Title.Contains("Auto")) { continue; } var app1 = GetById(app.AppId, tenant.Code, TestConfig.AdminUser); if (app1.Places != null && app1.Places.Count > 0) { foreach (var place in app1.Places) { try { var p = PlaceApi.GetById(place.Id, tenant.Code); p.Schedule.ScheduleApps.ForEach(x => x.DoDelete = true); PlaceApi.SavePlace(p); } catch { // ignored } } app1 = GetById(app.AppId, tenant.Code, TestConfig.AdminUser); } foreach (var version in app1.Versions) { RestController.HttpRequestJson( new Uri( string.Format( UriCxm.AppsDelete, version.Id, DateTime.MaxValue.ToString("yyyy-MM-ddTHH:mm:ss"), deleteCompletely.ToString().ToLower()), UriKind.Relative) .ToString(), Method.DELETE, tenantCode: tenant.Code, user: TestConfig.AdminUser); } } } }