This commit is contained in:
Daniel Schick 2015-07-05 19:15:48 +00:00
parent f2825a95f3
commit 87c54023c1
10 changed files with 0 additions and 504 deletions

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="bsmd.EMailReceiveService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<userSettings>
<bsmd.EMailReceiveService.Properties.Settings>
<setting name="ConnectionString" serializeAs="String">
<value>replace me!</value>
</setting>
<setting name="User" serializeAs="String">
<value>replace me!</value>
</setting>
<setting name="Host" serializeAs="String">
<value>replace me!</value>
</setting>
<setting name="Password" serializeAs="String">
<value>replace me!</value>
</setting>
<setting name="Port" serializeAs="String">
<value>995</value>
</setting>
</bsmd.EMailReceiveService.Properties.Settings>
</userSettings>
</configuration>

View File

@ -1,37 +0,0 @@
namespace bsmd.EMailReceiveService
{
partial class EmailReceiveService
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "Service1";
}
#endregion
}
}

View File

@ -1,152 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.IO;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.Threading.Tasks;
using OpenPop;
using log4net;
using bsmd.database;
namespace bsmd.EMailReceiveService
{
/// <summary>
/// Simpler Windows-Service zum Abruf von NSW Antworten via E-mail. Ich verwende OpenPop.NET Library (via NuGet)
/// http://hpop.sourceforge.net/
///
/// </summary>
public partial class EmailReceiveService : ServiceBase
{
private Timer _timer;
private object _timerlock = new object();
private bool processRunning = false;
private ILog _log = LogManager.GetLogger(typeof(EmailReceiveService));
public EmailReceiveService()
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
InitializeComponent();
}
protected override void OnStart(string[] args)
{
this.EventLog.Source = this.ServiceName;
this.EventLog.Log = "Application";
this.EventLog.BeginInit();
if (!EventLog.SourceExists(this.EventLog.Source, this.EventLog.Log))
EventLog.CreateEventSource(this.EventLog.Source, this.EventLog.Log);
this.EventLog.EndInit();
this.Init(args);
this.EventLog.WriteEntry("NSW EMail Receive Service started.", EventLogEntryType.Information);
}
protected override void OnStop()
{
_log.Info("EmailReceiveService stopped");
}
public void Init(string[] args)
{
this._timer = new Timer();
this._timer.Interval = 600000; // 10 Min, TODO: Settings
this._timer.Elapsed += _timer_Elapsed;
this._timer.Enabled = true;
if (Debugger.IsAttached)
this._timer_Elapsed(null, null);
}
void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
lock (this._timerlock)
{
if (this.processRunning) return;
else this.processRunning = true;
}
if (DBManager.Instance.Connect(Properties.Settings.Default.ConnectionString))
{
try
{
// dbh E-Mail aus Postfach abrufen
using (OpenPop.Pop3.Pop3Client client = new OpenPop.Pop3.Pop3Client())
{
client.Connect(Properties.Settings.Default.Host, Properties.Settings.Default.Port, true);
client.Authenticate(Properties.Settings.Default.User, Properties.Settings.Default.Password);
int messageNum = client.GetMessageCount();
_log.DebugFormat("Mail Server has {0} messages", messageNum);
if (messageNum > 0)
{
// We want to download all messages
List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageNum);
// Messages are numbered in the interval: [1, messageCount]
// Ergo: message numbers are 1-based.
// Most servers give the latest message the highest number
for (int i = 1; i <= messageNum; i++)
{
allMessages.Add(client.GetMessage(i));
}
for (int i = 0; i < allMessages.Count; i++)
{
// XML Anhang extrahieren und in einen string schreiben
OpenPop.Mime.Message message = allMessages[i];
List<OpenPop.Mime.MessagePart> messageParts = message.FindAllAttachments();
for (int partIndex = 0; partIndex < messageParts.Count; partIndex++)
{
OpenPop.Mime.MessagePart part = messageParts[partIndex];
_log.DebugFormat("{0} Encoding: {1}", partIndex, part.ContentTransferEncoding);
switch (part.ContentTransferEncoding)
{
case OpenPop.Mime.Header.ContentTransferEncoding.Base64:
// decode base64 body
break;
default:
break;
}
}
// E-Mail entfernen
// client.DeleteMessage(i+1);
}
}
}
}
catch (Exception ex)
{
_log.ErrorFormat("Exception occurred: {0}", ex.ToString());
}
}
else
{
this.EventLog.WriteEntry("FormService stopped: DB connection failed", EventLogEntryType.Error);
this.Stop();
}
lock (this._timerlock)
{
this.processRunning = false;
}
}
}
}

