Permalink
Browse files

Can now configure network settings (port, hostname) in Web.config

  • Loading branch information...
1 parent 54bee14 commit b9c1188f1180fa33737d5fc59b2f1cdecb13ca25 @SteveSanderson committed Mar 8, 2010
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <configSections>
+ <section name="deleporter" type="DeleporterCore.Configuration.DeleporterConfigurationSection, Deleporter"/>
+ </configSections>
+ <deleporter Port="54321"/> <!-- By default, it uses port 38473. The test specifies a different port just to check that it can be done. -->
+</configuration>
@@ -36,16 +36,10 @@ public void CanPassParameterViaCapturedLocal()
}
[Test]
- public void CanReturnMultipleValuesViaAnonymousType()
+ public void DelegateRunsInRemoteAppDomain()
{
- var result = Deleporter.Run(() => {
- return new {
- ServerTime = DateTime.UtcNow,
- WebApplicationPath = HostingEnvironment.ApplicationPhysicalPath
- };
- });
- Assert.AreNotEqual(1, result.ServerTime);
- //StringAssert.Contains("Deleporter.Test.Server", result.AppPath.ToString());
+ var result = Deleporter.Run(() => HostingEnvironment.ApplicationPhysicalPath);
+ StringAssert.Contains("Deleporter.Test.Server", result);
}
}
}
@@ -54,6 +54,9 @@
<Name>Deleporter</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </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.
@@ -8,9 +8,9 @@
[assembly: AssemblyTitle("Deleporter.Test.Client")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyCompany("Steven Sanderson")]
[assembly: AssemblyProduct("Deleporter.Test.Client")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyCopyright("Copyright © Steven Sanderson 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -8,9 +8,9 @@
[assembly: AssemblyTitle("Deleporter.Test.Server")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyCompany("Steven Sanderson")]
[assembly: AssemblyProduct("Deleporter.Test.Server")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyCopyright("Copyright © Steven Sanderson 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -13,8 +13,11 @@
</sectionGroup>
</sectionGroup>
</sectionGroup>
- </configSections>
+ <section name="deleporter" type="DeleporterCore.Configuration.DeleporterConfigurationSection, Deleporter"/>
+ </configSections>
+ <deleporter Port="54321" />
+
<appSettings />
<connectionStrings />
<system.web>
@@ -0,0 +1,26 @@
+using System.Configuration;
+
+namespace DeleporterCore.Configuration
+{
+ public class DeleporterConfigurationSection : ConfigurationSection
+ {
+ [ConfigurationProperty("Port", DefaultValue = NetworkConfiguration.DefaultPort)]
+ public int Port {
+ get { return (int) this["Port"]; }
+ set { this["Port"] = value; }
+ }
+
+ [ConfigurationProperty("Host", DefaultValue = NetworkConfiguration.DefaultHost)]
+ public string Host {
+ get { return (string)this["Host"]; }
+ set { this["Host"] = value; }
+ }
+
+ [ConfigurationProperty("ServiceName", DefaultValue = NetworkConfiguration.DefaultServiceName)]
+ public string ServiceName {
+ get { return (string)this["ServiceName"]; }
+ set { this["ServiceName"] = value; }
+ }
+
+ }
+}
@@ -1,4 +1,5 @@
using System.Collections;
+using System.Configuration;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Serialization.Formatters;
@@ -7,20 +8,34 @@ namespace DeleporterCore.Configuration
{
public static class NetworkConfiguration
{
- public static string HostName { get; set; }
- public static string ServiceName { get; set; }
- public static int PortNumber { get; set; }
+ internal const int DefaultPort = 38473;
+ internal const string DefaultHost = "localhost";
+ internal const string DefaultServiceName = "Deleporter.rm";
+
+ public static int Port { get; private set; }
+ public static string Host { get; private set; }
+ public static string ServiceName { get; private set; }
static NetworkConfiguration()
{
- HostName = "localhost";
- ServiceName = "Deleporter.rm";
- PortNumber = 39084;
+ var config = (DeleporterConfigurationSection)ConfigurationManager.GetSection("deleporter");
+ if (config != null)
+ {
+ Port = config.Port;
+ Host = config.Host;
+ ServiceName = config.ServiceName;
+ }
+ else
+ {
+ Port = DefaultPort;
+ Host = DefaultHost;
+ ServiceName = DefaultServiceName;
+ }
}
public static IChannel CreateChannel()
{
- IDictionary props = new Hashtable { {"port", PortNumber}, {"typeFilterLevel", TypeFilterLevel.Full} };
+ IDictionary props = new Hashtable { { "port", Port }, { "typeFilterLevel", TypeFilterLevel.Full } };
return new TcpChannel(props, null, new BinaryServerFormatterSinkProvider {
TypeFilterLevel = TypeFilterLevel.Full
@@ -29,7 +44,7 @@ public static IChannel CreateChannel()
public static string HostAddress
{
- get { return string.Format("tcp://{0}:{1}/{2}", HostName, PortNumber, ServiceName); }
+ get { return string.Format("tcp://{0}:{1}/{2}", Host, Port, ServiceName); }
}
}
}
@@ -32,6 +32,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.Web" />
@@ -42,6 +43,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyProvider.cs" />
+ <Compile Include="Configuration\DeleporterConfigurationSection.cs" />
<Compile Include="FuncExecutionResult.cs" />
<Compile Include="Configuration\NetworkConfiguration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

0 comments on commit b9c1188

Please sign in to comment.