Skip to content

Commit 63b1de3

Browse files
author
Ahmad Noman Musleh
committed
Icon packs dependency has been removed except material icon pack and logger class is now static
1 parent b5c9e80 commit 63b1de3

File tree

14 files changed

+149
-61
lines changed

14 files changed

+149
-61
lines changed

src/Alert/Alert.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
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.1.0.1, Culture=neutral, processorArchitecture=MSIL">
42-
<HintPath>..\..\packages\cAlgo.API.Alert.UI.2.1.0.1\lib\net45\cAlgo.API.Alert.UI.dll</HintPath>
41+
<Reference Include="cAlgo.API.Alert.UI, Version=2.1.0.2, Culture=neutral, processorArchitecture=MSIL">
42+
<HintPath>..\..\packages\cAlgo.API.Alert.UI.2.1.0.2\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>
@@ -53,8 +53,8 @@
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>
5555
</Reference>
56-
<Reference Include="MahApps.Metro.IconPacks, Version=2.3.0.4, Culture=neutral, processorArchitecture=MSIL">
57-
<HintPath>..\..\packages\MahApps.Metro.IconPacks.2.3.0\lib\net45\MahApps.Metro.IconPacks.dll</HintPath>
56+
<Reference Include="MahApps.Metro.IconPacks.Material, Version=2.3.0.4, Culture=neutral, processorArchitecture=MSIL">
57+
<HintPath>..\..\packages\MahApps.Metro.IconPacks.Material.2.3.0\lib\net45\MahApps.Metro.IconPacks.Material.dll</HintPath>
5858
</Reference>
5959
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
6060
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>

src/Alert/Launcher.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,8 @@ public class Launcher
2626

2727
private List<AlertModel> _alerts;
2828

29-
private Logger _logger;
30-
3129
#endregion Fields
3230

33-
public Launcher()
34-
{
35-
_logger = new Logger(Configuration.Current.Tracer);
36-
}
37-
3831
#region Properties
3932

4033
public static Launcher Current => _current;
@@ -169,7 +162,7 @@ public void Launch(INotifications notifications, AlertModel alert)
169162
}
170163
catch (InvalidOperationException ex)
171164
{
172-
_logger.Log(ex);
165+
Logger.LogException(ex);
173166
}
174167
}));
175168

src/Alert/Models/Configuration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public Configuration()
2323

2424
AlertFilePath = Path.Combine(calgoDirPath, $"Alerts_{version}.db");
2525
SettingsFilePath = Path.Combine(calgoDirPath, $"AlertPopupSettings_{version}.xml");
26+
LogFilePath = Path.Combine(calgoDirPath, $"Alerts_{version}.log");
2627

2728
Title = $"Alerts - cTrader {version}";
2829
}
@@ -33,6 +34,8 @@ public Configuration()
3334

3435
public string SettingsFilePath { get; set; }
3536

37+
public string LogFilePath { get; set; }
38+
3639
public Action<string> Tracer { get; set; }
3740

3841
public string Title { get; set; }

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.1.0.1")]
36-
[assembly: AssemblyFileVersion("2.1.0.1")]
35+
[assembly: AssemblyVersion("2.1.0.2")]
36+
[assembly: AssemblyFileVersion("2.1.0.2")]
3737
[assembly: NeutralResourcesLanguage("en-US")]

src/Alert/Utility/Logger.cs

Lines changed: 110 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,133 @@
1-
using System;
1+
using cAlgo.API.Alert.Models;
2+
using System;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
27

