From 0c2ee771c6f6bc2011f69cd3a9e86604864d5112 Mon Sep 17 00:00:00 2001 From: Lior Banai <36262995+LiorBanai@users.noreply.github.com> Date: Sat, 21 Nov 2020 19:39:12 +0200 Subject: [PATCH] add net48 --- .../Analogy.LogViewer.GitHistory.csproj | 5 +- Analogy.LogViewer.GitHistory/GitPullUC.cs | 11 ++++- .../GitRepositoryLoader.cs | 49 +++++++++---------- .../IAnalogy/DownloadInformation.cs | 2 +- .../GitHistoryCustomActionsFactory.cs | 2 +- .../IAnalogy/GitHistoryDataProviderFactory.cs | 31 +++++++----- .../GitHistoryDataProviderSettings.cs | 17 +++---- .../IAnalogy/GitHistoryFactory.cs | 31 ------------ .../IAnalogy/GitHistoryPrimaryFactory.cs | 24 +++++++++ .../Managers/LogManager.cs | 25 ++++++---- .../RepositoriesSetting.cs | 34 +++++++++++-- 11 files changed, 132 insertions(+), 99 deletions(-) delete mode 100644 Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryFactory.cs create mode 100644 Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryPrimaryFactory.cs diff --git a/Analogy.LogViewer.GitHistory/Analogy.LogViewer.GitHistory.csproj b/Analogy.LogViewer.GitHistory/Analogy.LogViewer.GitHistory.csproj index 241d6e1..c38f7af 100644 --- a/Analogy.LogViewer.GitHistory/Analogy.LogViewer.GitHistory.csproj +++ b/Analogy.LogViewer.GitHistory/Analogy.LogViewer.GitHistory.csproj @@ -2,7 +2,7 @@ Library - net471;net472;netcoreapp3.1 + net48;net471;net472;netcoreapp3.1 true true true @@ -17,7 +17,7 @@ Aligh with latest API Analogy.GitHistoryBanner.png true - 1.3.5.1 + 1.3.6 Analogy.LogViewer enable 8.0 @@ -27,7 +27,6 @@ - diff --git a/Analogy.LogViewer.GitHistory/GitPullUC.cs b/Analogy.LogViewer.GitHistory/GitPullUC.cs index d2cfc34..64e8b58 100644 --- a/Analogy.LogViewer.GitHistory/GitPullUC.cs +++ b/Analogy.LogViewer.GitHistory/GitPullUC.cs @@ -27,7 +27,10 @@ public GitPullUC(RepositorySetting repositorySetting) private void BtnOperation_Click(object sender, EventArgs e) { - if (RepositorySetting == null) return; + if (RepositorySetting == null) + { + return; + } string logMessage = ""; using (var repo = new Repository(RepositorySetting.RepositoryPath)) @@ -52,7 +55,11 @@ private void BtnOperation_Click(object sender, EventArgs e) private void GitPullUC_Load(object sender, EventArgs e) { - if (DesignMode) return; + if (DesignMode) + { + return; + } + RefreshList(); } private void RefreshList() diff --git a/Analogy.LogViewer.GitHistory/GitRepositoryLoader.cs b/Analogy.LogViewer.GitHistory/GitRepositoryLoader.cs index 4a9f3f4..b53efa9 100644 --- a/Analogy.LogViewer.GitHistory/GitRepositoryLoader.cs +++ b/Analogy.LogViewer.GitHistory/GitRepositoryLoader.cs @@ -10,19 +10,17 @@ namespace Analogy.LogViewer.GitHistory { - public class GitRepositoryLoader : IAnalogyRealTimeDataProvider + public class GitRepositoryLoader : Template.OnlineDataProvider { - public Guid Id { get; set; } = new Guid("3CD8B586-5AB0-4C84-A1F8-0F093F846A5D"); - public Image ConnectedLargeImage { get; set; } = null; - public Image ConnectedSmallImage { get; set; } = null; - public Image DisconnectedLargeImage { get; set; } = null; - public Image DisconnectedSmallImage { get; set; } = null; - public string OptionalTitle { get; set; } - public Task CanStartReceiving() => Task.FromResult(true); - public IAnalogyOfflineDataProvider FileOperationsHandler { get; } = null; - public event EventHandler OnDisconnected; - public event EventHandler OnMessageReady; - public event EventHandler OnManyMessagesReady; + public override Guid Id { get; set; } = new Guid("3CD8B586-5AB0-4C84-A1F8-0F093F846A5D"); + public override Image? ConnectedLargeImage { get; set; } = null; + public override Image? ConnectedSmallImage { get; set; } = null; + public override Image? DisconnectedLargeImage { get; set; } = null; + public override Image? DisconnectedSmallImage { get; set; } = null; + public override string OptionalTitle { get; set; } + public override Task CanStartReceiving() => Task.FromResult(true); + public override IAnalogyOfflineDataProvider FileOperationsHandler { get; set; } = null; + private RepositorySetting RepositorySetting { get; } private GitOperationType Operation { get; } public bool UseCustomColors { get; set; } = false; @@ -38,18 +36,13 @@ public GitRepositoryLoader(RepositorySetting rs, GitOperationType operation) OptionalTitle = RepositorySetting.RepositoryPath; } - public Task InitializeDataProviderAsync(IAnalogyLogger logger) + public override async Task InitializeDataProviderAsync(IAnalogyLogger logger) { + await base.InitializeDataProviderAsync(logger); LogManager.Instance.SetLogger(logger); - return Task.CompletedTask; - } - - public void MessageOpened(AnalogyLogMessage message) - { - //noop } - - public Task StartReceiving() + + public override Task StartReceiving() { try { @@ -80,7 +73,7 @@ public Task StartReceiving() Level = AnalogyLogLevel.Error, Class = AnalogyLogClass.General }; - OnMessageReady?.Invoke(this, new AnalogyLogMessageArgs(m, "", "", Id)); + MessageReady(this, new AnalogyLogMessageArgs(m, "", "", Id)); } return Task.CompletedTask; @@ -93,11 +86,17 @@ private void GetGitHistory() var RFC2822Format = "ddd dd MMM HH:mm:ss yyyy K"; IEnumerable commits; if (RepositorySetting.FetchType == FetchType.Count) + { commits = repo.Commits.Take(RepositorySetting.NumberOfCommits); + } else if (RepositorySetting.FetchType == FetchType.DateTime) + { commits = repo.Commits.Where(c => c.Author.When >= RepositorySetting.HistoryDateTime); + } else + { commits = new List(0); + } foreach (Commit c in commits) { @@ -115,7 +114,7 @@ private void GetGitHistory() Level = (c.Committer.Name == c.Author.Name) ? AnalogyLogLevel.Information : AnalogyLogLevel.Warning, Class = AnalogyLogClass.General }; - OnMessageReady?.Invoke(this, new AnalogyLogMessageArgs(m, "", "", Id)); + MessageReady(this, new AnalogyLogMessageArgs(m, "", "", Id)); } } @@ -149,12 +148,12 @@ private void PerformGitFetch() Level = AnalogyLogLevel.Information, Class = AnalogyLogClass.General }; - OnMessageReady?.Invoke(this, new AnalogyLogMessageArgs(m, "", "", Id)); + MessageReady(this, new AnalogyLogMessageArgs(m, "", "", Id)); } } } - public Task StopReceiving() => Task.CompletedTask; + public override Task StopReceiving() => Task.CompletedTask; } } diff --git a/Analogy.LogViewer.GitHistory/IAnalogy/DownloadInformation.cs b/Analogy.LogViewer.GitHistory/IAnalogy/DownloadInformation.cs index 7698f71..3b60ba6 100644 --- a/Analogy.LogViewer.GitHistory/IAnalogy/DownloadInformation.cs +++ b/Analogy.LogViewer.GitHistory/IAnalogy/DownloadInformation.cs @@ -15,7 +15,7 @@ public class DownloadInformation : Analogy.LogViewer.Template.AnalogyDownloadInf protected override string RepositoryURL { get; set; } = "https://api.github.com/repos/Analogy-LogViewer/Analogy.LogViewer.GitHistory"; public override TargetFrameworkAttribute CurrentFrameworkAttribute { get; set; } = (TargetFrameworkAttribute)Assembly.GetExecutingAssembly().GetCustomAttribute(typeof(TargetFrameworkAttribute)); - public override Guid FactoryId { get; set; } = GitHistoryFactory.Id; + public override Guid FactoryId { get; set; } = GitHistoryPrimaryFactory.Id; public override string Name { get; set; } = "Affirmations Data Provider"; private string? _installedVersionNumber; diff --git a/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryCustomActionsFactory.cs b/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryCustomActionsFactory.cs index 28cff95..9c78bfd 100644 --- a/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryCustomActionsFactory.cs +++ b/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryCustomActionsFactory.cs @@ -11,7 +11,7 @@ namespace Analogy.LogViewer.GitHistory.IAnalogy { public class GitHistoryCustomActionsFactory { - public Guid FactoryId { get; } = GitHistoryFactory.Id; + public Guid FactoryId { get; } = GitHistoryPrimaryFactory.Id; public string Title { get; } = "Git Operations"; public IEnumerable Actions { get; } = new List { new GitFetchAction() }; } diff --git a/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryDataProviderFactory.cs b/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryDataProviderFactory.cs index 595a27b..60040b6 100644 --- a/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryDataProviderFactory.cs +++ b/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryDataProviderFactory.cs @@ -1,32 +1,37 @@ using Analogy.Interfaces; -using Analogy.Interfaces.Factories; using Analogy.LogViewer.GitHistory.Managers; using System; using System.Collections.Generic; +using System.Linq; using Analogy.LogViewer.GitHistory.Data_Types; namespace Analogy.LogViewer.GitHistory.IAnalogy { - public class GitHistoryDataProviderFactory : IAnalogyDataProvidersFactory + public class GitHistoryDataProviderFactory : Template.DataProvidersFactory { - public Guid FactoryId { get; set; } = GitHistoryFactory.Id; - public string Title { get; set; } = "Repositories History"; + public override Guid FactoryId { get; set; } = GitHistoryPrimaryFactory.Id; + public override string Title { get; set; } = "Repositories History"; - public IEnumerable DataProviders + public override IEnumerable DataProviders { - get - { - foreach (RepositorySetting rs in UserSettingsManager.UserSettings.RepositoriesSetting.Repositories) - { - yield return new GitRepositoryLoader(rs, GitOperationType.History); - } - } + get => _dataProviders; + set => _dataProviders = value.ToList(); + } + + private List _dataProviders; + + public GitHistoryDataProviderFactory() + { + _dataProviders = UserSettingsManager.UserSettings.RepositoriesSetting.Repositories + .Select(rs => new GitRepositoryLoader(rs, GitOperationType.History)).Cast() + .ToList(); } } + public class GitFetchDataProviderFactory { - public Guid FactoryId { get; } = GitHistoryFactory.Id; + public Guid FactoryId { get; } = GitHistoryPrimaryFactory.Id; public string Title => "Repositories Fetches"; public IEnumerable DataProviders diff --git a/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryDataProviderSettings.cs b/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryDataProviderSettings.cs index b0f16a6..48cdaca 100644 --- a/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryDataProviderSettings.cs +++ b/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryDataProviderSettings.cs @@ -2,22 +2,21 @@ using System.Drawing; using System.Threading.Tasks; using System.Windows.Forms; -using Analogy.Interfaces; using Analogy.LogViewer.GitHistory.Managers; namespace Analogy.LogViewer.GitHistory.IAnalogy { - public class GitHistoryDataProviderSettings : IAnalogyDataProviderSettings + public class GitHistoryDataProviderSettings : Template.UserSettingsFactory { - public string Title { get; set; } = "Git History settings"; - public UserControl DataProviderSettings { get; } = new GitRepositoriesSettings(); - public Image SmallImage { get; set; } - public Image LargeImage { get; set; } - public Guid FactoryId { get; set; } = GitHistoryFactory.Id; - public Guid Id { get; set; } = new Guid("AEE6AA94-A0B6-4313-8C65-D81943B542DB"); + public override string Title { get; set; } = "Git History settings"; + public override UserControl DataProviderSettings { get; set; } = new GitRepositoriesSettings(); + public override Image? SmallImage { get; set; } + public override Image? LargeImage { get; set; } + public override Guid FactoryId { get; set; } = GitHistoryPrimaryFactory.Id; + public override Guid Id { get; set; } = new Guid("AEE6AA94-A0B6-4313-8C65-D81943B542DB"); - public Task SaveSettingsAsync() + public override Task SaveSettingsAsync() { UserSettingsManager.UserSettings.Save(); return Task.CompletedTask; diff --git a/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryFactory.cs b/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryFactory.cs deleted file mode 100644 index f31289d..0000000 --- a/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryFactory.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Analogy.Interfaces; -using Analogy.Interfaces.Factories; -using System; -using System.Collections.Generic; -using System.Drawing; -using Analogy.LogViewer.GitHistory.Properties; - -namespace Analogy.LogViewer.GitHistory.IAnalogy -{ - public class GitHistoryFactory : IAnalogyFactory - { - internal static Guid Id = new Guid("B842CC0F-AD83-48FB-8394-3189F9A75024"); - - public Guid FactoryId { get; set; } = Id; - - public string Title { get; set; } = "Git History"; - public Image SmallImage { get; set; } = Resources.Git_icon_16x16; - public Image LargeImage { get; set; } = Resources.Git_icon_32x32; - public IEnumerable ChangeLog { get; set; } = new List - { - new AnalogyChangeLog("Initial version",AnalogChangeLogType.None, "Lior Banai",new DateTime(2020, 04, 02)) - }; - public IEnumerable Contributors { get; set; } = new List { "Lior Banai" }; - public string About { get; set; } = "Analogy Git History"; - - public void RegisterNotificationCallback(INotificationReporter notificationReporter) - { - - } - } -} diff --git a/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryPrimaryFactory.cs b/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryPrimaryFactory.cs new file mode 100644 index 0000000..9b30f82 --- /dev/null +++ b/Analogy.LogViewer.GitHistory/IAnalogy/GitHistoryPrimaryFactory.cs @@ -0,0 +1,24 @@ +using Analogy.Interfaces; +using Analogy.LogViewer.GitHistory.Properties; +using System; +using System.Collections.Generic; +using System.Drawing; + +namespace Analogy.LogViewer.GitHistory.IAnalogy +{ + public class GitHistoryPrimaryFactory : Template.PrimaryFactory + { + internal static Guid Id = new Guid("B842CC0F-AD83-48FB-8394-3189F9A75024"); + public override Guid FactoryId { get; set; } = Id; + public override string Title { get; set; } = "Git History"; + public override Image? SmallImage { get; set; } = Resources.Git_icon_16x16; + public override Image? LargeImage { get; set; } = Resources.Git_icon_32x32; + public override IEnumerable ChangeLog { get; set; } = new List + { + new AnalogyChangeLog("Initial version",AnalogChangeLogType.None, "Lior Banai",new DateTime(2020, 04, 02)) + }; + public override IEnumerable Contributors { get; set; } = new List { "Lior Banai" }; + public override string About { get; set; } = "Analogy Git History"; + + } +} diff --git a/Analogy.LogViewer.GitHistory/Managers/LogManager.cs b/Analogy.LogViewer.GitHistory/Managers/LogManager.cs index ab92fc5..b419021 100644 --- a/Analogy.LogViewer.GitHistory/Managers/LogManager.cs +++ b/Analogy.LogViewer.GitHistory/Managers/LogManager.cs @@ -9,7 +9,7 @@ public class LogManager : IAnalogyLogger { private static Lazy _instance = new Lazy(() => new LogManager()); - private IAnalogyLogger Logger { get; set; } + private IAnalogyLogger? Logger { get; set; } public static LogManager Instance { get; } = _instance.Value; private List<(AnalogyLogLevel level, string source, string message, string memberName, int lineNumber, string filePath)> PendingMessages { get; set; } public LogManager() @@ -29,9 +29,7 @@ public void SetLogger(IAnalogyLogger logger) case AnalogyLogLevel.Debug: logger.LogDebug(message, source, memberName, lineNumber, filePath); break; - case AnalogyLogLevel.Information: - logger.LogInformation(message, source, memberName, lineNumber, filePath); - break; + case AnalogyLogLevel.Warning: logger.LogWarning(message, source, memberName, lineNumber, filePath); break; @@ -41,12 +39,9 @@ public void SetLogger(IAnalogyLogger logger) case AnalogyLogLevel.Critical: logger.LogCritical(message, source, memberName, lineNumber, filePath); break; - case AnalogyLogLevel.Analogy: - case AnalogyLogLevel.None: - case AnalogyLogLevel.Trace: - case AnalogyLogLevel.Verbose: default: - throw new ArgumentOutOfRangeException(); + logger.LogInformation(message, source, memberName, lineNumber, filePath); + break; } } } @@ -58,7 +53,9 @@ public void LogInformation(string message, string source, string memberName = "" PendingMessages.Add((AnalogyLogLevel.Information, source, message, memberName, lineNumber, filePath)); } else + { Logger.LogInformation(message, source, memberName, lineNumber, filePath); + } } public void LogWarning(string message, string source, string memberName = "", int lineNumber = 0, string filePath = "") @@ -68,7 +65,9 @@ public void LogWarning(string message, string source, string memberName = "", in PendingMessages.Add((AnalogyLogLevel.Warning, source, message, memberName, lineNumber, filePath)); } else + { Logger.LogWarning(message, source, memberName, lineNumber, filePath); + } } public void LogDebug(string message, string source, string memberName = "", int lineNumber = 0, string filePath = "") @@ -78,7 +77,9 @@ public void LogDebug(string message, string source, string memberName = "", int PendingMessages.Add((AnalogyLogLevel.Debug, source, message, memberName, lineNumber, filePath)); } else + { Logger.LogDebug(message, source, memberName, lineNumber, filePath); + } } public void LogError(string message, string source, string memberName = "", int lineNumber = 0, string filePath = "") @@ -88,7 +89,9 @@ public void LogError(string message, string source, string memberName = "", int PendingMessages.Add((AnalogyLogLevel.Error, source, message, memberName, lineNumber, filePath)); } else + { Logger.LogError(message, source, memberName, lineNumber, filePath); + } } public void LogCritical(string message, string source, string memberName = "", int lineNumber = 0, string filePath = "") @@ -98,7 +101,9 @@ public void LogCritical(string message, string source, string memberName = "", i PendingMessages.Add((AnalogyLogLevel.Critical, source, message, memberName, lineNumber, filePath)); } else + { Logger.LogCritical(message, source, memberName, lineNumber, filePath); + } } public void LogException(string message, Exception ex, string source, string memberName = "", int lineNumber = 0, @@ -109,7 +114,9 @@ public void LogException(string message, Exception ex, string source, string mem PendingMessages.Add((AnalogyLogLevel.Error, source, $"Error: {message.Length }Exception: {ex}", memberName, lineNumber, filePath)); } else + { Logger.LogException(message, ex, source, memberName, lineNumber, filePath); + } } } } diff --git a/Analogy.LogViewer.GitHistory/RepositoriesSetting.cs b/Analogy.LogViewer.GitHistory/RepositoriesSetting.cs index bb95396..bfacaba 100644 --- a/Analogy.LogViewer.GitHistory/RepositoriesSetting.cs +++ b/Analogy.LogViewer.GitHistory/RepositoriesSetting.cs @@ -16,12 +16,16 @@ public RepositoriesSetting() public void AddRepository(RepositorySetting repository) { if (!Repositories.Contains(repository)) + { Repositories.Add(repository); + } } public void DeleteRepository(RepositorySetting repository) { if (Repositories.Contains(repository)) + { Repositories.Remove(repository); + } } } @@ -48,17 +52,37 @@ public RepositorySetting(string repositoryPath, int numberOfCommits, DateTime hi public bool Equals(RepositorySetting other) { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + return RepositoryPath == other.RepositoryPath && NumberOfCommits == other.NumberOfCommits && HistoryDateTime.Equals(other.HistoryDateTime) && FetchType == other.FetchType; } public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; + if (ReferenceEquals(null, obj)) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != this.GetType()) + { + return false; + } + return Equals((RepositorySetting)obj); }