Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 4
0
        internal static bool BuildFileType(string fileTypeCode, bool debug)
        {
            builtFileType = null;

            const string projectName = "MyFileType";

            UIElement[] userControls = UIElement.ProcessUIControls(fileTypeCode, ProjectType.FileType);

            string sourceCode =
                ScriptWriter.UsingPartCode(ProjectType.FileType) +
                ScriptWriter.NamespacePart(projectName, ProjectType.FileType) +
                ScriptWriter.FileTypePart(projectName, "\".foo\"", "\".foo\"", false, projectName) +
                ScriptWriter.ConstructorPart(debug) +
                ScriptWriter.PropertyPart(userControls, projectName, string.Empty, HelpType.None, string.Empty, ProjectType.FileType) +
                ScriptWriter.FileTypePart2(userControls) +
                ScriptWriter.UserEnteredPart(fileTypeCode) +
                ScriptWriter.EndPart();

            Assembly assembly = CreateAssembly(sourceCode, debug);

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

            Intelli.UserDefinedTypes.Clear();

            foreach (Type type in assembly.GetTypes())
            {
                if (type.IsSubclassOf(typeof(PropertyBasedFileType)) && !type.IsAbstract)
                {
                    builtFileType = (FileType)type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0].Invoke(null);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 5
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);
        }