-
Notifications
You must be signed in to change notification settings - Fork 3
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
Apress
committed
Oct 15, 2016
0 parents
commit c1ec556
Showing
456 changed files
with
61,297 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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,27 @@ | ||
Freeware License, some rights reserved | ||
|
||
Copyright (c) 2011 Klaus Aschenbrenner | ||
|
||
Permission is hereby granted, free of charge, to anyone obtaining a copy | ||
of this software and associated documentation files (the "Software"), | ||
to work with the Software within the limits of freeware distribution and fair use. | ||
This includes the rights to use, copy, and modify the Software for personal use. | ||
Users are also allowed and encouraged to submit corrections and modifications | ||
to the Software for the benefit of other users. | ||
|
||
It is not allowed to reuse, modify, or redistribute the Software for | ||
commercial use in any way, or for a user�s educational materials such as books | ||
or blog articles without prior permission from the copyright holder. | ||
|
||
The above copyright notice and this permission notice need to be included | ||
in all copies or substantial portions of the software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
|
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,15 @@ | ||
#Apress Source Code | ||
|
||
This repository accompanies [*Pro SQL Server 2008 Service Broker*](http://www.apress.com/9781430243021) by Klaus Aschenbrenner (Apress, 2011). | ||
|
||
![Cover image](9781430243021.jpg) | ||
|
||
Download the files as a zip using the green button, or clone the repository to your machine using Git. | ||
|
||
##Releases | ||
|
||
Release v1.0 corresponds to the code in the published book, without corrections or updates. | ||
|
||
##Contributions | ||
|
||
See the file Contributing.md for more information on how you can contribute to this repository. |
4 changes: 4 additions & 0 deletions
4
Samples/Chapter10/01 Asynchronous Trigger/AsynchronousTrigger.gpState
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<GuidancePackagesState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/pag/gax-gpstate"> | ||
<Packages /> | ||
</GuidancePackagesState> |
26 changes: 26 additions & 0 deletions
26
Samples/Chapter10/01 Asynchronous Trigger/AsynchronousTrigger.sln
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,26 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 9.00 | ||
# Visual Studio 2005 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceBrokerInterface", "ServiceBrokerInterface\ServiceBrokerInterface.csproj", "{00683377-A75F-47EB-8934-1484D6480877}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsynchronousTrigger", "AsynchronousTrigger\AsynchronousTrigger.csproj", "{C72BE8AE-C474-4A30-8CCC-C83059AC6D8C}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{00683377-A75F-47EB-8934-1484D6480877}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{00683377-A75F-47EB-8934-1484D6480877}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{00683377-A75F-47EB-8934-1484D6480877}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{00683377-A75F-47EB-8934-1484D6480877}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{C72BE8AE-C474-4A30-8CCC-C83059AC6D8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C72BE8AE-C474-4A30-8CCC-C83059AC6D8C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C72BE8AE-C474-4A30-8CCC-C83059AC6D8C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C72BE8AE-C474-4A30-8CCC-C83059AC6D8C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
53 changes: 53 additions & 0 deletions
53
Samples/Chapter10/01 Asynchronous Trigger/AsynchronousTrigger/AsynchronousTrigger.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,53 @@ | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.50727</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{C72BE8AE-C474-4A30-8CCC-C83059AC6D8C}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>AsynchronousTrigger</RootNamespace> | ||
<AssemblyName>AsynchronousTrigger</AssemblyName> | ||
</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.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="TargetService.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\ServiceBrokerInterface\ServiceBrokerInterface.csproj"> | ||
<Project>{00683377-A75F-47EB-8934-1484D6480877}</Project> | ||
<Name>ServiceBrokerInterface</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\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> |
35 changes: 35 additions & 0 deletions
35
Samples/Chapter10/01 Asynchronous Trigger/AsynchronousTrigger/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,35 @@ | ||
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("AsynchronousTrigger")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("AsynchronousTrigger")] | ||
[assembly: AssemblyCopyright("Copyright © 2007")] | ||
[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("9c3fd8c6-bd16-4c15-8bd2-541630f1ae9e")] | ||
|
||
// 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 Revision and Build Numbers | ||
// by using the '*' as shown below: | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
110 changes: 110 additions & 0 deletions
110
Samples/Chapter10/01 Asynchronous Trigger/AsynchronousTrigger/TargetService.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,110 @@ | ||
using System; | ||
using System.IO; | ||
using System.Xml; | ||
using System.Text; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
using System.Collections.Generic; | ||
using Microsoft.Samples.SqlServer; | ||
|
||
namespace AsynchronousTrigger | ||
{ | ||
/// <summary> | ||
/// This class implements the TargetService. | ||
/// </summary> | ||
public class TargetService : Service | ||
{ | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="Connection">Name of the Service Broker target service</param> | ||
public TargetService(SqlConnection Connection) : base("CustomerInsertedService", Connection) | ||
{ | ||
WaitforTimeout = TimeSpan.FromSeconds(1); | ||
} | ||
|
||
/// <summary> | ||
/// This is the entry point for the managed stored procedure used with Service Broker. | ||
/// </summary> | ||
public static void ServiceProcedure() | ||
{ | ||
Service service = null; | ||
SqlConnection cnn = null; | ||
|
||
try | ||
{ | ||
// Open the database connection | ||
cnn = new SqlConnection("context connection=true;"); | ||
cnn.Open(); | ||
|
||
// Instantiate the Service Broker service "TargetService" | ||
service = new TargetService(cnn); | ||
service.FetchSize = 1; | ||
|
||
// Run the message loop of the service | ||
service.Run(true, cnn, null); | ||
} | ||
catch (ServiceException ex) | ||
{ | ||
if (ex.Transaction != null) | ||
ex.Transaction.Rollback(); | ||
} | ||
finally | ||
{ | ||
if (cnn != null) | ||
cnn.Close(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// This method is called when a new customer was inserted into the database table. | ||
/// </summary> | ||
/// <param name="ReceivedMessage"></param> | ||
/// <param name="Connection"></param> | ||
/// <param name="Transaction"></param> | ||
[BrokerMethod("http://ssb.csharp.at/SSB_Book/c10/CustomerInsertedRequestMessage")] | ||
public void OnCustomerInsertedRequestMessage(Message ReceivedMessage, SqlConnection Connection, SqlTransaction Transaction) | ||
{ | ||
WriteCustomerDetails(ReceivedMessage.BodyAsString); | ||
} | ||
|
||
/// <summary> | ||
/// This method is called, when the client has finished to submit all messages across the same Service Broker conversation. | ||
/// Therefore we are ending in this case the current conversation. | ||
/// </summary> | ||
/// <param name="ReceivedMessage"></param> | ||
/// <param name="Connection"></param> | ||
/// <param name="Transaction"></param> | ||
[BrokerMethod("http://ssb.csharp.at/SSB_Book/c10/EndOfMessageStream")] | ||
public void EndConversation(Message ReceivedMessage, SqlConnection Connection, SqlTransaction Transaction) | ||
{ | ||
// Ends the current Service Broker conversation | ||
ReceivedMessage.Conversation.End(Connection, Transaction); | ||
} | ||
|
||
/// <summary> | ||
/// This method writes the Service Broker message to the file system. So the Managed Assembly needs the permission set EXTERNAL ACCESS. | ||
/// </summary> | ||
/// <param name="xmlMessage"></param> | ||
private static void WriteCustomerDetails(string xmlMessage) | ||
{ | ||
// Loading the message into a XmlDocument | ||
XmlDocument xmlDoc = new XmlDocument(); | ||
xmlDoc.LoadXml(xmlMessage); | ||
|
||
// Appening data to the text file | ||
using (StreamWriter writer = new StreamWriter(@"c:\InsertedCustomers.txt", true)) | ||
{ | ||
// Writing the message to the file system | ||
writer.WriteLine("New Customer arrived:"); | ||
writer.WriteLine("====================="); | ||
writer.WriteLine("CustomerNumber: " + xmlDoc.SelectSingleNode("//CustomerNumber").InnerText); | ||
writer.WriteLine("CustomerName: " + xmlDoc.SelectSingleNode("//CustomerName").InnerText); | ||
writer.WriteLine("CustomerAddress: " + xmlDoc.SelectSingleNode("//CustomerAddress").InnerText); | ||
writer.WriteLine("EmailAddress: " + xmlDoc.SelectSingleNode("//EmailAddress").InnerText); | ||
|
||
writer.Close(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.