-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathExampleService.cs
More file actions
52 lines (44 loc) · 1.45 KB
/
ExampleService.cs
File metadata and controls
52 lines (44 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using Microsoft.Extensions.PlatformAbstractions;
using PeterKottas.DotNetCore.WindowsService.Interfaces;
using System;
using System.IO;
using System.Timers;
namespace PeterKottas.DotNetCore.WindowsService.Example
{
public class ExampleService : IMicroService
{
private IMicroServiceController _controller;
private readonly Timer _timer = new Timer(1000);
private readonly string _fileName = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "log.txt");
public ExampleService()
{
_controller = null;
}
public ExampleService(IMicroServiceController controller)
{
_controller = controller;
}
public void Start()
{
Console.WriteLine("I started");
Console.WriteLine(_fileName);
File.AppendAllText(_fileName, "Started\n");
/**
* A timer is a simple example. But this could easily
* be a port or messaging queue client
*/
_timer.Elapsed += _timer_Elapsed;
_timer.Start();
}
public void Stop()
{
_timer.Stop();
File.AppendAllText(_fileName, "Stopped\n");
Console.WriteLine("I stopped");
}
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
File.AppendAllText(_fileName, string.Format("Polling at {0}\n", DateTime.Now.ToString("o")));
}
}
}