From 4505ac67335e065f7483f15e25c0e7ea9a28e9da Mon Sep 17 00:00:00 2001 From: lelmarir Date: Wed, 14 Oct 2015 15:55:52 +0200 Subject: [PATCH] remove unused files and classes --- CmisSync.Lib/Auth/Auth.cs | 2 +- CmisSync.Lib/Auth/Credentials.cs | 4 +- CmisSync.Lib/Auth/Crypto.cs | 2 +- CmisSync.Lib/ChunkedStream.cs | 175 ---------- CmisSync.Lib/Cmis/CmisUtils.cs | 116 ------- CmisSync.Lib/CmisSync.Lib.csproj | 8 - .../Events/ActiveActivitiesManager.cs | 70 ---- CmisSync.Lib/Events/ConfigChangedEvent.cs | 40 --- CmisSync.Lib/Events/DebugLoggingHandler.cs | 29 -- CmisSync.Lib/Events/FileTransmissionEvent.cs | 323 ------------------ CmisSync.Lib/Events/ISyncEvent.cs | 11 - CmisSync.Lib/Events/SyncEventHandler.cs | 42 --- CmisSync.Lib/Events/SyncEventManager.cs | 56 --- CmisSync.Lib/Events/SyncEventQueue.cs | 112 ------ CmisSync.Lib/LoggingStream.cs | 125 ------- CmisSync.Lib/Sync/SyncFolderSyncronizer.cs | 2 - .../Sync/SyncFolderSyncronizerBase.cs | 1 - CmisSync.Lib/UserNotificationListener.cs | 19 -- 18 files changed, 4 insertions(+), 1133 deletions(-) delete mode 100644 CmisSync.Lib/ChunkedStream.cs delete mode 100644 CmisSync.Lib/Events/ActiveActivitiesManager.cs delete mode 100644 CmisSync.Lib/Events/ConfigChangedEvent.cs delete mode 100644 CmisSync.Lib/Events/DebugLoggingHandler.cs delete mode 100644 CmisSync.Lib/Events/FileTransmissionEvent.cs delete mode 100644 CmisSync.Lib/Events/ISyncEvent.cs delete mode 100644 CmisSync.Lib/Events/SyncEventHandler.cs delete mode 100644 CmisSync.Lib/Events/SyncEventManager.cs delete mode 100644 CmisSync.Lib/Events/SyncEventQueue.cs delete mode 100644 CmisSync.Lib/LoggingStream.cs delete mode 100644 CmisSync.Lib/UserNotificationListener.cs diff --git a/CmisSync.Lib/Auth/Auth.cs b/CmisSync.Lib/Auth/Auth.cs index c7e5f1d4b..75082fd7b 100644 --- a/CmisSync.Lib/Auth/Auth.cs +++ b/CmisSync.Lib/Auth/Auth.cs @@ -27,7 +27,7 @@ public static IList GetCmisRepositories(Uri url, string user, Passw Dictionary parameters = GetParameters(); parameters[SessionParameter.AtomPubUrl] = url.ToString(); parameters[SessionParameter.User] = user; - parameters[SessionParameter.Password] = Crypto.Deobfuscate(obfuscatedPassword.ObfuscatedPassword); + parameters[SessionParameter.Password] = CryptoUtils.Deobfuscate(obfuscatedPassword.ObfuscatedPassword); // Create session factory. SessionFactory factory = SessionFactory.NewInstance(); diff --git a/CmisSync.Lib/Auth/Credentials.cs b/CmisSync.Lib/Auth/Credentials.cs index ff99a23bb..bc89d7644 100644 --- a/CmisSync.Lib/Auth/Credentials.cs +++ b/CmisSync.Lib/Auth/Credentials.cs @@ -69,7 +69,7 @@ public class Password /// as plain text public Password(string password) { - this.password = Crypto.Obfuscate(password); + this.password = CryptoUtils.Obfuscate(password); } /// @@ -104,7 +104,7 @@ public string ToString() { if (password == null) return null; - return Crypto.Deobfuscate(password); + return CryptoUtils.Deobfuscate(password); } /// diff --git a/CmisSync.Lib/Auth/Crypto.cs b/CmisSync.Lib/Auth/Crypto.cs index c6aa3f58f..9032a33a7 100644 --- a/CmisSync.Lib/Auth/Crypto.cs +++ b/CmisSync.Lib/Auth/Crypto.cs @@ -9,7 +9,7 @@ namespace CmisSync.Lib.Auth /// Obfuscation for sensitive data, making password harvesting a little less straightforward. /// Web browsers employ the same technique to store user passwords. /// - public static class Crypto + public static class CryptoUtils { /// /// Obfuscate a string. diff --git a/CmisSync.Lib/ChunkedStream.cs b/CmisSync.Lib/ChunkedStream.cs deleted file mode 100644 index 47aebc8cf..000000000 --- a/CmisSync.Lib/ChunkedStream.cs +++ /dev/null @@ -1,175 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; - -namespace CmisSync.Lib -{ - /// - public class ChunkedStream : Stream - { - private Stream source; - private long chunkSize; - - /// - /// - /// - public ChunkedStream(Stream stream, long chunk) - { - source = stream; - chunkSize = chunk; - - //if (!source.CanRead) - //{ - // throw new System.NotSupportedException("Read access is needed for ChunkedStream"); - //} - } - - /// - public override bool CanRead { get { return source.CanRead; } } - - /// - public override bool CanWrite { get { return source.CanWrite; } } - - /// - public override bool CanSeek { get { return source.CanSeek; } } - - /// - public override void Flush() { source.Flush(); } - - private long chunkPosition; - - /// - public long ChunkPosition - { - get - { - return chunkPosition; - } - - set - { - source.Position = value; - chunkPosition = value; - } - } - - /// - public override long Length - { - get - { - long lengthSource = source.Length; - if (lengthSource <= ChunkPosition) - { - return 0; - } - - long length = lengthSource - ChunkPosition; - if (length >= chunkSize) - { - return chunkSize; - } - else - { - return length; - } - } - } - - private long position; - - /// - public override long Position - { - get - { - if (!CanSeek) - { - return position; - } - - long offset = source.Position - ChunkPosition; - if (offset < 0 || offset > chunkSize) - { - Debug.Assert(false, String.Format("Position {0} not in [0,{1}]", offset, chunkSize)); - } - return offset; - } - - set - { - if (value < 0 || value > chunkSize) - { - throw new System.ArgumentOutOfRangeException(String.Format("Position {0} not in [0,{1}]", value, chunkSize)); - } - source.Position = ChunkPosition + value; - } - } - - /// - /// - /// - /// - /// - public override int Read(byte[] buffer, int offset, int count) - { - if (offset < 0) - { - throw new System.ArgumentOutOfRangeException("offset", offset, "offset is negative"); - } - if (count < 0) - { - throw new System.ArgumentOutOfRangeException("count", count, "count is negative"); - } - - if (count > chunkSize - Position) - { - count = (int)(chunkSize - Position); - } - count = source.Read(buffer, offset, count); - position += count; - return count; - } - - /// - /// - /// - /// - public override void Write(byte[] buffer, int offset, int count) - { - if (offset < 0) - { - throw new System.ArgumentOutOfRangeException("offset", offset, "offset is negative"); - } - if (count < 0) - { - throw new System.ArgumentOutOfRangeException("count", count, "count is negative"); - } - - if (count > chunkSize - Position) - { - throw new System.ArgumentOutOfRangeException("count", count, "count is overflow"); - } - source.Write(buffer, offset, count); - position += count; - } - - /// - /// - /// - /// - public override long Seek(long offset, SeekOrigin origin) - { - Debug.Assert(false, "TODO"); - return source.Seek(offset, origin); - } - - /// - /// - public override void SetLength(long value) - { - Debug.Assert(false, "TODO"); - source.SetLength(value); - } - } -} diff --git a/CmisSync.Lib/Cmis/CmisUtils.cs b/CmisSync.Lib/Cmis/CmisUtils.cs index e89bd5d74..93dfc9dec 100755 --- a/CmisSync.Lib/Cmis/CmisUtils.cs +++ b/CmisSync.Lib/Cmis/CmisUtils.cs @@ -13,31 +13,6 @@ namespace CmisSync.Lib.Cmis { - /// - /// Data object representing a CMIS server. - /// - public class CmisServer - { - /// - /// URL of the CMIS server. - /// - public Uri Url { get; private set; } - - /// - /// Repositories contained in the CMIS server. - /// - public Dictionary Repositories { get; private set; } - - /// - /// Constructor. - /// - public CmisServer(Uri url, Dictionary repositories) - { - Url = url; - Repositories = repositories; - } - } - /// /// Useful CMIS methods. /// @@ -254,97 +229,6 @@ static public string[] GetSubfolders(string repositoryId, string path, return result.ToArray(); } - - /// - /// Folder tree. - /// - public class FolderTree - { - /// - /// Children. - /// - public List Children = new List(); - - /// - /// Folder path. - /// - public string Path; - - /// - /// Folder name. - /// - public string Name { get; set; } - - /// - /// - /// - public bool Finished { get; set; } - - /// - /// Constructor. - /// - public FolderTree(IList> trees, IFolder folder, int depth) - { - this.Path = folder.Path; - this.Name = folder.Name; - if (depth == 0) - { - this.Finished = false; - } - else - { - this.Finished = true; - } - - if (trees != null) - { - foreach (ITree tree in trees) - { - Folder f = tree.Item as Folder; - if (f != null) - this.Children.Add(new FolderTree(tree.Children, f, depth - 1)); - } - } - } - } - - ///// - ///// Get the sub-folders of a particular CMIS folder. - ///// - ///// Full path of each sub-folder, including leading slash. - //static public FolderTree GetSubfolderTree( CmisRepoCredentials credentials, string path, int depth) - //{ - // // Connect to the CMIS repository. - // ISession session = Auth.Auth.GetCmisSession(credentials.Address.ToString(), credentials.UserName, credentials.Password.ToString(), credentials.RepoId); - - // // Get the folder. - // IFolder folder; - // try - // { - // folder = (IFolder)session.GetObjectByPath(path); - // } - // catch (Exception ex) - // { - // Logger.Warn(String.Format("CmisUtils | exception when session GetObjectByPath for {0}", path), ex); - // throw; - // } - - // // Debug the properties count, which allows to check whether a particular CMIS implementation is compliant or not. - // // For instance, IBM Connections is known to send an illegal count. - // Logger.Info("CmisUtils | folder.Properties.Count:" + folder.Properties.Count.ToString()); - // try - // { - // IList> trees = folder.GetFolderTree(depth); - // return new FolderTree(trees, folder, depth); - // } - // catch (Exception e) - // { - // Logger.Info("CmisUtils getSubFolderTree | Exception " + e.Message, e); - // throw; - // } - //} - - /// /// Guess the web address where files can be seen using a browser. /// Not bulletproof. It depends on the server, and on some servers there is no web UI at all. diff --git a/CmisSync.Lib/CmisSync.Lib.csproj b/CmisSync.Lib/CmisSync.Lib.csproj index 10aef2ff7..0d7dbb231 100644 --- a/CmisSync.Lib/CmisSync.Lib.csproj +++ b/CmisSync.Lib/CmisSync.Lib.csproj @@ -82,14 +82,6 @@ - - - - - - - - diff --git a/CmisSync.Lib/Events/ActiveActivitiesManager.cs b/CmisSync.Lib/Events/ActiveActivitiesManager.cs deleted file mode 100644 index c6e674c54..000000000 --- a/CmisSync.Lib/Events/ActiveActivitiesManager.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using System.Text; -using System.Collections.ObjectModel; -using log4net; - -namespace CmisSync.Lib.Events -{ - /// - /// Active activities manager. - /// - public class ActiveActivitiesManager - { - private static readonly ILog Logger = LogManager.GetLogger(typeof(ActiveActivitiesManager)); - - private object Lock = new object(); - - private ObservableCollection activeTransmissions = new ObservableCollection(); - - /// - /// Gets the active transmissions. This Collection can be obsered for changes. - /// - /// - /// The active transmissions. - /// - public ObservableCollection ActiveTransmissions { get { return activeTransmissions; } } - - /// - /// Add a new Transmission to the active transmission manager - /// - /// - public bool AddTransmission(FileTransmissionEvent transmission) { - lock (Lock) - { - if(!activeTransmissions.Contains(transmission)) { - transmission.TransmissionStatus += TransmissionFinished; - activeTransmissions.Add(transmission); - return true; - } - } - return false; - } - - /// - /// If a transmission is reported as finished/aborted/failed, the transmission is removed from the collection - /// - /// - /// The transmission event. - /// - /// - /// The progress parameters of the transmission. - /// - private void TransmissionFinished(object sender, TransmissionProgressEventArgs e) - { - if ((e.Aborted == true || e.Completed == true || e.FailedException != null)) - { - lock (Lock) - { - FileTransmissionEvent transmission = sender as FileTransmissionEvent; - if(transmission!=null && activeTransmissions.Contains(transmission)) { - activeTransmissions.Remove(transmission); - transmission.TransmissionStatus-=TransmissionFinished; - Logger.Debug("Transmission removed"); - } - } - } - } - } -} diff --git a/CmisSync.Lib/Events/ConfigChangedEvent.cs b/CmisSync.Lib/Events/ConfigChangedEvent.cs deleted file mode 100644 index d13d04a1f..000000000 --- a/CmisSync.Lib/Events/ConfigChangedEvent.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using CmisSync.Lib; - -namespace CmisSync.Lib.Events -{ - /// - public class ConfigChangedEvent : ISyncEvent - { - /// - /// - public override string ToString() - { - return "ConfigChangedEvent"; - } - } - - /// - public class RepoConfigChangedEvent : ConfigChangedEvent - { - /// - public readonly Config.SyncConfig.SyncFolder RepoInfo; - - /// - /// - public RepoConfigChangedEvent(Config.SyncConfig.SyncFolder repoInfo) - { - RepoInfo = repoInfo; - } - - /// - /// - public override string ToString() - { - return String.Format("RepoConfigChangedEvent: {0}", RepoInfo.DisplayName); - } - } -} diff --git a/CmisSync.Lib/Events/DebugLoggingHandler.cs b/CmisSync.Lib/Events/DebugLoggingHandler.cs deleted file mode 100644 index f149248f9..000000000 --- a/CmisSync.Lib/Events/DebugLoggingHandler.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; - -using log4net; - -namespace CmisSync.Lib.Events -{ - /// - public class DebugLoggingHandler : SyncEventHandler - { - private static readonly ILog Logger = LogManager.GetLogger(typeof(DebugLoggingHandler)); - private static readonly int DEBUGGINGLOGGERPRIORITY = 10000; - - /// - /// - /// - public override bool Handle(ISyncEvent e) - { - Logger.Debug("Incomming Event: " + e.ToString()); - return false; - } - - /// - public override int Priority - { - get {return DEBUGGINGLOGGERPRIORITY;} - } - } -} - diff --git a/CmisSync.Lib/Events/FileTransmissionEvent.cs b/CmisSync.Lib/Events/FileTransmissionEvent.cs deleted file mode 100644 index f16f5ca8c..000000000 --- a/CmisSync.Lib/Events/FileTransmissionEvent.cs +++ /dev/null @@ -1,323 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace CmisSync.Lib.Events -{ - /// - /// File transmission event. - /// This event should be queued only once. The progress will not be reported on the queue. - /// Interested entities should add themselfs as TransmissionEventHandler on the event TransmissionStatus to get informed about the progress. - /// - public class FileTransmissionEvent: ISyncEvent - { - /// - /// Gets the type of the transmission. - /// - /// - /// The type of the transmission. - /// - public FileTransmissionType Type { get; private set; } - - /// - /// Gets the path to the file, which is transmitted. - /// - /// - /// The path. - /// - public string Path { get; private set; } - - /// - /// If a download happens, a cache file could be used. If the cache is used, this should be the path. - /// - /// - /// The cache path. - /// - public string CachePath { get; private set; } - - /// - /// - /// - public delegate void TransmissionEventHandler(object sender, TransmissionProgressEventArgs e); - - /// - /// Occurs when transmission status changes. - /// - public event TransmissionEventHandler TransmissionStatus = delegate { }; - - private TransmissionProgressEventArgs status; - - /// - /// Gets the actual status of the transmission. - /// - /// - /// The status. - /// - public TransmissionProgressEventArgs Status { get {return this.status;} private set { this.status = value; } } - - /// - /// Initializes a new instance of the class. - /// - /// - /// Type of the transmission. - /// - /// - /// Path to the file of the transmission. - /// - /// - /// If a download runs and a cache file is used, this should be the path to the cache file - /// - public FileTransmissionEvent(FileTransmissionType type, string path, string cachePath = null) - { - if(path == null) { - throw new ArgumentNullException("Argument null in FSEvent Constructor","path"); - } - Type = type; - Path = path; - status = new TransmissionProgressEventArgs(); - CachePath = cachePath; - } - - /// - /// Returns a that represents the current . - /// - /// - /// A that represents the current . - /// - public override string ToString() - { - return string.Format("FileTransmissionEvent with type \"{0}\" on path \"{1}\"", Type, Path); - } - - /// - /// Reports the progress. Every non null value will update the actual status. - /// All other values will be taken from the last reported progress. - /// - /// - /// Status update. - /// - public void ReportProgress(TransmissionProgressEventArgs status) - { - Status.Aborted = (status.Aborted != null) ? status.Aborted : Status.Aborted; - Status.ActualPosition = (status.ActualPosition != null) ? status.ActualPosition : Status.ActualPosition; - Status.Length = (status.Length != null) ? status.Length : Status.Length; - Status.Completed = (status.Completed != null) ? status.Completed : Status.Completed; - Status.BitsPerSecond = (status.BitsPerSecond != null && Status.BitsPerSecond!=status.BitsPerSecond) ? status.BitsPerSecond : null; - if (TransmissionStatus != null) - TransmissionStatus(this, Status); - } - } - - /// - /// Transmission progress event arguments. - /// - public class TransmissionProgressEventArgs - { - /// - /// Gets or sets the bits per second. Can be null if its unknown. - /// - /// - /// The bits per second or null. - /// - public long? BitsPerSecond { get; set; } - - /// - /// Gets the percentage of the transmission progress if known. Otherwise null. - /// - /// - /// The percentage of the transmission progress. - /// - public double? Percent { get{ - if(Length==null || ActualPosition == null || ActualPosition < 0 || Length < 0) - return null; - if(Length == 0) - return 100d; - return ((double)ActualPosition*100d)/(double)Length; - } } - - /// - /// Gets or sets the length of the file transmission in bytes. - /// - /// - /// The transmission length. - /// - public long? Length { get; set; } - - /// - /// Gets or sets the actual position of the transmission progress. - /// - /// - /// The actual transmission position. - /// - public long? ActualPosition { get; set; } - - /// - /// Gets or sets if the transmission is paused. - /// - /// - /// Transmission paused. - /// - public bool? Paused { get; set; } - - /// - /// Gets or sets if the transmission is resumed. - /// - /// - /// Transmission resumed. - /// - public bool? Resumed { get; set; } - - /// - /// Gets or sets if the transmission is aborted. - /// - /// - /// Transmission aborted. - /// - public bool? Aborted{ get; set; } - - /// - /// Gets or sets if the transmission is completed. - /// - /// - /// Transmission completed. - /// - public bool? Completed { get; set; } - - /// - /// Gets or sets the failed exception of the transmission, if any exception occures. - /// - /// - /// Transmission failed exception. - /// - public Exception FailedException { get; set;} - - /// - /// Calculates the bits per second. - /// - /// - /// The bits per second. - /// - /// - /// Start time for calculation. - /// - /// - /// End time for calculation. - /// - /// - /// Bytes in period between start end end. - /// - public static long? CalcBitsPerSecond(DateTime start, DateTime end, long bytes){ - if(end < start) - throw new ArgumentException("The end of a transmission must be higher than the start"); - if(start == end){ - return null; - } - TimeSpan difference = end - start; - if(difference.Seconds == 0) - return null; - return (bytes*8) / (difference.Seconds); - } - - /// - /// Initializes a new instance of the class. - /// - public TransmissionProgressEventArgs() - { - BitsPerSecond = null; - Length = null; - ActualPosition = null; - Paused = null; - Resumed = null; - Aborted = null; - FailedException = null; - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// - /// The to compare with the current . - /// - /// - /// true if the specified is equal to the current - /// ; otherwise, false. - /// - public override bool Equals(System.Object obj) { - // If parameter is null return false. - if (obj == null) - { - return false; - } - TransmissionProgressEventArgs e = obj as TransmissionProgressEventArgs; - if ((System.Object)e == null) - { - return false; - } - - // Return true if the fields match: - return (Length == e.Length) && - (BitsPerSecond == e.BitsPerSecond || BitsPerSecond==null || e.BitsPerSecond==null) && - (ActualPosition == e.ActualPosition) && - (Paused == e.Paused) && - (Resumed == e.Resumed) && - (Aborted == e.Aborted) && - (FailedException == e.FailedException); - } - - /// - /// Serves as a hash function for a object. - /// - /// - /// A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a - /// hash table. - /// - public override int GetHashCode () - { - return base.GetHashCode (); - } - - /// - /// Returns a that represents the current . - /// - /// - /// A that represents the current . - /// - public override string ToString() - { - string status = ""; - if(Paused == true) - status += "Paused"; - if(Resumed == true) - status += "Resumed"; - if(Aborted == true) - status += "Aborted"; - if(Completed == true) - status += "Completed"; - return String.Format("[TransmissionProgressEventArgs: [Length: {0}] [ActualPosition: {1}] [Percent: {2}] [Status: {3}]] [Exception: {4}]", - Length, ActualPosition, Percent, status, FailedException); - } - } - - /// - /// File transmission types. - /// - public enum FileTransmissionType - { - /// - /// A new file is uploaded - /// - UPLOAD_NEW_FILE, - /// - /// A locally modified file is uploaded - /// - UPLOAD_MODIFIED_FILE, - /// - /// A new remote file is downloaded - /// - DOWNLOAD_NEW_FILE, - /// - /// A remotely modified file is downloaded - /// - DOWNLOAD_MODIFIED_FILE - } -} diff --git a/CmisSync.Lib/Events/ISyncEvent.cs b/CmisSync.Lib/Events/ISyncEvent.cs deleted file mode 100644 index 57b1979b3..000000000 --- a/CmisSync.Lib/Events/ISyncEvent.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace CmisSync.Lib.Events -{ - /// - public interface ISyncEvent - { - /// - /// - string ToString(); - } -} - diff --git a/CmisSync.Lib/Events/SyncEventHandler.cs b/CmisSync.Lib/Events/SyncEventHandler.cs deleted file mode 100644 index 507e3491e..000000000 --- a/CmisSync.Lib/Events/SyncEventHandler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; - -using log4net; - -namespace CmisSync.Lib.Events -{ - /// Base class for all Event-Handlers - public abstract class SyncEventHandler : IComparable, IComparable - { - /// - /// - /// - public abstract bool Handle(ISyncEvent e); - - ///May not be changed during runtime - public abstract int Priority {get;} - - /// - /// - /// - public int CompareTo(SyncEventHandler other) { - return Priority.CompareTo(other.Priority); - } - - // CompareTo is implemented for Sorting EventHandlers - // Equals is not implemented because EventHandler removal shall work by Object.Equals - int IComparable.CompareTo(object obj) { - if(!(obj is SyncEventHandler)){ - throw new ArgumentException("Argument is not a SyncEventHandler", "obj"); - } - SyncEventHandler other = obj as SyncEventHandler; - return this.CompareTo(other); - } - - /// - /// - public override string ToString() { - return this.GetType() + " with Priority " + Priority.ToString(); - } - } -} - diff --git a/CmisSync.Lib/Events/SyncEventManager.cs b/CmisSync.Lib/Events/SyncEventManager.cs deleted file mode 100644 index 8bc9cb670..000000000 --- a/CmisSync.Lib/Events/SyncEventManager.cs +++ /dev/null @@ -1,56 +0,0 @@ -using log4net; - -using System; -using System.Collections.Generic; - -namespace CmisSync.Lib.Events -{ - /// - public class SyncEventManager - { - private static readonly ILog logger = LogManager.GetLogger(typeof(SyncEventManager)); - - private List handler = new List(); - - /// - public SyncEventManager() - { - } - - /// - /// - public void AddEventHandler(SyncEventHandler h) - { - //The zero-based index of item in the sorted List, - //if item is found; otherwise, a negative number that - //is the bitwise complement of the index of the next - //element that is larger than item or. - int pos = handler.BinarySearch(h); - if(pos < 0){ - pos = ~pos; - } - handler.Insert(pos, h); - } - - /// - /// - public virtual void Handle(ISyncEvent e) { - for(int i = handler.Count-1; i >= 0; i--) - { - var h = handler[i]; - logger.Debug("Forwarding to Handler " + h); - if(handler[i].Handle(e)){ - return; - } - } - } - - /// - /// - public void RemoveEventHandler(SyncEventHandler h) - { - handler.Remove(h); - } - } -} - diff --git a/CmisSync.Lib/Events/SyncEventQueue.cs b/CmisSync.Lib/Events/SyncEventQueue.cs deleted file mode 100644 index b467b242f..000000000 --- a/CmisSync.Lib/Events/SyncEventQueue.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Threading.Tasks; - -using log4net; - -namespace CmisSync.Lib.Events -{ - /// - public class SyncEventQueue : IDisposable { - private static readonly ILog Logger = LogManager.GetLogger(typeof(SyncEventQueue)); - - private BlockingCollection queue = new BlockingCollection(); - - private SyncEventManager manager; - - private Task consumer; - - private bool alreadyDisposed = false; - - /// Constructor. - public SyncEventQueue(SyncEventManager manager) - { - if (manager == null) - { - throw new ArgumentException("manager may not be null"); - } - this.manager = manager; - - // Start to listen in a separate thread. - this.consumer = new Task(() => Listen(this.queue, this.manager)); - this.consumer.Start(); - } - - private static void Listen(BlockingCollection queue, SyncEventManager manager) - { - Logger.Debug("Starting to listen on SyncEventQueue"); - while (!queue.IsCompleted) - { - ISyncEvent syncEvent = null; - // Blocks if number.Count == 0 - // IOE means that Take() was called on a completed collection. - // Some other thread can call CompleteAdding after we pass the - // IsCompleted check but before we call Take. - // In this example, we can simply catch the exception since the - // loop will break on the next iteration. - try - { - syncEvent = queue.Take(); - } - catch (InvalidOperationException) { } - - if (syncEvent != null) - { - try{ - manager.Handle(syncEvent); - }catch(Exception e) { - Logger.Error("Exception in EventHandler"); - Logger.Error(e); - } - } - } - Logger.Debug("Stopping to listen on SyncEventQueue"); - } - - /// - /// - /// - public void AddEvent(ISyncEvent newEvent) { - if(alreadyDisposed) { - throw new ObjectDisposedException("SyncEventQueue", "Called AddEvent on Disposed object"); - } - this.queue.Add(newEvent); - } - - /// - public void StopListener() { - if(alreadyDisposed) { - return; - } - this.queue.CompleteAdding(); - } - - /// - public bool IsStopped { - get { - return this.consumer.IsCompleted; - } - } - - /// - public void Dispose() { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// - protected virtual void Dispose(bool isDisposing) { - if(alreadyDisposed) { - return; - } - if(!IsStopped){ - Logger.Warn("Disposing a not yet stopped SyncEventQueue"); - } - if(isDisposing) { - this.queue.Dispose(); - } - this.alreadyDisposed = true; - } - } -} diff --git a/CmisSync.Lib/LoggingStream.cs b/CmisSync.Lib/LoggingStream.cs deleted file mode 100644 index 9fd31c594..000000000 --- a/CmisSync.Lib/LoggingStream.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using log4net; -using System.IO; - -namespace CmisSync.Lib -{ - public class LoggingStream : Stream - { - private static readonly ILog Logger = LogManager.GetLogger(typeof(LoggingStream)); - private string prefix = ""; - private Stream stream; - private bool isDebuggingEnabled = Logger.IsDebugEnabled; - private long length; - private long readpos = 0; - private long writepos = 0; - public LoggingStream(Stream stream, string prefix, string filename, long streamlength) - { - this.stream = stream; - this.length = streamlength; - this.prefix = String.Format("{0} {1}: ", prefix, filename, SyncUtils.FormatSize(Length)); - } - public override bool CanRead - { - get - { - return this.stream.CanRead; - } - } - public override bool CanSeek - { - get - { - return this.stream.CanSeek; - } - } - public override bool CanWrite - { - get - { - return this.stream.CanWrite; - } - } - public override long Length - { - get - { - try{ - return Math.Max(this.stream.Length, this.length); - }catch(System.NotSupportedException) { - return this.length; - } - - } - } - public override long Position - { - get - { - return this.stream.Position; - } - set - { - this.stream.Position = value; - } - } - public override void Flush() - { - if(isDebuggingEnabled) - Logger.Debug("Flushing stream"); - this.stream.Flush(); - } - public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) - { - if(isDebuggingEnabled) - Logger.Debug(String.Format("{0}BeginRead(..., int offset={1}, int count={2}, ...)", prefix, offset, count)); - return this.stream.BeginRead(buffer, offset, count, callback, state); - } - public override long Seek(long offset, SeekOrigin origin) - { - if(isDebuggingEnabled) - Logger.Debug(String.Format("{0}Seek(long offset={1}, ...)", prefix, offset)); - return this.stream.Seek(offset,origin); - } - public override int Read(byte[] buffer, int offset, int count) - { - if(isDebuggingEnabled) { - int result = this.stream.Read(buffer,offset,count); - readpos+=result; - long percentage = (readpos * 100)/ (Length>0?Length:100); - Logger.Debug(String.Format("{0}% {1} of {2}", - percentage, - SyncUtils.FormatSize(this.readpos), - SyncUtils.FormatSize(Length))); - return result; - } - else - return this.stream.Read(buffer,offset,count); - } - public override void SetLength(long value) - { - if(isDebuggingEnabled) - Logger.Debug(String.Format("{0}SetLength(long value={1})", prefix, value)); - this.length = value; - this.stream.SetLength(value); - } - public override void Write(byte[] buffer, int offset, int count) - { - this.stream.Write(buffer, offset, count); - if(isDebuggingEnabled) - { - writepos += count; - long percentage = (writepos * 100)/ (Length>0?Length:100); - Logger.Debug(String.Format("{0}% {1} of {2})", - percentage, - SyncUtils.FormatSize(this.writepos), - SyncUtils.FormatSize(Length))); - } - } - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - } - } -} - diff --git a/CmisSync.Lib/Sync/SyncFolderSyncronizer.cs b/CmisSync.Lib/Sync/SyncFolderSyncronizer.cs index b42164953..9d4ac4228 100644 --- a/CmisSync.Lib/Sync/SyncFolderSyncronizer.cs +++ b/CmisSync.Lib/Sync/SyncFolderSyncronizer.cs @@ -33,8 +33,6 @@ using System.Threading; using CmisSync.Lib.Database; -using CmisSync.Lib.Events; - namespace CmisSync.Lib.Sync { /// diff --git a/CmisSync.Lib/Sync/SyncFolderSyncronizerBase.cs b/CmisSync.Lib/Sync/SyncFolderSyncronizerBase.cs index c286fafa4..2a0297a19 100644 --- a/CmisSync.Lib/Sync/SyncFolderSyncronizerBase.cs +++ b/CmisSync.Lib/Sync/SyncFolderSyncronizerBase.cs @@ -19,7 +19,6 @@ using System; using System.IO; using Timers = System.Timers; -using CmisSync.Lib.Events; using CmisSync.Lib.Auth; using DotCMIS.Exceptions; using CmisSync.Lib.Cmis; diff --git a/CmisSync.Lib/UserNotificationListener.cs b/CmisSync.Lib/UserNotificationListener.cs deleted file mode 100644 index 4170ba123..000000000 --- a/CmisSync.Lib/UserNotificationListener.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace CmisSync.Lib -{ - /// - /// Interface for a component that can display a notification message to the end user. - /// A GUI program might raise a pop-up, a CLI program might print a line. - /// - public interface UserNotificationListener - { - /// - /// Send a message to the end user. - /// - void NotifyUser(string message); - } -}