Prune Explorer folder callout method template

Implementation of the desired algorithm for pruning the Explorer folder contents must be done by the application developer. We provide this method template to leverage the LoadExplorerResponseData class to deserialize and serialize the OriginalExplorerXML and PrunedExplorerXML input or output parameter.
[IDOMethod]
public int method_name( 
   string userName, 
   string originalExplorerXML, 
   ref string prunedExplorerXML )
{
   int result = (int)StdMethodResult.Success;
   LoadExplorerResponseData expRespData = null;

   if ( string.IsNullOrEmpty( userName ) )
      prunedExplorerXML = originalExplorerXML;
   else
   {
      expRespData = LoadExplorerResponseData.FromXml( originalExplorerXML );
      // Begin user implementation
      // End user implementation
      prunedExplorerXML = expRespData.ToXml();
   }   

   return result;
}
Note: The method_name above must be replaced by whatever method name the developer chooses to use. The content of the method must include the template code provided above.
One possible criteria to determine form names to be pruned is whether the user has permissions to execute a given form. The following sample C# code can prune form names that do not have executable permissions for a given user. This sample implementation also illustrates how to build a list of executable form names and then prune the form names from the LoadExplorerResponseData class instance.
// Begin user implementation
ListString executableForms = new ListString();
using ( AppDB db = IDORuntime.Context.CreateAppDB() )
{
  try
  {
     // Get list of form names (ObjectName1) and associated executable flag 
     // for each 
     using ( SqlCommand cmd = db.Connection.CreateCommand() )
     {
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "select ObjectName1, " +
        "CASE WHEN SUM(ISNULL(aau.ExecutePrivilege, 0)) >= 1 THEN 1 ELSE 
           0 END " +
        "FROM AccountAuthorizations aau " + 
        "INNER JOIN UserNames una ON una.Username = N'" + userName + "' " + 
        "WHERE aau.ObjectType = 0 AND " +
        "aau.ObjectName2 = aau.ObjectName1 AND " +
        "aau.UserFlag = 0 AND aau.Id IN ( " + 
        "SELECT ugm.GroupId " +                  
        "FROM UserGroupMap ugm " +                 
        "WHERE ugm.UserId = una.UserId ) " + 
        "group by ObjectName1";

        using ( IDataReader reader = db.ExecuteReader( cmd ) )
        {
           while ( reader.Read() )
           {
              if ( (int) reader.GetValue(1) == 1 )
              { 
                 string formName = reader.GetString(0);
                 if ( formName != string.Empty )
                    executableForms.Add( formName );
              }
           }
        }
     }
  }
  catch
  {
  }
}
// Prune form names from node that aren't in list of executable forms
var node = (FormServer.Protocol.ExplorerNodeDef) null;
int idx = 0;
while ( idx < expRespData.Nodes.Count )
{
   node = expRespData.Nodes[idx];
   if ( node.ObjectType == WinStudio.Enums.ExplorerObjectType.NormalForm || 
        node.ObjectType == WinStudio.Enums.ExplorerObjectType.QueryForm )
   {
      if ( !executableForms.Contains( node.ObjectTextData ) )
         expRespData.Nodes.RemoveAt( idx );
      else
         idx++;
   }
   else
      idx++;   
}
// End user implementation

The ido.method: AccountAuthorizations.PruneExplorerFolder is included in the Core framework as a sample callout.

This method leverages the method template and sample implementation code included above. AccountAuthorizations.PruneExplorerFolder must not be used for an actual implementation as it is not designed for efficiency when running against a large repository of forms and does not include robust error handling. However, AccountAuthorizations.PruneExplorerFolder can be specified as the value for the Prune Explorer Callout process default as a sample test implementation.