Skip to content

Commit 4810dc5

Browse files
author
Ahmad Noman Musleh
committed
Fixed several issues and increased performance
1 parent e7c4ca4 commit 4810dc5

21 files changed

+155
-173
lines changed

src/Alert/Alert.csproj

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838
<Reference Include="cAlgo.API">
3939
<HintPath>..\..\..\..\..\Documents\cAlgo\API\cAlgo.API.dll</HintPath>
4040
</Reference>
41-
<Reference Include="cAlgo.API.Alert.UI, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
42-
<HintPath>..\..\packages\cAlgo.API.Alert.UI.2.2.0\lib\net45\cAlgo.API.Alert.UI.dll</HintPath>
41+
<Reference Include="cAlgo.API.Alert.UI, Version=2.2.1.0, Culture=neutral, processorArchitecture=MSIL">
42+
<HintPath>..\..\packages\cAlgo.API.Alert.UI.2.2.1\lib\net45\cAlgo.API.Alert.UI.dll</HintPath>
4343
</Reference>
4444
<Reference Include="CommonServiceLocator, Version=2.0.4.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
4545
<HintPath>..\..\packages\CommonServiceLocator.2.0.4\lib\net45\CommonServiceLocator.dll</HintPath>
4646
</Reference>
4747
<Reference Include="ControlzEx, Version=3.0.2.4, Culture=neutral, processorArchitecture=MSIL">
4848
<HintPath>..\..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll</HintPath>
4949
</Reference>
50-
<Reference Include="LiteDB, Version=5.0.7.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
51-
<HintPath>..\..\packages\LiteDB.5.0.7\lib\net45\LiteDB.dll</HintPath>
50+
<Reference Include="LiteDB, Version=5.0.8.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
51+
<HintPath>..\..\packages\LiteDB.5.0.8\lib\net45\LiteDB.dll</HintPath>
5252
</Reference>
5353
<Reference Include="MahApps.Metro, Version=1.6.5.1, Culture=neutral, processorArchitecture=MSIL">
5454
<HintPath>..\..\packages\MahApps.Metro.1.6.5\lib\net45\MahApps.Metro.dll</HintPath>
@@ -58,18 +58,21 @@
5858
</Reference>
5959
<Reference Include="PresentationCore" />
6060
<Reference Include="PresentationFramework" />
61-
<Reference Include="Prism, Version=7.1.0.431, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59, processorArchitecture=MSIL">
62-
<HintPath>..\..\packages\Prism.Core.7.1.0.431\lib\net45\Prism.dll</HintPath>
61+
<Reference Include="Prism, Version=7.2.0.1422, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59, processorArchitecture=MSIL">
62+
<HintPath>..\..\packages\Prism.Core.7.2.0.1422\lib\net45\Prism.dll</HintPath>
6363
</Reference>
64-
<Reference Include="Prism.Wpf, Version=7.1.0.431, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59, processorArchitecture=MSIL">
65-
<HintPath>..\..\packages\Prism.Wpf.7.1.0.431\lib\net45\Prism.Wpf.dll</HintPath>
64+
<Reference Include="Prism.Wpf, Version=7.2.0.1422, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59, processorArchitecture=MSIL">
65+
<HintPath>..\..\packages\Prism.Wpf.7.2.0.1422\lib\net45\Prism.Wpf.dll</HintPath>
6666
</Reference>
6767
<Reference Include="System" />
6868
<Reference Include="System.Configuration" />
6969
<Reference Include="System.Core" />
7070
<Reference Include="System.Runtime" />
71+
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
72+
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
73+
</Reference>
7174
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
72-
<HintPath>..\..\packages\Prism.Wpf.7.1.0.431\lib\net45\System.Windows.Interactivity.dll</HintPath>
75+
<HintPath>..\..\packages\Prism.Wpf.7.2.0.1422\lib\net45\System.Windows.Interactivity.dll</HintPath>
7376
</Reference>
7477
<Reference Include="System.Xaml" />
7578
<Reference Include="System.Xml.Linq" />
@@ -92,7 +95,7 @@
9295
<DesignTimeSharedInput>True</DesignTimeSharedInput>
9396
<DependentUpon>Settings.settings</DependentUpon>
9497
</Compile>
95-
<Compile Include="Helpers\AlertManager.cs" />
98+
<Compile Include="DataManager.cs" />
9699
<Compile Include="Utility\ExceptionTools.cs" />
97100
<Compile Include="Utility\Logger.cs" />
98101
<Compile Include="Utility\Serializer.cs" />
Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,85 @@
11
using cAlgo.API.Alert.Models;
22
using cAlgo.API.Alert.UI.Models;
33
using LiteDB;
4-
using System;
54
using System.Collections.Generic;
65
using System.IO;
76
using System.Linq;
7+
using System.Threading;
88

