Add copyright notices to all source files and put a license in LICENSE.
[versaplex.git] / wvdotnet / servtest.cs
blob06c7782fefc379c27edc41be8911b7dd53b37b37
1 /*
2 * Versaplex:
3 * Copyright (C)2007-2008 Versabanq Innovations Inc. and contributors.
4 * See the included file named LICENSE for license information.
5 */
6 using System;
7 using System.IO;
8 using System.Collections;
9 using System.ComponentModel;
10 using System.ServiceProcess;
11 using System.Configuration.Install;
12 using System.Timers;
13 using Wv;
14 using Wv.Extensions;
17 namespace ServTest
19 public static class SillyHelper
21 public static void print(this Stream stream, string s)
23 byte[] utf8 = s.ToUTF8();
24 stream.Write(utf8, 0, utf8.Length);
25 stream.Flush();
29 [RunInstaller(true)]
30 public class ProjectInstaller: Installer
32 ServiceProcessInstaller spi;
33 ServiceInstaller si;
35 public ProjectInstaller()
37 si = new ServiceInstaller();
38 si.ServiceName = "ServTest";
39 si.Description = "Description++";
40 si.StartType = ServiceStartMode.Automatic;
42 spi = new ServiceProcessInstaller();
43 spi.Account = ServiceAccount.LocalSystem;
44 spi.Password = null;
45 spi.Username = null;
47 Installers.Add(si);
48 Installers.Add(spi);
52 public class ServTest: ServiceBase
54 FileStream f;
55 Timer t;
56 int i = 0;
58 public ServTest()
60 f = File.Open("/tmp/test.txt",
61 FileMode.Append,
62 FileAccess.Write,
63 FileShare.ReadWrite | FileShare.Delete);
64 t = new Timer();
65 t.Interval = 5000;
66 t.Elapsed += new ElapsedEventHandler(t_Elapsed);
68 ServiceName = "ServTest";
71 static void Main(string[] args)
73 ServTest o = new ServTest();
74 o.f.print(String.Format("args: ({0}) ({1}) {2}\n",
75 Environment.UserName,
76 Environment.UserInteractive,
77 args.Length));
79 if (Environment.UserInteractive
80 || (args.Length > 0 && args[0] == "-f"))
82 Console.WriteLine("Running in foreground!");
83 o.OnStart(args);
84 while (true)
85 wv.sleep(1000);
87 else
89 Console.WriteLine("Running in background!");
90 ServiceBase.Run(o);
94 protected override void OnStart(string[] args)
96 f.print("Service started.\n");
97 t.Enabled = true;
100 protected override void OnStop()
102 t.Enabled = false;
103 f.print("Service stopped.\n");
106 private void t_Elapsed(object sender, ElapsedEventArgs e)
108 f.print("Timer elapsed! " + (++i).ToString() + "\n");