38
namespace cAlgo.API.Alert.Utility
49
{
5-
public class Logger
10+
public static class Logger
611
{
7-
#region Fields
12+
#region Methods
813

9-
private Action<string> _tracer;
14+
public static void LogException(Exception exception)
15+
{
16+
string exceptionData = GetExceptionData(exception);
1017

11-
#endregion Fields
18+
Log(exceptionData);
19+
}
1220

13-
public Logger(Action<string> tracer)
21+
public static void Log(string message, params object[] parameters)
1422
{
15-
_tracer = tracer;
23+
string messageFormatted = string.Format(message, parameters);
1624

17-
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
18-
}
25+
Configuration.Current.Tracer?.Invoke(messageFormatted);
1926

20-
#region Methods
27+
string logFilePath = Configuration.Current.LogFilePath;
2128

22-
public void Log(string message)
23-
{
24-
_tracer.Invoke(message);
29+
using (FileStream stream = File.Open(logFilePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
30+
using (TextWriter writer = new StreamWriter(stream))
31+
{
32+
string line = string.Format("{0:yyyy-MM-dd HH:mm:ss} => {1}", DateTime.UtcNow, messageFormatted);
33+
34+
writer.WriteLine(line);
35+
}
2536
}
2637

27-
public void Log(Exception exception)
38+
private static string GetExceptionData(Exception exception, bool addStackTrace = true, bool isInnerException = false,
39+
string intend = null)
2840
{
29-
string exceptionSummary = ExceptionTools.GetDetail(exception);
41+
StringBuilder stringBuilder = new StringBuilder();
42+
43+
intend = intend ?? string.Empty;
44+
45+
if (isInnerException)
46+
{
47+
stringBuilder.AppendLine();
48+
stringBuilder.Append(string.Format("{0}InnerException:", intend));
49+
}
50+
else
51+
{
52+
string systemType = Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit";
53+
54+
stringBuilder.AppendLine();
55+
stringBuilder.Append(string.Format("OS Version: {0}", Environment.OSVersion.VersionString));
56+
stringBuilder.AppendLine();
57+
stringBuilder.Append(string.Format("System Type: {0}", systemType));
58+
}
59+
60+
stringBuilder.AppendLine();
61+
stringBuilder.Append(string.Format("{0}Source: {1}", intend, exception.Source));
62+
stringBuilder.AppendLine();
63+
stringBuilder.Append(string.Format("{0}Message: {1}", intend, exception.Message));
64+
stringBuilder.AppendLine();
65+
stringBuilder.Append(string.Format("{0}TargetSite: {1}", intend, exception.TargetSite));
66+
stringBuilder.AppendLine();
67+
stringBuilder.Append(string.Format("{0}Type: {1}", intend, exception.GetType()));
68+
stringBuilder.AppendLine();
69+
70+
if (addStackTrace)
71+
{
72+
string stackTrace = GetExceptionStackTrace(exception, intend);
73+
74+
stringBuilder.AppendLine(stackTrace);
75+
76+
stringBuilder.AppendLine();
77+
}
3078

31-
_tracer.Invoke(exceptionSummary);
79+
if (exception.InnerException != null)
80+
{
81+
string innerExceptionIntent = new string(' ', intend.Length + 4);
82+
83+
string innerExceptionSummary = GetExceptionData(exception.InnerException, isInnerException: true, intend: innerExceptionIntent);
84+
85+
stringBuilder.Append(innerExceptionSummary);
86+
}
87+
88+
return stringBuilder.ToString();
3289
}
3390

34-
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
91+
private static string GetExceptionStackTrace(Exception exception, string intend = null)
3592
{
36-
if (e.ExceptionObject != null)
93+
if (string.IsNullOrEmpty(exception.StackTrace))
3794
{
38-
Log(e.ExceptionObject as Exception);
95+
return string.Empty;
3996
}
97+
98+
StackTrace stackTrace = new StackTrace(exception, true);
99+
100+
StackFrame[] frames = stackTrace.GetFrames();
101+
102+
if (frames == null || !frames.Any())
103+
{
104+
return string.Empty;
105+
}
106+
107+
StringBuilder stringBuilder = new StringBuilder();
108+
109+
stringBuilder.Append(string.Format("{0}StackTrace:", intend));
110+
stringBuilder.AppendLine();
111+
112+
string tracesIntend = new string(' ', string.IsNullOrEmpty(intend) ? 4 : intend.Length + 4);
113+
114+
foreach (StackFrame stackFram in frames)
115+
{
116+
string fileName = stackFram.GetFileName();
117+
118+
fileName = !string.IsNullOrEmpty(fileName)
119+
? fileName.Substring(fileName.LastIndexOf(@"\", StringComparison.InvariantCultureIgnoreCase) + 1)
120+
: string.Empty;
121+
122+
string stackFrameText = string.Format("{0}File: {1} | Line: {2} | Col: {3} | Offset: {4} | Method: {5}", tracesIntend, fileName,
123+
stackFram.GetFileLineNumber(), stackFram.GetFileColumnNumber(), stackFram.GetILOffset(), stackFram.GetMethod());
124+
125+
stringBuilder.Append(stackFrameText);
126+
127+
stringBuilder.AppendLine();
128+
}
129+
130+
return stringBuilder.ToString();
40131
}
41132

42133
#endregion Methods

src/Alert/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="cAlgo.API.Alert.UI" version="2.1.0.1" targetFramework="net45" />
3+
<package id="cAlgo.API.Alert.UI" version="2.1.0.2" targetFramework="net45" />
44
<package id="CommonServiceLocator" version="2.0.4" targetFramework="net45" />
55
<package id="ControlzEx" version="3.0.2.4" targetFramework="net45" />
66
<package id="LiteDB" version="4.1.4" targetFramework="net45" />
77
<package id="MahApps.Metro" version="1.6.5" targetFramework="net45" />
8-
<package id="MahApps.Metro.IconPacks" version="2.3.0" targetFramework="net45" />
8+
<package id="MahApps.Metro.IconPacks.Material" version="2.3.0" targetFramework="net45" />
99
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net45" />
1010
<package id="Prism.Core" version="7.1.0.431" targetFramework="net45" />
1111
<package id="Prism.Wpf" version="7.1.0.431" targetFramework="net45" />

src/UI/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.1.0.1")]
36-
[assembly: AssemblyFileVersion("2.1.0.1")]
35+
[assembly: AssemblyVersion("2.1.0.2")]
36+
[assembly: AssemblyFileVersion("2.1.0.2")]
3737
[assembly: NeutralResourcesLanguage("en-US")]

src/UI/Resources/AlertsViewResources.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
55
xmlns:converters="clr-namespace:cAlgo.API.Alert.UI.Converters"
6-
xmlns:iconsPack="clr-namespace:MahApps.Metro.IconPacks;assembly=MahApps.Metro.IconPacks"
6+
xmlns:iconsPack="http://metro.mahapps.com/winfx/xaml/iconpacks"
77
xmlns:local="clr-namespace:cAlgo.API.Alert.UI">
88
<ResourceDictionary.MergedDictionaries>
99
<ResourceDictionary Source="SharedResources.xaml" />

src/UI/Resources/SettingsViewResources.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
55
xmlns:converters="clr-namespace:cAlgo.API.Alert.UI.Converters"
6-
xmlns:iconsPack="clr-namespace:MahApps.Metro.IconPacks;assembly=MahApps.Metro.IconPacks"
6+
xmlns:iconsPack="http://metro.mahapps.com/winfx/xaml/iconpacks"
77
xmlns:local="clr-namespace:cAlgo.API.Alert.UI">
88
<ResourceDictionary.MergedDictionaries>
99
<ResourceDictionary Source="./SharedResources.xaml" />
@@ -49,7 +49,7 @@
4949
Command="{Binding Path=DataContext.RemoveSelectedTelegramBotsCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}"
5050
CommandParameter="{Binding Path=SelectedItems, RelativeSource={RelativeSource AncestorType=DataGrid}}"
5151
ToolTip="Remove Selected">
52-
<iconsPack:Material Kind="Delete" />
52+
<iconsPack:PackIconMaterial Kind="Delete" />
5353
</Button>
5454
</StackPanel>
5555
</DataTemplate>
@@ -61,7 +61,7 @@
6161
Command="{Binding Path=DataContext.RemoveTelegramBotCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}"
6262
CommandParameter="{Binding}"
6363
ToolTip="Remove">
64-
<iconsPack:Material Kind="Delete" />
64+
<iconsPack:PackIconMaterial Kind="Delete" />
6565
</Button>
6666
</StackPanel>
6767
</DataTemplate>

src/UI/UI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
<Reference Include="MahApps.Metro, Version=1.6.5.1, Culture=neutral, processorArchitecture=MSIL">
4646
<HintPath>..\..\packages\MahApps.Metro.1.6.5\lib\net45\MahApps.Metro.dll</HintPath>
4747
</Reference>
48-
<Reference Include="MahApps.Metro.IconPacks, Version=2.3.0.4, Culture=neutral, processorArchitecture=MSIL">
49-
<HintPath>..\..\packages\MahApps.Metro.IconPacks.2.3.0\lib\net45\MahApps.Metro.IconPacks.dll</HintPath>
48+
<Reference Include="MahApps.Metro.IconPacks.Material, Version=2.3.0.4, Culture=neutral, processorArchitecture=MSIL">
49+
<HintPath>..\..\packages\MahApps.Metro.IconPacks.Material.2.3.0\lib\net45\MahApps.Metro.IconPacks.Material.dll</HintPath>
5050
</Reference>
5151
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
5252
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>

0 commit comments

Comments
 (0)