summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2019-12-29 17:29:36 +0000
committersr55 <[email protected]>2019-12-29 17:29:53 +0000
commit282b04f2fe39205664fbccc81aaab1048294811c (patch)
tree68e6b1a9d16e2d4e8479338462b641aa05bf4d4c /win/CS/HandBrakeWPF/Services
parentf63e7b79c83d62055f96f0a1a687cffae208a9c8 (diff)
WinGui: Experimental Worker Process (Basic logging is now operational) + UI Infrastructure (currently hidden) needed for the feature. + More Refactoring.
Diffstat (limited to 'win/CS/HandBrakeWPF/Services')
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs2
-rw-r--r--win/CS/HandBrakeWPF/Services/Logging/EventArgs/LogEventArgs.cs2
-rw-r--r--win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs21
-rw-r--r--win/CS/HandBrakeWPF/Services/Logging/LogService.cs152
-rw-r--r--win/CS/HandBrakeWPF/Services/Logging/Model/LogHandlerConfig.cs34
-rw-r--r--win/CS/HandBrakeWPF/Services/Logging/Model/LogMessage.cs42
-rw-r--r--win/CS/HandBrakeWPF/Services/PrePostActionService.cs6
-rw-r--r--win/CS/HandBrakeWPF/Services/Presets/PresetService.cs1
-rw-r--r--win/CS/HandBrakeWPF/Services/SystemService.cs6
9 files changed, 175 insertions, 91 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs b/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs
index 300f27f15..22249e5e6 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs
@@ -132,7 +132,7 @@ namespace HandBrakeWPF.Services.Encode
string encodeDestinationPath = Path.GetDirectoryName(destination);
string destinationFile = Path.GetFileName(destination);
string encodeLogFile = destinationFile + " " + DateTime.Now.ToString(CultureInfo.InvariantCulture).Replace("/", "-").Replace(":", "-") + ".txt";
- string logContent = this.logService.ActivityLog;
+ string logContent = this.logService.GetFullLog();
// Make sure the log directory exists.
if (!Directory.Exists(logDir))
diff --git a/win/CS/HandBrakeWPF/Services/Logging/EventArgs/LogEventArgs.cs b/win/CS/HandBrakeWPF/Services/Logging/EventArgs/LogEventArgs.cs
index 121010e31..034d3cb90 100644
--- a/win/CS/HandBrakeWPF/Services/Logging/EventArgs/LogEventArgs.cs
+++ b/win/CS/HandBrakeWPF/Services/Logging/EventArgs/LogEventArgs.cs
@@ -11,7 +11,7 @@ namespace HandBrakeWPF.Services.Logging.EventArgs
{
using System;
- using LogMessage = HandBrakeWPF.Services.Logging.Model.LogMessage;
+ using HandBrake.Worker.Logging.Models;
/// <summary>
/// The Message Logged Event Args
diff --git a/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs b/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs
index 07f3ea635..d82a1ed0d 100644
--- a/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs
+++ b/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs
@@ -12,15 +12,17 @@ namespace HandBrakeWPF.Services.Logging.Interfaces
using System;
using System.Collections.Generic;
+ using HandBrake.Worker.Logging.Interfaces;
using HandBrake.Worker.Logging.Models;
+ using HandBrakeWPF.Services.Logging.Model;
+
using LogEventArgs = HandBrakeWPF.Services.Logging.EventArgs.LogEventArgs;
- using LogMessage = HandBrakeWPF.Services.Logging.Model.LogMessage;
/// <summary>
/// The Log interface.
/// </summary>
- public interface ILog
+ public interface ILog : ILogHandler
{
/// <summary>
/// The message logged.
@@ -33,21 +35,6 @@ namespace HandBrakeWPF.Services.Logging.Interfaces
event EventHandler LogReset;
/// <summary>
- /// Gets the log messages.
- /// </summary>
- IEnumerable<LogMessage> LogMessages { get; }
-
- /// <summary>
- /// Gets the activity log.
- /// </summary>
- string ActivityLog { get; }
-
- /// <summary>
- /// The reset.
- /// </summary>
- void Reset();
-
- /// <summary>
/// Enable logging for this worker process.
/// </summary>
/// <param name="config">
diff --git a/win/CS/HandBrakeWPF/Services/Logging/LogService.cs b/win/CS/HandBrakeWPF/Services/Logging/LogService.cs
index 3bc4c2b5b..c11b764b0 100644
--- a/win/CS/HandBrakeWPF/Services/Logging/LogService.cs
+++ b/win/CS/HandBrakeWPF/Services/Logging/LogService.cs
@@ -18,16 +18,23 @@ namespace HandBrakeWPF.Services.Logging
using System.IO;
using System.Linq;
using System.Text;
+ using System.Timers;
using HandBrake.Interop.Interop;
using HandBrake.Interop.Interop.EventArgs;
using HandBrake.Worker.Logging.Models;
+ using HandBrakeWPF.Instance.Model;
+ using HandBrakeWPF.Services.Interfaces;
+ using HandBrakeWPF.Services.Logging.Model;
+ using HandBrakeWPF.Utilities;
+
+ using Newtonsoft.Json;
+
using ILog = Interfaces.ILog;
using LogEventArgs = EventArgs.LogEventArgs;
- using LogMessage = Model.LogMessage;
- public class LogService : ILog
+ public class LogService : HttpRequestBase, ILog
{
// TODO List.
// Maybe make the event weak?
@@ -39,17 +46,29 @@ namespace HandBrakeWPF.Services.Logging
private bool isLoggingEnabled;
private List<LogMessage> logMessages = new List<LogMessage>();
- private long messageIndex;
+ private int messageIndex;
private string diskLogPath;
private bool deleteLogFirst;
private bool isDiskLoggingEnabled;
private StreamWriter fileWriter;
private string logHeader;
+ private Timer remoteLogPollTimer;
+ private int remoteIndex = 0;
+ private bool isRemotePollingEnabled = false;
- public LogService()
+ public LogService(IUserSettingService userSettingService)
{
HandBrakeUtils.MessageLogged += this.HandBrakeUtils_MessageLogged;
HandBrakeUtils.ErrorLogged += this.HandBrakeUtils_ErrorLogged;
+
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.RemoteServiceEnabled))
+ {
+ this.ActivateRemoteLogPolling();
+ this.isRemotePollingEnabled = true;
+
+ this.port = userSettingService.GetUserSetting<int>(UserSettingConstants.RemoteServicePort);
+ this.serverUrl = string.Format("http://127.0.0.1:{0}/", this.port);
+ }
}
public event EventHandler<LogEventArgs> MessageLogged;
@@ -67,17 +86,6 @@ namespace HandBrakeWPF.Services.Logging
}
}
- public string ActivityLog
- {
- get
- {
- lock (this.lockObject)
- {
- return this.logBuilder.ToString();
- }
- }
- }
-
public void LogMessage(string content)
{
if (!this.isLoggingEnabled)
@@ -85,7 +93,6 @@ namespace HandBrakeWPF.Services.Logging
return;
}
-
LogMessage msg = new LogMessage(content, this.messageIndex);
lock (this.lockObject)
{
@@ -127,10 +134,64 @@ namespace HandBrakeWPF.Services.Logging
this.LogMessage(config.Header);
}
- public void Reset()
+ public string GetFullLog()
{
lock (this.lockObject)
{
+ return this.logBuilder.ToString();
+ }
+ }
+
+ public List<LogMessage> GetLogMessages()
+ {
+ lock (this.lockObject)
+ {
+ return new List<LogMessage>(this.logMessages);
+ }
+ }
+
+ public List<LogMessage> GetLogMessagesFromIndex(int index)
+ {
+ List<LogMessage> log = new List<LogMessage>();
+ lock (this.lockObject)
+ {
+ // Note messageIndex is not 0 based.
+ for (int i = index; i < this.messageIndex; i++)
+ {
+ log.Add(this.logMessages[i]);
+ }
+ }
+
+ return log;
+ }
+
+ public long GetLatestLogIndex()
+ {
+ lock (this.lockObject)
+ {
+ return this.messageIndex;
+ }
+ }
+
+ public async void Reset()
+ {
+ //if (this.isRemotePollingEnabled)
+ //{
+ // try
+ // {
+ // await this.MakeHttpGetRequest("ResetLogging");
+ // }
+ // catch (Exception e)
+ // {
+ // if (this.remoteLogPollTimer != null)
+ // {
+ // this.remoteLogPollTimer.Stop();
+ // }
+ // }
+ //}
+
+ lock (this.lockObject)
+ {
this.logMessages.Clear();
this.logBuilder.Clear();
this.messageIndex = 0;
@@ -297,5 +358,62 @@ namespace HandBrakeWPF.Services.Logging
this.LogMessage(e.Message);
}
+
+ private void ActivateRemoteLogPolling()
+ {
+ this.remoteLogPollTimer = new Timer();
+ this.remoteLogPollTimer.Interval = 1000;
+
+ this.remoteLogPollTimer.Elapsed += (o, e) =>
+ {
+ try
+ {
+ this.PollRemoteLog();
+ }
+ catch (Exception exc)
+ {
+ Debug.WriteLine(exc);
+ }
+ };
+ this.remoteLogPollTimer.Start();
+ }
+
+ private async void PollRemoteLog()
+ {
+ ServerResponse response = null;
+ try
+ {
+ int nextIndex = this.remoteIndex + 1;
+ string json = JsonConvert.SerializeObject(nextIndex, Formatting.Indented, this.jsonNetSettings);
+
+ response = await this.MakeHttpJsonPostRequest("GetLogMessagesFromIndex", json);
+ }
+ catch (Exception e)
+ {
+ Debug.WriteLine("No Endpoint");
+ }
+
+ if (response == null || !response.WasSuccessful)
+ {
+ return;
+ }
+
+ string statusJson = response.JsonResponse;
+
+ List<LogMessage> messages = null;
+ if (!string.IsNullOrEmpty(statusJson))
+ {
+ messages = JsonConvert.DeserializeObject<List<LogMessage>>(statusJson, this.jsonNetSettings);
+ }
+
+ if (messages != null)
+ {
+ foreach (var item in messages)
+ {
+ this.LogMessage(item.Content);
+ this.remoteIndex = item.MessageIndex;
+ }
+ }
+ }
}
}
diff --git a/win/CS/HandBrakeWPF/Services/Logging/Model/LogHandlerConfig.cs b/win/CS/HandBrakeWPF/Services/Logging/Model/LogHandlerConfig.cs
new file mode 100644
index 000000000..183590ca1
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Services/Logging/Model/LogHandlerConfig.cs
@@ -0,0 +1,34 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="LogHandlerConfig.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Defines the LogHandlerConfig type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services.Logging.Model
+{
+ public class LogHandlerConfig
+ {
+ public LogHandlerConfig(bool enableDiskLogging, string logFile, bool deleteCurrentLogFirst, string header)
+ {
+ this.EnableDiskLogging = enableDiskLogging;
+ this.LogFile = logFile;
+ this.DeleteCurrentLogFirst = deleteCurrentLogFirst;
+ this.Header = header;
+ }
+
+ public LogHandlerConfig()
+ {
+ }
+
+ public bool EnableDiskLogging { get; set; }
+
+ public string LogFile { get; set; }
+
+ public bool DeleteCurrentLogFirst { get; set; }
+
+ public string Header { get; set; }
+ }
+} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Services/Logging/Model/LogMessage.cs b/win/CS/HandBrakeWPF/Services/Logging/Model/LogMessage.cs
deleted file mode 100644
index 51e5a1cb6..000000000
--- a/win/CS/HandBrakeWPF/Services/Logging/Model/LogMessage.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------
-// <copyright file="LogMessage.cs" company="HandBrake Project (http://handbrake.fr)">
-// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
-// </copyright>
-// <summary>
-// The message.
-// </summary>
-// --------------------------------------------------------------------------------------------------------------------
-
-namespace HandBrakeWPF.Services.Logging.Model
-{
- /// <summary>
- /// An Immutable Log Entry.
- /// </summary>
- public class LogMessage
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="LogMessage"/> class.
- /// </summary>
- /// <param name="content">
- /// The content.
- /// </param>
- /// <param name="messageIndex">
- /// The message Index.
- /// </param>
- public LogMessage(string content, long messageIndex)
- {
- this.Content = content;
- this.MessageIndex = messageIndex;
- }
-
- /// <summary>
- /// Gets the content.
- /// </summary>
- public string Content { get; private set; }
-
- /// <summary>
- /// Gets the message index.
- /// </summary>
- public long MessageIndex { get; private set; }
- }
-}
diff --git a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
index 57be5051e..636f82d7b 100644
--- a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
+++ b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
@@ -17,15 +17,9 @@ namespace HandBrakeWPF.Services
using Caliburn.Micro;
- using HandBrake.Interop.Utilities;
-
using HandBrakeWPF.EventArgs;
- using HandBrakeWPF.Instance;
using HandBrakeWPF.Model.Options;
- using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Interfaces;
- using HandBrakeWPF.Services.Logging;
- using HandBrakeWPF.Services.Logging.Model;
using HandBrakeWPF.Services.Queue.Interfaces;
using HandBrakeWPF.Services.Scan.Interfaces;
using HandBrakeWPF.Utilities;
diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
index 8b4a1ba68..6c715fa8f 100644
--- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
+++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
@@ -33,7 +33,6 @@ namespace HandBrakeWPF.Services.Presets
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Logging;
using HandBrakeWPF.Services.Logging.Interfaces;
- using HandBrakeWPF.Services.Logging.Model;
using HandBrakeWPF.Services.Presets.Factories;
using HandBrakeWPF.Services.Presets.Interfaces;
using HandBrakeWPF.Services.Presets.Model;
diff --git a/win/CS/HandBrakeWPF/Services/SystemService.cs b/win/CS/HandBrakeWPF/Services/SystemService.cs
index 587a82128..2eb5bebb3 100644
--- a/win/CS/HandBrakeWPF/Services/SystemService.cs
+++ b/win/CS/HandBrakeWPF/Services/SystemService.cs
@@ -10,20 +10,14 @@
namespace HandBrakeWPF.Services
{
using System;
- using System.Runtime.CompilerServices;
using System.Timers;
using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Encode.Interfaces;
- using HandBrakeWPF.Services.Encode.Model;
using HandBrakeWPF.Services.Interfaces;
- using HandBrakeWPF.Services.Logging;
using HandBrakeWPF.Services.Logging.Interfaces;
- using HandBrakeWPF.Services.Logging.Model;
using HandBrakeWPF.Utilities;
- using Ookii.Dialogs.Wpf;
-
public class SystemService : ISystemService
{
private readonly IUserSettingService userSettingService;