Hi
First of all: can c# functions (external) be added directly in Content or do they have to be called from XSLT functions and then XSLT fn added to the page in Content.
Now about XslLoadException
I'm teaching new guys to work with Composite C1 and we are on C1 functions.
The function c# function Detects Debug mode and if in debug mode we'll serve *.max.js and
*.max.css files (not minimized/minimified/optimized), otherwise we are serving .js and .css
(obfuscated/minimized for page-speed)
c# function in App_Code/HolisticWare/Optimizations/
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Reflection; using System.Diagnostics; using System.Configuration; namespace HolisticWare.Optimizations { ///<summary>/// Implementation of Debug mode detection for ASP.net applications.////// HolisticWare team uses this class for detecting Debug mode in Composite C1/// Composite C1 Console +/ Functions +/ C3 Functions +/ Add external function /// for type paste:/// HolisticWare.Optimizations.Configuration.DebugModeDetection/// then select methods to use.////// Note: ///+ Composite C1 XSLT function that uses all methods for detecting/// HolisticWare.Optimizations.DebugModeDetection.xslt///+ DebugMacroDefined - most accurate (in Release mode in Visual Studio other/// methods return true, meaning it is Debug mode)///+ when using in WebApplications after copying to App_Code folder set /// Build Action = None. Otherwise Compilation erros will occur//////<see cref="holisticware webapps vs websites"/>///<see cref="http://docs.composite.net/ASP-NET/CSharpFunctions/Creating-External-C-Functions"/>///<see cref="http://docs.composite.net/ASP-NET/CSharpFunctions/Using-C-Functions"/>///<see cref="http://docs.composite.net/XSLT/XSLTFAQ?q=How+to+run+CSharp+function+in+XSLT%3F"/>///</summary>publicclass DebugModeDetection { publicstaticreadonlybool HttpContextDebuggingEnabled; publicstaticreadonlybool AssemblyExecutingDebuggableAttributeApplied; publicstaticreadonlybool DebuggerAttached; publicstaticreadonlystring WebConfigDebug; publicstaticreadonlybool DebugMacroDefined; static DebugModeDetection() { //=====================================================================================// property basically encapsulates the web.config setting// It doesn't actually take the page-level debug directive into account. HttpContextDebuggingEnabled = HttpContext.Current.IsDebuggingEnabled; Debug.WriteLine ( "HttpContextDebuggingEnabled = {0}" , HttpContextDebuggingEnabled.ToString() ); //=====================================================================================//=====================================================================================// take page-level debug directive into account: check if the DebuggableAttribute is // applied on the current assembly AssemblyExecutingDebuggableAttributeApplied = Assembly.GetExecutingAssembly().IsDefined(typeof(DebuggableAttribute), false); Debug.WriteLine ( "AssemblyExecutingDebuggableAttributeApplied = {0}" , AssemblyExecutingDebuggableAttributeApplied.ToString() ); //=====================================================================================//===================================================================================== DebuggerAttached = Debugger.IsAttached; Debug.WriteLine ( "DebuggerAttached = {0}" , DebuggerAttached.ToString() ); //=====================================================================================//===================================================================================== WebConfigDebug = ConfigurationSettings.GetConfig("system.web/compilation").ToString(); Debug.WriteLine ( "WebConfigDebug = {0}" , WebConfigDebug.ToString() ); //=====================================================================================//=====================================================================================#if DEBUG DebugMacroDefined = true; Debug.WriteLine ( "DebugMacroDefined = {0}" , DebugMacroDefined.ToString() ); #endif//=====================================================================================return; } ///<summary>/// Use this one if working from Visual Studio - differs Debug and Release///</summary>///<returns></returns>publicstaticbool IsHttpContextDebuggingEnabled() { return HttpContextDebuggingEnabled; } publicstaticbool IsAssemblyExecutingDebuggableAttributeApplied() { return AssemblyExecutingDebuggableAttributeApplied; } publicstaticbool IsDebuggerAttached() { return DebuggerAttached; } publicstaticbool IsDebugMacroDefined() { return DebugMacroDefined; } } }
I have added (I call it imported) 4 methods as external c# functions in Composite C1Console, but could not add any of those fncts to some page in Content view.
To solve that I decided (and because of academic sample for our teammates) to call those functions from XSLT function wit MS scripting....
XSLT fn:
<?xmlversion="1.0"encoding="UTF-8"?><xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:in="http://www.composite.net/ns/transformation/input/1.0"xmlns:lang="http://www.composite.net/ns/localization/1.0"xmlns:f="http://www.composite.net/ns/function/1.0"xmlns="http://www.w3.org/1999/xhtml"xmlns:msxsl="urn:schemas-microsoft-com:xslt"xmlns:user="urn:my-scripts"exclude-result-prefixes="xsl in lang f"><!-- Docummentation.MarkDown.Begin =============================================================================== ## Composite C1 Debug Mode Detection (for runtime [page] speed optimizations) * name: HolisticWare.Optimizations.DebugModeDetection.xslt * namespace: HolisticWare.Optimizations.DebugModeDetection * description: Detection of the Debug mode, so no compressed css and js files are served (serving .max.js, .max.css). In Release mode compressed/minified/minimized js and css files are served (.js, .css) * url refrences sample: []() documentation: * [http://docs.composite.net/ASP-NET/CSharpFunctions/Creating-External-C-Functions](http://docs.composite.net/ASP-NET/CSharpFunctions/Creating-External-C-Functions) * [http://docs.composite.net/ASP-NET/CSharpFunctions/Using-C-Functions](http://docs.composite.net/ASP-NET/CSharpFunctions/Using-C-Functions) * author: HolisticWare, [http://holisticware.net](http://holisticware.net) Miljenko Cvjetko * licence: MIT [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT) ### html sample (starting point) ### Usage Composite C1 - Function <f:function name="HolisticWare.Optimizations.DebugModeDetection" xmlns:f="http://www.composite.net/ns/function/1.0" > </f:function> Parameter description: =============================================================================== Docummentation.MarkDown.End --><msxsl:scriptlanguage="C#"implements-prefix="user"><msxsl:assemblyname="System.Web"/><msxsl:usingnamespace="System.Web"/><msxsl:usingnamespace="HolisticWare.Optimizations"/><![CDATA[ public bool IsHttpContextDebuggingEnabled() { return DebugModeDetection.IsHttpContextDebuggingEnabled(); } public bool IsAssemblyExecutingDebuggableAttributeApplied() { return DebugModeDetection.IsAssemblyExecutingDebuggableAttributeApplied(); } public bool IsDebuggerAttached() { return DebugModeDetection.IsDebuggerAttached(); } public bool IsDebugMacroDefined() { return DebugModeDetection.IsDebugMacroDefined(); } ]]></msxsl:script><xsl:templatematch="/"><html><head><!-- markup placed here will be shown in the head section of the rendered page --></head><body><!-- Debugging output: --><div> HttpContextDebuggingEnabled = <xsl:value-ofselect="user:IsHttpContextDebuggingEnabled()"/><br/> AssemblyExecutingDebuggableAttributeApplied = <xsl:value-ofselect="user:IsAssemblyExecutingDebuggableAttributeApplied()"/><br/> DebuggerAttached = <xsl:value-ofselect="user:IsDebuggerAttached()"/><br/> DebugMacroDefined = <xsl:value-ofselect="user:IsDebugMacroDefined()"/></div><!-- Optimization.Speed: Javascript at the end before closing <body> tag in order to defer javascript loading and executing (non html generating javascript). --></body></html></xsl:template></xsl:stylesheet>
In XSLT preview I get
XslLoadExceptionThe type or namespace 'HolisticWare' could not be found (are you missing using directive or assembly reference?)
Do I need global:: prefix or something else?!
Thanks
mel