Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.11.2 #112

Merged
merged 6 commits into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 63 additions & 63 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
#* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
173 changes: 173 additions & 0 deletions CumulusMX/Alarm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CumulusMX
{
public class Alarm
{
public Cumulus cumulus { get; set; }

public bool Enabled { get; set; }
public double Value { get; set; }
public bool Sound { get; set; }
public string SoundFile { get; set; }

bool triggered;
public bool Triggered
{
get => triggered;
set
{
if (value)
{
triggerCount++;
TriggeredTime = DateTime.Now;

// do we have a threshold value
if (triggerCount >= TriggerThreshold)
{
// If we were not set before, so we need to send an email?
if (!triggered && Enabled && Email && cumulus.SmtpOptions.Enabled)
{
// Construct the message - preamble, plus values
var msg = cumulus.AlarmEmailPreamble + "\r\n" + string.Format(EmailMsg, Value, Units);
if (!string.IsNullOrEmpty(LastError))
{
msg += "\r\nLast error: " + LastError;
}
cumulus.emailer.SendEmail(cumulus.AlarmDestEmail, cumulus.AlarmFromEmail, cumulus.AlarmEmailSubject, msg, cumulus.AlarmEmailHtml);
}

// If we get a new trigger, record the time
triggered = true;
}
}
else
{
// If the trigger is cleared, check if we should be latching the value
if (Latch)
{
if (DateTime.Now > TriggeredTime.AddHours(LatchHours))
{
// We are latching, but the latch period has expired, clear the trigger
triggered = false;
triggerCount = 0;
}
}
else
{
// No latch, just clear the trigger
triggered = false;
triggerCount = 0;
}
}
}
}
public DateTime TriggeredTime { get; set; }
public bool Notify { get; set; }
public bool Email { get; set; }
public bool Latch { get; set; }
public int LatchHours { get; set; }
public string EmailMsg { get; set; }
public string Units { get; set; }
public string LastError { get; set; }
int triggerCount = 0;
public int TriggerThreshold { get; set; }
}

public class AlarmChange : Alarm
{
//public bool changeUp { get; set; }
//public bool changeDown { get; set; }

bool upTriggered;
public bool UpTriggered
{
get => upTriggered;
set
{
if (value)
{
// If we were not set before, so we need to send an email?
if (!upTriggered && Enabled && Email && cumulus.SmtpOptions.Enabled)
{
// Construct the message - preamble, plus values
var msg = Program.cumulus.AlarmEmailPreamble + "\r\n" + string.Format(EmailMsgUp, Value, Units);
cumulus.emailer.SendEmail(cumulus.AlarmDestEmail, cumulus.AlarmFromEmail, cumulus.AlarmEmailSubject, msg, cumulus.AlarmEmailHtml);
}

// If we get a new trigger, record the time
upTriggered = true;
UpTriggeredTime = DateTime.Now;
}
else
{
// If the trigger is cleared, check if we should be latching the value
if (Latch)
{
if (DateTime.Now > UpTriggeredTime.AddHours(LatchHours))
{
// We are latching, but the latch period has expired, clear the trigger
upTriggered = false;
}
}
else
{
// No latch, just clear the trigger
upTriggered = false;
}
}
}
}
public DateTime UpTriggeredTime { get; set; }


bool downTriggered;
public bool DownTriggered
{
get => downTriggered;
set
{
if (value)
{
// If we were not set before, so we need to send an email?
if (!downTriggered && Enabled && Email && cumulus.SmtpOptions.Enabled)
{
// Construct the message - preamble, plus values
var msg = Program.cumulus.AlarmEmailPreamble + "\n" + string.Format(EmailMsgDn, Value, Units);
cumulus.emailer.SendEmail(cumulus.AlarmDestEmail, cumulus.AlarmFromEmail, cumulus.AlarmEmailSubject, msg, cumulus.AlarmEmailHtml);
}

// If we get a new trigger, record the time
downTriggered = true;
DownTriggeredTime = DateTime.Now;
}
else
{
// If the trigger is cleared, check if we should be latching the value
if (Latch)
{
if (DateTime.Now > DownTriggeredTime.AddHours(LatchHours))
{
// We are latching, but the latch period has expired, clear the trigger
downTriggered = false;
}
}
else
{
// No latch, just clear the trigger
downTriggered = false;
}
}
}
}

public DateTime DownTriggeredTime { get; set; }

public string EmailMsgUp { get; set; }
public string EmailMsgDn { get; set; }
}
}
Loading