-
Notifications
You must be signed in to change notification settings - Fork 1
/
DateDevice.cs
83 lines (66 loc) · 2.4 KB
/
DateDevice.cs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//========================================================================================
/// <copyright from='2005' to='2008' company='Embedded Automation, Inc.'>
///
/// mHome Automation Server
///
/// Copyright (c) Embedded Automation, Inc. All rights reserved.
/// Copyright (c) Michael Shulman. All rights reserved.
///
/// </copyright>
//
// $Id$
//
//========================================================================================
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Cache;
using System.Net;
using System.Text;
using System.Threading;
namespace EmbeddedAutomation.mServer.Adapters
{
using EmbeddedAutomation.mHome.Api;
using EmbeddedAutomation.mServer.Api;
public class DateDevice : AbstractDevice
{
public override string PluginName { get { return "Date Device"; } }
public override Version PluginVersion { get { return new Version(1, 0, 0); } }
private AutoResetEvent _evRespRcvd; // response received
protected DateTime currentDate;
public DateDevice(AbstractAdapterDriver mngr, IKnownModule module) : base(mngr, module)
{
}
public override void UninitDevice()
{
SrvUtil.DisposeWaitHandle(ref _evRespRcvd);
}
public override void InitDevice()
{
tellServerDate();
_evRespRcvd = new AutoResetEvent(false);
}
public void tellServerDate()
{
currentDate = DateTime.Now;
tellServer("Year", currentDate.Year.ToString());
tellServer("Month", currentDate.Month.ToString());
tellServer("Day", currentDate.Day.ToString());
tellServer("DayOfWeekNum", Convert.ToInt32(currentDate.DayOfWeek).ToString()); // sunday = 0
tellServer("DateIsOdd", Convert.ToString(((currentDate.Day & 1) == 1)).ToUpper());
base.CurrentStatus = CurrentStatusAsString(); // this will announce to the clients;
}
public void processMidnight()
{
tellServerDate();
}
private void tellServer(string message, string state)
{
DeviceCommandReceived(new DeviceChangeEvent(message, state));
}
public string CurrentStatusAsString()
{
return currentDate.ToShortDateString() +" "+ currentDate.ToShortTimeString();
}
}
}