Permalink
Browse files

some daemon work

  • Loading branch information...
1 parent ff211d4 commit d3c7e1ada897ddb56c2fe4633739b1d7e7879a21 @wfraser committed Apr 3, 2012
@@ -12,6 +12,21 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -44,18 +59,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="Installer.cs">
- <SubType>Component</SubType>
- </Compile>
+ <Compile Include="Installer.cs" />
<Compile Include="ProgramArguments.cs" />
- <Compile Include="Service.cs">
- <SubType>Component</SubType>
- </Compile>
- <Compile Include="Service.Designer.cs">
- <DependentUpon>Service.cs</DependentUpon>
- </Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Service.cs" />
+ <Compile Include="Session.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
@@ -77,6 +86,23 @@
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
+ <Visible>False</Visible>
+ <ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ </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.
@@ -26,6 +26,7 @@ namespace Codewise.FooSync.Daemon
/// %windir%\Microsoft.NET\Framework\[version]\InstallUtil.exe FooSync.Daemon.exe
/// </summary>
[RunInstaller(true)]
+ [System.ComponentModel.DesignerCategory("Code")] // suppress annoying VS behavior
public class FooSyncServiceInstaller : Installer
{
public FooSyncServiceInstaller()
@@ -37,22 +38,20 @@ public FooSyncServiceInstaller()
var serviceAdmin = new ServiceInstaller();
serviceAdmin.StartType = ServiceStartMode.Manual;
- serviceAdmin.ServiceName = "FooSyncService";
- serviceAdmin.DisplayName = "FooSync Daemon";
- serviceAdmin.Description = "Serves FooSync repositories across the network.";
+ serviceAdmin.ServiceName = FooSyncService.Name;
+ serviceAdmin.DisplayName = FooSyncService.DisplayName;
+ serviceAdmin.Description = FooSyncService.Description;
Installers.Add(process);
Installers.Add(serviceAdmin);
}
#if !__MonoCS__
/// <summary>
- /// This region is specific to WinNT, namely the Windows Firewall with Advanced Security
+ /// This region is specific to WinNT, namely the Windows Firewall with Advanced Security.
/// This code probably will also not work prior to Windows Vista, but this is untested.
/// </summary>
- static readonly string FirewallRuleName = "FooSync Daemon";
-
protected override void OnAfterInstall(System.Collections.IDictionary savedState)
{
AddFirewallRule();
@@ -74,7 +73,7 @@ public void AddFirewallRule()
foreach (INetFwRule r in policy.Rules)
{
- if (r != null && r.Name != null && r.Name.Equals(FirewallRuleName))
+ if (r != null && r.Name != null && r.Name.Equals(FooSyncService.Name))
{
Console.WriteLine("Not adding FW rule; it already exists.");
return;
@@ -94,7 +93,7 @@ public void AddFirewallRule()
rule.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN;
rule.Enabled = true;
rule.InterfaceTypes = "All";
- rule.Name = FirewallRuleName;
+ rule.Name = FooSyncService.Name;
rule.ApplicationName = System.Reflection.Assembly.GetExecutingAssembly().Location;
policy.Rules.Add(rule);
@@ -118,7 +117,7 @@ private void RemoveFirewallRule()
}
var policy = (INetFwPolicy2)Activator.CreateInstance(NetFwPolicy2Type);
- policy.Rules.Remove(FirewallRuleName);
+ policy.Rules.Remove(FooSyncService.Name);
}
#endif // !__MonoCS__
}
Oops, something went wrong.
@@ -25,13 +25,17 @@
namespace Codewise.FooSync.Daemon
{
- public partial class FooSyncService : ServiceBase
+ [System.ComponentModel.DesignerCategory("Code")] // suppress annoying VS behavior
+ public class FooSyncService : ServiceBase
{
- static readonly int DefaultPort = 22022;
+ public static readonly int DefaultPort = 22022;
+ public static readonly string Name = "FooSyncService";
+ public static readonly string DisplayName = "FooSync Daemon";
+ public static readonly string Description = "Serves FooSync repositories across the network.";
public FooSyncService()
{
- InitializeComponent();
+ ServiceName = Name;
_shuttingDown = false;
}
@@ -130,13 +134,13 @@ void Listener_AcceptClient(object arg)
{
try
{
- var client = listener.AcceptSocket();
+ var client = listener.AcceptTcpClient();
- client.Send(
+ client.Client.Send(
Encoding.ASCII.GetBytes(
string.Format(
"Codewise.FooSync.Daemon says hi {0}\r\n",
- (client.RemoteEndPoint as IPEndPoint).Address.ToString()
+ (client.Client.RemoteEndPoint as IPEndPoint).Address.ToString()
)));
//
@@ -0,0 +1,53 @@
+///
+/// Codewise/FooSync/Daemon/Session.cs
+///
+/// by William R. Fraser:
+/// http://www.codewise.org/
+/// https://github.com/wfraser/FooSync
+///
+/// Copyright (c) 2012
+///
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Net.Security;
+using System.Threading;
+using System.Text;
+
+namespace Codewise.FooSync.Daemon
+{
+ public class Session
+ {
+ public bool UseSSL { get; set; }
+
+ private TcpClient _client;
+ private SslStream _ssl;
+ private Stream _stream;
+
+ public Session(TcpClient client)
+ {
+ UseSSL = false; // default to false until this functionality actually works
+ _client = client;
+ }
+
+ /// <summary>
+ /// Handle the session.
+ /// Use this as the main method in session threads.
+ /// </summary>
+ public void Run()
+ {
+ if (UseSSL)
+ {
+ _ssl = new SslStream(_client.GetStream(), true);
+ _stream = _ssl;
+ }
+ else
+ {
+ _stream = _client.GetStream();
+ }
+ }
+ }
+}

0 comments on commit d3c7e1a

Please sign in to comment.