コード例 #1
0
 /// <summary>
 /// Gets the key for storing a set of keys that related to a desktop
 /// </summary>
 /// <param name="desktop"></param>
 /// <returns></returns>
 public static string GetSetCacheKey(this Desktop desktop)
 => desktop.Organization.GetSetCacheKey($"Desktop:{desktop.ID}");
コード例 #2
0
 /// <summary>
 /// Gets the key for storing HTML code of a desktop that specified by alias and requested URL
 /// </summary>
 /// <param name="desktop"></param>
 /// <param name="requestURI"></param>
 /// <returns></returns>
 public static string GetDesktopCacheKey(this Desktop desktop, Uri requestURI)
 => desktop.Organization.GetDesktopCacheKey(desktop.Alias, requestURI);
コード例 #3
0
 /// <summary>
 /// Gets the key for storing HTML code of a desktop that specified by alias and requested URL
 /// </summary>
 /// <param name="desktop"></param>
 /// <param name="requestURL"></param>
 /// <returns></returns>
 public static string GetDesktopCacheKey(this Desktop desktop, string requestURL)
 => desktop.GetDesktopCacheKey(new Uri(requestURL.IsStartsWith("http://") || requestURL.IsStartsWith("https://") ? requestURL : "https://site.vieapps.net/" + (requestURL.Equals("#") ? "" : requestURL.Replace("~/", ""))));
コード例 #4
0
        internal static async Task ClearCacheAsync(this Organization organization, CancellationToken cancellationToken, string correlationID = null, bool clearObjectsCache = true, bool clearRelatedDataCache = true, bool clearRelatedHtmlCache = true, bool doRefresh = true)
        {
            // clear cache of home desktop (html)
            var tasks = new List <Task>
            {
                organization.ClearRelatedCacheAsync(cancellationToken, correlationID, clearRelatedDataCache, clearRelatedHtmlCache, false)
            };

            // clear cache of objects
            if (clearObjectsCache)
            {
                // clear cache of expressions
                var expressions = await Expression.FindAsync(Filters <Expression> .And(Filters <Expression> .Equals("SystemID", organization.ID)), null, 0, 1, null, cancellationToken).ConfigureAwait(false);

                tasks = tasks.Concat(expressions.Select(expression => expression.ClearCacheAsync(cancellationToken, correlationID, clearRelatedDataCache, clearRelatedHtmlCache, doRefresh))).ToList();

                // clear cache of roles
                var roles = await Role.FindAsync(Filters <Role> .And(Filters <Role> .Equals("SystemID", organization.ID)), null, 0, 1, null, cancellationToken).ConfigureAwait(false);

                tasks = tasks.Concat(roles.Select(role => role.ClearCacheAsync(cancellationToken, correlationID, clearRelatedDataCache))).ToList();

                // clear cache of modules, content-types and business objects
                tasks = tasks.Concat(organization.Modules.Select(module => module.ClearCacheAsync(cancellationToken, correlationID, clearObjectsCache, clearRelatedDataCache, clearRelatedHtmlCache, doRefresh))).ToList();

                // clear cache of desktops
                var desktops = await Desktop.FindAsync(Filters <Desktop> .And(Filters <Desktop> .Equals("SystemID", organization.ID)), null, 0, 1, null, cancellationToken).ConfigureAwait(false);

                tasks = tasks.Concat(desktops.Select(desktop => desktop.ClearCacheAsync(cancellationToken, correlationID, clearRelatedDataCache, clearRelatedHtmlCache, doRefresh))).ToList();

                // clear cache of sites
                tasks = tasks.Concat(organization.Sites.Select(site => site.ClearCacheAsync(cancellationToken, correlationID, clearRelatedDataCache, clearRelatedHtmlCache, doRefresh))).ToList();
            }

            // clear cache of the organization
            tasks = tasks.Concat(new[]
            {
                Utility.Cache.RemoveAsync(organization.Remove(), cancellationToken),
                Utility.RTUService.SendInterCommunicateMessageAsync(new CommunicateMessage(ServiceBase.ServiceComponent.ServiceName)
                {
                    Type           = $"{organization.GetObjectName()}#Delete",
                    Data           = organization.ToJson(),
                    ExcludedNodeID = Utility.NodeID
                }, cancellationToken),
                Utility.WriteCacheLogs ? Utility.WriteLogAsync(correlationID, $"Clear cache of an organization [{organization.Title} - ID: {organization.ID}]", ServiceBase.ServiceComponent.CancellationToken, "Caches") : Task.CompletedTask
            }).ToList();

            await Task.WhenAll(tasks).ConfigureAwait(false);

            // re-load organization & sites/modules/content-types
            organization = await organization.ID.GetOrganizationByIDAsync(cancellationToken).ConfigureAwait(false);

            await Task.WhenAll(
                organization.FindSitesAsync(cancellationToken, false),
                organization.FindModulesAsync(cancellationToken, false)
                ).ConfigureAwait(false);

            await organization.Modules.ForEachAsync(async module =>
            {
                await module.FindContentTypesAsync(cancellationToken, false).ConfigureAwait(false);
                await Task.WhenAll
                (
                    Utility.WriteCacheLogs ? Utility.WriteLogAsync(correlationID, $"The module was reloaded when all cache were clean\r\n{module.ToJson()}", cancellationToken, "Caches") : Task.CompletedTask,
                    Utility.WriteCacheLogs ? Utility.WriteLogAsync(correlationID, $"The content-types were reloaded when all cache were clean\r\n{module.ContentTypes.Select(contentType => contentType.ToJson().ToString(Formatting.Indented)).Join("\r\n")}", cancellationToken, "Caches") : Task.CompletedTask
                ).ConfigureAwait(false);
            }, true, false).ConfigureAwait(false);

            await Task.WhenAll(
                organization.SetAsync(false, true, cancellationToken),
                Task.WhenAll(organization.Sites.Select(site => site.SetAsync(false, true, cancellationToken))),
                Task.WhenAll(organization.Modules.Select(module => module.SetAsync(true, cancellationToken))),
                Task.WhenAll(organization.Modules.Select(module => Task.WhenAll(module.ContentTypes.Select(contentType => contentType.SetAsync(true, cancellationToken)))))
                ).ConfigureAwait(false);

            // re-load and refresh the home desktop
            var homedesktop = await Desktop.GetAsync <Desktop>(organization.HomeDesktopID, cancellationToken).ConfigureAwait(false);

            await Task.WhenAll(
                homedesktop.FindChildrenAsync(cancellationToken, false),
                homedesktop.FindPortletsAsync(cancellationToken, false)
                ).ConfigureAwait(false);

            await homedesktop.SetAsync(false, true, cancellationToken).ConfigureAwait(false);

            await Task.WhenAll
            (
                $"{Utility.PortalsHttpURI}/~{organization.Alias}/".RefreshWebPageAsync(0, correlationID, $"Refresh the home desktop when all cache of an organization were clean [{organization.Title} - ID: {organization.ID}]"),
                Utility.WriteCacheLogs?Utility.WriteLogAsync(correlationID, $"The organization was reloaded when all cache were clean\r\n{organization.ToJson()}", cancellationToken, "Caches") : Task.CompletedTask
            ).ConfigureAwait(false);
        }