View File

@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace bsmd.EMailReceiveService
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new EmailReceiveService()
};
if (Debugger.IsAttached)
{
((EmailReceiveService)ServicesToRun[0]).Init(null);
while (true) ;
}
else
{
ServiceBase.Run(ServicesToRun);
}
}
}
}

View File

@ -1,17 +0,0 @@
using System.Reflection;
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("bsmd.EMailReceiveService")]
[assembly: AssemblyDescription("E-Mail checker for NSW response messages sent by mail")]
[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("03d0b447-a06c-46ad-b888-94501a6ea618")]

View File

@ -1,86 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace bsmd.EMailReceiveService.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("replace me!")]
public string ConnectionString {
get {
return ((string)(this["ConnectionString"]));
}
set {
this["ConnectionString"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("replace me!")]
public string User {
get {
return ((string)(this["User"]));
}
set {
this["User"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("replace me!")]
public string Host {
get {
return ((string)(this["Host"]));
}
set {
this["Host"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("replace me!")]
public string Password {
get {
return ((string)(this["Password"]));
}
set {
this["Password"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("995")]
public int Port {
get {
return ((int)(this["Port"]));
}
set {
this["Port"] = value;
}
}
}
}

View File

@ -1,21 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="bsmd.EMailReceiveService.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="ConnectionString" Type="System.String" Scope="User">
<Value Profile="(Default)">replace me!</Value>
</Setting>
<Setting Name="User" Type="System.String" Scope="User">
<Value Profile="(Default)">replace me!</Value>
</Setting>
<Setting Name="Host" Type="System.String" Scope="User">
<Value Profile="(Default)">replace me!</Value>
</Setting>
<Setting Name="Password" Type="System.String" Scope="User">
<Value Profile="(Default)">replace me!</Value>
</Setting>
<Setting Name="Port" Type="System.Int32" Scope="User">
<Value Profile="(Default)">995</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -1,110 +0,0 @@
<?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>{6D46F847-24F2-4883-8B0E-21386FFD0C96}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>bsmd.EMailReceiveService</RootNamespace>
<AssemblyName>bsmd.EMailReceiveService</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference>
<Reference Include="OpenPop">
<HintPath>packages\OpenPop.NET.2.0.6.1102\lib\net40\OpenPop.dll</HintPath>
</Reference>
<Reference Include="System" />
<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.ServiceProcess" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\bsmd.database\Properties\AssemblyProductInfo.cs">
<Link>Properties\AssemblyProductInfo.cs</Link>
</Compile>
<Compile Include="..\bsmd.database\Properties\AssemblyProjectInfo.cs">
<Link>Properties\AssemblyProjectInfo.cs</Link>
</Compile>
<Compile Include="..\bsmd.database\Properties\AssemblyProjectKeyInfo.cs">
<Link>Properties\AssemblyProjectKeyInfo.cs</Link>
</Compile>
<Compile Include="EmailReceiveService.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="EmailReceiveService.Designer.cs">
<DependentUpon>EmailReceiveService.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="..\bsmdKey.snk" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\bsmd.database\bsmd.database.csproj">
<Project>{19945af2-379b-46a5-b27a-303b5ec1d557}</Project>
<Name>bsmd.database</Name>
</ProjectReference>
<ProjectReference Include="..\bsmd.dbh\bsmd.dbh.csproj">
<Project>{df625ff0-2265-4686-9cb6-2a8511cb3b9d}</Project>
<Name>bsmd.dbh</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="readme.txt" />
</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

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="OpenPop.NET" version="2.0.6.1102" targetFramework="net45" />
</packages>

View File

@ -1,11 +0,0 @@
DB Connection string lokal:
Data Source=(localdb)\Projects;Initial Catalog=nsw;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False
Testaccount:
nsw@textbausteine.net
Passwort: 3kjksJSD343
Server: pop3.strato.de
Port: 995