Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • marthin 87 posts 106 karma points
    Feb 11, 2010 @ 09:09
    marthin
    0

    External source for nodeFactory

    Hi all,

    I have created my own db table in the umbraco DB. The table is very similar to the node table in umb and my question is this: is it possible to extend the nodeFactory in umbraco? perhaps by overloading some method or something similar? I need this for showing my "products nodes" to the public in a smooth jquery tree.

    Best Regards

    Marthin

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Feb 11, 2010 @ 09:22
    Lee Kelleher
    2

    Hi Marthin,

    The nodeFactory class accesses the XML cache (umbraco.config) to return the node data. It doesn't access the database.  You would usually use umbraco.cms.businesslogic.web.Document() to do that.

    If your products table is similar to the umbracoNode table, then why not use that instead? Use a unique Guid in the nodeOjectType column for your Products "type".  (but you probably thought of this anyway, and require extra columns?)

    Could your Products not be stored as content nodes? (then they'd be cached in the XML umbraco.config - and usable by nodeFactory?)

    All the best, Lee.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 11, 2010 @ 09:26
    Thomas Höhler
    1

    Create your own xslt extension fetching the external data (implemented with caching) would be my way for retrieving external data. I think rewriting the nodefactory isn't allowed by the licence (as I know).

    hth, Thomas

  • marthin 87 posts 106 karma points
    Feb 11, 2010 @ 09:48
    marthin
    0

    Thx for the quick responses!

    The product list is a new section where users who login to the backend see different products in the tree depending on what "company" they belong to. This is my first "big" project with umbraco and to be honest, i didnt think i could use my "products" as normal nodes when i started this but as the project whent on and i learnt more and more I now realize that it was a mistake not to implement it as normal umb Nodes.

    I dont think I can store them as content nodes since i need to have the content section seperated from my products section (to confusing with both "normal" pages and product pages)

    @Thomas. Creating my own xslt extension seems to be a good solution, got any good tutorials on how to accomplish this? especially the caching part?

     

    Thx guys!

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 11, 2010 @ 10:13
    Thomas Höhler
    0

    It's easy to use I used it to have the configuration of my client tools in cache. I have a class structure which I am serializing into the file and back into the memory. To get and set the configuration from / to the cache I have written this code:

    private const string Configfilename = "SimpleSearch4Umbraco.config";
    private const string Cachekey = "SimpleSearchConfiguration";

    public static ConfigurationRoot Root
    {
    get
    {
    return (ConfigurationRoot)HttpRuntime.Cache[Cachekey] ?? LoadConfiguration();
    }
    }

    private static ConfigurationRoot LoadConfiguration()
    {
    umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, 0, "Loading SS4U Configuration");

    var ser = new XmlSerializer(typeof(ConfigurationRoot));
    var path = umbraco.GlobalSettings.FullpathToRoot + System.IO.Path.DirectorySeparatorChar + "config" + System.IO.Path.DirectorySeparatorChar + Configfilename;

    using (var fs = new System.IO.FileStream(path, System.IO.FileMode.Open))
    {
    try
    {
    var retVal = (ConfigurationRoot)ser.Deserialize(fs);
    fs.Close();
    HttpRuntime.Cache.Insert(Cachekey, retVal, new System.Web.Caching.CacheDependency(path));
    return retVal;
    }
    catch (Exception ex)
    {
    umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Error, 0, "Error loading SS4U Configuration: " + ex.Message + ex.StackTrace);
    return null;
    }
    }
    }

    and if I change something in the configuration by code I can call afterwards this code to reflect the changes in memory:

    public static void SaveConfiguration()
    {
    var ser = new XmlSerializer(typeof(ConfigurationRoot));
    var path = umbraco.GlobalSettings.FullpathToRoot + System.IO.Path.DirectorySeparatorChar + "config" + System.IO.Path.DirectorySeparatorChar + Configfilename;

    using (var fs = new System.IO.FileStream(path, System.IO.FileMode.Create))
    {
    ser.Serialize(fs, Root);
    fs.Close();
    }
    HttpRuntime.Cache[Cachekey] = Root;
    }

    So, the code to set the objects intot the cache is:

    HttpRuntime.Cache[Cachekey] = MYOBJECT;

    and the code to get the objects from the cache is:

    var myobjects = (MYTYPECASTING)HttpRuntime.Cache[Cachekey]

    hth, Thomas

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Feb 11, 2010 @ 12:01
    Douglas Robar
    0

    Making your own (caching) xslt extension is a great solution. But if you're in a hurry you might be able to use Jeser's "SQL for XSLT" package, which is very powerful. http://our.umbraco.org/projects/sql-for-xslt-%28jespercom%29

    cheers,
    doug.

  • marthin 87 posts 106 karma points
    Feb 11, 2010 @ 12:02
    marthin
    0

    okej i think i understand how that would work, but for me when using a "product" - object and caching it, do i only cach the XML-file or is it in some way possible to cache functions that always return the same value? I'm thinking something like

    public List<Product> GetProducts(Xml)
    

    {

     return List<Product>

    }

    HttpRuntime.Cache["uniqkey"] = GetProducts;

     

    So when im creating my jQuery Tree i only need to call:

    List<Product> allProducts = (???)HttpRuntime.Cache["uniqkey"];

     

    Is this possible or should i only cache the XML file?

    Thank you for helping me!

  • marthin 87 posts 106 karma points
    Feb 11, 2010 @ 12:03
    marthin
    0

    EDIT: GetProducts(Xml) should not take any argument: GetProducts()

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 11, 2010 @ 12:22
    Thomas Höhler
    0

    It's on you what to cache, if you are working with the list just cahce the list, if you want an xml just open an xml and cache it. It depends on you what you want to use in the frontend :-)

    Thomas

Please Sign in or register to post replies

Write your reply to:

Draft