- updated the MEF.Bonjour

- updated the Rest Infrastructure
- added a new project for standard bonjour services
master
neonp_cp 2009-02-08 01:23:24 -08:00
parent 6e72f8a9c3
commit def44384aa
17 changed files with 402 additions and 2 deletions

View File

@ -21,6 +21,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MEF.Bonjour", "MEF.Bonjour\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MEF.Bonjour.Tests", "MEF.Bonjour.Tests\MEF.Bonjour.Tests.csproj", "{770EE8FF-624F-445F-A6ED-B29E2DAFA591}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Network.Rest.MEF", "Network.Rest.MEF\Network.Rest.MEF.csproj", "{75A1C6F7-756C-494A-9B21-8C2BCD2F809D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Network.Bonjour.Services", "Network.Bonjour.Services\Network.Bonjour.Services.csproj", "{8CC2B14D-E24B-41A8-AB93-17F130905E29}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -67,6 +71,14 @@ Global
{770EE8FF-624F-445F-A6ED-B29E2DAFA591}.Debug|Any CPU.Build.0 = Debug|Any CPU
{770EE8FF-624F-445F-A6ED-B29E2DAFA591}.Release|Any CPU.ActiveCfg = Release|Any CPU
{770EE8FF-624F-445F-A6ED-B29E2DAFA591}.Release|Any CPU.Build.0 = Release|Any CPU
{75A1C6F7-756C-494A-9B21-8C2BCD2F809D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75A1C6F7-756C-494A-9B21-8C2BCD2F809D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75A1C6F7-756C-494A-9B21-8C2BCD2F809D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75A1C6F7-756C-494A-9B21-8C2BCD2F809D}.Release|Any CPU.Build.0 = Release|Any CPU
{8CC2B14D-E24B-41A8-AB93-17F130905E29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CC2B14D-E24B-41A8-AB93-17F130905E29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CC2B14D-E24B-41A8-AB93-17F130905E29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CC2B14D-E24B-41A8-AB93-17F130905E29}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?><ItemProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Properties><Property><Name>svn:ignore</Name><Value>bin
obj
</Value></Property></Properties></ItemProperties>

View File

@ -40,5 +40,10 @@ namespace DLNA.ContentDirectory
//request.Headers["Content-Length"] = (request.ContentType.Length).ToString();
return request;
}
public override void Execute(RequestEventArgs e)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?><ItemProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Properties><Property><Name>svn:ignore</Name><Value>bin
obj
</Value></Property></Properties></ItemProperties>

View File

@ -35,7 +35,7 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition, Version=2009.1.23.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\bin\System.ComponentModel.Composition.dll</HintPath>
<HintPath>..\System.ComponentModel.Composition.dll</HintPath>
</Reference>
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?><ItemProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Properties><Property><Name>svn:ignore</Name><Value>bin
obj
</Value></Property></Properties></ItemProperties>

View File

@ -34,7 +34,7 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition, Version=2009.1.23.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\bin\System.ComponentModel.Composition.dll</HintPath>
<HintPath>..\System.ComponentModel.Composition.dll</HintPath>
</Reference>
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8CC2B14D-E24B-41A8-AB93-17F130905E29}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Network.Bonjour.Pear</RootNamespace>
<AssemblyName>Network.Bonjour.Pear</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<StartupObject>Network.Bonjour.Services.Pear.AirDiskService</StartupObject>
</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.ComponentModel.Composition, Version=2009.1.23.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\System.ComponentModel.Composition.dll</HintPath>
</Reference>
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Pear\AirDiskService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WebDav.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bonjour.NET\Network.Bonjour.csproj">
<Project>{CA2E95A3-CF9D-4524-85FC-12CAD9D81479}</Project>
<Name>Network.Bonjour</Name>
</ProjectReference>
<ProjectReference Include="..\DnsResolver\Network.Dns.csproj">
<Project>{36528547-53DC-46CD-8C97-1BAE69262B00}</Project>
<Name>Network.Dns</Name>
</ProjectReference>
<ProjectReference Include="..\SD\Network.ZeroConf.csproj">
<Project>{2B2D41E0-DBC7-4075-873C-394D02448281}</Project>
<Name>Network.ZeroConf</Name>
</ProjectReference>
</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>

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Network.ZeroConf;
using System.Threading;
using System.ComponentModel.Composition;
namespace Network.Bonjour.Services.Pear
{
[Export("_adisk._tcp._local.")]
public class AirDiskService : Bonjour.Service
{
public AirDiskService() { }
public AirDiskService(string diskName, string sys, params string[] dk)
{
HostName = Environment.MachineName + ".local.";
Name = diskName;
Protocol = "_adisk._tcp._local.";
this.addresses.Add(ResolverHelper.GetEndPoint());
this["sys"] = sys;
for (int i = 0; i < dk.Length; i++)
this["dk" + i] = dk[i];
}
public static void Main()
{
IService s = new AirDiskService("toto", string.Format("waMA={0}", ResolverHelper.GetMacAddresses().First().ToString()), string.Format("adVF=0xa1,adVN=toto,adVU={0}", Guid.NewGuid()));
s.Publish();
Thread.Sleep(10000);
s.Stop();
}
}
}

