Size: 3685
Comment: ByteArray, StringArray and IPAddress added
|
Size: 3530
Comment: Function IP improved
|
Deletions are marked like this. | Additions are marked like this. |
Line 66: | Line 66: |
The following function prepare a .Net IPAddress | The following function construct a .Net IPAddress: |
Line 70: | Line 70: |
⍝ r = IPAddress .net object if success or ⎕NULL if failure :If ' '=↑1↑0⍴ip ⍝ Characters ? ip←2⊃'.'⎕VFI ip :End :If 4≠⍴ip ⍝ 4 Numbers ? ⎕←'Address is not 4 numbers' r←⎕NULL →0 :End |
⍝ r = IPAddress .net object if success or ⎕NULL (error) if failure |
Line 84: | Line 73: |
⎕USING←'System,mscorlib.dll' 'System.Net,System.dll' byteArray←Array.CreateInstance(Byte 4) {byteArray.Set ⍵}¨↓0 1 2 3,[1.5]ip r←⎕NEW IPAddress byteArray |
⎕USING←'System.Net,System.dll' :If ' '=↑1↑0⍴ip ⍝ Characters ? ip←IPAddress.Parse(⊂,ip) r←⎕NEW IPAddress(ip.Address) :Else ⍝ Numbers r←⎕NEW IPAddress(⊂,ip) :End |
Line 92: | Line 87: |
r←⎕NULL ⎕←('EXCEPTION: ',⎕EXCEPTION.Message) |
r←⎕NULL('EXCEPTION: ',⎕EXCEPTION.Message) |
Line 95: | Line 90: |
r←⎕NULL ⎕←((1⊃⎕DM),': ',(2⊃⎕DM)) |
r←⎕NULL((1⊃⎕DM),': ',(2⊃⎕DM)) |
Contents
netVaria
Overview
This Wiki is about sharing snippets of Dyalog Apl code that are useful when using .Net
.Net version installed
GetNetVersion is used for detecting the .Net version installed on the computer.
v←GetNetVersion;DI;dir;dirs;⎕USING ⍝ Function to Get the Latest .Net Framework Installed on this Computer ⍝ Based on: http://msdn.microsoft.com/en-us/library/y549e41e.aspx ⍝ ⍝ v = Latest Version Installed ⍝ v = 0, When There is no Version of .Net Installed :Trap 0 ⎕USING←'System,mscorlib.dll' 'System.IO,mscorlib.dll' dir←Environment.ExpandEnvironmentVariables(⊂'%WINDIR%\Microsoft.NET\Framework') DI←⎕NEW DirectoryInfo(⊂dir) ⍝ Get the DirectoryInfo Object for the Directory dirs←DI.GetDirectories(⊂'v*') ⍝ v* is the filter dirs←1↓¨dirs.Name ⍝ To remove the letter 'v' at the beginning of each directory v←+/¨(⊂1 0.1)ר2↑¨⊃¨(//¨'.'⎕VFI¨dirs) ⍝ To Add the first 2 numbers of each directory v←1↑∪v[⍒v] ⍝ To order the directory names as numbers and return the highest number :Else ⍝ There is no .Net installed v←0 :EndTrap
Close the Application Domain
CloseAppDomain is the equivalent to File --> CloseAppDomain. It is used to remove the dll loaded in the memory of the interpreter. Usefull when experimenting with .Net. (From version 14.1 there is a I beam for that now: 2101⌶0)
CloseAppDomain ⍝ To erase all the loaded dll from memory. 'Closing AppDomain...' 1 ⎕NQ'⎕SE.mb.file.closead' 'Select' 'AppDomain Closed'
Byte Array: Byte[]
If the constructor needs a Byte Array you can use the following function to build it:
ba←ByteArray bytes;⎕IO;⎕USING ⍝ Function to get a .Net byte array ⍝ bytes = numbers in the range of 0 to 255 ⍝ ba = .Net Byte[] ⎕USING ⎕IO←'System,mscorlib.dll' 0 ba←Array.CreateInstance(Byte(⍴,bytes)) ⍝ Empty array of type 'Byte' {ba.Set ⍵}¨↓(⍳⍴,bytes),[0.5]bytes ⍝ Populate the Byte array
String Array: String[]
If the constructor needs a String Array you can use the following function to build it:
sa←StringArray strings;⎕USING;⎕IO ⍝ Function to get a .Net string array ⍝ strings = characters ⍝ sa = .Net String[] ⎕USING ⎕IO←'System,mscorlib.dll' 0 sa←Array.CreateInstance(String(⍴,strings)) ⍝ Empty array of type 'String' {sa.Set(⍵[0](,⍵[1]))}¨↓(⍳⍴,strings),[0.5]strings ⍝ Populate the String array
IPAddress
The following function construct a .Net IPAddress:
r←IP ip;byteArray;⎕USING ⍝ ip = IP address as 4 numbers or characters (like '192.168.1.1') ⍝ r = IPAddress .net object if success or ⎕NULL (error) if failure :Trap 0 ⎕USING←'System.Net,System.dll' :If ' '=↑1↑0⍴ip ⍝ Characters ? ip←IPAddress.Parse(⊂,ip) r←⎕NEW IPAddress(ip.Address) :Else ⍝ Numbers r←⎕NEW IPAddress(⊂,ip) :End :Else ⍝ There is an error. :If 90=⎕EN r←⎕NULL('EXCEPTION: ',⎕EXCEPTION.Message) :Else r←⎕NULL((1⊃⎕DM),': ',(2⊃⎕DM)) :EndIf :End
CategoryDyalog - CategoryDyalogDotNet - CategoryDyalogDotNetUtilities - CategoryDotNet