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AgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH8AAP//AAD//wAA/38AAP9/AAD/fwAA/38AAP9/AAD/fwAA/38AAP8AAAD/gIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAfwAA//8AAP//AAD/fwAA/38AAP9/AAD/fwAA/38AAP9/AAD/fwAA/wAAAP+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAAB/AAD//wAA//8AAP9/AAD/fwAA/38AAP9/AAD/fwAA/38AAP9/AAD/AAAA/4CAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH8AAP//AAD//wAA/38AAP9/AAD/fwAA/38AAP9/AAD/fwAA/38AAP8AAAD/gIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAfwAA//8AAP//AAD/fwAA/38AAP9/AAD/fwAA/38AAP9/AAD/fwAA/wAAAP+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAfwAA/38AAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/gIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAAB/f3//nM7//5zO//+czv//nM7//5zO//+czv//v7+//wAAAP+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH9/f/+czv//nM7//5zO//+czv//nM7//5zO//+/v7//AAAA/4CAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAAB/f3//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+/v7//AAAA/4CAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAf39//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//7+/v/8AAAD/gIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH9/f/+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//7+/v/8AAAD/gIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAf39//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//v7+//wAAAP+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH9/f/+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+/v7//AAAA/4CAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAf39//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+/v7//AAAA/4CAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH9/f/+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//7+/v/8AAAD/gIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAf39//5zO//+czv//v7+//7+/v/+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//v7+//wAAAP+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH9/f/+czv//nM7//7+/v/8AAAD/AAAA/5zO//+czv//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//+/v7//AAAA/4CAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAf39//5zO//+/v7//AAAA/4CAAAB/f3//nM7//5zO//+czv//nM7//5zO//+czv//nM7//5zO//9/f3//nM7//7+/v/8AAAD/gIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH9/f/+czv//v7+//wAAAP+AgAAAgIAAAH9/f/+czv//nM7//39/f/+czv//nM7//39/f/+czv//v7+//wAAAP+czv//v7+//wAAAP+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAf39//39/f/8AAAD/gIAAAICAAACAgAAAf39//5zO//+/v7//AAAA/5zO//+/v7//AAAA/5zO//+/v7//AAAA/5zO//+/v7//AAAA/4CAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAAB/f3//nM7//7+/v/8AAAD/nM7//7+/v/8AAAD/nM7//7+/v/8AAAD/f39//39/f/+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH9/f/+czv//v7+//wAAAP+czv//v7+//wAAAP+czv//v7+//wAAAP+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAf39//5zO//+/v7//AAAA/5zO//+/v7//AAAA/39/f/9/f3//gIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAAB/f3//nM7//7+/v/8AAAD/f39//39/f/+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH9/f/+czv//v7+//wAAAP+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAf39//5zO//+/v7//AAAA/4CAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAAB/f3//nM7//7+/v/8AAAD/gIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH9/f/+czv//v7+//wAAAP+AgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAH9/f/9/f3//gIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAAgIAAAICAAACAgAAA///////////+AD///gA///4AP//+AD///gA///8Af///AH///wB///4AP//8AD//+AAf//gAH//wAB//8AAP/+AAD//gAA//wAAP/8IAD/+GAA//jgAP//4AH//+AH///gD///4H///+H////h////4f///+H////z////////8=' Paste_b64 ←'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAAeFBMVEUAAAB7e3ucnJy1tbXOpUrOpVLOrVrnzpz39/f////OrWPn5+fOzs7WtWvWvXuEhITnzqXn1qWUlJRaWlq1nGO9zt6MjIyle0KlhDmljFqlpaXWrWOthEKtlFrW1tbexoTnzpS1hDG1lGOUc0KMYxjv7++9vb3GrXO+vRrUAAAAAXRSTlMAQObYZgAAAKNJREFUeF6NzVcOwyAQRVHTi3tL73X/OwzjeISxiZT7hXT0huRbCSVhV4hQSskDXhOo66pqCSFtp5QK4FwUDXTIiwCqPLfv7nbcbqScgXUxjDKGYAcwY2kGEgGdGZAlmJMGQZAeUpa9EKR04HumuwGkC6DHjFkBKADhYFI5ghBREFBwygPnkcVlz3kchiKn1ndoscCY0b4Z9Jj+a/H7j6aclnwANmEWNaPqN4UAAAAASUVORK5CYII=' Print_b64 ←'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAEUUlEQVR4nN2UTWwUZRzGf/O+szPUlo8tRaGK3aQpmJZ+kTSGSEQ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euTweMW11/3RaDR+JRgcfWnz99f/G2B68pnnl5tMGWsAurp9dHX7Eoqz7KmV8YWByVEQXyZfeG7Xo2+9uc+/5UcPr1t+dWm9oiiH273n/hDrf8ZT0HQzIMec0yX/PvJo7dcefKDqjXi77rn/PRtX8Lad/U+z2TKvYPacb8zU4eDFi691drS/tWJl2SOyLOcAnDvbetcjNff9CVC+c9fmwl3PPt5G9FJGSfudEuhl04MPVO2L/9/ywwfXyJKELEmMjo7s3/rQD1+4719/8Ms4T5Yknnmq9o4fP3zf15J5p042//6Xv3jkQE9355NxXkHB7Ovjdnc9+3jHlWC6IgeSyes91+kPDLqBof977ZXH4nxJlpFkmbHxsTPvvXuor+1c60gg4H87zpdiB/v/uL/qufHw+NHAkL/u8NsHpt2oLkXT5YAGhIk6GInJyYCJ6FTqXvndnvZXfrfnUeAxJkINhBiWZTk7MDjYGDd2od/XaLPZb9Y0bXhoKJDI7o3f/vq3gDFgPNanGmtrRMNG4xI58Ff6S9P/AxzSkKqndbIyAAAAAElFTkSuQmCC' _←⍬ _,←'' _,←L,'' NewWindow←_ _←⍬ _,←'' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,'' sample1←_ _←⍬ _,←'' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,'' sample2←_ _←⍬ _,←'' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,' ' _,←L,'' sample3←_ ⎕ex¨ 'L' '_' ⍝ === End of variables definition === (⎕IO ⎕ML ⎕WX)←1 3 3 ∇ cursor←CursorFromBase64String base64String;imageBytes;MS;⎕USING ⍝ Convert a Base64String to a cursor. ⎕USING←'System.IO,mscorlib.dll' 'System,mscorlib.dll' 'System.Windows,WPF/PresentationCore.dll' ⍝ Convert Base64 String to byte[] imageBytes←Convert.FromBase64String(⊂base64String) ⍝ Create a new MemoryStream with the byte[] MS←⎕NEW MemoryStream(⊂imageBytes) ⍝ Create the icon cursor←⎕NEW Input.Cursor MS ⍝ Erase the MemoryStream MS.Close ⋄ MS.Dispose ⋄ MS←⎕NULL ∇ ∇ DemoSample3;imgNames ⍝ Parse the xaml of the variable sample3 win←FixSimpleXaml sample3 ⍝ Get the names of all the 'Image' object that has been fixed in rootObj imgNames←{((⊂'Image')≡¨(⍵.⍎¨(⍵.⎕NL-9)).GetType.Name)/(⍵.⎕NL-9)}win ⍝ Set the Source of all the 'Image'. Each 'Image' must have a Base64 variable of the same name. win{(⍺.⍎⍵).Source←ImageFromBase64String⍎⍵}¨imgNames ⍝ Fix manually the Icon of the main window. win.Icon←ImageFromBase64String Settings_b64 ⍝ Fix manually the Cursor of the main window. win.Cursor←CursorFromBase64String HandCursor_b64 ⍝ Set Routed Events on the whole Window for ClickEvent when a MenuItem or a Button are clicked. ⎕USING←'System.Windows,WPF/PresentationCore.dll' 'System.Windows.Controls.Primitives,WPF/PresentationFramework.dll' win.AddHandler(Controls.MenuItem.ClickEvent)(⎕NEW RoutedEventHandler(⎕OR'__EventHandler')) win.AddHandler(ButtonBase.ClickEvent)(⎕NEW RoutedEventHandler(⎕OR'__EventHandler')) ⍝ Show the window. win.Show ∇ ∇ obj DispatchDelegate action;delegate;⎕USING ⍝ Function to write asynchronously to the UI thread from another thread. ⍝ The calling thread does not wait for the operation to finish. ⍝ obj = UI Object that you want to write to from another thread ⍝ action = Line to execute in the UI thread. Use '⋄' to write multiple lines. :Trap 0 ⎕USING←'System,System.dll' 'System.Windows.Threading,WPF/WindowsBase.dll' ⍝ Create a function (⍙Delegate) with the 'action' to execute in the UI thread. ⍝ The function will be executed where 'DispatchDelegate' is called and not where ⍝ 'DispatchDelegate' is located. delegate←(⎕IO⊃⎕RSI).⎕OR(⎕IO⊃⎕RSI).⎕FX'⍙Delegate'action'⎕EX ''⍙Delegate''' ⍝ Get a 'Dispatcher' from the UI object. That way we are sure to have the right UI thread. ⍝ Use the method '.Invoke' instead of '.BeginInvoke' for synchronous call. {}obj.Dispatcher.BeginInvoke(DispatcherPriority.Normal(⎕NEW Action delegate)) :Else ⎕←'Error DispatchDelegate: ',action ⍝ Returns the Last Error :If 90=⎕EN ⎕←'EXCEPTION: ',⎕EXCEPTION.Message :Else ⎕←(1⊃⎕DM),': ',(2⊃⎕DM) :EndIf :End ∇ ∇ base64String←FileToBase64String fileName;bytes;⎕USING ⍝ Converts a file to a Base64 String. ⎕USING←'System,mscorlib.dll' ⍝ Read the file bytes←IO.File.ReadAllBytes(⊂,fileName) ⍝ Convert to a Base64 string base64String←Convert.ToBase64String(⊂bytes) ∇ ∇ rootObj←FixSimpleXaml xamlString;names;⎕USING ⍝ Parse simple and correctly formed Xaml that contains only names to fix (no events). ⍝ Each named element(s) object will be attached to rootObject. ⍝ You can see the list of attached elements by doing rootObject.⎕NL -9 ⍝ It is recommended to do not name the root object in the xaml (to prevent a recursive call). ⍝ For 3rd party dll, ⎕USING must be properly initiated before calling this function. ⍝ For Xaml with event callbacks and error trapping see the function: FixXaml. ⍝ ⍝ xamlString = Vector of Characters representing a XAML string ⍝ rootObj = WPF Root Element Object if no error ⍝ = ⎕NULL if error :Trap 0 ⍝ Parse the simple Xaml and obtain the root element object: ⎕USING,←⊂'System.Windows.Markup,WPF/PresentationFramework.dll' ⍝ was ⎕USING←' before rootObj←XamlReader.Parse(⊂xamlString) ⍝ Extract the names beginning with 'x:Name' or 'Name' names←{{(,⊃0≠⍴¨⍵)/⍵}{1⊃(((⍵[;1]∊⊂'x:Name')∨(⍵[;1]∊⊂'Name'))/⍵[;2]),⊂''}¨(⎕XML ⍵)[;4]}xamlString ⍝ Assign the value of each names to the root object: :If 0≠⍴names rootObj{⍎'⍺.',⍵,'←⍺.FindName(⊂,⍵)'}¨names :Else ⍝ Do nothing, there is no names. :End :Else ⍝ There is an error. rootObj←⎕NULL :EndTrap ∇ ∇ rootObj←FixXaml xamlString;attribs;caller;data;err;event;events;expr;inter;name;names;ref ⍝ Creates a WPF Object From an APL Character Vector Representing XAML. ⍝ Each named element(s) object will be attached to rootObject. ⍝ You can see the list of attached elements by doing rootObject.⎕NL -9 ⍝ The callback functions of events must begin with '__' (ex.: Click="__Button_Click") ⍝ For 3rd party dll, ⎕USING must be properly initiated before calling this function. ⍝ If there is an error parsing the Xaml, the function will return ⎕NULL with an explanation of the error. ⍝ Parts of code is taken from Dyalog. ⍝ ⍝ xamlString = Vector of Characters representing a XAML string ⍝ rootObj = WPF Root Element Object if no error ⍝ = ⎕NULL (explanation of error) if error ⍝ ⍝ If an Element has an event attribute that begins with '__' and is named, it will be fixed. ⍝ If an Element has an event attribute that begins with '__' and is not named, it will not be fixed and make a warning. ⍝ If an Element has an event attribute that does not begins with '__', it will make an error and return a ⎕NULL rootObj. ⍝ Function of an event attribute must be defined in the WS otherwise it will not be fixed and make a warning. ⍝ Root element with an event must be named, otherwise it is recommended to be nameless. ⍝ Root element name is removed in all cases. Use the rootObj variable directly to access its properties/methods. :Trap 0 ⍝ Check if Valid XML ⍝ The following line will bug with an explanation if there is a syntax error in xamlString. ⎕USING∪←⊂'System.Xml,System.Xml.dll' (⎕NEW XmlDocument).LoadXml(⊂xamlString) ⍝ The string is valid XML. Clean-it before 'compiling'. data←⎕XML xamlString ⍝ Convert the characters to APL representation of Xml attribs←data[;4] ⍝ Attributes of all the nodes names←{1⊃(((⍵[;1]∊⊂'x:Name')∨(⍵[;1]∊⊂'Name'))/⍵[;2]),⊂''}¨attribs ⍝ Find all 'x:Name' and 'Name' attributes events←⊃⍪/names{(⊂⍺),((⊂'__')≡¨2↑¨⊃¨⍵[;2])⌿⍵}¨attribs ⍝ Events are all attributes with values beginning with '__' data[;4]←{(~(⊂'__')≡¨2↑¨⊃¨⍵[;2])⌿⍵}¨attribs ⍝ Remove the events: attribute definition beginning with '__' data[1;4]←⊂{(~(⊂'x:Class')≡¨7↑¨⊃¨⍵[;1])⌿⍵}⊃data[1;4] ⍝ Remove the x:Class attribute if present in first node xamlString←⎕XML data ⍝ Convert the APL representation of Xml to characters :Else ⍝ There is an Error. Exit. →ERROR :EndTrap ⍝ Obtain the Root Element Object of the clean-up XAML String. ⍝ You can get an error here if, for example, there is an event that does not begin with '__' and was not remove in Xaml Clean-up. :Trap 0 ⎕USING∪←⊂'System.Windows.Markup,WPF/PresentationFramework.dll' ⍝ was ⎕USING←' before rootObj←XamlReader.Parse(⊂xamlString) ⍝ ↓↓↓ Alternative way of doing the same thing. ⍝ ⎕USING∪ ← '' 'System.IO' 'System.Xml,system.xml.dll' 'System.Windows,WPF/PresentationFramework.dll' 'System.Windows.Markup' ⍝ rootObj ← XamlReader.Load ⎕NEW XmlTextReader (⎕NEW StringReader (⊂xamlString)) rootObj.∆Events←events ⍝ Optional: List the events in the property ∆Events :Else ⍝ There is an error. Exit. →ERROR :EndTrap ⍝ Fix the events of the rootObj before removing its name: ⍝ Will bug if the rootObj does not have a name. :Trap 0 :If 1∊events[;1]∊⊂rootObj.Name ⍝ Check if the rootObj has an event :For (ref event expr) :In ↓(events[;1]∊⊂rootObj.Name)⌿events ⍝ Loop through the events caller←(1⊃⎕NSI),'.' ⍝ Namespace that is calling this function expr←((~'#'∊expr)/caller),expr ⍝ Add the namespace of the caller to the name of the event ⍎'rootObj.on',event,'←''',expr,'''' ⍝ Hook-up the event :EndFor :EndIf :Else ⍝ Do nothing. rootObj does not have a name or events to fix. :EndTrap ⍝ Create refs to all named child objects :Trap 0 names←(,⊃0≠⍴¨names)/names ⍝ Keep only the not empty names names←(0=rootObj.⎕NC↑names)/names ⍝ Only names which do not already have a meaning names←(~names∊⊂rootObj.Name)/names ⍝ Remove the name of the rootObj to prevent a recursive entry. events←(~events[;1]∊⊂rootObj.Name)⌿events ⍝ Remove the event(s) of the rootObj from the list now that they have been fixed. :Else ⍝ Do nothing. The previous 2 lines will bug if rootObj does not have a name. :EndTrap ⍝ Add a reference of all the named object to the rootObj. ⍝ FindName will not find the names on certain object (like template), ⍝ so we need to iterate and Trap the error when the name is not found. :For name :In names :Trap 0 ⍎'rootObj.(',name,')←rootObj.FindName ⊂name' :Else ⎕←'FixXaml Warning - Name Not found: ',name :EndTrap :EndFor ⍝ Show a Warning for Events that begins with '__' that will not be fixed because they are nameless: :If 0≠↑⍴inter←(~events[;1]∊names)⌿events ⎕←(⎕UCS 13),'FixXaml Warning - Following Nameless Event(s) Are Not Fixed:' ⎕←inter :End ⍝ Hook-up events events←(events[;1]∊names)⌿events ⍝ Named objects only caller←(1⊃⎕NSI),'.' ⍝ Namespace that is calling this function :For (ref event expr) :In ↓events :Trap 0 ⍝ Add the namespace of the caller to the name of the event expr←((~'#'∊expr)/caller),expr :If 0≠⎕NC expr ⍝ Callback function exist. Hook-up the event. ⍎'rootObj.',ref,'.on',event,'←''',expr,'''' :Else ⍝ Callback function does not exist. Show warning and do not fix the event. ⎕←'FixXaml Warning - Function ',expr,' does not exist. The Event ''',event,''' of ''',ref,''' is not fixed.' :End :Else ⍝ There is an error. Exit. →ERROR :EndTrap :EndFor →0 ⍝ rootObj is returned here if there is no error. ERROR: ⍝ Build the Error Message :If 90≠⎕EN ⍝ APL Error err←(1⊃⎕DM),': ',{(' '=1↑⍵)↓((1↓a,0)∨a←' '≠⍵)/⍵}(2⊃⎕DM),(⎕UCS 13) :Else ⍝ .Net Error :If '(NULL)'≢⍕⎕EXCEPTION ⍝ Show the value of ⎕EXCEPTION if not (NULL). err←('EXCEPTION: ',⎕EXCEPTION.Message),(⎕UCS 13) :Else ⍝ If ⎕EXCEPTION is (NULL) than the .Message property is empty. err←'EXCEPTION: Unknown error',(⎕UCS 13) :EndIf :End rootObj←⎕NULL err ∇ ∇ winParent←GetWindowParent object ⍝ Obtain the Windows Parent (Root Object) of a children's element. winParent←object :While 'System.Windows.Window'≢winParent.GetType.ToString winParent←winParent.Parent :EndWhile ∇ ∇ bmpimg←ImageFromBase64String base64String;imageBytes;MS;⎕USING ⍝ Convert a Base64String to a System.Windows.Media.Imaging.BitmapImage. ⎕USING←'System.IO,mscorlib.dll' 'System,mscorlib.dll' 'System.Windows.Media.Imaging,WPF/PresentationCore.dll' ⍝ Convert Base64 String to byte[] as numbers. imageBytes←Convert.FromBase64String(⊂base64String) ⍝ Create a new MemoryStream with the byte[] MS←⎕NEW MemoryStream(⊂imageBytes) ⍝ Create a BitmapImage Object from the Memory Stream bmpimg←⎕NEW BitmapImage bmpimg.BeginInit ⍝ The .OnLoad CacheOption will load the MemoryStream right now so it can be dispose. ⍝ That way there is no need to use a WriteableBitmap. bmpimg.CacheOption←bmpimg.CacheOption.OnLoad bmpimg.StreamSource←MS bmpimg.EndInit ⍝ ⍝ Create a WriteableBitmap that does not need the MemoryStream to persist ⍝ ⍝ That way it is possible to erase the MemoryStream after creating the Image ⍝ bmpimg←⎕NEW WriteableBitmap bmpimg ⍝ Erase the MemoryStream MS.Close ⋄ MS.Dispose ⋄ MS←⎕NULL ∇ ∇ ScriptFollowsDispatchDelegate obj;actions;delegate;dtlb;⎕IO;⎕ML;⎕USING ⍝ Function to write asynchronously to the UI thread from another thread. ⍝ The calling thread does not wait for the operation to finish. ⍝ Treat following commented lines in caller as a script. ⍝ Lines beginning with ⍝∇ are kept ⍝ Lines beginning with ⍝∇⍝ are stripped out (comments) ⍝ obj = UI Object that you want to write to from another thread ⍝ actions = Lines to execute in the UI thread. (⎕IO ⎕ML)←1 3 :Trap 0 ⎕USING←'System,System.dll' 'System.Windows.Threading,WPF/WindowsBase.dll' ⍝ Create a function (⍙Delegate) with the 'action' to execute in the UI thread. ⍝ The function will be executed where 'DispatchDelegate' is called and not where ⍝ 'DispatchDelegate' is located. dtlb←{⍵{((∨\⍵)∧⌽∨\⌽⍵)/⍺}' '≠⍵} actions←{{'⍝'=↑⍵:'' ⋄ ' ',dtlb ⍵}¨2↓¨⍵/⍨∧\(⊂'⍝∇')≡¨2↑¨⍵}dtlb¨(1+2⊃⎕LC)↓⎕NR 2⊃⎕XSI delegate←(⎕IO⊃⎕RSI).⎕OR(⎕IO⊃⎕RSI).⎕FX(⊂'⍙Delegate'),actions,(⊂'⎕EX ''⍙Delegate''') ⍝ Get a 'Dispatcher' from the UI object. That way we are sure to have the right UI thread. ⍝ Use the method '.Invoke' instead of '.BeginInvoke' for synchronous call. {}obj.Dispatcher.BeginInvoke(DispatcherPriority.Normal(⎕NEW Action delegate)) :Else ⎕←'Error ScriptFollowsDispatchDelegate: ',actions ⍝ Returns the Last Error :If 90=⎕EN ⎕←'EXCEPTION: ',⎕EXCEPTION.Message :Else ⎕←(1⊃⎕DM),': ',(2⊃⎕DM) :EndIf :End ∇ ∇ rootObj←ScrubAndFix xamlString;err;names;nodeNumber;reader;stringReader;writer ⍝ Function to remove the Class and Events elements of Xaml and fix the resulting Xaml. ⍝ Each named element(s) object will be attached to rootObject. ⍝ Root element name is removed in all cases. Use the rootObj directly to access its properties/methods. ⍝ This function is most usefull when experimenting with Xaml taken directly from the Web but is slower than FixXaml. ⍝ Inspired from the code of XAMLPAD2009. ⍝ ⍝ XamlString = Vector of Characters representing a XAML string ⍝ rootObj = WPF Root Element Object if no error ⍝ = ⎕NULL (explanation of error) if error :Trap 0 ⎕USING∪←'System.IO' 'System.Windows.Markup,WPF/PresentationFramework.dll' 'System.Xaml,System.Xaml.dll' stringReader←⎕NEW StringReader(⊂xamlString) reader←⎕NEW XamlXmlReader(stringReader XamlReader.GetWpfSchemaContext) writer←⎕NEW XamlObjectWriter(reader.SchemaContext) ⎕USING←0⍴⊂'' names←'' ⍝ Initial value of the names to fix. nodeNumber←0 ⍝ Initial value of the node number. :While reader.Read :If 'StartObject'≡⍕reader.NodeType ⍝ Will increment of 1 each time a new node (with a new object) begins. nodeNumber+←1 :End :If 'StartMember'≡⍕reader.NodeType :AndIf reader.Member.Name≡'Class' {}reader.Read {}reader.Read :ElseIf 'StartMember'≡⍕reader.NodeType :AndIf reader.Member.IsEvent {}reader.Read {}reader.Read :ElseIf 'StartMember'≡⍕reader.NodeType :AndIf reader.Member.Name≡'Name' writer.WriteNode(reader) {}reader.Read writer.WriteNode(reader) ⍝ Check if reader is on first node :If 1≠nodeNumber ⍝ reader is not on first node. Keep the name. names,←⊂reader.Value :Else ⍝ reader is on first node. Don't keep the name. :End {}reader.Read writer.WriteNode(reader) :Else writer.WriteNode(reader) :End :EndWhile rootObj←writer.Result ⍝ Assign the value of each names found to the root object: :If 0≠⍴names rootObj{⍎'⍺.',⍵,'←⍺.FindName(⊂,⍵)'}¨names :Else ⍝ Do nothing, there is no names. :End :Else ⍝ Build the Error Message :If 90≠⎕EN ⍝ APL Error err←(1⊃⎕DM),': ',{(' '=1↑⍵)↓((1↓a,0)∨a←' '≠⍵)/⍵}(2⊃⎕DM),(⎕UCS 13) :Else ⍝ .Net Error :Trap 0 ⍝ Show the value of ⎕EXCEPTION.Message if not ⎕NULL. err←('EXCEPTION: ',⎕EXCEPTION.Message),(⎕UCS 13) :Else ⍝ Sometimes ⎕EXCEPTION is (NULL) and will bug here. err←'Exception (NULL): Unknown error',(⎕UCS 13) :EndTrap :End rootObj←⎕NULL err :EndTrap ∇ ∇ __Button_Click(sender event);rootObject;⎕USING ⍝ Click Event Handler for the Button ⍝ Get the Root Object from the Button object (sender) rootObject←GetWindowParent sender ⍝ Assign the new text to the TextBox. rootObject.textBox1.Text←'I Was Clicked !' ⍝ Change some colors of the TextBox ⎕USING←'System.Windows.Media,WPF/PresentationCore.dll' 'System.Windows,WPF/PresentationFramework.dll' rootObject.textBox1.Background←⎕NEW SolidColorBrush(Colors.Yellow) rootObject.textBox1.BorderBrush←⎕NEW SolidColorBrush(Colors.Red) rootObject.textBox1.BorderThickness←⎕NEW Thickness 3 ∇ ∇ __EventHandler(sender event);name ⍝ Single Event Handler for the Window ⍝ Get name of the control that was clicked name←event.Source.Name ⍝ sender is the Root Object in this case because ⍝ the routed event was attached to it. sender.lStatusBar.Content←'I Was Clicked: ',name ⍝ Select the code to be executed: :Select name :Case 'mnuCut' :Case 'mnuCopy' :Case 'mnuPaste' :Case 'mnuPrint' :Case 'mnuQuit' :Case 'mnuAbout' :Case 'btnButton1' :Case 'btnButton2' :Case 'btnButton3' :Else 'Error: Unknow Name' :EndSelect ∇ ⍝ Section BackgroundWorker ∇ BackgroundWorkerSample max;xaml ⍝ If you have an operation that will take a long time to complete, and you do not want to cause delays in your ⍝ user interface (UI), you can use the BackgroundWorker class from Microsoft to run the operation on another thread. ⍝ ⍝ The BackgroundWorker offers several features which include spawning a background thread, the ability ⍝ to cancel the background process before it has completed, and the chance to report the progress back to your UI. ⍝ ⍝ For multithread operation with APL it is recommended to wait on the Window on a different thread, ⍝ that way the thread 0 of the session is not blocked. So the Window will wait on thread 1 and the ⍝ long calculation will be done on tread 2. ⍝ ⍝ This function will simulate a long calculation with the use of a BackgroundWorker. ⍝ It is finding all the numbers that are a multiple of 42 between 1 and 'max' ⍝ Start the demo function by doing: BackgroundWorkerSample& 1000 ⍝ In this case it will find all the multiple of 42 between 1 and 1000. ⍝ The Spawn operator '&' is telling APL to run the function on another thread (in our case thread no 1) ⍝ ⍝ BackgroundWorkerSample = Main function ⍝ __btnDoAsynchronousCalculation_Click = Callback of the 'Start' button ⍝ __btnCancelAsynchronousCalculation_Click = Callback of the 'Cancel' button ⍝ __worker_DoWork = Does the long calculation on another thread (in our case thread no 2) ⍝ __worker_ProgressChanged = Change the UI to show the progress. Executed on thread no 1 (UI). ⍝ __worker_RunWorkerCompleted = Callback when the DoWork callback is finished. Executed on thread no 1 (UI). ⍝ Inspired from the following: ⍝ http://www.wpf-tutorial.com/misc/multi-threading-with-the-backgroundworker/ ⍝ http://www.wpf-tutorial.com/misc/cancelling-the-backgroundworker/ ⍝ http://www.jeremybytes.com/downloads/backgroundworkerinwpf.pdf ⍝ https://msdn.microsoft.com/fr-fr/library/cc221403(v=vs.95).aspx {}2520⌶1 ⍝ Use separate thread for .Net ⎕USING←'' ⎕USING,←⊂'System,mscorlib.dll' ⎕USING,←⊂'System.Threading,mscorlib.dll' ⎕USING,←⊂'System.ComponentModel,System.dll' ⎕USING,←⊂'System.Windows,WPF/PresentationFramework.dll' xaml←'' xaml,←' ' xaml,←' ' xaml,←' Start' xaml,←' ' xaml,←' Cancel' xaml,←' ' xaml,←' ' xaml,←' ' xaml,←' ' xaml,←' ' xaml,←'' :If ⎕NULL≡↑win←FixXaml xaml ⍝ Fixing the Xaml did not work. Show the error and exit. ⎕←2⊃win :Else ⍝ There is no error. win.max←max {}win.ShowDialog :EndIf ∇ ∇ __btnDoAsynchronousCalculation_Click(sender event) ⍝ Function using a 'BackgroundWorker' thread to do long calculation or blocking action on another thread. ⍝ The ProgressBar and ListBox are reset win.pbCalculationProgress.Value←0 win.lbResults.Items.Clear ⍝ Get a BackgroundWorker object from System.ComponentModel in System.dll win.worker←⎕NEW BackgroundWorker ⍝ The event 'DoWork' occurs when the method 'RunWorkerAsync' is called. ⍝ The event handler executes on another thread the time-consuming operation. ⍝ You cannot access the UI thread from this callback. win.worker.onDoWork←'__worker_DoWork' ⍝ The event 'ProgressChanged' occurs when the method 'ReportProgress' is called within the 'DoWork' event function (__worker_DoWork). ⍝ The 'ProgressChanged' event handler executes on the thread that created the BackgroundWorker (should be the UI thread). win.worker.WorkerReportsProgress←1 ⍝ Specify that you want the background operation to report progress. win.worker.onProgressChanged←'__worker_ProgressChanged' ⍝ The event 'RunWorkerCompleted' occurs when the DoWork event handler returns. win.worker.onRunWorkerCompleted←'__worker_RunWorkerCompleted' ⍝ Specify you want the background operation to allow cancellation. win.worker.WorkerSupportsCancellation←1 ⍝ Starts execution of the background operation by raising the 'DoWork' event asynchronously. ⍝ The .IsBusy property can be used to check if the worker is already running. win.worker.RunWorkerAsync win.max ⍝ The previous line returns immediately so we can set the properties of the buttons. win.btnDoAsynchronousCalculation.IsEnabled←0 win.btnCancel.IsEnabled←1 ∇ ∇ __btnCancelAsynchronousCalculation_Click(sender event) ⍝ To cancel the calculation execute the method .CancelAsync of the BackgroundWorker ⍝ This will sets the CancellationPending property to true of the BackgroundWorker ⍝ The function of the 'DoWork' event should periodically check the CancellationPending property to see if it has been set to true. ⍝ event = System.Windows.RoutedEventArgs win.worker.CancelAsync ∇ ∇ __worker_DoWork(sender event);errorException;errorMessage;i;max;progressPercentage;result ⍝ Event handler executed on another thread when the method 'RunWorkerAsync' is called on the BackgroundWorker object. ⍝ If your background operation requires a parameter, call 'RunWorkerAsync' with your parameter. ⍝ You can extract the parameter from the 'DoWorkEventArgs.Argument' property. ⍝ ⍝ You must be careful not to manipulate any user-interface objects in your 'DoWork' event handler. ⍝ Instead, communicate to the user interface through 'ProgressChanged' and 'RunWorkerCompleted' events. ⍝ ⍝ event = System.ComponentModel.DoWorkEventArgs ⍝ It is recommended to put the calculations executed on this other thread inside a ':Trap' statement ⍝ and report the error(s) on the UI thread via an 'ArgumentException'. ⍝ This make it easier to debug and to report the error. {}2501⌶0 ⍝ Discard thread on exit :Trap 0 max←event.Argument ⍝ Get the argument of the 'RunWorkerAsync' method. result←⍳0 ⍝ Find all the number divisible by 42 from 1 to 'max' :For i :In ⍳max ⍝ Test if the Cancel button was clicked :If sender.CancellationPending event.Cancel←1 →END :Else ⍝ No cancellation. Do the next calculation. progressPercentage←Convert.ToInt32(100×i÷max) ⍝ Must be an Int32. (Not coerce by APL) ⍝ Do the calculation and report progress on the UI with the '.ReportProgress' method of the BackgroundWorker. :If 0=42|i ⍝ 'i' is a multiple of 42 result,←i ⍝ The first argument will be in event.ProgressPercentage (Int32) ⍝ The second argument (optional) will be in event.UserState (object) sender.ReportProgress(progressPercentage,i) :Else ⍝ 'i' is not a multiple of 42 sender.ReportProgress(progressPercentage) :EndIf :EndIf ⍝ Simulate a long calculation by blocking the thread artificially Thread.Sleep 10 ⍝ With Thread.Sleep 1 it does not work. APL too fast for Windows ? :EndFor END: ⍝ ↓↓↓ This will call the event 'RunWorkerCompleted' with an argument in the .Result property. event.Result←max result :Else ⍝ There has been an error. Build the error message :If 90≠⎕EN ⍝ APL Error errorMessage←(1⊃⎕DM),': ',{(' '=1↑⍵)↓((1↓a,0)∨a←' '≠⍵)/⍵}(2⊃⎕DM),(⎕UCS 13) :Else ⍝ .Net Error :If '(NULL)'≢⍕⎕EXCEPTION ⍝ Show the value of ⎕EXCEPTION if not (NULL). errorMessage←('EXCEPTION: ',⎕EXCEPTION.Message),(⎕UCS 13) :Else ⍝ If ⎕EXCEPTION is (NULL) than the .Message property is empty. errorMessage←'EXCEPTION: Unknown error',(⎕UCS 13) :EndIf :End ⍝ This Exception will terminate the iteration and call the 'RunWorkerCompleted' event. ⍝ The error can be obtained in the function '__worker_RunWorkerCompleted' that is running on the UI thread. errorException←⎕NEW ArgumentException(⊂errorMessage) errorException ⎕SIGNAL 90 :EndTrap ∇ ∇ __worker_ProgressChanged(sender event) ⍝ Callback function of the event 'ProgressChanged' ⍝ It is excuted on the thread that created the BackgroundWorker ⍝ The UI can be access from this function ⍝ ⍝ event = System.ComponentModel.ProgressChangedEventArgs ⍝ Get first argument win.pbCalculationProgress.Value←event.ProgressPercentage ⍝ Get second argument of callback if not [Null]. :If '[Null]'≢⍕event.get_UserState {}win.lbResults.Items.Add(event.UserState) ⍝ Position the ListBox at the end. win.lbResults.ScrollIntoView(win.lbResults.Items[win.lbResults.Items.Count-1]) :EndIf ∇ ∇ __worker_RunWorkerCompleted(sender event);max;result ⍝ This event is raised when the DoWork event handler returns. ⍝ It is excuted on the thread that created the BackgroundWorker ⍝ The UI can be access from this function ⍝ ⍝ event = System.ComponentModel.RunWorkerCompletedEventArgs ⍝ Check if it was cancelled :If event.Cancelled {}MessageBox.Show(⊂'The calculation was Cancel') ⍝ Check if there was an error :ElseIf '[Null]'≢⍕event.get_Error ⍝ The 'errorMessage' of '__worker_DoWork' is in 'event.Error.Message' {}MessageBox.Show(⊂event.Error.Message) :Else ⍝ The argument passed by '__worker_DoWork' is in 'event.Result' (max result)←event.Result {}MessageBox.Show(⊂'Numbers between 1 and ',(⍕max),' divisible by 42: ',⍕result) :EndIf ⍝ Setup the UI for another calculation win.btnDoAsynchronousCalculation.IsEnabled←1 win.btnCancel.IsEnabled←0 win.pbCalculationProgress.Value←0 ⍝ Clean-up win.worker.Dispose ∇ :EndNamespace