View File

@ -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("Network.Bonjour.Pear")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Network.Bonjour.Pear")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2009")]
[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("c57c1f46-a294-402f-9807-1261a914829e")]
// 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")]

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
namespace Network.Bonjour.Pear
{
[Export("_webdav._tcp._local.")]
public class WebDav : Service
{
public WebDav() { }
public WebDav(string userName, string password, string path)
{
this["u"] = userName;
this["p"] = password;
this["path"] = path;
}
}
}

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{75A1C6F7-756C-494A-9B21-8C2BCD2F809D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Network.Rest.MEF</RootNamespace>
<AssemblyName>Network.Rest.MEF</AssemblyName>
<TargetFrameworkVersion>v3.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.ComponentModel.Composition, Version=2009.1.23.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\System.ComponentModel.Composition.dll</HintPath>
</Reference>
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="RestServer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Rest\Network.Rest.csproj">
<Project>{3FFE9D8C-3914-4DD1-BB7C-8D4359216806}</Project>
<Name>Network.Rest</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</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>

View File

@ -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("Network.Rest.MEF")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Network.Rest.MEF")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2009")]
[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("883148ce-4e76-45ce-bcb5-563f9f726704")]
// 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")]

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.Text.RegularExpressions;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.Reflection;
namespace Network.Rest.MEF
{
public abstract class RestServer : Network.Rest.RestServer
{
public ComposablePartCatalog Catalog { get; set; }
private CompositionBatch batch;
public RestServer(ushort port, Assembly assemblyContainingCommands)
: this(port)
{
Catalog = new AssemblyCatalog(assemblyContainingCommands);
}
public RestServer(ushort port, string pathContainingCommands)
: this(port)
{
Catalog = new DirectoryCatalog(pathContainingCommands, true);
}
public RestServer(ushort port)
: base(port)
{
this.RequestReceived += new EventHandler<RequestEventArgs>(RestServer_RequestReceived);
batch = new CompositionBatch();
batch.AddPart(this);
}
protected override void OnStart()
{
CompositionContainer container = new CompositionContainer(Catalog);
container.Compose(batch);
base.OnStart();
}
void RestServer_RequestReceived(object sender, RequestEventArgs e)
{
Command c = commands.Where(command => command.Metadata["Method"].ToString() == e.Request.Method && command.Metadata.ContainsKey("UriConstraint") ? Regex.IsMatch(e.Request.Uri, command.Metadata["UriConstraint"].ToString()) : true).Single().GetExportedObject();
c.Execute(e);
}
[Import]
[ImportRequiredMetadata("Method")]
protected ExportCollection<Command> commands;
}
}

View File

@ -53,5 +53,7 @@ namespace Network.Rest
}
return doc;
}
public abstract void Execute(RequestEventArgs e);
}
}

View File

@ -31,6 +31,12 @@ namespace Network.Rest
IsStarted = false;
}
public void Restart()
{
Stop();
Start();
}
protected virtual void OnStart()
{
if (Started != null)

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Network.Dns;
using System.Net.NetworkInformation;
namespace Network.ZeroConf
{
@ -33,5 +35,33 @@ namespace Network.ZeroConf
services.Add(item);
syncLock.Set();
}
public static EndPoint GetEndPoint()
{
EndPoint ep = new EndPoint();
ep.DomainName = Environment.MachineName + ".local.";
foreach (NetworkInterface iface in NetworkInterface.GetAllNetworkInterfaces())
{
if (iface.OperationalStatus == OperationalStatus.Up)
{
foreach (var address in iface.GetIPProperties().UnicastAddresses)
ep.Addresses.Add(address.Address);
}
}
return ep;
}
public static IEnumerable<PhysicalAddress> GetMacAddresses()
{
foreach (NetworkInterface iface in NetworkInterface.GetAllNetworkInterfaces())
{
if (iface.OperationalStatus == OperationalStatus.Up)
{
yield return iface.GetPhysicalAddress();
}
}
}
}
}