Beispiel #1
0
        /// <summary>
        /// Deletes specified app version. If no more uploaded app versions are left after removal,
        /// the app will be fully removed. If some versions are left, the latest one will be set as
        /// actual app version.
        /// </summary>
        /// <param name="app">App object</param>
        /// <param name="version">App version (e.g. "0.0.1")</param>
        /// <param name="isDeleteCompletely">Optional. If true, removes the app version completely.
        /// If false, marks the version as deleted.</param>
        public static void DeleteAppVersion(AppResponse app, string version, bool isDeleteCompletely = true)
        {
            var ver = app?.Versions?
                      .FirstOrDefault(x => string.Join(".", x.Major, x.Minor, x.Revision) == version &&
                                      x.Status != (int)AppStatus.Deleted);

            if (ver != null)
            {
                if (ver.Status == (int)AppStatus.Published)
                {
                    foreach (var place in app.Places)
                    {
                        try
                        {
                            var p = PlaceApi.GetById(place.Id);
                            p.Schedule.ScheduleApps.ForEach(x => x.DoDelete = true);
                            PlaceApi.SavePlace(p);
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                }

                app = GetById(app.AppId, user: TestConfig.AdminUser);

                if (ver.Status == (int)AppStatus.New && !isDeleteCompletely)
                {
                    app.Versions.Single(x => string.Join(".", x.Major, x.Minor, x.Revision) == version).Status =
                        (int)AppStatus.Available;
                    if (string.Join(".", app.ActualAppVersion.Major, app.ActualAppVersion.Minor, app.ActualAppVersion.Revision) == version &&
                        app.ActualAppVersion.Status == (int)AppStatus.New)
                    {
                        app.ActualAppVersion.Status = (int)AppStatus.Available;
                    }
                    app = SaveApp(AppResponseToRequest(app));
                }

                try
                {
                    RestController.HttpRequestJson(
                        new Uri(string.Format(UriCxm.AppsDelete, ver.Id, app.Updated, isDeleteCompletely),
                                UriKind.Relative)
                        .ToString(),
                        Method.DELETE,
                        user: TestConfig.AdminUser);
                }
                catch
                {
                    // ignored
                }
            }
        }
Beispiel #2
0
        /// <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);
                    }
                }
            }
        }