Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 31f5644
Showing
189 changed files
with
10,247 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
.Net/InMemoryOLTP/AboutSqlServer.Com.Classes/AboutSqlServer.Com.Classes.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{1D6335A4-DB2A-4A3C-8300-0E98D3114092}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>AboutSqlServer.Com.Classes</RootNamespace> | ||
<AssemblyName>AboutSqlServer.Com.Classes</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</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="System" /> | ||
<Reference Include="System.Configuration" /> | ||
<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="BaseThread.cs" /> | ||
<Compile Include="ConnectionManager.cs" /> | ||
<Compile Include="ObjStoreUtils.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="StatThread.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> |
106 changes: 106 additions & 0 deletions
106
.Net/InMemoryOLTP/AboutSqlServer.Com.Classes/BaseThread.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/****************************************************************************/ | ||
/* Expert SQL Server In-Memory OLTP */ | ||
/* APress. 1st Edition. ISBN-13:978-1484211373 ISBN-10:1484211375 */ | ||
/* */ | ||
/* Written by Dmitri V. Korotkevitch */ | ||
/* http://aboutsqlserver.com */ | ||
/* dk@aboutsqlserver.com */ | ||
/****************************************************************************/ | ||
/* Common Classes */ | ||
/****************************************************************************/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace AboutSqlServer.Com.Classes | ||
{ | ||
public abstract class BaseThread | ||
{ | ||
public BaseThread(int sleep) | ||
{ | ||
_thread = new Thread(this.Execute); | ||
_sleep = sleep; | ||
_terminated = true; | ||
_iteration = 0; | ||
} | ||
|
||
public void Start() | ||
{ | ||
_active = true; | ||
_terminated = false; | ||
OnStart(); | ||
_thread.Start(); | ||
} | ||
|
||
public void Terminate() | ||
{ | ||
if (IsActive) | ||
{ | ||
_terminated = true; | ||
OnTerminate(); | ||
} | ||
|
||
} | ||
|
||
public int CallsPerSec | ||
{ | ||
get | ||
{ | ||
// We are not using any thread sync constructs - we do not worry much about possible error. | ||
return (_iteration == 0) ? 0 : (int)(1000 * _iteration / DateTime.Now.Subtract(_startTime).TotalMilliseconds); | ||
} | ||
} | ||
|
||
protected virtual void OnTerminate() { } | ||
protected virtual void OnStart() { } | ||
protected virtual void OnExecute() { _iteration = 0; _startTime = DateTime.Now; } | ||
|
||
private void Execute() | ||
{ | ||
using (GetExecuteDisposable()) | ||
{ | ||
OnExecute(); | ||
while (!_terminated) | ||
{ | ||
_iteration++; | ||
DoIteration(); | ||
if (_sleep == 0) | ||
Thread.Sleep(0); | ||
else | ||
{ | ||
int delay = _sleep; | ||
while (!_terminated && (delay > 0)) | ||
{ | ||
Thread.Sleep((_sleep < 1000) ? _sleep : 1000); | ||
delay -= 1000; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected virtual IDisposable GetExecuteDisposable() | ||
{ | ||
return null; | ||
} | ||
|
||
protected abstract void DoIteration(); | ||
|
||
public bool IsActive { get { return _active; } } | ||
public int Iteration { get { return _iteration; } } | ||
|
||
private Thread _thread; | ||
private int _sleep; | ||
|
||
protected bool _terminated = true; | ||
protected int _iteration; | ||
|
||
private bool _active = false; | ||
|
||
private DateTime _startTime; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
.Net/InMemoryOLTP/AboutSqlServer.Com.Classes/ConnectionManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/****************************************************************************/ | ||
/* Expert SQL Server In-Memory OLTP */ | ||
/* APress. 1st Edition. ISBN-13:978-1484211373 ISBN-10:1484211375 */ | ||
/* */ | ||
/* Written by Dmitri V. Korotkevitch */ | ||
/* http://aboutsqlserver.com */ | ||
/* dk@aboutsqlserver.com */ | ||
/****************************************************************************/ | ||
/* Common Classes */ | ||
/****************************************************************************/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Configuration; | ||
using System.Data.SqlClient; | ||
|
||
namespace AboutSqlServer.Com.Classes | ||
{ | ||
public class ConnectionManager | ||
{ | ||
public ConnectionManager(string connStrName) | ||
{ | ||
if (!String.IsNullOrEmpty(connStrName) && ConfigurationManager.ConnectionStrings[connStrName] != null) | ||
_connStr = ConfigurationManager.ConnectionStrings[connStrName].ConnectionString; | ||
} | ||
|
||
public SqlConnection GetConnection() | ||
{ | ||
SqlConnection conn = GetSqlConnection(); | ||
conn.Open(); | ||
return conn; | ||
} | ||
|
||
public bool ValidateConnection(out string connError) | ||
{ | ||
using (SqlConnection conn = GetSqlConnection()) | ||
{ | ||
try | ||
{ | ||
conn.Open(); | ||
conn.Close(); | ||
connError = null; | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
connError = ex.Message; | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
private SqlConnection GetSqlConnection() | ||
{ | ||
if (String.IsNullOrEmpty(_connStr)) | ||
throw new Exception("ConnectionManager::GetSqlConnection() - Connection string has not been specified"); | ||
return new SqlConnection( _connStr); | ||
} | ||
|
||
public string ConnStr | ||
{ | ||
get { return _connStr; } | ||
set | ||
{ | ||
if (String.IsNullOrEmpty(value)) | ||
throw new Exception("ConnectionManager::SetConnStr() - Connection String is Empty"); | ||
_connStr = value; | ||
} | ||
} | ||
|
||
private string _connStr = null; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
.Net/InMemoryOLTP/AboutSqlServer.Com.Classes/ObjStoreUtils.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/****************************************************************************/ | ||
/* Expert SQL Server In-Memory OLTP */ | ||
/* APress. 1st Edition. ISBN-13:978-1484211373 ISBN-10:1484211375 */ | ||
/* */ | ||
/* Written by Dmitri V. Korotkevitch & Vladimir Zatuliveter */ | ||
/* http://aboutsqlserver.com */ | ||
/* dk@aboutsqlserver.com */ | ||
/****************************************************************************/ | ||
/* Common Classes */ | ||
/****************************************************************************/ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.Serialization.Formatters.Binary; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AboutSqlServer.Com.Classes | ||
{ | ||
public static class ObjStoreUtils | ||
{ | ||
/// <summary> | ||
/// Serialize object of type T to the byte array | ||
/// </summary> | ||
public static byte[] Serialize<T>(T obj) | ||
{ | ||
using (var ms = new MemoryStream()) | ||
{ | ||
var formatter = new BinaryFormatter(); | ||
formatter.Serialize(ms, obj); | ||
|
||
return ms.ToArray(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Deserialize byte array to the object | ||
/// </summary> | ||
public static T Deserialize<T>(byte[] data) | ||
{ | ||
using (var output = new MemoryStream(data)) | ||
{ | ||
var binForm = new BinaryFormatter(); | ||
return (T)binForm.Deserialize(output); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Split byte array to the multiple chunks | ||
/// </summary> | ||
public static List<byte[]> Split(byte[] data, int chunkSize) | ||
{ | ||
var result = new List<byte[]>(); | ||
|
||
for (int i = 0; i < data.Length; i += chunkSize) | ||
{ | ||
int currentChunkSize = chunkSize; | ||
if (i + chunkSize > data.Length) | ||
currentChunkSize = data.Length - i; | ||
|
||
var buffer = new byte[currentChunkSize]; | ||
Array.Copy(data, i, buffer, 0, currentChunkSize); | ||
|
||
result.Add(buffer); | ||
} | ||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Combine multiple chunks into the byte array | ||
/// </summary> | ||
public static byte[] Merge(List<byte[]> arrays) | ||
{ | ||
var rv = new byte[arrays.Sum(a => a.Length)]; | ||
int offset = 0; | ||
foreach (byte[] array in arrays) | ||
{ | ||
Buffer.BlockCopy(array, 0, rv, offset, array.Length); | ||
offset += array.Length; | ||
} | ||
return rv; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
.Net/InMemoryOLTP/AboutSqlServer.Com.Classes/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("AboutSqlServer.Com.Classes")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("AboutSqlServer.Com.Classes")] | ||
[assembly: AssemblyCopyright("Copyright © 2015")] | ||
[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("a6852c40-5c61-4754-b628-a7113d06c279")] | ||
|
||
// 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")] |
Oops, something went wrong.