Skip to content

Commit 44a295e

Browse files
committed
Added Python and .Net implementations
1 parent 354926f commit 44a295e

File tree

11 files changed

+191
-2
lines changed

11 files changed

+191
-2
lines changed

isc/zlib/Test.cls

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ ClassMethod callout6(text = "Hello World", rounds As %Integer = 10000)
4040
}
4141
}
4242

43+
/// Python
44+
/// do ##class(isc.zlib.Test).pythonInit()
45+
ClassMethod pythonInit()
46+
{
47+
set sc = ##class(isc.py.Callout).SimpleString("import zlib")
48+
}
49+
50+
/// Python deflate
51+
/// do ##class(isc.zlib.Test).python()
52+
ClassMethod python(text = "Hello World", rounds As %Integer = 10000)
53+
{
54+
for i=1:1:rounds{
55+
kill out
56+
set out = ##class(isc.py.Callout).SimpleString("x = zlib.compress(b'" _ text _ "')", "x")
57+
set out = $zcvt($e(out, 3, *-1), "I", "JSON")
58+
}
59+
}
60+
4361
/// Java GateWay implementation
4462
/// do ##class(isc.zlib.Test).jgw()
4563
ClassMethod jgw(text = "Hello World", rounds As %Integer = 10000)
@@ -51,6 +69,17 @@ ClassMethod jgw(text = "Hello World", rounds As %Integer = 10000)
5169
}
5270
}
5371

72+
/// .Net GateWay implementation
73+
/// w ##class(isc.zlib.Test).net()
74+
ClassMethod net(text = "Hello World", rounds As %Integer = 10000)
75+
{
76+
set gateway = ##class(isc.zlib.Utils).connect(##class(isc.zlib.Utils).#GATEWAYNET, ##class(isc.zlib.Utils).#CLASSPATHNET)
77+
for i=1:1:rounds{
78+
kill out
79+
set out = ##class(isc.zlib.Net).compress(gateway, text)
80+
}
81+
}
82+
5483
/// Default system implementation
5584
/// do ##class(isc.zlib.Test).system()
5685
ClassMethod system(text = "Hello World", rounds As %Integer = 10000)
@@ -80,7 +109,7 @@ ClassMethod node(text = "Hello World", rounds As %Integer = 10000)
80109
/// textLength - either text, or a number of symbols in text
81110
/// rounds - number of calls to zlib
82111
/// do ##class(isc.zlib.Test).test()
83-
ClassMethod test(textLength As %Integer = 100, rounds As %Integer = 10000)
112+
ClassMethod test(textLength As %Integer = 1000, rounds As %Integer = 1000000)
84113
{
85114
set:textLength="" textLength = 100
86115

@@ -92,11 +121,12 @@ ClassMethod test(textLength As %Integer = 100, rounds As %Integer = 10000)
92121
}
93122

94123
do ..callout6Init()
124+
do ..pythonInit()
95125

96126
write "Text: ", text, !
97127
write "Text length: ", $l(text), !
98128
write "Rounds: ", rounds, !
99-
for method="callout3", "callout6", "system", "jgw", "node" {
129+
for method= "callout3", "callout6", "system", "jgw", "node", "python", "net" {
100130
set start = $zh
101131
do $classmethod(,method, text, rounds)
102132
set end = $zh
@@ -107,6 +137,7 @@ ClassMethod test(textLength As %Integer = 100, rounds As %Integer = 10000)
107137
write "Time: ", time, !
108138
write "Speed (Kb/sec): ", $normalize(textLength*rounds/1024/time, 0), !
109139
write "Speed (calls/sec): ", $normalize(rounds/time, 0), !
140+
write "_______", !
110141
}
111142
}
112143

isc/zlib/Utils.cls

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ Parameter CLASS = "isc.zlib.Java";
55

66
Parameter CLASSPATH = {$g(^%SYS("bindir")) _ "zlib.jar"};
77

