From 9e4a2eb24ad1882cee1cc9d43f0af0faff2ba861 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 10 Sep 2020 14:30:00 +0300 Subject: Working on Tango.Git and Tag creation upon release. --- .../FSE/Tango.FSE.Publisher.UI/App.config | 7 +- .../FSE/Tango.FSE.Publisher.UI/MainWindow.xaml | 2 + .../FSE/Tango.FSE.Publisher.UI/MainWindowVM.cs | 45 +++++++ .../Tango.FSE.Publisher.UI.csproj | 4 + .../Tango.Emulations/Emulators/MachineEmulator.cs | 5 + Software/Visual_Studio/Tango.Git/GitCommit.cs | 13 ++ Software/Visual_Studio/Tango.Git/GitFile.cs | 14 +++ Software/Visual_Studio/Tango.Git/GitFileState.cs | 14 +++ .../Tango.Git/GitRepositoryManager.cs | 132 +++++++++++++++++++++ .../Tango.Git/Properties/AssemblyInfo.cs | 36 ++++++ Software/Visual_Studio/Tango.Git/Tango.Git.csproj | 72 +++++++++++ Software/Visual_Studio/Tango.Git/packages.config | 5 + Software/Visual_Studio/Tango.sln | 34 +++++- .../Tango.MachineEM.UI/ViewModels/MainViewVM.cs | 21 ++++ .../Tango.MachineEM.UI/Views/MainView.xaml | 12 +- 15 files changed, 404 insertions(+), 12 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Git/GitCommit.cs create mode 100644 Software/Visual_Studio/Tango.Git/GitFile.cs create mode 100644 Software/Visual_Studio/Tango.Git/GitFileState.cs create mode 100644 Software/Visual_Studio/Tango.Git/GitRepositoryManager.cs create mode 100644 Software/Visual_Studio/Tango.Git/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Tango.Git/Tango.Git.csproj create mode 100644 Software/Visual_Studio/Tango.Git/packages.config (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/App.config b/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/App.config index 3c53533de..7caec2cba 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/App.config +++ b/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/App.config @@ -1,9 +1,10 @@  - - - + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/MainWindow.xaml b/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/MainWindow.xaml index 143113bf1..91b8bfae5 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/MainWindow.xaml +++ b/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/MainWindow.xaml @@ -59,6 +59,8 @@ Password + + Create Tag On Repository diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/MainWindowVM.cs b/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/MainWindowVM.cs index 148ee37f6..9fce64c89 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/MainWindowVM.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/MainWindowVM.cs @@ -13,6 +13,7 @@ using Tango.Core; using Tango.Core.Commands; using Tango.FSE.BL.Web; using Tango.FSE.Web.Messages; +using Tango.Git; using Tango.MachineService.Gateway; using Tango.Settings; using Tango.SharedUI; @@ -82,6 +83,13 @@ namespace Tango.FSE.Publisher.UI set { _comments = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } + private bool _createTag; + public bool CreateTag + { + get { return _createTag; } + set { _createTag = value; RaisePropertyChangedAuto(); } + } + private TangoProgress _progress; public TangoProgress Progress { @@ -202,6 +210,43 @@ namespace Tango.FSE.Publisher.UI IsFree = false; UpdateProgress("Publishing Tango FSE..."); + if (CreateTag) + { + await Task.Factory.StartNew(() => + { + String repoPath = Path.GetFullPath("../../../../../../"); + using (GitRepositoryManager git = new GitRepositoryManager(repoPath, Email, ConfigurationManager.AppSettings.Get("PAT"))) + { + UpdateProgress("Checking repository changes..."); + int changes = git.GetChanges().Count; + if (changes > 0) + { + throw new InvalidOperationException($"There are {changes} uncommitted changes on the repository. Please commit and push all changes before creating the Tag"); + } + + UpdateProgress("Checking outgoing commits..."); + int commits = git.GetOutgoingCommits().Count; + if (commits > 0) + { + throw new InvalidOperationException($"There are {commits} outgoing commits on the repository. Please push all commits before creating the Tag"); + } + + String tagVersion = System.Version.Parse(LocalVersion).ToString(3); + String tagName = $"FSE_v{tagVersion}"; + String tagDescription = $"Snapshot of Tango FSE v{tagVersion}"; + + git.Progress += (x, e) => + { + UpdateProgress($"Pushing Tag '{tagName}'...", false, e.Progress.Value, e.Progress.Maximum); + }; + + UpdateProgress($"Creating Tag '{tagName}'...", true); + + git.CreatePushTag(tagName, tagDescription, "Roy Ben Shabat"); + } + }); + } + var settings = SettingsManager.Default.GetOrCreate(); settings.Email = Email; settings.Password = Password; diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/Tango.FSE.Publisher.UI.csproj b/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/Tango.FSE.Publisher.UI.csproj index 26a0ee007..f58e3bdec 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/Tango.FSE.Publisher.UI.csproj +++ b/Software/Visual_Studio/FSE/Tango.FSE.Publisher.UI/Tango.FSE.Publisher.UI.csproj @@ -108,6 +108,10 @@ {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core + + {99081c0e-065c-4d68-bf60-f82330cca02d} + Tango.Git + {d8f1ad85-526a-4f50-b6dc-d437af63d8d8} Tango.Settings diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index b0d4236bb..e594416f9 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -1695,6 +1695,11 @@ namespace Tango.Emulations.Emulators _cancelJob = true; } + public async void SetThreadLoadingState(ThreadLoadingState state) + { + await Transporter.SendResponse(new StartThreadLoadingResponse() { State = state, Message = $"{state.ToString()}", ErrorReason = "Fake emulator error" }, _threadLoadingToken); + } + #endregion } } diff --git a/Software/Visual_Studio/Tango.Git/GitCommit.cs b/Software/Visual_Studio/Tango.Git/GitCommit.cs new file mode 100644 index 000000000..fc388176b --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/GitCommit.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Git +{ + public class GitCommit + { + public String Message { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Git/GitFile.cs b/Software/Visual_Studio/Tango.Git/GitFile.cs new file mode 100644 index 000000000..899fa839e --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/GitFile.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Git +{ + public class GitFile + { + public String File { get; set; } + public GitFileState State { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Git/GitFileState.cs b/Software/Visual_Studio/Tango.Git/GitFileState.cs new file mode 100644 index 000000000..4c8bb6c14 --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/GitFileState.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Git +{ + public enum GitFileState + { + Added, + Modified + } +} diff --git a/Software/Visual_Studio/Tango.Git/GitRepositoryManager.cs b/Software/Visual_Studio/Tango.Git/GitRepositoryManager.cs new file mode 100644 index 000000000..e7fdf8e32 --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/GitRepositoryManager.cs @@ -0,0 +1,132 @@ +using LibGit2Sharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.Git +{ + public class GitRepositoryManager : IDisposable + { + private Repository _repo; + private String _pat; + private String _userEmail; + + public event EventHandler> Progress; + + public GitRepositoryManager(String localFolder, String userEmail, String personalAccessToken) + { + _pat = personalAccessToken; + _userEmail = userEmail; + _repo = new Repository(localFolder); + } + + public void CreatePushTag(String name, String description, String userName) + { + var tag = _repo.ApplyTag(name, new Signature(userName, _userEmail, DateTime.Now), description); + + _repo.Network.Push(_repo.Network.Remotes.First(), tag.CanonicalName, new PushOptions() + { + CredentialsProvider = new LibGit2Sharp.Handlers.CredentialsHandler(CredentialsHandlerMethod), + OnPushTransferProgress = new LibGit2Sharp.Handlers.PushTransferProgressHandler(PushTagProgressHandlerMethod) + }); + } + + private bool PushTagProgressHandlerMethod(int current, int total, long bytes) + { + //TODO: Implement via TangoProgress & event... + RaiseProgress("Pushing Tag...", false, 0, total); + return true; + } + + public List GetOutgoingCommits(String branchName = "master") + { + List commits = new List(); + + var branch = _repo.Branches.FirstOrDefault(x => x.FriendlyName == branchName); + + if (branch.TrackingDetails.AheadBy != null) + { + foreach (var commit in _repo.Commits.Take(branch.TrackingDetails.AheadBy.Value)) + { + commits.Add(new GitCommit() + { + Message = commit.Message + }); + } + } + + return commits; + } + + public List GetIncomingCommits() + { + List commits = new List(); + + var trackingBranch = _repo.Head.TrackedBranch; + var log = _repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = trackingBranch.Tip.Id, ExcludeReachableFrom = _repo.Head.Tip.Id }); + + var count = log.Count(); + + foreach (var commit in log) + { + commits.Add(new GitCommit() + { + Message = commit.Message + }); + } + + return commits; + } + + public List GetChanges() + { + List files = new List(); + + var status = _repo.RetrieveStatus(); + + foreach (var file in status.Added) + { + files.Add(new GitFile() + { + File = file.FilePath, + State = GitFileState.Added + }); + } + + foreach (var file in status.Modified) + { + files.Add(new GitFile() + { + File = file.FilePath, + State = GitFileState.Modified + }); + } + + return files; + } + + private Credentials CredentialsHandlerMethod(string url, string usernameFromUrl, SupportedCredentialTypes types) + { + return new UsernamePasswordCredentials { Username = _userEmail, Password = _pat }; + } + + protected virtual void RaiseProgress(String message, bool isIndeterminate = true, double value = 0, double maximum = 100) + { + Progress?.Invoke(this, new TangoProgressChangedEventArgs(new TangoProgress() + { + IsIndeterminate = isIndeterminate, + Message = message, + Value = value, + Maximum = maximum + })); + } + + public void Dispose() + { + _repo.Dispose(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Git/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Tango.Git/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..4e07415b3 --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tango.Git")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.Git")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("99081c0e-065c-4d68-bf60-f82330cca02d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio/Tango.Git/Tango.Git.csproj b/Software/Visual_Studio/Tango.Git/Tango.Git.csproj new file mode 100644 index 000000000..8bbf79eea --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/Tango.Git.csproj @@ -0,0 +1,72 @@ + + + + + + Debug + AnyCPU + {99081C0E-065C-4D68-BF60-F82330CCA02D} + Library + Properties + Tango.Git + Tango.Git + v4.6.1 + 512 + true + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\LibGit2Sharp.0.26.2\lib\net46\LibGit2Sharp.dll + + + + + + + + + + + + + + + + + + + + + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Git/packages.config b/Software/Visual_Studio/Tango.Git/packages.config new file mode 100644 index 000000000..576f27245 --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index e43333a4a..b1771998e 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -415,6 +415,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.PPC.Packages.JobRunsS EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.CctOptimizer.CLI", "Utilities\Tango.CctOptimizer.CLI\Tango.CctOptimizer.CLI.csproj", "{69168924-9AA8-447D-AD64-F07DBF4F0909}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.Git", "Tango.Git\Tango.Git.csproj", "{99081C0E-065C-4D68-BF60-F82330CCA02D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -3902,6 +3904,26 @@ Global {69168924-9AA8-447D-AD64-F07DBF4F0909}.Release|x64.Build.0 = Release|Any CPU {69168924-9AA8-447D-AD64-F07DBF4F0909}.Release|x86.ActiveCfg = Release|Any CPU {69168924-9AA8-447D-AD64-F07DBF4F0909}.Release|x86.Build.0 = Release|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Debug|ARM.ActiveCfg = Debug|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Debug|ARM.Build.0 = Debug|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Debug|ARM64.Build.0 = Debug|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Debug|x64.ActiveCfg = Debug|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Debug|x64.Build.0 = Debug|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Debug|x86.ActiveCfg = Debug|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Debug|x86.Build.0 = Debug|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Release|Any CPU.Build.0 = Release|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Release|ARM.ActiveCfg = Release|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Release|ARM.Build.0 = Release|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Release|ARM64.ActiveCfg = Release|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Release|ARM64.Build.0 = Release|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Release|x64.ActiveCfg = Release|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Release|x64.Build.0 = Release|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Release|x86.ActiveCfg = Release|Any CPU + {99081C0E-065C-4D68-BF60-F82330CCA02D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -4046,12 +4068,12 @@ Global {69168924-9AA8-447D-AD64-F07DBF4F0909} = {5F6BBAA8-EAD0-4B18-97E5-55B4F56DD760} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - BuildVersion_UseGlobalSettings = False - BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs - BuildVersion_StartDate = 2000/1/1 - BuildVersion_UpdateFileVersion = False - BuildVersion_UpdateAssemblyVersion = True - BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} + BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear + BuildVersion_UpdateAssemblyVersion = True + BuildVersion_UpdateFileVersion = False + BuildVersion_StartDate = 2000/1/1 + BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs + BuildVersion_UseGlobalSettings = False EndGlobalSection EndGlobal diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs index 62a05472d..a66ed6b7e 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs @@ -12,6 +12,7 @@ using Tango.Transport.Servers; using Tango.Transport.Transporters; using Tango.Core; using Tango.Settings; +using Tango.PMR.ThreadLoading; namespace Tango.MachineEM.UI.ViewModels { @@ -64,10 +65,30 @@ namespace Tango.MachineEM.UI.ViewModels set { _selectedPort = value; RaisePropertyChanged(nameof(SelectedPort)); } } + private ThreadLoadingState _threadLoadingState; + public ThreadLoadingState ThreadLoadingState + { + get { return _threadLoadingState; } + set { _threadLoadingState = value; OnThreadLoadingStateChanged(); } + } + + #endregion #region Private Methods + private void OnThreadLoadingStateChanged() + { + try + { + Emulator?.SetThreadLoadingState(ThreadLoadingState); + } + catch (Exception ex) + { + LogManager.Log(ex); + } + } + #endregion #region Commands diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml index 6ebd1cde2..62bacd6d2 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml @@ -9,6 +9,7 @@ xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:vm="clr-namespace:Tango.MachineEM.UI.ViewModels" xmlns:pmr="clr-namespace:Tango.PMR.MachineStatus;assembly=Tango.PMR" + xmlns:threadLoading="clr-namespace:Tango.PMR.ThreadLoading;assembly=Tango.PMR" xmlns:local="clr-namespace:Tango.MachineEM.UI.Views" mc:Ignorable="d" d:DesignHeight="720" d:DesignWidth="1300" Foreground="Gainsboro" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" > @@ -137,11 +138,16 @@ + + + Thread Loading State + + -- cgit v1.3.1