Develop from Visual Studio

Develop from Visual Studio

This question is answered

Hi,

We are starting with Telligent Community and wonder if it's still possible to use the .NET controls from Telligent Community 7, descriped here: telligent.com/.../4325.implement-a-basic-widget.aspx

Or is this way of doing deprecated? The widget studio way doesn't seem to be a favorite way for team development, and since there is a lot of .NET knowledge in the team we want to avoid switching to Velocity.

Verified Answer
  • Hi, In 6.0 these kind of .net widgets were phased out in favour of the nvelocity ones. In 7.0 I believe the support has been removed completely. Even if it hasn't yet though it will be in 7.5 or 8 so I would strongly advise you against building your widgets in this way as they will be obsolete soon and need upgrading anway. There is a learning curve to nvelocity but once you have it widget development can be quicker and there are lots of api methods in core_v2_ that you can take advantage off and do a lot of the heaving lifting for you already. It is possible to build these widgets in visual studio still using a factory default provider to create a package of deployable widgets. This is the approach we use as we can keep all the widgets in source control and edit them in visual studio (as xml files) still but use nvelocity to program them. Here is how to do this: telligent.com/.../31468.widget-version-control.aspx

    hope this helps

    Adam

  • Thanks Patrick. Glad you agree on the MVC pattern, In summary then I think what you are saying is:

    • If you have existing ascx based widgets and they use the public apis, or rest apis then their is no real reason to upgrade them if they work ok now.
       
    • however If you have existing ascx based widgets that use either chameleon controls in them or use the private apis then you should upgrade them to nVelocity (you could switch them to use the public apis or rest, but it may be just as easy to write a plugin or use the widget api that exists instead).
       
    • If you are writing new widgets form scratch then create nvelocity widgets (if at all possible - and there is no need to change a ui that is difficult to change).

    IJsbeer - there are some benefits to using nvelocity widgets, some of which Patrick touched on:

    • Portability - nVelocity widgets and packages of widgets (factory default providers) can be exported/imported between different environments using just xml files (or in the case of factory default providers a dll & an xml file with the widgets exported in it). you can't do this with .ascx widgets.
       
    • Flexibility - nVelocity widgets can be enabled/disabled and the code can be viewed and tweaked in the control panel allowing you to debug or test things easier than if using ascx widgets. For this reason though we develop our in VS and use source control locally in case changes are made in the control panel and we need to roll-back.
       
    • Organisation & Visibility - nVelocity can be grouped together organised in the control panel. ascx widgets will not show up in the control panel which could confuse users of the site when they see other widgets listed and not the custom ones.
       
    • Labels/Text -  nVelocity widgets have their labels/text (resources) attached to them rather than being in a single resources file which means they can be updated and/or translated in the control panel without the need for a developer.
       
    • Modularisation - nVelocity widgets have all their additional files (such as JS) attached as tabs so it is easy to see what is included in each widget, In ascx widgets often the js is included lazily in the widget or in a bloated js file used by many other widgets. The plugins also encourage modularisation of code allowing for easier deployment of features / enhancements and bug fixes.
       
    • Re-use - the ootb widgets have a lot of code you can re-use (core_v2_xxx) and have integration with jquery (such as the validation framework) which you can use if you create nVelocity widgets. Often this means you can develop custom widgets quicker in this way than building ascx ones from scratch.


    These are some good reasons to go with nVelocity widgets. I agree there is a learning curve though and it may take your devs a while to get up to speed but nVelocity isn't hard to pick-up and when you get used to it development is fairly quick.
    thanks
    Adam
  • I think this is a pretty could summarization yes.
     
    I also would not be super concerned with the learning curve, especially if your .NET developers are primarily web developers.  The biggest challenge I have faced teaching it is getting people to simplify their thoughts around it.  At the end of the day its using HTML and javascript and then you add templating syntax, and there are only a handful of syntax items  to learn to be functional.
     
    Someone gave me the example once that creating a list in Velocity syntax was much harder than using a GridView which I took as a challenge. 
     
    The reality is by the time you setup the databinding, all the attributes, templating, etc you have actually done a good amount of work before you even do styling
     
    In velocity I believe it was 7 lines total( a for each loop), most of which was plain old html and included getting your data items, a header and footer.  9 with a no- data template.
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Adam Seabridge [mailto:bounce-aseabridgethebuildingblockscouk@communities.telligent.com]
    Sent: Tuesday, February 26, 2013 9:06 AM
    To: bugsandissues@communities.telligent.com
    Subject: RE: [Bugs and Issues - Telligent Community] Develop from Visual Studio
     

    Thanks Patrick. Glad you agree on the MVC pattern, In summary then I think what you are saying is:

    • If you have existing ascx based widgets and they use the public apis, or rest apis then their is no real reason to upgrade them if they work ok now.
       
    • however If you have existing ascx based widgets that use either chameleon controls in them or use the private apis then you should upgrade them to nVelocity (you could switch them to use the public apis or rest) but it may be just as easy to write a plugin or use the widget api that exists instead).
       
    • If you are writing new widgets form scratch then create nvelocity widgets if at all possible and there is no need to change a ui that is difficult to change.
    IJsbeer - there are some benefits to using nvelocity widgets, some of which Patrick touched on:
    • Portability - nVelocity widgets and packages of widgets (factory default providers) can be exported/imported between different environments using just xml files (or in the case of factory default providers a dll & an xml file with the widgets exported in it). you can't do this with .ascx widgets.
       
    • Flexibility - nVelocity widgets can be enabled/disabled and the code can be viewed and tweaked in the control panel allowing you to debug or test things easier than if using ascx widgets. For this reason though we develop our in VS and use source control locally in case changes are made in the control panel and we need to roll-back.
       
    • Organisation & Viability - nVelocity can be grouped together organised in the control panel. ascx widgets will not show up in the control panel which could confuse users of the site when they see other widgets listed and not the custom ones.
       
    • Labels/Text -  nVelocity widgets have their labels/text (resources) attached to them rather than being in a single resources file which means they can be updated and/or translated in the control panel without the need for a developer.
       
    • Modularisation - nVelocity widgets have all their additional files (such as JS) attached as tabs so it is easy to see what is included in each widget, In ascx widgets often the js is included lazily in the widget or in a bloated js file used by many other widgets. The plugins also encourage modularisation of code allowing for easier deployment of features / enhancements and bug fixes.
       
    • Re-use - the ootb widgets have a lot of code you can re-use (core_v2_xxx) and have integration with jquery (such as the validation framework) which you can use if you create nVelocity widgets. Often this means you can develop custom widgets quicker in this way than building ascx ones from scratch.
    These are some good reasons to go with nVelocity widgets. I agree their is a learning curve though and it may take your devs a while to get up to speed but nVelocity isn't hard to pick-up and when you get used to it development is fairly quick.
    thanks
    Adam
  • IJsbeer
    Your solution would load the VM file from disk and execute it (if caching is off), which could be a minor performance penalty. But that shouldn't be noticable for site performance.

    Regarding a performance hit for multiple files: VM files (those in the original content script and external VM files) are cached as execution plans for around 5 minutes and are not subject to the Evolution cache duration policy (this cache cannot be disabled).  Additional files would be read at most once every five minutes.  This is a negligible performance impact and should not be a cause for a specific development approach.

    Representing optional functionality in external VM files will slightlyl *improve* performance because the parsing time and cache size of the execution plan for the critical path will be decreased.

