2018-05-22 10:11:50 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Core.Main;
|
|
|
|
|
using Core.Helper;
|
|
|
|
|
using Core.Main.DataObjects.PTMagicData;
|
|
|
|
|
using Core.MarketAnalyzer;
|
|
|
|
|
using System.Diagnostics;
|
2019-10-13 22:08:48 +02:00
|
|
|
|
using Core.Main.DataObjects;
|
2018-05-22 10:11:50 +02:00
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
namespace Monitor._Internal
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
public class BasePageModel : PageModel
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
public string PTMagicBasePath = "";
|
|
|
|
|
public string PTMagicMonitorBasePath = "";
|
|
|
|
|
public PTMagicConfiguration PTMagicConfiguration = null;
|
|
|
|
|
public Summary Summary { get; set; } = new Summary();
|
|
|
|
|
public LogHelper Log = null;
|
|
|
|
|
public string LatestVersion = "";
|
|
|
|
|
public string CurrentBotVersion = "";
|
|
|
|
|
public string NotifyHeadline = "";
|
|
|
|
|
public string NotifyMessage = "";
|
|
|
|
|
public string NotifyType = "";
|
|
|
|
|
|
|
|
|
|
public string MainFiatCurrencySymbol = "$";
|
2019-10-13 22:08:48 +02:00
|
|
|
|
private volatile object _ptDataLock = new object();
|
|
|
|
|
private static ProfitTrailerData _ptData = null;
|
|
|
|
|
|
|
|
|
|
// Profit Trailer data accessor object
|
|
|
|
|
public ProfitTrailerData PtDataObject
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_ptData == null)
|
|
|
|
|
{
|
|
|
|
|
lock (_ptDataLock)
|
|
|
|
|
{
|
|
|
|
|
_ptData = new ProfitTrailerData(PTMagicConfiguration);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _ptData;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-22 10:11:50 +02:00
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
public void PreInit()
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
PTMagicMonitorBasePath = Directory.GetCurrentDirectory();
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (!System.IO.File.Exists(PTMagicMonitorBasePath + Path.DirectorySeparatorChar + "appsettings.json"))
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
PTMagicMonitorBasePath += Path.DirectorySeparatorChar + "Monitor";
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (!PTMagicMonitorBasePath.EndsWith(Path.DirectorySeparatorChar))
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
PTMagicMonitorBasePath += Path.DirectorySeparatorChar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IConfiguration config = new ConfigurationBuilder()
|
|
|
|
|
.SetBasePath(PTMagicMonitorBasePath)
|
|
|
|
|
.AddJsonFile("appsettings.json", false)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
PTMagicBasePath = config.GetValue<string>("PTMagicBasePath");
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (!PTMagicBasePath.EndsWith(Path.DirectorySeparatorChar))
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
PTMagicBasePath += Path.DirectorySeparatorChar;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-13 19:19:26 +02:00
|
|
|
|
PTMagicConfiguration = new PTMagicConfiguration(PTMagicBasePath);
|
2018-05-22 10:11:50 +02:00
|
|
|
|
|
|
|
|
|
IServiceProvider logProvider = ServiceHelper.BuildLoggerService(PTMagicBasePath);
|
|
|
|
|
Log = logProvider.GetRequiredService<LogHelper>();
|
|
|
|
|
|
|
|
|
|
Summary = JsonConvert.DeserializeObject<Summary>(System.IO.File.ReadAllText(PTMagicBasePath + Constants.PTMagicPathData + Path.DirectorySeparatorChar + "LastRuntimeSummary.json"));
|
|
|
|
|
if (Summary.CurrentGlobalSetting == null) Summary.CurrentGlobalSetting = PTMagicConfiguration.AnalyzerSettings.GlobalSettings.Find(s => s.SettingName.IndexOf("default", StringComparison.InvariantCultureIgnoreCase) > -1);
|
|
|
|
|
|
|
|
|
|
MainFiatCurrencySymbol = SystemHelper.GetCurrencySymbol(Summary.MainFiatCurrency);
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
// Get latest release from GitHub
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (!String.IsNullOrEmpty(HttpContext.Session.GetString("LatestVersion")))
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
LatestVersion = HttpContext.Session.GetString("LatestVersion");
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
LatestVersion = BaseAnalyzer.GetLatestGitHubRelease(Log, Summary.Version);
|
|
|
|
|
HttpContext.Session.SetString("LatestVersion", LatestVersion);
|
|
|
|
|
}
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
// Get current bot version
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (!String.IsNullOrEmpty(HttpContext.Session.GetString("CurrentBotVersion")))
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
CurrentBotVersion = HttpContext.Session.GetString("CurrentBotVersion");
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
string ptMagicBotDllPath = PTMagicBasePath + "PTMagic.dll";
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (System.IO.File.Exists(ptMagicBotDllPath))
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
FileVersionInfo ptMagicDllInfo = FileVersionInfo.GetVersionInfo(ptMagicBotDllPath);
|
|
|
|
|
|
|
|
|
|
CurrentBotVersion = ptMagicDllInfo.ProductVersion.Substring(0, ptMagicDllInfo.ProductVersion.LastIndexOf("."));
|
|
|
|
|
HttpContext.Session.SetString("CurrentBotVersion", CurrentBotVersion);
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
CurrentBotVersion = Summary.Version;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
CurrentBotVersion = Summary.Version;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
protected string GetStringParameter(string paramName, string defaultValue)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
string result = defaultValue;
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (HttpContext.Request.Query.ContainsKey(paramName))
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
result = HttpContext.Request.Query[paramName];
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
else if (HttpContext.Request.Method.Equals("POST") && HttpContext.Request.Form.ContainsKey(paramName))
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
result = HttpContext.Request.Form[paramName];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Holt einen Url-Parameter als Integer, wenn vorhanden.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paramName">Name des Parameters</param>
|
|
|
|
|
/// <param name="defaultValue">Defaultvalue, wenn Parameter nicht vorhanden ist.</param>
|
|
|
|
|
/// <returns>Der Wert des Parameters als Integer.</returns>
|
2018-12-15 22:07:29 +01:00
|
|
|
|
protected int GetIntParameter(string paramName, int defaultValue)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
int result = defaultValue;
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (HttpContext.Request.Query.ContainsKey(paramName))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
result = Int32.Parse(HttpContext.Request.Query[paramName]);
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
result = defaultValue;
|
|
|
|
|
}
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
else if (HttpContext.Request.Method.Equals("POST") && HttpContext.Request.Form.ContainsKey(paramName))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
result = Int32.Parse(HttpContext.Request.Form[paramName]);
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
result = defaultValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|