public void Duplicate(VersionControl control) { int index = VersionParent.Children.IndexOf(control); if (index == -1) { return; } VersionController versionController = MainWindow.GetInstance().VersionController; ChangeLog changeLog = versionController.GetChangeLog().Result; VersionRef oldVersionRef = changeLog.Versions[index]; string duplicateName = GetDuplicateName(oldVersionRef.VersionName); VersionRef newVersionRef = new VersionRef(versionController, oldVersionRef.RelativeFilePath, duplicateName); changeLog.Versions.Insert(index + 1, newVersionRef); VersionControl newControl = new VersionControl(newVersionRef); VersionParent.Children.Insert(index + 1, newControl); Version oldVersion = oldVersionRef.GetVersion(false).Result; Version version = new Version(versionController, duplicateName, oldVersion.Description, oldVersion.DownloadLink, oldVersion.ReleaseDate, new System.Collections.Generic.List <ChangeRef>()); if (oldVersion.AdditionalData != null) { version.AdditionalData = (JObject)oldVersion.AdditionalData.DeepClone(); } foreach (ChangeRef oldChangeRef in oldVersion.Changes) { string guid = Guid.NewGuid().ToString(); string newChangePath = Path.Combine(version.VersionName, "changes", $"{guid}.json"); ChangeRef newChangeRef = new ChangeRef(versionController, guid, newChangePath); Change oldChange = oldChangeRef.GetChange(false).Result; Change newChange = new Change(versionController, guid, newChangePath, oldChange.Title, oldChange.Description, newVersionRef); if (oldChange.ReleaseVersion != null) { newChange.ReleaseVersion = new VersionRef(versionController, newVersionRef.RelativeFilePath, newVersionRef.VersionName); } if (oldChange.AdditionalData != null) { newChange.AdditionalData = (JObject)oldChange.AdditionalData.DeepClone(); } version.Changes.Add(newChangeRef); versionController.CacheChange(newChange); } versionController.CacheVersion(version); }
public void Refresh(VersionRef versionRef) { AdditionalDataExpander.IsExpanded = false; openVersionRef = versionRef; Version version = versionRef.GetVersion().Result; VersionField.Foreground = whiteColor; VersionTitle.Foreground = whiteColor; AdditionalDataExpander.IsExpanded = false; eventBlock = true; VersionField.Text = versionRef.VersionName; eventBlock = true; DescriptionField.Text = version.Description; eventBlock = true; LinkField.Text = version.DownloadLink; eventBlock = true; ReleaseDateField.SelectedDate = version.ReleaseDate; if (FunctioningField.IsChecked == !version.IsFunctioning) { eventBlock = true; FunctioningField.IsChecked = version.IsFunctioning; } if (version.AdditionalData == null) { version.AdditionalData = JObject.Parse("{}"); } eventBlock = true; AdditionalDataField.Text = version.AdditionalData.ToString(Newtonsoft.Json.Formatting.Indented); ChangeParent.Children.Clear(); foreach (ChangeRef changeRef in version.Changes) { ChangeControl changeControl = new ChangeControl(changeRef); ChangeParent.Children.Add(changeControl); } }
private static async Task <int> MainAsync(string[] args) { string currentVersion = "1.0.0"; string baseUrl = "https://start-menu-manager.jam-es.com/versions"; // Create instance of VersionController by passing in this version of the application, and the URL of the directory containing changelog file: VersionController versionController = new VersionController(currentVersion, baseUrl); Console.WriteLine($"This Version: {currentVersion}"); // Check this is the latest version bool isLatestVersion = await versionController.IsLatestVersion(); Console.WriteLine($"Is Latest Version: {isLatestVersion}"); // If not latest, you can check this version is still meant to function correctly bool isFunctioningVersion = await versionController.IsFunctioningVersion(); Console.WriteLine($"Is Version Functioning: {isFunctioningVersion}"); // The ChangeLog object contains a list of all versions that have been released // We can list version properties like this: ChangeLog changeLog = await versionController.GetChangeLog(); Console.WriteLine(); Console.WriteLine("All Versions:"); foreach (VersionRef versionRef in changeLog.Versions) { Version version = await versionRef.GetVersion(); Console.WriteLine($"Version Name: {version.VersionName}"); Console.WriteLine($"Version Description: {version.Description}"); Console.WriteLine($"Version Download Link: {version.DownloadLink}"); Console.WriteLine($"Version Release Date: {version.ReleaseDate}"); // You can get all changes in a version with version.Changes } // Get individual versions with: VersionRef firstAppVersionRef = await versionController.GetFirstVersionRef(); Version latestAppVersionRef = await versionController.GetLatestVersion(); VersionRef specificVersionRef = await versionController.GetVersionRef("1.0.0b4"); Console.WriteLine(); Console.WriteLine($"First Version: {firstAppVersionRef.VersionName}"); Console.WriteLine($"Latest Version: {latestAppVersionRef.VersionName}"); Console.WriteLine($"Found Version 1.0.0b4: {specificVersionRef != null}"); // Convert references to Version objects to get all the properties Version firstVersion = await firstAppVersionRef.GetVersion(); Console.WriteLine($"First Version Description: {firstVersion.Description}"); // ChangeLog, Version and Change objects can all have additional data stored within them (set in the WPF app) // You can access this data by deserializing the AdditionalData property (it is a JObject) // For example, to retrieve additional data from a version ExtraVersionData extraData = firstVersion.AdditionalData.ToObject <ExtraVersionData>(); // ^ The version files with the given URI don't actually use additional data so this is null // You could use this to order lists of versions or changes using Linq: /* * List<Task<Version>> getVersionTasks = changeLog.Versions.Select(async v => await v.GetVersion()).ToList(); * IEnumerable<Version> versions = await Task.WhenAll(getVersionTasks); * versions.OrderBy(v => v.AdditionalData.ToObject<ExtraVersionData>().Importance); * // It is gerenally a good idea to surround this in try{}catch{} in case ToObject throws an error */ Console.ReadKey(); return(0); }
private void NewChangeButtonPressed(object sender, RoutedEventArgs args) { Version version = openVersionRef.GetVersion().Result; VersionController versionController = MainWindow.GetInstance().VersionController; string guid = Guid.NewGuid().ToString(); string relativePath = Path.Combine(version.VersionName, "changes", $"{guid}.json"); ChangeRef changeRef = new ChangeRef(versionController, guid, relativePath); version.Changes.Insert(0, changeRef); Change change = new Change(versionController, guid, relativePath, "New Change", string.Empty, openVersionRef); change.ReleaseVersion = new VersionRef(versionController, openVersionRef.RelativeFilePath, openVersionRef.VersionName); versionController.CacheChange(change); ChangeControl newControl = new ChangeControl(changeRef); ChangeParent.Children.Insert(0, newControl); ContentArea.GetInstance().OpenPage(ContentArea.PageType.Change, openVersionRef, changeRef); }