0

I want to use data from another app like in code

But I want to get appId from app name or folder? Is there any method to get this?

Jernej Pirc
  • 504
  • 1
  • 4
  • 13

1 Answers1

0

This is my working code with functions for getting AppId:

public int GetAppIdFromName(string appName){
    foreach(var app in sxApps()) if (app.Name==appName) return App.AppId;
    return -1;
}

public int GetAppIdFromFolder(string appFolder){
    foreach(var app in sxApps()) if (app.Folder==appFolder) return App.AppId;
    return -1;
}

public List<ToSic.SexyContent.App> sxApps() 
{
    var zoneId=(int)ToSic.SexyContent.Internal.ZoneHelpers.GetZoneID(Dnn.Module.PortalID);
    var eavApps = ((ToSic.Eav.DataSources.Caches.BaseCache)ToSic.Eav.DataSource.GetCache(zoneId, null)).ZoneApps[zoneId].Apps;
    var ps = DotNetNuke.Entities.Portals.PortalSettings.Current;
    return eavApps.Select<KeyValuePair<int, string>, ToSic.SexyContent.App>(eavApp => new ToSic.SexyContent.App(zoneId, eavApp.Key, ps)).ToList();
}

Is this OK or can be done easyer?

==================== added =======================

I updated 2sxc from 8.7 to 9.30 and this code don't work anymore.

error:

    Compiler Error Message: CS1502: The best overloaded method match for 'ToSic.SexyContent.App.App(ToSic.Eav.Apps.Interfaces.ITenant, int, ToSic.Eav.Logging.Simple.Log)' has some invalid arguments

Source Error:    
    Line 22:             return eavApps.Select<KeyValuePair<int, string>, ToSic.SexyContent.App>(eavApp => new ToSic.SexyContent.App(zoneId, eavApp.Key, ps)).ToList();

Can someone help me with converting this to new version? I don't understand how new ITenant work.

============ edit new solution for 2sxc version 9.30 =============

public static List<ToSic.SexyContent.App> sxApps(int portalID) 
{
    var zm = new ToSic.SexyContent.Environment.Dnn7.ZoneMapper();
    var zoneId = zm.GetZoneId(portalID);
    var eavApps = ((ToSic.Eav.DataSources.Caches.BaseCache)ToSic.Eav.DataSource.GetCache(zoneId, null)).ZoneApps[zoneId].Apps;
    var ps = DotNetNuke.Entities.Portals.PortalSettings.Current;
    var tenant = new ToSic.SexyContent.Environment.Dnn7.DnnTenant(ps);
    return eavApps.Select<KeyValuePair<int, string>, ToSic.SexyContent.App>(eavApp => new ToSic.SexyContent.App(tenant, eavApp.Key)).ToList();
}

====================== new edit ===================

On version 9.33 stuff brake again... (on 9.32.1 still work)

Compiler Error Message: CS1729: 'ToSic.SexyContent.App' does not contain a constructor that takes 2 arguments

Line 23: return eavApps.Select, ToSic.SexyContent.App>(eavApp => new ToSic.SexyContent.App(tenant, eavApp.Key)).ToList();

anyone know how to fix this?

Jernej Pirc
  • 504
  • 1
  • 4
  • 13
  • 1
    As of now 2sxc 8.5 that's more or less it. I could rewrite it, but it would still go through the list of apps on the basecache. This can be risky though, because multiple apps could have the same name (if hosted on different portal...) – iJungleBoy Aug 02 '16 at 09:49
  • @iJungleBoy can you please help me how to convert this to ITenant? Or is there some new way to get this in new version? – Jernej Pirc May 06 '18 at 08:10
  • @iJungleBoy found and posted the solution, don't need help anymore – Jernej Pirc May 06 '18 at 10:23
  • @iJungleBoy On version 9.33 stuff brake again.. I posted another answer with new problem – Jernej Pirc Nov 27 '18 at 08:11