9-
namespace cAlgo.API.Alert.Helpers
9+
namespace cAlgo.API.Alert
1010
{
11-
internal static class AlertManager
11+
internal static class DataManager
1212
{
13-
private static readonly object _locker = new object();
14-
1513
public static IEnumerable<AlertModel> GetAlerts()
1614
{
15+
var result = new List<AlertModel>();
16+
1717
if (!File.Exists(Configuration.Current.AlertsFilePath))
1818
{
19-
return new List<AlertModel>();
19+
return result;
2020
}
2121

22-
var alertsFileCopy = Configuration.Current.GetAlertsFileCopy();
23-
24-
try
22+
using (var eventWaitHandle = GetWaitHandle())
2523
{
26-
var connectionString = GetConnectionString(alertsFileCopy.FullName);
24+
eventWaitHandle.WaitOne();
2725

28-
using (LiteDatabase database = new LiteDatabase(connectionString))
26+
using (LiteDatabase database = new LiteDatabase(GetConnectionString()))
2927
{
3028
var collection = database.GetCollection<AlertModel>();
3129

32-
return collection.FindAll().ToList();
30+
result = collection.FindAll().ToList();
3331
}
32+
33+
eventWaitHandle.Set();
3434
}
35-
catch (Exception)
36-
{
37-
throw;
38-
}
39-
finally
40-
{
41-
File.Delete(alertsFileCopy.FullName);
42-
}
35+
36+
return result;
4337
}
4438

4539
public static void AddAlerts(params AlertModel[] alerts)
4640
{
47-
var connectionString = GetConnectionString(Configuration.Current.AlertsFilePath);
48-
49-
lock (_locker)
41+
using (var eventWaitHandle = GetWaitHandle())
5042
{
51-
using (LiteDatabase database = new LiteDatabase(connectionString))
43+
eventWaitHandle.WaitOne();
44+
45+
using (LiteDatabase database = new LiteDatabase(GetConnectionString()))
5246
{
5347
var collection = database.GetCollection<AlertModel>();
5448

5549
collection.InsertBulk(alerts);
5650
}
51+
52+
eventWaitHandle.Set();
5753
}
5854
}
5955

6056
public static void RemoveAlerts(params AlertModel[] alerts)
6157
{
62-
var connectionString = GetConnectionString(Configuration.Current.AlertsFilePath);
63-
64-
lock (_locker)
58+
using (var eventWaitHandle = GetWaitHandle())
6559
{
66-
using (LiteDatabase database = new LiteDatabase(connectionString))
60+
eventWaitHandle.WaitOne();
61+
62+
using (LiteDatabase database = new LiteDatabase(GetConnectionString()))
6763
{
6864
var collection = database.GetCollection<AlertModel>();
6965

7066
collection.DeleteMany(iAlert => alerts.Contains(iAlert));
7167
}
68+
69+
eventWaitHandle.Set();
7270
}
7371
}
7472

75-
private static string GetConnectionString(string fileNmae)
73+
private static string GetConnectionString()
7674
{
77-
return string.Format("Filename={0};Connection=shared", fileNmae);
75+
return string.Format("Filename={0};Connection=shared", Configuration.Current.AlertsFilePath);
76+
}
77+
78+
private static EventWaitHandle GetWaitHandle()
79+
{
80+
var waitHandleName = Configuration.Current.AlertsFilePath.Replace(Path.DirectorySeparatorChar, '_');
81+
82+
return new EventWaitHandle(true, EventResetMode.AutoReset, waitHandleName);
7883
}
7984
}
8085
}

