CustomDBProvider with CustomContentProvider

3 posts, 0 answers
  1. Erik
    Erik avatar
    6 posts
    Member since:
    Aug 2012

    Posted 20 Nov 2012 Link to this post

    I'm using the documentation and online source to try and build my own CustomDBProvider and CustomContentProvider.  I'm running into some issues and was hoping to get some help.  My goal is to have some "top-level" folders which will dynamically query a third-party system (via a COM SDK) and display folders and/or documents.  One of the top-level folders might be called "My Documents" and should only show documents.  Another might be called "My folders" and could show folders (which might in-turn have sub-folders).  Another example would be "My Labels" which might contain either documents or folders.  I"m using some static pathing so that I know how to execute different commands in the third party system.  I can't use DataTables because I need to load the information on-demand.  

    For now I just want things to be displayed in the UI.  I've made everything read-only.  I'm not worried about uploading at this point.

    I've gotten the "My Documents" to work perfectly.  But I can't get "My Containers" to work.  It executes the code and loads the directories into the function, but nothing gets displayed.  Any help would be greatly appreciated!



    public override DirectoryItem ResolveRootDirectoryAsTree(string path)
    {
        DirectoryItem directory = null;
        if (path.Equals("ROOT/TE"))
        {
            directory = new DirectoryItem("File Explorer", "ROOT/TE", "ROOT/TE", "ROOT/TE", PathPermissions.Read, null, null);
            List<DirectoryItem> subDirs = new List<DirectoryItem>();
            subDirs.Add(new DirectoryItem("My Labels", string.Empty, "ROOT/TE/TL-1", "TL-1", PathPermissions.Read, null, null));
            subDirs.Add(new DirectoryItem("Recent Documents", string.Empty, "ROOT/TE/TL-2", "TL-2", PathPermissions.Read, null, null));
            subDirs.Add(new DirectoryItem("Recent Folders", string.Empty, "ROOT/TE/TL-3", "TL-3", PathPermissions.Read, null, null));
            directory.Directories = subDirs.ToArray();
            if (directory.Directories != null)
            {
     
                foreach (DirectoryItem dir in directory.Directories)
                {
                    dir.Permissions = GetPermissions(path);
                }
            }
            return directory;
        } else {
            return directory;
        }
    }

    public override DirectoryItem ResolveDirectory(string path)
    {
        DirectoryItem directory = dataServer.GetDirectoryItem(path, true, true);
        if (directory == null) return null;
        return directory;
    }

    public DirectoryItem GetDirectoryItem(string path, bool bIncludeSubfolders, bool bIncludeFiles)
    {
        DirectoryItem diDirectory = null;
        MyObject item = this.GetObjectFromPath(path);
        if (item != null )
        {
            if (item.sType.Equals("TL"))
            {
                diDirectory = LoadSubNode(item, path, bIncludeSubfolders, bIncludeFiles);
            }
            else if (item.sType.Equals("C"))
            {
                //diDirectory = CreateDirectoryItem(item, true);
            }
            else if (item.sType.Equals("FP"))
            {
                //diDirectory = CreateDirectoryItem(item, true);
            }
            else if (item.sType.Equals("UL"))
            {
                //diDirectory = CreateDirectoryItem(item, true);
            }
        }
        return diDirectory;
        //return (item != null && item.sType.Equals("C")) ? this.CreateDirectoryItem(item, includeSubfolders) : null;
    }
     
    private DirectoryItem LoadSubNode(MyObject ktoItem, string sPath, bool bIncludeSubFolders, bool bIncludeFiles) {
        DirectoryItem diDirectory = null;
        if (ktoItem.sUri.Equals("2"))
        {
            diDirectory = GetTopLevel_RecentDocuments(sPath, bIncludeFiles);
        }
        else if (ktoItem.sUri.Equals("3"))
        {
            diDirectory = GetTopLevel_RecentContainers(sPath, bIncludeSubFolders, bIncludeFiles);
        }
        return diDirectory;
    }
     
     
    private DirectoryItem GetTopLevel_RecentDocuments(string sPath, bool bIncludeFiles) {
        DirectoryItem diDirectory = new DirectoryItem("Recent Documents", sPath, sPath, "TL-2", PathPermissions.Read, null, null);
        if (bIncludeFiles)
        {
            diDirectory.Files = LoadRecentDocuments(sPath);
        }
        return diDirectory;
    }
    private DirectoryItem GetTopLevel_RecentContainers(string sPath, bool bIncludeSubFolders, bool bIncludeFiles)
    {
        DirectoryItem diDirectory = null;
        diDirectory = new DirectoryItem("Recent Containers", sPath, sPath, "TL-3", PathPermissions.Read, null, null);
        SomeSDK.Records tRecords = tDatabase.MakeRecords();
        tRecords.SearchString = "myContainers";
        SomeSDK.Record tRecord = null;
        List<DirectoryItem> diFolders = new List<DirectoryItem>();
        while ((tRecord = tRecords.Next()) != null)
        {
            string sItemPath = GetValidPath(sPath) + "C-" + tRecord.Uri.ToString();
            DirectoryItem diSubItem = new DirectoryItem(tRecord.Title + " (" + tRecord.Number + ")", sItemPath, sItemPath, sItemPath, PathPermissions.Read, null, null);
            diSubItem.Files = (new List<FileItem>()).ToArray();
            diSubItem.Directories = (new List<DirectoryItem>()).ToArray();
            //diFolders.Add(new DirectoryItem(tRecord.Title + " (" + tRecord.Number + ")", sItemPath, sItemPath, sItemPath, PathPermissions.Read, null, null));
            diFolders.Add(diSubItem);
            //diFolders.Add(new DirectoryItem("test", string.Empty, sPath + "/1", "1", PathPermissions.Read, null, null));
        }
        diDirectory.Directories = diFolders.ToArray();
        List<FileItem> fiDocuments = new List<FileItem>();
        diDirectory.Files = fiDocuments.ToArray();
        return diDirectory;
    }
     
    private FileItem[] LoadRecentDocuments(string sPath)
    {
        SomeSDK.Records tRecords = tDatabase.MakeRecords();
        tRecords.SearchString = "myDocuments";
        SomeSDK.Record tRecord = null;
        List<FileItem> fiDocuments = new List<FileItem>();
        while ((tRecord = tRecords.Next()) != null)
        {
            string sItemPath = GetValidPath(sPath) + "D-" + tRecord.Uri.ToString();
            fiDocuments.Add(new FileItem(tRecord.Title + " (" + tRecord.Number + ")", tRecord.Extension, tRecord.DocumentSize, sItemPath, sItemPath, tRecord.Number, PathPermissions.Read));
        }
        return fiDocuments.ToArray();
    }
    private string GetValidPath(string sInputPath)
    {
        if (!sInputPath.EndsWith("/"))
        {
            return sInputPath + "/";
        }
        else
        {
            return sInputPath;
        }
    }
  2. Erik
    Erik avatar
    6 posts
    Member since:
    Aug 2012

    Posted 20 Nov 2012 Link to this post

    Just to add a bit more information here.... I need the top-level folders to be dynamic.  I thought I could use the path attribute of the DirectoryItem for this purpose.  When the ResolveDirectory method is called I can parse out what's being requested.

    • If the user clicks "My Containers" I want to execute a certain bit of code, which will load child-folders into the explorer interface.  
    • If the user clicks a folder within "My Containers" then I want to show the files for that container, but there could also be sub-folders to display.
    • If the user clicks "My Documents" then only a certain set of documents should be shown (loaded via some specialized COM SDK logic).

    Is it okay to use the path attribute like this?  The way I've build it now I'm embedding the "breadcrumbs" in the path.

    For instance:
    1. User clicked "My Containers": path to this object might be "ROOT/TE/TL-3"
    2. User clicks a folder within "My Containers", the path might be "ROOT/TE/TL-3/C:1234".  "C:" denotes this is a container in the third party system.  "1234" denotes the unique identifier within the other system.
    3. User clicked "My Labels": path to this object might be "ROOT/TE/TL-4"
    4. User clicks a folder within "My Labels", the path might be "ROOT/TE/TL-4/C:1234".  
    5. User clicks a folder within the folder from step #4.  The path might be "ROOT/TE/TL-4/C:1234/C:4321". 

    I hope this helps.  Maybe I'm using the path feature wrong.  The main point is that the path could always be dynamic.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vessy
    Admin
    Vessy avatar
    1381 posts

    Posted 23 Nov 2012 Link to this post

    Hi Erik,

    i am affraid to say that the provided information was not enough for us to determine what is causing the issue. This is why, could you please open a formal support ticket and provide a sample fully runnable project reproducing the issue so we can examine and debug it locally?

    Kind regards,
    Vesi
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top