コード例 #1
0
        /// <summary>
        /// Creates the or update cached apps from user.
        /// </summary>
        /// <returns>The or update cached apps from user.</returns>
        /// <param name="user">User.</param>
        public List <int> CreateOrUpdateCachedAppsFromUser(UserTep user)
        {
            List <int> upIds  = new List <int>();
            var        app    = user.GetPrivateThematicApp();
            var        domain = user.GetPrivateDomain();

            foreach (var appItem in app.Items)
            {
                var ids = CreateOrUpdateCachedAppFromUrl(appItem.Location, domain.Id);
                upIds.AddRange(ids);
            }
            return(upIds);
        }
コード例 #2
0
        /// <summary>
        /// Refreshs the cached apps for user.
        /// </summary>
        /// <param name="user">User.</param>
        public void RefreshCachedAppsForUser(UserTep user)
        {
            //Get all existing apps for the user
            EntityList <ThematicApplicationCached> existingApps = new EntityList <ThematicApplicationCached>(context);
            List <int> existingIds = new List <int>();
            var        domain      = user.GetPrivateDomain();

            existingApps.SetFilter("DomainId", domain.Id);
            existingApps.Load();

            //will be filled with all updated ids
            List <int> upIds = CreateOrUpdateCachedAppsFromUser(user);

            //delete apps not updated
            foreach (var app in existingApps)
            {
                if (!upIds.Contains(app.Id))
                {
                    this.LogInfo(string.Format("RefreshThematicAppsCache -- Delete not updated app '{0}' from domain {1}", app.UId, app.DomainId));
                    app.Delete();
                }
            }
        }
コード例 #3
0
        public object Get(ThematicAppCurrentUserSearchRequestTep request)
        {
            IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

            context.Open();
            context.LogInfo(this, string.Format("/user/current/apps/search GET"));

            IOpenSearchResultCollection result;
            OpenSearchEngine            ose = MasterCatalogue.OpenSearchEngine;
            var  httpRequest  = HttpContext.Current.Request;
            Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
            List <Terradue.OpenSearch.IOpenSearchable> osentities = new List <Terradue.OpenSearch.IOpenSearchable>();
            var settings = MasterCatalogue.OpenSearchFactorySettings;
            OpenSearchableFactorySettings specsettings = (OpenSearchableFactorySettings)settings.Clone();

            UserTep user = null;

            if (context.UserId != 0)
            {
                user = UserTep.FromId(context, context.UserId);
                if (request.cache)
                {
                    var domain = user.GetPrivateDomain();
                    EntityList <ThematicApplicationCached> appsCached = new EntityList <ThematicApplicationCached>(context);
                    appsCached.SetFilter("DomainId", domain.Id);
                    appsCached.AddSort("LastUpdate", SortDirection.Descending);

                    result = ose.Query(appsCached, Request.QueryString, responseType);
                    OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(appsCached, result);
                }
                else
                {
                    //get user private thematic app
                    var apikey   = user.GetSessionApiKey();
                    var t2userid = user.TerradueCloudUsername;
                    if (!string.IsNullOrEmpty(apikey))
                    {
                        specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey);
                    }
                    var app = user.GetPrivateThematicApp();
                    if (app != null)
                    {
                        foreach (var item in app.Items)
                        {
                            if (!string.IsNullOrEmpty(item.Location))
                            {
                                try {
                                    var sgOs = OpenSearchFactory.FindOpenSearchable(specsettings, new OpenSearchUrl(item.Location));
                                    osentities.Add(sgOs);
                                    context.LogDebug(this, string.Format("Apps search -- Add '{0}'", item.Location));
                                } catch (Exception e) {
                                    context.LogError(this, e.Message, e);
                                }
                            }
                        }
                    }
                    MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(osentities, specsettings);
                    result = ose.Query(multiOSE, Request.QueryString, responseType);
                }
            }
            else
            {
                result = ose.Query(new MultiGenericOpenSearchable(osentities, specsettings), Request.QueryString, responseType);
            }

            string sresult = result.SerializeToString();

            //replace usernames in apps
            if (user != null)
            {
                try {
                    sresult = sresult.Replace("${USERNAME}", user.Username);
                    sresult = sresult.Replace("${T2USERNAME}", user.TerradueCloudUsername);
                    sresult = sresult.Replace("${T2APIKEY}", user.GetSessionApiKey());
                } catch (Exception e) {
                    context.LogError(this, e.Message, e);
                }
            }

            context.Close();

            return(new HttpResult(sresult, result.ContentType));
        }