-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b96500
commit e4d4dbf
Showing
16 changed files
with
199 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,101 @@ | ||
namespace Lemegeton.Core | ||
using Lemegeton.Action; | ||
using System; | ||
using System.Text.RegularExpressions; | ||
using static Lemegeton.Core.Timeline.Entry; | ||
|
||
namespace Lemegeton.Core | ||
{ | ||
|
||
public class Context | ||
{ | ||
|
||
// ${...} | ||
internal static Regex rex = new Regex(@"\$\{(?<id>[^${}]*)\}"); | ||
|
||
public State State { get; set; } = null; | ||
|
||
public DateTime Created { get; set; } = DateTime.Now; | ||
public string SourceName { get; set; } = "(source name)"; | ||
public string DestName { get; set; } = "(destination name)"; | ||
public string EffectName { get; set; } = "(effect name)"; | ||
|
||
internal Context Duplicate() | ||
{ | ||
return (Context)MemberwiseClone(); | ||
} | ||
|
||
internal string ParseExpressions(Action a, string text) | ||
{ | ||
int i = 0; | ||
while (true) | ||
{ | ||
Match m = rex.Match(text); | ||
if (m.Success == false) | ||
{ | ||
break; | ||
} | ||
string val = ""; | ||
switch (m.Groups["id"].Value.ToLower()) | ||
{ | ||
case "_triggeredtime": | ||
val = Created.ToString(); | ||
break; | ||
case "_currenttime": | ||
val = DateTime.Now.ToString(); | ||
break; | ||
case "_since": | ||
val = Math.Floor((DateTime.Now - Created).TotalSeconds).ToString(); | ||
break; | ||
case "_sincems": | ||
val = Math.Floor((DateTime.Now - Created).TotalMilliseconds).ToString(); | ||
break; | ||
case "_ttl": | ||
if (a is Lemegeton.Action.Notification) | ||
{ | ||
Lemegeton.Action.Notification n = (Lemegeton.Action.Notification)a; | ||
val = (Math.Ceiling(n.TTL) - Math.Floor((DateTime.Now - Created).TotalSeconds)).ToString(); | ||
} | ||
else | ||
{ | ||
val = "0"; | ||
} | ||
break; | ||
case "_ttlms": | ||
if (a is Lemegeton.Action.Notification) | ||
{ | ||
Lemegeton.Action.Notification n = (Lemegeton.Action.Notification)a; | ||
val = (Math.Ceiling(n.TTL * 1000.0f) - Math.Floor((DateTime.Now - Created).TotalMilliseconds)).ToString(); | ||
} | ||
else | ||
{ | ||
val = "0"; | ||
} | ||
break; | ||
case "_effect": | ||
val = EffectName; | ||
break; | ||
case "_src": | ||
val = SourceName; | ||
break; | ||
case "_dest": | ||
val = DestName; | ||
break; | ||
} | ||
text = text.Substring(0, m.Index) + val + text.Substring(m.Index + m.Length); | ||
i++; | ||
if (i > 100) | ||
{ | ||
break; | ||
} | ||
} | ||
return text; | ||
} | ||
|
||
internal string ParseText(Action a, string text) | ||
{ | ||
return ParseExpressions(a, text); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.