All Replies
  • Hi, In 6.0 these kind of .net widgets were phased out in favour of the nvelocity ones. In 7.0 I believe the support has been removed completely. Even if it hasn't yet though it will be in 7.5 or 8 so I would strongly advise you against building your widgets in this way as they will be obsolete soon and need upgrading anway. There is a learning curve to nvelocity but once you have it widget development can be quicker and there are lots of api methods in core_v2_ that you can take advantage off and do a lot of the heaving lifting for you already. It is possible to build these widgets in visual studio still using a factory default provider to create a package of deployable widgets. This is the approach we use as we can keep all the widgets in source control and edit them in visual studio (as xml files) still but use nvelocity to program them. Here is how to do this: telligent.com/.../31468.widget-version-control.aspx

    hope this helps

    Adam

  • Thanks for your answer. But with Velocity you miss all the power from .NET / VS. No Debugger, IntelliSense, etc. It feels like going back to classic ASP.  Also it add's another abstraction, and hence a (minor) performance penalty, since the velocity code has te be 'compiled' to something .NET can render.

    The only suggested way to develop a widget is through Velocity? There are no other ways?  The user control way is in there a long long time. Meaning all developers switched to the Velocity approach?

  • For custom development one thing to consider is creation of custom widget extensions, which are nothing more than .NET code that expose functionality to widgets. If your development team is more comfortable with developing inside Visual Studio then you can try to make the widget/Velocity layer as this as possible by putting as much as you can into the extensions and layers below. You may find that this works better for you than trying to do as much as possible in widgets.

  • A couple of things in addition to Dan’s feedback which is spot on.
     
    First, code based widgets are not deprecated and still fully supported in 6.x, 7.1 and even in the next release, though widget studio is recommended.  As of now there is no plan to stop support for them yet. What isn’t supported any longer are the built in server controls used in versions of Telligent Community prior to 6(Chameleon).
     
    That being said if you choose to do ascx based widgets you must use the public in-process/REST API and not everything you can do in a studio widgets is exposed this way.  For example, you cannot get contextual content in a supported way like the blog post for a page you are on.
     
    In terms of debugging, as Dan pointed out its all .NET code so its still debuggable to an extent.  Meaning you can step through you’re the extensions you create just as you can from an ascx based server control.  In terms of Evolution API calls you can only step as deep as our API whether it’s a studio widget or ascx control.  Factor in server controls it’s the same.  And unless you are using server controls, you are just in-lining code similar to the way classic asp was(internal workings aside).  
     
    All that aside, you lose the ability to make tweaks and or adjustments to your core widgets from the UI which sounds ok until you found you missed something small in your code that is causing you problems and you need to do a deployment to fix it.  In addition all the widgets we ship are done with the widget studio so if you have any plans to customize them you will need to understand Velocity and how it works, or you will have to build any widget you want from scratch.  There is also no concept of importing ascx based widgets, maintaining resources specific to the widgets within the widget(you will need a custom resource file as well) or tying them to a specific theme.  
     
    Again, you can use ascx widgets and as long as they only use APIs they are fully supported, however I want to be sure you make a fully informed decision that isn’t necessarily based on the medium you want to develop on(which as also pointed out can still be visual studio.. that’s how we develop at Telligent in product and services)
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Dan Hounshell [mailto:bounce-diggerdanh@communities.telligent.com]
    Sent: Tuesday, February 26, 2013 6:49 AM
    To: bugsandissues@communities.telligent.com
    Subject: RE: [Bugs and Issues - Telligent Community] Develop from Visual Studio
     

    For custom development one thing to consider is creation of custom widget extensions, which are nothing more than .NET code that expose functionality to widgets. If your development team is more comfortable with developing inside Visual Studio then you can try to make the widget/Velocity layer as this as possible by putting as much as you can into the extensions and layers below. You may find that this works better for you than trying to do as much as possible in widgets.

  • Hi Patrick,

    Thanks for the clarification on the use of .net based widgets and sorry for the miss-information. I may have got confused when this was discussed a year or so ago. Perhaps I was mixing this up with the Chameleon controls support.

    Is is still ok to build widgets in this way then Patrick if it's easier or they already exist (perhaps from an upgrade)? or would you advise that  the widgets are upgraded to use nVelocity so they are 100% upgrade proof? It would be good to know for sure for things like upgrades and how best to approach them.

    With regard to putting most of the logic in plugins and being able to step into your plugin and debug in this way is what we tend to do. For me it follows more of an MVC pattern, with very little code and logic in your widget (mostly just mark-up and loops/variables) which is better and easier to maintain than your code being split between in .net controls (where there is a tendency to put bits of code all over the place). It is a shame that there is no intellisense through, hopefully that can be improved in some way in later releases.

    thanks

    Adam

  • It depends.. not straight forward but true. 
     
    We still consider ascx based widgets upgrade safe provided they use APIs… no chameleon or internal code.  This means you will have ample notice if this is going to change.  If your widgets fall under this then there is no immediate need to convert them unless you want to provide some of the features I mentioned, like in-site editing, portability, etc.  I also look at effort, if its an easy port then it may be worth doing just to get the benefits.  I am a fan of conversion..especially if you will be enhancing old functionality, it usually pays off in the long run since upkeep and support tends to be easier in the widget studio once you have the experience.
     
    For new development, I have not found a reason to use the ascx method.  The only one that comes to mind is a ui that cannot be altered for functional reasons.  There may be more, but I am yet to encounter one or be presented with one.
     
    I think your mindset of viewing it as MVC is right on.. provided you mean the compound pattern and not the product/framework J Really if you step back that is what this is
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Adam Seabridge [mailto:bounce-aseabridgethebuildingblockscouk@communities.telligent.com]
    Sent: Tuesday, February 26, 2013 8:16 AM
    To: bugsandissues@communities.telligent.com
    Subject: RE: [Bugs and Issues - Telligent Community] Develop from Visual Studio
     

    Hi Patrick,

    Thanks for the clarification on the use of .net based widgets and sorry for the miss-information. I may have got confused when this was discussed a year or so ago. Perhaps I was mixing this up with the Chameleon controls support.

    Is is still ok to build widgets in this way then Patrick if it's easier or they already exist (perhaps from an upgrade)? or would you advise that  the widgets are upgraded to use nVelocity so they are 100% upgrade proof? It would be good to know for sure for things like upgrades and how best to approach them.

    With regard to putting most of the logic in plugins and being able to step into your plugin and debug in this way is what we tend to do. For me it follows more of an MVC pattern, with very little code and logic in your widget (mostly just mark-up and loops/variables) which is better and easier to maintain than your code being split between in .net controls (where there is a tendency to put bits of code all over the place). It is a shame that there is no intellisense through, hopefully that can be improved in some way in later releases.

    thanks

    Adam

  • Thanks Patrick. Glad you agree on the MVC pattern, In summary then I think what you are saying is:

    • If you have existing ascx based widgets and they use the public apis, or rest apis then their is no real reason to upgrade them if they work ok now.
       
    • however If you have existing ascx based widgets that use either chameleon controls in them or use the private apis then you should upgrade them to nVelocity (you could switch them to use the public apis or rest, but it may be just as easy to write a plugin or use the widget api that exists instead).
       
    • If you are writing new widgets form scratch then create nvelocity widgets (if at all possible - and there is no need to change a ui that is difficult to change).

    IJsbeer - there are some benefits to using nvelocity widgets, some of which Patrick touched on:

    • Portability - nVelocity widgets and packages of widgets (factory default providers) can be exported/imported between different environments using just xml files (or in the case of factory default providers a dll & an xml file with the widgets exported in it). you can't do this with .ascx widgets.
       
    • Flexibility - nVelocity widgets can be enabled/disabled and the code can be viewed and tweaked in the control panel allowing you to debug or test things easier than if using ascx widgets. For this reason though we develop our in VS and use source control locally in case changes are made in the control panel and we need to roll-back.
       
    • Organisation & Visibility - nVelocity can be grouped together organised in the control panel. ascx widgets will not show up in the control panel which could confuse users of the site when they see other widgets listed and not the custom ones.
       
    • Labels/Text -  nVelocity widgets have their labels/text (resources) attached to them rather than being in a single resources file which means they can be updated and/or translated in the control panel without the need for a developer.
       
    • Modularisation - nVelocity widgets have all their additional files (such as JS) attached as tabs so it is easy to see what is included in each widget, In ascx widgets often the js is included lazily in the widget or in a bloated js file used by many other widgets. The plugins also encourage modularisation of code allowing for easier deployment of features / enhancements and bug fixes.
       
    • Re-use - the ootb widgets have a lot of code you can re-use (core_v2_xxx) and have integration with jquery (such as the validation framework) which you can use if you create nVelocity widgets. Often this means you can develop custom widgets quicker in this way than building ascx ones from scratch.


    These are some good reasons to go with nVelocity widgets. I agree there is a learning curve though and it may take your devs a while to get up to speed but nVelocity isn't hard to pick-up and when you get used to it development is fairly quick.
    thanks
    Adam
  • I think this is a pretty could summarization yes.
     
    I also would not be super concerned with the learning curve, especially if your .NET developers are primarily web developers.  The biggest challenge I have faced teaching it is getting people to simplify their thoughts around it.  At the end of the day its using HTML and javascript and then you add templating syntax, and there are only a handful of syntax items  to learn to be functional.
     
    Someone gave me the example once that creating a list in Velocity syntax was much harder than using a GridView which I took as a challenge. 
     
    The reality is by the time you setup the databinding, all the attributes, templating, etc you have actually done a good amount of work before you even do styling
     
    In velocity I believe it was 7 lines total( a for each loop), most of which was plain old html and included getting your data items, a header and footer.  9 with a no- data template.
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Adam Seabridge [mailto:bounce-aseabridgethebuildingblockscouk@communities.telligent.com]
    Sent: Tuesday, February 26, 2013 9:06 AM
    To: bugsandissues@communities.telligent.com
    Subject: RE: [Bugs and Issues - Telligent Community] Develop from Visual Studio
     

    Thanks Patrick. Glad you agree on the MVC pattern, In summary then I think what you are saying is:

    • If you have existing ascx based widgets and they use the public apis, or rest apis then their is no real reason to upgrade them if they work ok now.
       
    • however If you have existing ascx based widgets that use either chameleon controls in them or use the private apis then you should upgrade them to nVelocity (you could switch them to use the public apis or rest) but it may be just as easy to write a plugin or use the widget api that exists instead).
       
    • If you are writing new widgets form scratch then create nvelocity widgets if at all possible and there is no need to change a ui that is difficult to change.
    IJsbeer - there are some benefits to using nvelocity widgets, some of which Patrick touched on:
    • Portability - nVelocity widgets and packages of widgets (factory default providers) can be exported/imported between different environments using just xml files (or in the case of factory default providers a dll & an xml file with the widgets exported in it). you can't do this with .ascx widgets.
       
    • Flexibility - nVelocity widgets can be enabled/disabled and the code can be viewed and tweaked in the control panel allowing you to debug or test things easier than if using ascx widgets. For this reason though we develop our in VS and use source control locally in case changes are made in the control panel and we need to roll-back.
       
    • Organisation & Viability - nVelocity can be grouped together organised in the control panel. ascx widgets will not show up in the control panel which could confuse users of the site when they see other widgets listed and not the custom ones.
       
    • Labels/Text -  nVelocity widgets have their labels/text (resources) attached to them rather than being in a single resources file which means they can be updated and/or translated in the control panel without the need for a developer.
       
    • Modularisation - nVelocity widgets have all their additional files (such as JS) attached as tabs so it is easy to see what is included in each widget, In ascx widgets often the js is included lazily in the widget or in a bloated js file used by many other widgets. The plugins also encourage modularisation of code allowing for easier deployment of features / enhancements and bug fixes.
       
    • Re-use - the ootb widgets have a lot of code you can re-use (core_v2_xxx) and have integration with jquery (such as the validation framework) which you can use if you create nVelocity widgets. Often this means you can develop custom widgets quicker in this way than building ascx ones from scratch.
    These are some good reasons to go with nVelocity widgets. I agree their is a learning curve though and it may take your devs a while to get up to speed but nVelocity isn't hard to pick-up and when you get used to it development is fairly quick.
    thanks
    Adam
  • As stated, I'm new to Telligent development, but I'm stunned by the speed, amount and quality of the responses! Thanks a lot.

    Wat we need to archieve is a 'platform', meaning we will have several communities with the same look and feel. So the same widgets on the same place. The only difference should be the stylesheet en our site owners shouldn't be to free to change a lot (in terms of: focus on the content, not on the look and feel).

    So the portability of the 'widget-studio' way seems to be the way to go, but I don't want that anybody can change widgets via the widget studio. Changes should be done via our team and all need to be done in Source Control.

    For now we extended the 'widget to source control' way, which Adam pointed out. The extension is we strip out the 'body' of all widget XML to create a 'contentScript.html' file, headerScript.html, configuration.xml. With the initialization we will load all widget XML from disk, add the files to the proper way, and 'install' them in Telligent.

    This way we have a widget contains of several files, which all have the proper type. So we have Syntax Highlighting and all the good things Visual Studio provides us and hence all under TFS Sourc Control (instead of working within a 'CDATA" block for 1 XML file). We keep the widgets as thin as possible (thanks Dan), the same way we should treat a normal ASCX. The onlyl velocity I foresee is a 'foreach' for repeater kind of stuff. All other things we will do from C# code, so we have all the debugging stuff.
    We currently don't support additional CSS/JS files etc which should be placed within the filestorage. But in our case I would like to get rid of them anyway, because I would like 1 main site CSS and  JS file. This for maintenance reasons and it's also a big win for client performance.

    Via TFS we can automaticly deploy to our Development environment and stage it for automatic deploying to test, acceptance and production. So the automatic import of the widget XML's comes in fine here!

    So we've settled for the widget way, because it seems to be the most preferable and future proof way! We now are going to do the same trick for the theming, so for the most part we decide which widgets are in what place. Site owners should only have limited placeholders for customiziation.

  • I would like to see an example if you don’t mind…
     
    For example I am wondering what the logic is behind creating html files.  Is it just for Html intellisense?  If that’s the case just tell visual studio to use the Html Editor for*.vm files and you achieve the same thing.
     
    Then you can just reference them as external widget files from the original xml by calling $core_v2_widget.ExecuteFile(‘blah.vm’)
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: IJsbeer [mailto:bounce-IJsbeer@communities.telligent.com]
    Sent: Thursday, February 28, 2013 2:53 AM
    To: bugsandissues@communities.telligent.com
    Subject: RE: [Bugs and Issues - Telligent Community] Develop from Visual Studio
     

    As stated, I'm new to Telligent development, but I'm stunned by the speed, amount and quality of the responses! Thanks a lot.

    Wat we need to archieve is a 'platform', meaning we will have several communities with the same look and feel. So the same widgets on the same place. The only difference should be the stylesheet en our site owners shouldn't be to free to change a lot (in terms of: focus on the content, not on the look and feel).

    So the portability of the 'widget-studio' way seems to be the way to go, but I don't want that anybody can change widgets via the widget studio. Changes should be done via our team and all need to be done in Source Control.

    For now we extended the 'widget to source control' way, which Adam pointed out. The extension is we strip out the 'body' of all widget XML to create a 'contentScript.html' file, headerScript.html, configuration.xml. With the initialization we will load all widget XML from disk, add the files to the proper way, and 'install' them in Telligent.

    This way we have a widget contains of several files, which all have the proper type. So we have Syntax Highlighting and all the good things Visual Studio provides us and hence all under TFS Sourc Control. We keep the widgets as thin as possible (thanks Dan), the same way we should treat a normal ASCX. The onlyl velocity I foresee is a 'foreach' for repeater kind of stuff. All other things we will do from C# code, so we have all the debugging stuff.

    Via TFS we can automaticly deploy to our Development environment and stage it for automatic deploying to test, acceptance and production. So the automatic import of the widget XML's comes in fine here!

    So we've settled for the widget way, because it seems to be the most preferable and future proof way!

  • Also if you want syntax highlighting for NVelocity in Visual Studio, check out jonorossi.com/.../cvsi .

  • The solution for $core_v2_widget.ExecuteFile(‘blah.vm’) is indeed another aproach. It has the same purpose. The main advantage for 'our'  solution would be the widget XML contains all items within the XML. Your solution would load the VM file from disk and execute it (if caching is off), which could be a minor performance penalty. But that shouldn't be noticable for site performance.

    So to honestly answer your question: mainly because I wasn't familiar with the Executefile method :) In the end I think this solution is a (bit) cleaner. Mainly because we only want 1 'vm' file per widget, we can maintain a strict naming convention for the inclusion within the widget XML file.

    @Alex: Thx! But it doesn't seem to work for VS2012. Is there a solution for VS2012? Occording to this thread is should be possible, but it's never released: http://stackoverflow.com/questions/14714549/visual-studio-2012-colorizer-and-intellisense-for-the-nvelocity-language

    To be more technical., we are devvers after all:

    /// <summary>
            /// Function called at initialisation stage
            /// </summary>
            public void Initialize()
            {
           
                // Loop through all xml files within the directory
                foreach (FileInfo widgetFile in dirInfo.GetFiles("*.xml", SearchOption.AllDirectories))
                {
                    // Only load widget if xml file is same name as its directory (to prevent configuration.xml from rendering as widget)
                    if ((widgetFile.Name.Replace(widgetFile.Extension, "") == widgetFile.Directory.Name) )
                    {
                        FactoryDefaultScriptedContentFragmentProviderFiles.AddUpdateDefinitionFile(
                            this,
                            widgetFile.Name,
                            GetWidgetConfigStream(widgetFile)
                            );
                    }
                }
            }

     /// <summary>
            /// Get Stream for the given xml file with the subnodes replaces by according external files
            /// </summary>
            /// <param name="widgetFile">The widget xml file</param>
            /// <returns>The Stream</returns>
            public Stream GetWidgetConfigStream(FileInfo widgetFile)
            {
                // Create XmlDocument of the provided file
                XmlDocument doc = new XmlDocument();
                doc.Load(widgetFile.OpenRead());

                // List al nodes under /scriptedContentFragments/scriptedContentFragment/
                XmlNodeList elements = doc.SelectNodes("//scriptedContentFragments//scriptedContentFragment/*");
                foreach (XmlNode node in elements)
                {
                    // Check if a file exist with the current node name as filename. All files are loaded except .less files
                    string[] files = Directory.GetFiles(widgetFile.DirectoryName, node.Name + ".*").Where(name => !name.EndsWith(".less")).ToArray();
                    
                    if (files.Length > 0 )
                    {
                        using (StreamReader sr = new StreamReader(files.First()))
                        {
                            // replace node innerXml by the content of the first file with the node name as filename
                            node.InnerXml = string.Format("<![CDATA[{0}]]>", sr.ReadToEnd());
                        }
                    }
                }

                // Create stream from XmlDocument
                using (MemoryStream xmlStream = new MemoryStream())
                {
                    doc.Save(xmlStream);

                    xmlStream.Flush();
                    xmlStream.Position = 0;

                    return xmlStream;
                }
            }

  • IJsbeer
    Your solution would load the VM file from disk and execute it (if caching is off), which could be a minor performance penalty. But that shouldn't be noticable for site performance.

    Regarding a performance hit for multiple files: VM files (those in the original content script and external VM files) are cached as execution plans for around 5 minutes and are not subject to the Evolution cache duration policy (this cache cannot be disabled).  Additional files would be read at most once every five minutes.  This is a negligible performance impact and should not be a cause for a specific development approach.

    Representing optional functionality in external VM files will slightlyl *improve* performance because the parsing time and cache size of the execution plan for the critical path will be decreased.