Update x gestione estesa logging chiamate

This commit is contained in:
Samuele E. Locatelli
2019-04-02 16:08:00 +02:00
parent 6127866ad1
commit eeea58e700
8 changed files with 92 additions and 60 deletions
+40
View File
@@ -0,0 +1,40 @@
using NLog;
using NLog.Config;
using NLog.Targets;
namespace MConnectSDK
{
internal static class Log
{
public static Logger Instance { get; private set; }
static Log()
{
#if DEBUG
// Setup the logging view for Sentinel - http://sentinel.codeplex.com
var sentinalTarget = new NLogViewerTarget()
{
Name = "sentinal",
Address = "udp://127.0.0.1:9999",
IncludeNLogData = false
};
var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);
LogManager.Configuration.AddTarget("sentinal", sentinalTarget);
LogManager.Configuration.LoggingRules.Add(sentinalRule);
// Setup the logging view for Harvester - http://harvester.codeplex.com
var harvesterTarget = new OutputDebugStringTarget()
{
Name = "harvester",
Layout = "${log4jxmlevent:includeNLogData=false}"
};
var harvesterRule = new LoggingRule("*", LogLevel.Trace, harvesterTarget);
LogManager.Configuration.AddTarget("harvester", harvesterTarget);
LogManager.Configuration.LoggingRules.Add(harvesterRule);
#endif
LogManager.ReconfigExistingLoggers();
Instance = LogManager.GetCurrentClassLogger();
}
}
}
+34 -23
View File
@@ -834,7 +834,10 @@ namespace MConnectSDK
// riporto in risposta i dati...
answ.DeviceCode = tokResp.device_code;
answ.UserCode = tokResp.user_code;
answ.QrCode = string.Format(WebAppUrl, tokResp.user_code, MachineID);
string userCode = (tokResp != null && tokResp.user_code != null) ? tokResp.user_code : "";
answ.QrCode = string.Format(WebAppUrl, userCode, MachineID);
sb.AppendLine("--------------------------------------------------");
sb.AppendLine(string.Format("{0:HH.mm.ss.fff} | Try OAuth process", DateTime.Now));
sb.AppendLine("--------------------------------------------------");
@@ -1150,10 +1153,10 @@ namespace MConnectSDK
if (obj.LoginStatus != UserStatus.IMPORTED)
{
// elimino ANCHE da cache pwd (se c'era)
if (userPwdLocalCache.Exists(x => x.user_id == obj.UserId))
if (userPwdLocalCache.Exists(x => x.Username == obj.Username))
{
var tmpData = userPwdLocalCache;
tmpData.RemoveAll(x => x.user_id == obj.UserId);
tmpData.RemoveAll(x => x.Username == obj.Username);
userPwdLocalCache = tmpData;
}
// elimino...
@@ -1198,6 +1201,11 @@ namespace MConnectSDK
var taskCliInfo = Task.Run(() => GetClientStatusAsync());
taskCliInfo.Wait();
_currStatus = taskCliInfo.Result;
#if false1
// SOLO SE E' tutot ok come connessione procedo...
if (_currStatus.CloudStatusOk)
{
#endif
// parto pessimista...
bool userOk = false;
// variabili accessorie
@@ -1229,15 +1237,23 @@ namespace MConnectSDK
if (resp.status == "Ok" || resp.statusCode == 200)
{
userData item = resp.result.user;
// creo obj userData...
var imgRes = Task.Run(() => Utils.getImageAsync(pageUrlImgDownload, item.Image_Url));
imgRes.Wait();
Image userImg = null;
if (imgRes.Result != null)
try
{
//userImg = imgRes.Result;
userImg = imgRes.Result;
// creo obj userData... SE HO immagine...
if (item.Image_Url != "")
{
var imgRes = Task.Run(() => Utils.getImageAsync(pageUrlImgDownload, item.Image_Url));
imgRes.Wait();
if (imgRes.Result != null)
{
userImg = imgRes.Result;
}
}
}
catch (Exception ex)
{ }
userFound = new UserData()
{
UserId = item.Id,
@@ -1282,7 +1298,7 @@ namespace MConnectSDK
string pwdCyph = GenerateSaltedHash(password, salt.ToString());
// cerco nelle pwd salvate: se lo trovo e NON HO una pwd --> accetto questa e salvo!
var _usrPwdList = userPwdLocalCache;
var usrId_Found = _usrPwdList.Find(x => x.user_id == userFound.UserId);
var usrId_Found = _usrPwdList.Find(x => x.Username == userFound.Username);
if (usrId_Found != null)
{
// verifico la pwd locale...
@@ -1307,7 +1323,7 @@ namespace MConnectSDK
{
var _userPwd = new userPwdData()
{
user_id = userFound.UserId,
Username = userFound.Username,
passwordCyph = pwdCyph
};
_usrPwdList.Add(_userPwd);
@@ -1342,18 +1358,6 @@ namespace MConnectSDK
_currStatus.Payload = userList;
_currStatus.Error = errore;
}
//else
//{
// if (userFound != null && errore.Reason != Reason.AllOk)
// {
// errore = new ErrorResult
// {
// Reason = Reason.UserNotFound,
// message = "Username not found"
// };
// _currStatus.Error = errore;
// }
//}
}
else
{
@@ -1375,6 +1379,13 @@ namespace MConnectSDK
}
_currStatus.Error = errore;
}
#if false
}
else
{
_currStatus.Payload.Message = "Errore: manca connessione a cloud";
}
#endif
reqStatus = _currStatus;
});
return _currStatus;
+2 -1
View File
@@ -35,7 +35,7 @@
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.6.0\lib\net45\NLog.dll</HintPath>
<HintPath>..\packages\NLog.4.6.1\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="Pipelines.Sockets.Unofficial, Version=1.0.0.0, Culture=neutral, PublicKeyToken=42ea0a778e13fbe2, processorArchitecture=MSIL">
<HintPath>..\packages\Pipelines.Sockets.Unofficial.2.0.11\lib\net461\Pipelines.Sockets.Unofficial.dll</HintPath>
@@ -90,6 +90,7 @@
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Logging.cs" />
<Compile Include="MConnectClient.cs" />
<Compile Include="memLayer.cs" />
<Compile Include="Utils.cs" />
+11 -4
View File
@@ -80,10 +80,12 @@ namespace MConnectSDK
}
/// <summary>
/// Effettua download async della pagina indicata
/// </summary>
/// </summary>
/// <param name="pageURL"></param>
/// <param name="doLog"></param>
public static async Task<string> getPageAsync(string pageURL)
{
Log.Instance.Info($"[getPageAsync]: Calling URL: {pageURL}");
string answ = "";
// ... Use HttpClient.
using (HttpClient client = new HttpClient())
@@ -101,6 +103,7 @@ namespace MConnectSDK
/// <param name="pageURL"></param>
public static async Task<string> getPageAsync(string pageURL, string oauthToken)
{
Log.Instance.Info($"[getPageAsync]: Calling URL: {pageURL} | OAuth Token: {oauthToken}");
string answ = "";
//var authToken = new AuthenticationHeaderValue("Bearer", oauthToken);
// ... Use HttpClient.
@@ -124,6 +127,7 @@ namespace MConnectSDK
/// <param name="oauthToken">token da passare come bearer</param>
public static async Task<string> putAsync(Uri reqUri, HttpContent callCont, string oauthToken)
{
Log.Instance.Info($"[putAsync]: Calling reqUri: {reqUri} | callCont Token: {oauthToken} | callCont: {callCont}");
string answ = "";
// ... Use HttpClient.
using (HttpClient client = new HttpClient())
@@ -152,6 +156,7 @@ namespace MConnectSDK
/// <param name="imagePath">path immagine (cui applicare encode) e a cui appendere alt=media...</param>
public static async Task<Image> getImageAsync(string pageURL, string imagePath)
{
Log.Instance.Info($"[getImageAsync]: Calling URL: {pageURL} | imagePath: {imagePath}");
Image answ = null;
string imgEncoded = Uri.EscapeDataString(imagePath);
string fullImgPath = pageURL + imgEncoded + "?alt=media";
@@ -175,6 +180,7 @@ namespace MConnectSDK
/// <returns></returns>
public static async Task<string> postUriAsync(Uri reqUri, HttpContent callCont)
{
Log.Instance.Info($"[postUriAsync]: Calling reqUri: {reqUri} | callCont: {callCont}");
var response = string.Empty;
using (var client = new HttpClient())
{
@@ -195,6 +201,7 @@ namespace MConnectSDK
/// <returns></returns>
public static async Task<string> uploadAsync(string pageUrl, string fileName, byte[] fileContent)
{
Log.Instance.Info($"[uploadAsync]: Calling pageUrl: {pageUrl} | fileName: {fileName}");
string answ = "";
using (var client = new HttpClient())
{
@@ -696,9 +703,9 @@ namespace MConnectSDK
public class userPwdData
{
/// <summary>
/// Codice utente (es asfd.0002)
/// UserName
/// </summary>
public string user_id = "";
public string Username = "";
/// <summary>
/// Password (in formato cifrato)
/// </summary>
@@ -712,7 +719,7 @@ namespace MConnectSDK
{
var base64 = (string)reader.Value;
Image answ = null;
if(reader.Value != null && (string)reader.Value != "")
if (reader.Value != null && (string)reader.Value != "")
{
answ = Image.FromStream(new MemoryStream(Convert.FromBase64String(base64)));
}
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net462" />
<package id="NLog" version="4.6.0" targetFramework="net462" />
<package id="NLog" version="4.6.1" targetFramework="net462" />
<package id="Pipelines.Sockets.Unofficial" version="2.0.11" targetFramework="net462" />
<package id="StackExchange.Redis" version="2.0.571" targetFramework="net462" />
<package id="System.Buffers" version="4.5.0" targetFramework="net462" />
+2 -4
View File
@@ -8,7 +8,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © Steamware 2019")]
[assembly: AssemblyTrademark("_")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.1.1904.57")]
[assembly: AssemblyFileVersion("1.1.1904.57")]
[assembly: AssemblyVersion("1.1.1904.61")]
[assembly: AssemblyFileVersion("1.1.1904.61")]
+1 -26
View File
@@ -18,39 +18,14 @@
-->
<targets async="true">
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--
Write events to a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
<target xsi:type="File"
name="f"
fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}"
/>
<!--<target xsi:type="File"
name="default"
layout="${longdate} - ${level:uppercase=true}: ${message}${onexception:${newline}EXCEPTION\: ${exception:format=ToString}}"
fileName="${specialfolder:ApplicationData}\${appName}\Debug.log"
keepFileOpen="false"
archiveFileName="${specialfolder:ApplicationData}\${appName}\Debug_${shortdate}.{##}.log"
archiveNumbering="Sequence"
archiveEvery="Day"
maxArchiveFiles="30"
/>-->
/>
</targets>
<rules>
<!-- add your logging rules here -->
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
<logger name="*" minlevel="Debug" writeTo="f" />
</rules>
</nlog>
+1 -1
View File
@@ -5,7 +5,7 @@ conf:
PingTarget: "stg.api.maestroconnect.scmgroup.com"
AliveTarget: "https://stg.api.maestroconnect.scmgroup.com/health"
BaseUrl: "https://stg.api.maestroconnect.scmgroup.com/api"
WebAppUrl: "https://smart.maestroconnect.com/deviceauth?user_code={0}&machineID={1}"
WebAppUrl: "https://stg.maestroconnect.scmgroup.com/scm/settings/machine-settings/?nav=activation&user_code={0}&machineID={1}"
MemoryLayer:
Redis:
ConnectionString: "127.0.0.1,abortConnect=false,ssl=false"