vxodbc: render timeless datetimes correctly into strings.
[versaplex.git] / wvdotnet / servtest.cs
blobde1b46cbe668af9172aca4f155faad586a0b1a0f
1 using System;
2 using System.IO;
3 using System.Collections;
4 using System.ComponentModel;
5 using System.ServiceProcess;
6 using System.Configuration.Install;
7 using System.Timers;
8 using Wv;
9 using Wv.Extensions;
12 namespace ServTest
14 public static class SillyHelper
16 public static void print(this Stream stream, string s)
18 byte[] utf8 = s.ToUTF8();
19 stream.Write(utf8, 0, utf8.Length);
20 stream.Flush();
24 [RunInstaller(true)]
25 public class ProjectInstaller: Installer
27 ServiceProcessInstaller spi;
28 ServiceInstaller si;
30 public ProjectInstaller()
32 si = new ServiceInstaller();
33 si.ServiceName = "ServTest";
34 si.Description = "Description++";
35 si.StartType = ServiceStartMode.Automatic;
37 spi = new ServiceProcessInstaller();
38 spi.Account = ServiceAccount.LocalSystem;
39 spi.Password = null;
40 spi.Username = null;
42 Installers.Add(si);
43 Installers.Add(spi);
47 public class ServTest: ServiceBase
49 FileStream f;
50 Timer t;
51 int i = 0;
53 public ServTest()
55 f = File.Open("/tmp/test.txt",
56 FileMode.Append,
57 FileAccess.Write,
58 FileShare.ReadWrite | FileShare.Delete);
59 t = new Timer();
60 t.Interval = 5000;
61 t.Elapsed += new ElapsedEventHandler(t_Elapsed);
63 ServiceName = "ServTest";
66 static void Main(string[] args)
68 ServTest o = new ServTest();
69 o.f.print(String.Format("args: ({0}) ({1}) {2}\n",
70 Environment.UserName,
71 Environment.UserInteractive,
72 args.Length));
74 if (Environment.UserInteractive
75 || (args.Length > 0 && args[0] == "-f"))
77 Console.WriteLine("Running in foreground!");
78 o.OnStart(args);
79 while (true)
80 wv.sleep(1000);
82 else
84 Console.WriteLine("Running in background!");
85 ServiceBase.Run(o);
89 protected override void OnStart(string[] args)
91 f.print("Service started.\n");
92 t.Enabled = true;
95 protected override void OnStop()
97 t.Enabled = false;
98 f.print("Service stopped.\n");
101 private void t_Elapsed(object sender, ElapsedEventArgs e)
103 f.print("Timer elapsed! " + (++i).ToString() + "\n");