internal static bool Build(string scriptText, bool debug) { // Generate code string SourceCode = ScriptWriter.UsingPartCode + ScriptWriter.prepend_code + ScriptWriter.SetRenderPart(Array.Empty <UIElement>(), false, preRenderRegex.IsMatch(scriptText)) + ScriptWriter.UserEnteredPart(scriptText) + ScriptWriter.append_code; exceptionMsg = null; userScriptObject = null; // Compile code try { param.IncludeDebugInformation = debug; result = cscp.CompileAssemblyFromSource(param, SourceCode); param.IncludeDebugInformation = false; lineOffset = (SourceCode.Substring(0, SourceCode.IndexOf("#region User Entered Code", StringComparison.Ordinal)) + "\r\n").CountLines(); if (result.Errors.HasErrors) { return(false); } userAssembly = result.CompiledAssembly; Intelli.UserDefinedTypes.Clear(); foreach (Type type in userAssembly.GetTypes()) { if (type.IsSubclassOf(typeof(Effect)) && !type.IsAbstract) { userScriptObject = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(null); Intelli.UserScript = type; } else if (type.DeclaringType != null && type.DeclaringType.FullName.StartsWith("PaintDotNet.Effects.UserScript", StringComparison.Ordinal) && !Intelli.UserDefinedTypes.ContainsKey(type.Name)) { Intelli.UserDefinedTypes.Add(type.Name, type); } } return(userScriptObject != null); } catch (Exception ex) { exceptionMsg = ex.Message; } return(false); }
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); }
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); }
internal static bool Build(string scriptText, bool debug) { builtEffect = null; string SourceCode = ScriptWriter.UsingPartCode(ProjectType.Effect) + ScriptWriter.prepend_code + ScriptWriter.ConstructorPart(debug) + ScriptWriter.SetRenderPart(Array.Empty <UIElement>(), false, preRenderRegex.IsMatch(scriptText)) + ScriptWriter.UserEnteredPart(scriptText) + ScriptWriter.append_code; Assembly assembly = CreateAssembly(SourceCode, debug); if (assembly == null) { return(false); } Intelli.UserDefinedTypes.Clear(); foreach (Type type in assembly.GetTypes()) { if (type.IsSubclassOf(typeof(Effect)) && !type.IsAbstract) { builtEffect = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(null); Intelli.UserScript = type; } else if (type.DeclaringType != null && type.DeclaringType.FullName.StartsWith(Intelli.UserScriptFullName, StringComparison.Ordinal) && !Intelli.UserDefinedTypes.ContainsKey(type.Name)) { Intelli.UserDefinedTypes.Add(type.Name, type); } } return(builtEffect != null); }
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); }