src/Alert/INotificationsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public static void ShowPopup(this INotifications notifications, TimeFrame timeFr
5555

5656
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, TradeType type, string triggeredBy, double price, string comment, DateTimeOffset time)
5757
{
58-
ShowPopup(notifications, timeFrame.ToString(), symbol.Name.ToString(), type.ToString(), triggeredBy, price, comment, DateTimeOffset.Now);
58+
ShowPopup(notifications, timeFrame.ToString(), symbol.Name.ToString(), type.ToString(), triggeredBy, price, comment, time);
5959
}
6060

6161
public static void ShowPopup(this INotifications notifications, TimeFrame timeFrame, Symbol symbol, string type, string triggeredBy, double price, string comment, DateTimeOffset time)
6262
{
63-
ShowPopup(notifications, timeFrame.ToString(), symbol.Name.ToString(), type, triggeredBy, price, comment, DateTimeOffset.Now);
63+
ShowPopup(notifications, timeFrame.ToString(), symbol.Name.ToString(), type, triggeredBy, price, comment, time);
6464
}
6565

6666
public static void ShowPopup(this INotifications notifications, string timeFrame, string symbol, string type, string triggeredBy, double price, string comment, DateTimeOffset time)

src/Alert/Launcher.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using cAlgo.API.Alert.Helpers;
2-
using cAlgo.API.Alert.Models;
1+
using cAlgo.API.Alert.Models;
32
using cAlgo.API.Alert.UI;
43
using cAlgo.API.Alert.UI.Events;
54
using cAlgo.API.Alert.UI.Factories;
@@ -22,8 +21,6 @@ internal static class Launcher
2221

2322
private static App _app;
2423

25-
private static readonly object _locker = new object();
26-
2724
private static readonly List<AlertModel> _alerts = new List<AlertModel>();
2825

