diff options
author | Halil İbrahim Kalkan <hi_kalkan@yahoo.com> | 2013-04-08 21:44:58 +0300 |
---|---|---|
committer | Halil İbrahim Kalkan <hi_kalkan@yahoo.com> | 2013-04-08 21:44:58 +0300 |
commit | 79953cb56cda204f190ffcd9995b27ebea25e62d (patch) | |
tree | de939755c2e32eaa5fa3e41e21114e1c727ed0a4 /samples/CustomWireProtocol/CommonLib | |
parent | 934c543eb6b0bd7173038e45a7dac0241d091da4 (diff) | |
download | scs-79953cb56cda204f190ffcd9995b27ebea25e62d.zip scs-79953cb56cda204f190ffcd9995b27ebea25e62d.tar.gz scs-79953cb56cda204f190ffcd9995b27ebea25e62d.tar.bz2 |
Adding to github
Adding to github
Diffstat (limited to 'samples/CustomWireProtocol/CommonLib')
4 files changed, 139 insertions, 0 deletions
diff --git a/samples/CustomWireProtocol/CommonLib/CommonLib.csproj b/samples/CustomWireProtocol/CommonLib/CommonLib.csproj new file mode 100644 index 0000000..93fb6fb --- /dev/null +++ b/samples/CustomWireProtocol/CommonLib/CommonLib.csproj @@ -0,0 +1,59 @@ +<?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)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.30703</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{7F7D3248-4432-4E7B-9CFD-25982668AD5B}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>CommonLib</RootNamespace> + <AssemblyName>CommonLib</AssemblyName> + <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <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|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Scs, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\Scs-Binaries\Scs.dll</HintPath> + </Reference> + <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="MyWireProtocol.cs" /> + <Compile Include="MyWireProtocolFactory.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </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> + --> +</Project>
\ No newline at end of file diff --git a/samples/CustomWireProtocol/CommonLib/MyWireProtocol.cs b/samples/CustomWireProtocol/CommonLib/MyWireProtocol.cs new file mode 100644 index 0000000..11227f4 --- /dev/null +++ b/samples/CustomWireProtocol/CommonLib/MyWireProtocol.cs @@ -0,0 +1,32 @@ +using System.Text; +using Hik.Communication.Scs.Communication.Messages; +using Hik.Communication.Scs.Communication.Protocols.BinarySerialization; + +namespace CommonLib +{ + /// <summary> + /// This class is a sample custom wire protocol to use as wire protocol in SCS framework. + /// It extends BinarySerializationProtocol. + /// It is used just to send/receive ScsTextMessage messages. + /// + /// Since BinarySerializationProtocol automatically writes message length to the beggining + /// of the message, a message format of this class is: + /// + /// [Message length (4 bytes)][UTF-8 encoded text (N bytes)] + /// + /// So, total length of the message = (N + 4) bytes; + /// </summary> + public class MyWireProtocol : BinarySerializationProtocol + { + protected override byte[] SerializeMessage(IScsMessage message) + { + return Encoding.UTF8.GetBytes(((ScsTextMessage)message).Text); + } + + protected override IScsMessage DeserializeMessage(byte[] bytes) + { + //Decode UTF8 encoded text and create a ScsTextMessage object + return new ScsTextMessage(Encoding.UTF8.GetString(bytes)); + } + } +} diff --git a/samples/CustomWireProtocol/CommonLib/MyWireProtocolFactory.cs b/samples/CustomWireProtocol/CommonLib/MyWireProtocolFactory.cs new file mode 100644 index 0000000..7f5f1ae --- /dev/null +++ b/samples/CustomWireProtocol/CommonLib/MyWireProtocolFactory.cs @@ -0,0 +1,12 @@ +using Hik.Communication.Scs.Communication.Protocols; + +namespace CommonLib +{ + public class MyWireProtocolFactory : IScsWireProtocolFactory + { + public IScsWireProtocol CreateWireProtocol() + { + return new MyWireProtocol(); + } + } +} diff --git a/samples/CustomWireProtocol/CommonLib/Properties/AssemblyInfo.cs b/samples/CustomWireProtocol/CommonLib/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8461698 --- /dev/null +++ b/samples/CustomWireProtocol/CommonLib/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CommonLib")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("CommonLib")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("50d012ed-8149-4bfb-8cb4-0f325628bdf7")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] |