From 868a7ce9c8b50bd64c8b5ae33fec77abfd25ef7c Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Thu, 21 Feb 2013 23:23:06 -0500 Subject: isolated clickonce dependancies --- .../Api/Logging/LogFileWebSocketListener.cs | 146 --------------------- 1 file changed, 146 deletions(-) delete mode 100644 MediaBrowser.Common/Api/Logging/LogFileWebSocketListener.cs (limited to 'MediaBrowser.Common/Api/Logging/LogFileWebSocketListener.cs') diff --git a/MediaBrowser.Common/Api/Logging/LogFileWebSocketListener.cs b/MediaBrowser.Common/Api/Logging/LogFileWebSocketListener.cs deleted file mode 100644 index e873facb1..000000000 --- a/MediaBrowser.Common/Api/Logging/LogFileWebSocketListener.cs +++ /dev/null @@ -1,146 +0,0 @@ -using MediaBrowser.Common.IO; -using MediaBrowser.Common.Kernel; -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using MediaBrowser.Model.Logging; - -namespace MediaBrowser.Common.Api.Logging -{ - /// - /// Class ScheduledTasksWebSocketListener - /// - [Export(typeof(IWebSocketListener))] - public class LogFileWebSocketListener : BasePeriodicWebSocketListener, LogFileWebSocketState> - { - /// - /// Gets the name. - /// - /// The name. - protected override string Name - { - get { return "LogFile"; } - } - - /// - /// Initializes a new instance of the class. - /// - /// The logger. - [ImportingConstructor] - public LogFileWebSocketListener([Import("logger")] ILogger logger) - : base(logger) - { - - } - - /// - /// Initializes the specified kernel. - /// - /// The kernel. - public override void Initialize(IKernel kernel) - { - base.Initialize(kernel); - - kernel.LoggerLoaded += kernel_LoggerLoaded; - } - - /// - /// Gets the data to send. - /// - /// The state. - /// IEnumerable{System.String}. - protected override async Task> GetDataToSend(LogFileWebSocketState state) - { - if (!string.Equals(Kernel.LogFilePath, state.LastLogFilePath)) - { - state.LastLogFilePath = Kernel.LogFilePath; - state.StartLine = 0; - } - - var lines = await GetLogLines(state.LastLogFilePath, state.StartLine).ConfigureAwait(false); - - state.StartLine += lines.Count; - - return lines; - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected override void Dispose(bool dispose) - { - if (dispose) - { - Kernel.LoggerLoaded -= kernel_LoggerLoaded; - } - base.Dispose(dispose); - } - - /// - /// Handles the LoggerLoaded event of the kernel control. - /// - /// The source of the event. - /// The instance containing the event data. - void kernel_LoggerLoaded(object sender, EventArgs e) - { - // Reset the startline for each connection whenever the logger reloads - lock (ActiveConnections) - { - foreach (var connection in ActiveConnections) - { - connection.Item4.StartLine = 0; - } - } - } - - /// - /// Gets the log lines. - /// - /// The log file path. - /// The start line. - /// Task{IEnumerable{System.String}}. - internal static async Task> GetLogLines(string logFilePath, int startLine) - { - var lines = new List(); - - using (var fs = new FileStream(logFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, StreamDefaults.DefaultFileStreamBufferSize, true)) - { - using (var reader = new StreamReader(fs)) - { - while (!reader.EndOfStream) - { - lines.Add(await reader.ReadLineAsync().ConfigureAwait(false)); - } - } - } - - if (startLine > 0) - { - lines = lines.Skip(startLine).ToList(); - } - - return lines; - } - } - - /// - /// Class LogFileWebSocketState - /// - public class LogFileWebSocketState - { - /// - /// Gets or sets the last log file path. - /// - /// The last log file path. - public string LastLogFilePath { get; set; } - /// - /// Gets or sets the start line. - /// - /// The start line. - public int StartLine { get; set; } - } -} -- cgit v1.2.3