Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dev123 committed Apr 1, 2014
1 parent 1744389 commit bc49fd2
Show file tree
Hide file tree
Showing 69 changed files with 10,524 additions and 2 deletions.
151 changes: 151 additions & 0 deletions AsynchClient/AsynchQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
//
// Copyright (c) 2011-2014 Exxeleron GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace qSharp.Sample
{
class AsynchQuery
{
static void Main(string[] args)
{
QCallbackConnection q = new QCallbackConnection(host: (args.Length >= 1) ? args[0] : "localhost",
port: (args.Length >= 2) ? Int32.Parse(args[1]) : 5000);
try
{
q.DataReceived += OnData;
q.Open();
Console.WriteLine("conn: " + q + " protocol: " + q.ProtocolVersion);
Console.WriteLine("Press <ENTER> to close application");

// definition of asynchronous multiply function
// queryid - unique identifier of function call - used to identify
// the result
// a, b - actual parameters to the query
q.Sync("asynchMult:{[queryid;a;b] res:a*b; (neg .z.w)(`queryid`result!(queryid;res)) }");
q.StartListener();

Random gen = new Random();
// send asynchronous queries
for (int i = 0; i < 10; i++)
{
int a = gen.Next(20), b = gen.Next(20);
Console.WriteLine("Asynch call with queryid=" + i + " with arguments=" + a + "," + b);
q.Async("asynchMult", i, a, b);
}

Thread.Sleep(2000);

Console.ReadLine();
q.Sync("value \"\\\\t 0\"");
q.StopListener();
}
catch (Exception e)
{
Console.Error.WriteLine(e);
Console.ReadLine();
}
finally
{
q.Close();
}
}

static void OnData(object sender, QMessageEvent message)
{
PrintResult(message.Message.Data);
}

static void PrintResult(object obj)
{
if (obj == null)
{
Console.WriteLine("::");
}
else if (obj is Array)
{
PrintResult(obj as Array);
}
else if (obj is QDictionary)
{
PrintResult(obj as QDictionary);
}
else if (obj is QTable)
{
PrintResult(obj as QTable);
}
else
{
Console.WriteLine(obj);
}
}

static void PrintResult(Array a)
{
Console.WriteLine(Utils.ArrayToString(a));
}

static void PrintResult(QDictionary d)
{
foreach (QDictionary.KeyValuePair e in d)
{
Console.WriteLine(e.Key + "| " + e.Value);
}
}

static void PrintResult(QTable t)
{
var rowsToShow = Math.Min(t.RowsCount, 20);
var dataBuffer = new object[1 + rowsToShow][];
var columnWidth = new int[t.ColumnsCount];

dataBuffer[0] = new string[t.ColumnsCount];
for (int j = 0; j < t.ColumnsCount; j++)
{
dataBuffer[0][j] = t.Columns[j];
columnWidth[j] = t.Columns[j].Length + 1;
}

for (int i = 1; i < rowsToShow; i++)
{
dataBuffer[i] = new string[t.ColumnsCount];
for (int j = 0; j < t.ColumnsCount; j++)
{
var value = t[i - 1][j].ToString();
dataBuffer[i][j] = value;
columnWidth[j] = Math.Max(columnWidth[j], value.Length + 1);
}
}

var formatting = "";
for (int i = 0; i < columnWidth.Length; i++)
{
formatting += "{" + i + ",-" + columnWidth[i] + "}";
}

Console.WriteLine(formatting, dataBuffer[0]);
Console.WriteLine(new string('-', columnWidth.Sum()));
for (int i = 1; i < rowsToShow; i++)
{
Console.WriteLine(formatting, dataBuffer[i]);
}
}
}
}
134 changes: 134 additions & 0 deletions AsynchClient/AsynchQuery.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{EC7DE4EA-9B0C-4EA7-A2F6-F5AA0325897C}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>qSharp.Sample</RootNamespace>
<AssemblyName>AsynchClient</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<!-- The major, minor, build and revision parts defined -->
<PropertyGroup Condition="'$(VERSION_BUILD)' == ''">
<major>0</major>
<minor>0</minor>
<build>0</build>
<revision>0</revision>
<commit></commit>
</PropertyGroup>
<PropertyGroup Condition="'$(VERSION_BUILD)' != ''">
<major>$(VERSION_MAJOR)</major>
<minor>$(VERSION_MINOR)</minor>
<build>$(VERSION_BUILD)</build>
<revision>$(VERSION_REVISION)</revision>
<commit></commit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AsynchQuery.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\qSharp\qSharp.csproj">
<Project>{E8542C7D-B1DD-45E3-9C43-5DDCBA351D39}</Project>
<Name>qSharp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<!-- Import the msbuildtasks -->
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" Condition="Exists('$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets')" />
<!--
Execute the BeforeBuild step, creating the AssemblyVersionInfo.cs file containing the version numbers.
Both version and file version
-->
<Target Name="BeforeBuild" Condition="Exists('$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets')">
<Message Text="Version: $(major).$(minor).$(revision).$(build)" />
<Attrib Files="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs" Normal="true" />
<AssemblyInfo
CodeLanguage="CS"
OutputFile="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs"
AssemblyCompany="exxeleron"
AssemblyTitle="qSharp: AsynchQuery"
AssemblyProduct="qSharp"
AssemblyCopyright="Copyright © exxeleron 2011-2014"
AssemblyVersion="$(major).$(minor).$(revision).$(build)"
AssemblyFileVersion="$(major).$(minor).$(revision).$(build)" />
</Target>
</Project>
18 changes: 18 additions & 0 deletions AsynchClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18444
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

[assembly: System.Reflection.AssemblyCompany("exxeleron")]
[assembly: System.Reflection.AssemblyTitle("qSharp: AsynchQuery")]
[assembly: System.Reflection.AssemblyProduct("qSharp")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © exxeleron 2011-2014")]
[assembly: System.Reflection.AssemblyVersion("2.0.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("2.0.0.0")]


8 changes: 8 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
------------------------------------------------------------------------------
qSharp 2.0 [2014.04.02]
------------------------------------------------------------------------------

- Support for kdb+ protocol and types: v3.0, v2.6, v<=2.5
- Synchronous and asynchronous queries
- Convenient asynchronous callbacks mechanism
- Logging of the raw protocol data in case of parsing failure.
Loading

0 comments on commit bc49fd2

Please sign in to comment.