8+
Parameter CLASSPATHNET = {$g(^%SYS("bindir")) _ "zlibnet.dll"};
9+
810
Parameter GATEWAY = "ZLIB";
911

12+
Parameter GATEWAYNET = "zlib";
13+
1014
/// Create JGW. Java home must point to 1.8 jre.
1115
/// Write $System.Status.GetErrorText(##class(isc.zlib.Utils).createGateway())
1216
ClassMethod createGateway(gatewayName = {..#GATEWAY}, javaHome = {$SYSTEM.Util.GetEnviron("JAVA_HOME")}, path As %String = {..#CLASSPATH}, port As %Integer = 55559)
@@ -20,6 +24,22 @@ ClassMethod createGateway(gatewayName = {..#GATEWAY}, javaHome = {$SYSTEM.Util.G
2024
quit sys.%Save()
2125
}
2226

27+
/// Create .Net Gateway. Requires .Net Framework 4.5
28+
/// Write $System.Status.GetErrorText(##class(isc.zlib.Utils).createNetGateway())
29+
ClassMethod createNetGateway(gatewayName = {..#GATEWAYNET}, path As %String = {..#CLASSPATHNET}, port As %Integer = 2086)
30+
{
31+
set sys = ##class(%Net.Remote.ObjectGateway).%New()
32+
set sys.Name = gatewayName
33+
set sys.Type = 2
34+
set sys.ClassPath = path
35+
set sys.Port = port
36+
37+
set sys.DotNetVersion = 4.5
38+
set sys.Exec64 = $$$YES
39+
40+
quit sys.%Save()
41+
}
42+
2343
/// Load Jar from path.
2444
/// Write $System.Status.GetErrorText(##class(isc.zlib.Utils).updateJar())
2545
ClassMethod updateJar(gatewayName = {..#GATEWAY}, path As %String = {..#CLASSPATH})

net/.vs/zlib/v15/Server/sqlite3/db.lock

Whitespace-only changes.
4 KB
Binary file not shown.
32 KB
Binary file not shown.
499 KB
Binary file not shown.

net/Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("zlib")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("zlib")]
13+
[assembly: AssemblyCopyright("Copyright © 2020")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("8c7eec1e-1018-4e0c-942e-a6e565a0f6b9")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

net/zlib.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.IO;
3+
using System.IO.Compression;
4+
5+
namespace isc.zlib
6+
{
7+
public class Net
8+
{
9+
public static byte[] compress(String str)
10+
{
11+
using (MemoryStream output = new MemoryStream())
12+
{
13+
using (DeflateStream gzip = new DeflateStream(output, CompressionMode.Compress))
14+
{
15+
using (StreamWriter writer = new StreamWriter(gzip, System.Text.Encoding.UTF8))
16+
{
17+
writer.Write(str);
18+
}
19+
}
20+
21+
return output.ToArray();
22+
}
23+
}
24+
}
25+
}

net/zlib.csproj

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{8C7EEC1E-1018-4E0C-942E-A6E565A0F6B9}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>zlib</RootNamespace>
11+
<AssemblyName>zlib</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core" />
36+
<Reference Include="System.Xml.Linq" />
37+
<Reference Include="System.Data.DataSetExtensions" />
38+
<Reference Include="Microsoft.CSharp" />
39+
<Reference Include="System.Data" />
40+
<Reference Include="System.Net.Http" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="zlib.cs" />
45+
<Compile Include="Properties\AssemblyInfo.cs" />
46+
</ItemGroup>
47+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
48+
</Project>

net/zlib.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.106
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zlib", "zlib.csproj", "{8C7EEC1E-1018-4E0C-942E-A6E565A0F6B9}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{8C7EEC1E-1018-4E0C-942E-A6E565A0F6B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8C7EEC1E-1018-4E0C-942E-A6E565A0F6B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8C7EEC1E-1018-4E0C-942E-A6E565A0F6B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8C7EEC1E-1018-4E0C-942E-A6E565A0F6B9}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5163D673-E231-42C6-AA93-A0379F6956FA}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)