Skip to content

Commit 51f6b02

Browse files
author
Ahmad Noman Musleh
committed
Added alert type enum
1 parent 5dc23df commit 51f6b02

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

src/Alert/Alert.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<Compile Include="Behaviors\ScrollToItemBehavior.cs" />
8989
<Compile Include="Converters\EnumToDescription.cs" />
9090
<Compile Include="Converters\EnumToInt.cs" />
91+
<Compile Include="Enums\AlertType.cs" />
9192
<Compile Include="Enums\DataGridColumnSettingsType.cs" />
9293
<Compile Include="Enums\TimeFormat.cs" />
9394
<Compile Include="Events\AlertAddedEvent.cs" />

src/Alert/Enums/AlertType.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace cAlgo.API.Alert.Enums
2+
{
3+
public enum AlertType
4+
{
5+
None,
6+
Triggers,
7+
Popup
8+
}
9+
}

src/Alert/INotificationsExtensions.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using cAlgo.API.Alert.Models;
22
using cAlgo.API.Internals;
33
using System;
4+
using cAlgo.API.Alert.Enums;
45

56
namespace cAlgo.API.Alert
67
{
@@ -23,47 +24,57 @@ public static void ShowPopup(this INotifications notifications, TimeFrame timeFr
2324
ShowPopup(notifications, timeFrame, symbol, type, string.Empty);
2425
}
2526

26-
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, TradeType type, string triggeredBy)
27+
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, TradeType type,
28+
string triggeredBy)
2729
{
2830
ShowPopup(notifications, timeFrame, symbol, type, triggeredBy, symbol.Bid);
2931
}
3032

31-
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, string type, string triggeredBy)
33+
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, string type,
34+
string triggeredBy)
3235
{
3336
ShowPopup(notifications, timeFrame, symbol, type, triggeredBy, symbol.Bid);
3437
}
3538

36-
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, TradeType type, string triggeredBy, double price)
39+
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, TradeType type,
40+
string triggeredBy, double price)
3741
{
3842
ShowPopup(notifications, timeFrame, symbol, type, triggeredBy, price, string.Empty);
3943
}
4044

41-
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, string type, string triggeredBy, double price)
45+
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, string type,
46+
string triggeredBy, double price)
4247
{
4348
ShowPopup(notifications, timeFrame, symbol, type, triggeredBy, price, string.Empty);
4449
}
4550

46-
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, TradeType type, string triggeredBy, double price, string comment)
51+
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, TradeType type,
52+
string triggeredBy, double price, string comment)
4753
{
4854
ShowPopup(notifications, timeFrame, symbol, type, triggeredBy, price, comment, DateTimeOffset.Now);
4955
}
5056

51-
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, string type, string triggeredBy, double price, string comment)
57+
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, string type,
58+
string triggeredBy, double price, string comment)
5259
{
5360
ShowPopup(notifications, timeFrame, symbol, type, triggeredBy, price, comment, DateTimeOffset.Now);
5461
}
5562

56-
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, TradeType type, string triggeredBy, double price, string comment, DateTimeOffset time)
63+
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, TradeType type,
64+
string triggeredBy, double price, string comment, DateTimeOffset time)
5765
{
58-
ShowPopup(notifications, timeFrame.ToString(), symbol.Name.ToString(), type.ToString(), triggeredBy, price, comment, time);
66+
ShowPopup(notifications, timeFrame.ToString(), symbol.Name.ToString(), type.ToString(), triggeredBy, price, comment,
67+
time);
5968
}
6069

61-
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, string type, string triggeredBy, double price, string comment, DateTimeOffset time)
70+
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, string type,
71+
string triggeredBy, double price, string comment, DateTimeOffset time)
6272
{
6373
ShowPopup(notifications, timeFrame.ToString(), symbol.Name.ToString(), type, triggeredBy, price, comment, time);
6474
}
6575

66-
public static void ShowPopup(this INotifications notifications, string timeFrame, string symbol, string type, string triggeredBy, double price, string comment, DateTimeOffset time)
76+
public static void ShowPopup(this INotifications notifications, string timeFrame, string symbol, string type,
77+
string triggeredBy, double price, string comment, DateTimeOffset time)
6778
{
6879
AlertModel alert = new AlertModel
6980
{
@@ -81,12 +92,12 @@ public static void ShowPopup(this INotifications notifications, string timeFrame
8192

8293
public static void ShowPopup(this INotifications notifications, AlertModel alert)
8394
{
84-
Launcher.Launch(notifications, alert);
95+
Launcher.Launch(notifications, alert, AlertType.Popup);
8596
}
8697

8798
public static void TriggerAlert(this INotifications notifications, AlertModel alert)
8899
{
89-
Launcher.Launch(notifications, alert, showPopup: false);
100+
Launcher.Launch(notifications, alert, AlertType.Triggers);
90101
}
91102

92103
#endregion Methods

src/Alert/Launcher.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using cAlgo.API.Alert.Events;
1+
using cAlgo.API.Alert.Enums;
2+
using cAlgo.API.Alert.Events;
23
using cAlgo.API.Alert.Factories;
34
using cAlgo.API.Alert.Models;
45
using cAlgo.API.Alert.Utility;
@@ -41,22 +42,22 @@ static Launcher()
4142

4243
#region Methods
4344

44-
public static void Launch(INotifications notifications, AlertModel alert, bool triggerAlerts = true, bool showPopup = true)
45+
public static void Launch(INotifications notifications, AlertModel alert, AlertType alertType)
4546
{
4647
UpdateAlerts();
4748

4849
DataManager.AddAlerts(alert);
4950

5051
_alerts.Add(alert);
5152

52-
SettingsModel settings = SettingsFactory.GetSettings(Configuration.Current.SettingsFilePath);
53+
var settings = SettingsFactory.GetSettings(Configuration.Current.SettingsFilePath);
5354

54-
if (triggerAlerts)
55+
if (alertType == AlertType.Triggers || alertType == AlertType.Popup)
5556
{
5657
TriggerAlerts(notifications, settings, alert);
5758
}
5859

59-
if (showPopup)
60+
if (alertType == AlertType.Popup)
6061
{
6162
ShowPopup(alert);
6263
}
@@ -85,15 +86,18 @@ private static void PlaySound(string path)
8586

8687
private static string PutObjectInTemplate(object obj, string template)
8788
{
88-
Dictionary<string, object> properties = obj.GetType().GetProperties().Where(iProperty => iProperty.GetValue(obj) != null)
89+
Dictionary<string, object> properties = obj.GetType().GetProperties()
90+
.Where(iProperty => iProperty.GetValue(obj) != null)
8991
.ToDictionary(propertyInfo => propertyInfo.Name,
9092
propertyInfo => propertyInfo.GetValue(obj));
9193

9294
foreach (string keyword in _templateKeywords)
9395
{
9496
string propertyName = RemoveKeywordBrackets(keyword);
9597

96-
template = template.Replace(keyword, properties.ContainsKey(propertyName) ? properties[propertyName].ToString() : string.Empty);
98+
template = template.Replace(keyword, properties.ContainsKey(propertyName)
99+
? properties[propertyName].ToString()
100+
: string.Empty);
97101
}
98102

99103
return template;

0 commit comments

Comments
 (0)