2926
private static readonly List<string> _templateKeywords = new List<string>
@@ -50,7 +47,7 @@ public static void Launch(INotifications notifications, AlertModel alert, bool t
5047
{
5148
UpdateAlerts();
5249

53-
AlertManager.AddAlerts(alert);
50+
DataManager.AddAlerts(alert);
5451

5552
_alerts.Add(alert);
5653

@@ -162,8 +159,10 @@ private static void ShowPopup(AlertModel alert)
162159
{
163160
try
164161
{
165-
lock (_locker)
162+
using (var eventWaitHandle = new EventWaitHandle(true, EventResetMode.AutoReset, "AlertWindowWaitHandle"))
166163
{
164+
eventWaitHandle.WaitOne();
165+
167166
if (_app == null)
168167
{
169168
InitializeApp();
@@ -173,6 +172,8 @@ private static void ShowPopup(AlertModel alert)
173172
{
174173
_app.InvokeAlertAddedEvent(alert);
175174
}
175+
176+
eventWaitHandle.Set();
176177
}
177178

178179
_app.Run();
@@ -194,14 +195,14 @@ private static void ShowPopup(AlertModel alert)
194195

195196
private static void AlertRemovedEvent_Handler(IEnumerable<AlertModel> alerts)
196197
{
197-
AlertManager.RemoveAlerts(alerts.ToArray());
198+
DataManager.RemoveAlerts(alerts.ToArray());
198199
}
199200

200201
private static void UpdateAlerts()
201202
{
202203
_alerts.Clear();
203204

204-
var updatedAlerts = AlertManager.GetAlerts();
205+
var updatedAlerts = DataManager.GetAlerts();
205206

206207
if (updatedAlerts != null)
207208
{

src/Alert/Models/Configuration.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using System.Reflection;
4-
using System.Threading;
54

65
namespace cAlgo.API.Alert.Models
76
{
@@ -40,30 +39,5 @@ public Configuration()
4039
public static Configuration Current { get; set; } = new Configuration();
4140

4241
#endregion Properties
43-
44-
#region Methods
45-
46-
public FileInfo GetAlertsFileCopy()
47-
{
48-
if (!File.Exists(AlertsFilePath))
49-
{
50-
throw new FileNotFoundException("Couldn't find the alerts file to copy: " + AlertsFilePath);
51-
}
52-
53-
var alertsFileInfo = new FileInfo(AlertsFilePath);
54-
55-
var alertFileNameWithoutExtension = alertsFileInfo.Name.Substring(0, alertsFileInfo.Name.Length - 4);
56-
57-
var copyFileName = string.Format("{0}_{1}_{2}_{3}.db", alertFileNameWithoutExtension, DateTime.Now.Ticks,
58-
Thread.CurrentThread.ManagedThreadId, Assembly.GetExecutingAssembly().FullName);
59-
60-
var copyFilePath = Path.Combine(alertsFileInfo.DirectoryName, copyFileName);
61-
62-
File.Copy(alertsFileInfo.FullName, copyFilePath);
63-
64-
return new FileInfo(copyFilePath);
65-
}
66-
67-
#endregion
6842
}
6943
}

src/Alert/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.2.0.0")]
36-
[assembly: AssemblyFileVersion("2.2.0.0")]
35+
[assembly: AssemblyVersion("2.2.1.0")]
36+
[assembly: AssemblyFileVersion("2.2.1.0")]
3737
[assembly: NeutralResourcesLanguage("en-US")]

src/Alert/app.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
1818
<dependentAssembly>
1919
<assemblyIdentity name="Prism" publicKeyToken="40ee6c3a2184dc59" culture="neutral" />
20-
<bindingRedirect oldVersion="0.0.0.0-7.1.0.431" newVersion="7.1.0.431" />
20+
<bindingRedirect oldVersion="0.0.0.0-7.2.0.1422" newVersion="7.2.0.1422" />
2121
</dependentAssembly>
2222
<dependentAssembly>
2323
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />

src/Alert/packages.config

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="cAlgo.API.Alert.UI" version="2.2.0" targetFramework="net45" />
3+
<package id="cAlgo.API.Alert.UI" version="2.2.1" targetFramework="net45" />
44
<package id="CommonServiceLocator" version="2.0.4" targetFramework="net45" />
55
<package id="ControlzEx" version="3.0.2.4" targetFramework="net45" />
6-
<package id="LiteDB" version="5.0.7" targetFramework="net45" />
6+
<package id="LiteDB" version="5.0.8" targetFramework="net45" />
77
<package id="MahApps.Metro" version="1.6.5" targetFramework="net45" />
88
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net45" />
9-
<package id="Prism.Core" version="7.1.0.431" targetFramework="net45" />
10-
<package id="Prism.Wpf" version="7.1.0.431" targetFramework="net45" />
9+
<package id="Prism.Core" version="7.2.0.1422" targetFramework="net45" />
10+
<package id="Prism.Wpf" version="7.2.0.1422" targetFramework="net45" />
11+
<package id="System.ValueTuple" version="4.5.0" targetFramework="net45" />
1112
<package id="TelegramBotApi" version="1.0.2" targetFramework="net45" />
1213
</packages>

src/UI/Models/AlertModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,24 @@ public string Comment
121121

122122
public object Clone()
123123
{
124-
return this.MemberwiseClone();
124+
return MemberwiseClone();
125125
}
126126

127127
public static bool operator !=(AlertModel obj1, AlertModel obj2)
128128
{
129-
if (ReferenceEquals(obj1, null))
129+
if (obj1 is null)
130130
{
131-
return !ReferenceEquals(obj2, null);
131+
return obj2 is object;
132132
}
133133

134134
return !obj1.Equals(obj2);
135135
}
136136

137137
public static bool operator ==(AlertModel obj1, AlertModel obj2)
138138
{
139-
if (ReferenceEquals(obj1, null))
139+
if (obj1 is null)
140140
{
141-
return ReferenceEquals(obj2, null);
141+
return obj2 is null;
142142
}
143143

144144
return obj1.Equals(obj2);

src/UI/Models/DataGridColumnSettingsModels.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ public class DataGridColumnSettingsModel
2424

2525
public static bool operator !=(DataGridColumnSettingsModel obj1, DataGridColumnSettingsModel obj2)
2626
{
27-
if (ReferenceEquals(obj1, null))
27+
if (obj1 is null)
2828
{
29-
return !ReferenceEquals(obj2, null);
29+
return obj2 is object;
3030
}
3131

3232
return !obj1.Equals(obj2);
3333
}
3434

3535
public static bool operator ==(DataGridColumnSettingsModel obj1, DataGridColumnSettingsModel obj2)
3636
{
37-
if (ReferenceEquals(obj1, null))
37+
if (obj1 is null)
3838
{
39-
return ReferenceEquals(obj2, null);
39+
return obj2 is null;
4040
}
4141

4242
return obj1.Equals(obj2);

0 commit comments

Comments
 (0)