Exemple #1
0
        internal static bool BuildUiPreview(string uiCode)
        {
            const string FileName = "UiPreviewEffect";

            uiCode = "#region UICode\r\n" + uiCode + "\r\n#endregion\r\n";

            // Generate code
            UIElement[] UserControls = UIElement.ProcessUIControls(uiCode);

            string SourceCode =
                ScriptWriter.UsingPartCode +
                ScriptWriter.NamespacePart(FileName) +
                ScriptWriter.EffectPart(UserControls, FileName, string.Empty, "UI PREVIEW - Does NOT Render to canvas", string.Empty, EffectFlags.None, EffectRenderingSchedule.DefaultTilesForCpuRendering) +
                ScriptWriter.PropertyPart(UserControls, FileName, string.Empty, 0, string.Empty) +
                ScriptWriter.SetRenderPart(UserControls, true, false) +
                ScriptWriter.RenderLoopPart(UserControls) +
                uiCode +
                ScriptWriter.EmptyCode +
                ScriptWriter.EndPart();

            userScriptObject = null;
            // Compile code
            try
            {
                result = cscp.CompileAssemblyFromSource(param, SourceCode);

                if (result.Errors.HasErrors)
                {
                    return(false);
                }

                userAssembly = result.CompiledAssembly;
                foreach (Type type in userAssembly.GetTypes())
                {
                    if (type.IsSubclassOf(typeof(PropertyBasedEffect)) && !type.IsAbstract)
                    {
                        userScriptObject = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(null);
                        return(true);
                    }
                }
            }
            catch
            {
            }
            return(false);
        }
Exemple #2
0
        internal static bool BuildFullPreview(string scriptText)
        {
            const string FileName = "PreviewEffect";

            // Generate code
            UIElement[] UserControls = UIElement.ProcessUIControls(scriptText);

            string SourceCode =
                ScriptWriter.UsingPartCode +
                ScriptWriter.NamespacePart(FileName) +
                ScriptWriter.EffectPart(UserControls, FileName, string.Empty, FileName, string.Empty, EffectFlags.None, EffectRenderingSchedule.DefaultTilesForCpuRendering) +
                ScriptWriter.PropertyPart(UserControls, FileName, "FULL UI PREVIEW - Temporarily renders to canvas", 0, string.Empty) +
                ScriptWriter.SetRenderPart(UserControls, true, preRenderRegex.IsMatch(scriptText)) +
                ScriptWriter.RenderLoopPart(UserControls) +
                ScriptWriter.UserEnteredPart(scriptText) +
                ScriptWriter.EndPart();

            exceptionMsg     = null;
            userScriptObject = null;
            // Compile code
            try
            {
                result = cscp.CompileAssemblyFromSource(param, SourceCode);

                if (result.Errors.HasErrors)
                {
                    return(false);
                }

                userAssembly = result.CompiledAssembly;
                foreach (Type type in userAssembly.GetTypes())
                {
                    if (type.IsSubclassOf(typeof(PropertyBasedEffect)) && !type.IsAbstract)
                    {
                        userScriptObject = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(null);
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                exceptionMsg = ex.Message;
            }
            return(false);
        }
Exemple #3
0
        internal static bool BuildUiPreview(string uiCode)
        {
            builtEffect = null;

            const string FileName = "UiPreviewEffect";

            uiCode = "#region UICode\r\n" + uiCode + "\r\n#endregion\r\n";

            UIElement[] UserControls = UIElement.ProcessUIControls(uiCode, ProjectType.Effect);

            string SourceCode =
                ScriptWriter.UsingPartCode(ProjectType.Effect) +
                ScriptWriter.NamespacePart(FileName, ProjectType.Effect) +
                ScriptWriter.EffectPart(UserControls, FileName, string.Empty, "UI PREVIEW - Does NOT Render to canvas", string.Empty, EffectFlags.None, EffectRenderingSchedule.DefaultTilesForCpuRendering) +
                ScriptWriter.PropertyPart(UserControls, FileName, string.Empty, HelpType.None, string.Empty, ProjectType.Effect) +
                ScriptWriter.RenderLoopPart(UserControls) +
                uiCode +
                ScriptWriter.EmptyCode +
                ScriptWriter.EndPart();

            Assembly assembly = CreateAssembly(SourceCode, false);

            if (assembly == null)
            {
                return(false);
            }

            foreach (Type type in assembly.GetTypes())
            {
                if (type.IsSubclassOf(typeof(PropertyBasedEffect)) && !type.IsAbstract)
                {
                    builtEffect = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(null);
                    return(true);
                }
            }

            return(false);
        }
Exemple #4
0
        internal static bool BuildFullPreview(string scriptText)
        {
            builtEffect = null;

            const string FileName = "PreviewEffect";

            UIElement[] UserControls = UIElement.ProcessUIControls(scriptText, ProjectType.Effect);

            string SourceCode =
                ScriptWriter.UsingPartCode(ProjectType.Effect) +
                ScriptWriter.NamespacePart(FileName, ProjectType.Effect) +
                ScriptWriter.EffectPart(UserControls, FileName, string.Empty, FileName, string.Empty, EffectFlags.None, EffectRenderingSchedule.DefaultTilesForCpuRendering) +
                ScriptWriter.PropertyPart(UserControls, FileName, "FULL UI PREVIEW - Temporarily renders to canvas", HelpType.None, string.Empty, ProjectType.Effect) +
                ScriptWriter.SetRenderPart(UserControls, true, preRenderRegex.IsMatch(scriptText)) +
                ScriptWriter.RenderLoopPart(UserControls) +
                ScriptWriter.UserEnteredPart(scriptText) +
                ScriptWriter.EndPart();

            Assembly assembly = CreateAssembly(SourceCode, false);

            if (assembly == null)
            {
                return(false);
            }

            foreach (Type type in assembly.GetTypes())
            {
                if (type.IsSubclassOf(typeof(PropertyBasedEffect)) && !type.IsAbstract)
                {
                    builtEffect = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(null);
                    return(true);
                }
            }

            return(false);
        }