aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/AvalonEditCommands.cs
blob: 5aaed19d8f5c0d8f0c075fa7f10d4a7c728b2374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.Windows.Input;

namespace Tango.Scripting.Editors
{
	/// <summary>
	/// Custom commands for AvalonEdit.
	/// </summary>
	public static class AvalonEditCommands
	{
		/// <summary>
		/// Deletes the current line.
		/// The default shortcut is Ctrl+D.
		/// </summary>
		public static readonly RoutedCommand DeleteLine = new RoutedCommand(
			"DeleteLine", typeof(TextEditor),
			new InputGestureCollection {
				new KeyGesture(Key.D, ModifierKeys.Control)
			});
		
		/// <summary>
		/// Removes leading whitespace from the selected lines (or the whole document if the selection is empty).
		/// </summary>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "Whitespace",
		                                                 Justification = "WPF uses 'Whitespace'")]
		public static readonly RoutedCommand RemoveLeadingWhitespace = new RoutedCommand("RemoveLeadingWhitespace", typeof(TextEditor));
				
		/// <summary>
		/// Removes trailing whitespace from the selected lines (or the whole document if the selection is empty).
		/// </summary>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "Whitespace",
		                                                 Justification = "WPF uses 'Whitespace'")]
		public static readonly RoutedCommand RemoveTrailingWhitespace = new RoutedCommand("RemoveTrailingWhitespace", typeof(TextEditor));
		
		/// <summary>
		/// Converts the selected text to upper case.
		/// </summary>
		public static readonly RoutedCommand ConvertToUppercase = new RoutedCommand("ConvertToUppercase", typeof(TextEditor));
		
		/// <summary>
		/// Converts the selected text to lower case.
		/// </summary>
		public static readonly RoutedCommand ConvertToLowercase = new RoutedCommand("ConvertToLowercase", typeof(TextEditor));
		
		/// <summary>
		/// Converts the selected text to title case.
		/// </summary>
		public static readonly RoutedCommand ConvertToTitleCase = new RoutedCommand("ConvertToTitleCase", typeof(TextEditor));
		
		/// <summary>
		/// Inverts the case of the selected text.
		/// </summary>
		public static readonly RoutedCommand InvertCase = new RoutedCommand("InvertCase", typeof(TextEditor));
		
		/// <summary>
		/// Converts tabs to spaces in the selected text.
		/// </summary>
		public static readonly RoutedCommand ConvertTabsToSpaces = new RoutedCommand("ConvertTabsToSpaces", typeof(TextEditor));
		
		/// <summary>
		/// Converts spaces to tabs in the selected text.
		/// </summary>
		public static readonly RoutedCommand ConvertSpacesToTabs = new RoutedCommand("ConvertSpacesToTabs", typeof(TextEditor));
		
		/// <summary>
		/// Converts leading tabs to spaces in the selected lines (or the whole document if the selection is empty).
		/// </summary>
		public static readonly RoutedCommand ConvertLeadingTabsToSpaces = new RoutedCommand("ConvertLeadingTabsToSpaces", typeof(TextEditor));
		
		/// <summary>
		/// Converts leading spaces to tabs in the selected lines (or the whole document if the selection is empty).
		/// </summary>
		public static readonly RoutedCommand ConvertLeadingSpacesToTabs = new RoutedCommand("ConvertLeadingSpacesToTabs", typeof(TextEditor));
		
		/// <summary>
		/// Runs the IIndentationStrategy on the selected lines (or the whole document if the selection is empty).
		/// </summary>
		public static readonly RoutedCommand IndentSelection = new RoutedCommand(
			"IndentSelection", typeof(TextEditor),
			new InputGestureCollection {
				new KeyGesture(Key.I, ModifierKeys.Control)
			});
	}
}
>userName, personalToken) { _tempFolder = TemporaryManager.CreateFolder(); ResolvedWorkItems = new ObservableCollection<WorkItem>(); TangoIOC.Default.GetInstance<IAuthenticationProvider>().CurrentUserChanged += TeamFoundationServiceExtendedClient_CurrentUserChanged; } private void TeamFoundationServiceExtendedClient_CurrentUserChanged(object sender, User user) { if (user != null) { user_email = user.Email; Task.Factory.StartNew(async () => { Thread.Sleep(5000); await UpdateCurrentUserResolvedWorkItems(); }); } } public Task<WorkItem> UploadWorkItem(WorkItem workItem) { return UploadWorkItem(Project, workItem); } public async Task UpdateCurrentUserResolvedWorkItems() { try { if (Project != null) { IStudioApplicationManager app = TangoIOC.Default.GetInstance<IStudioApplicationManager>(); var member = GetUserTeamMember(); if (member != null) { var items = await GetWorkItemsCreatedBy(Project, member); items.Where(x => x.StepsToReproduce != null).ToList().ForEach(x => x.StepsToReproduce = x.StepsToReproduce.Replace("<div style=\"white-space:pre;\">", "").Replace("</div>", "")); ResolvedWorkItems = items.Where(x => x.State == State.Resolved && x.ResolvedReason == ResolvedReason.Fixed && x.IsBuildVersionValid && x.FoundInBuildVersion < app.Version).ToObservableCollection(); } else { LogManager.Default.Log($"User '{user_email}' is not part of the VSTS team.", LogCategory.Warning); } } } catch (Exception ex) { LogManager.Log(ex, "Error getting the current user resolved work items."); } } public async Task<WorkItem> CloseWorkItem(WorkItem workItem) { await SetWorkItemState(Project, workItem, State.Closed); var updated = await AddWorkItemComment(Project, workItem, GetUserTeamMember(), "Bug has been verified and closed by " + GetUserTeamMember().DisplayName + " (via Machine Studio)."); ResolvedWorkItems.Remove(workItem); return updated; } public async Task<WorkItem> ReactivateWorkItem(WorkItem workItem) { await SetWorkItemState(Project, workItem, State.New); var updated = await AddWorkItemComment(Project, workItem, GetUserTeamMember(), "Bug has been reactivated by " + GetUserTeamMember().DisplayName + " (via Machine Studio)."); updated = await SetWorkItemAssignment(Project, updated, workItem.ResolvedBy); ResolvedWorkItems.Remove(workItem); return updated; } public void Initialize() { Task.Factory.StartNew(() => { if (!IsInitialized) { try { Project = GetProject("Tango").Result; IsInitialized = true; } catch (Exception ex) { LogManager.Log(ex, "Error initializing the Team Foundation Service client."); } } }); } public WorkItem CreateBug() { WorkItem item = new WorkItem(); IAuthenticationProvider auth = TangoIOC.Default.GetInstance<IAuthenticationProvider>(); IStudioApplicationManager app = TangoIOC.Default.GetInstance<IStudioApplicationManager>(); item.Area = Project.Areas.FirstOrDefault(); item.Iteration = Project.Iterations.FirstOrDefault(); TeamMember currentUser = GetUserTeamMember(); if (currentUser == null) { throw LogManager.Default.Log(new AuthenticationException($"User '{user_email}' is not part of the Tango VSTS team. Please contact your administrator.")); } item.CreatedBy = currentUser; item.ChangedBy = currentUser; item.AuthorizedAs = currentUser; item.FoundInBuild = app.Version.ToString(); item.Priority = Priority.Priority3; item.Severity = Severity.Medium; item.State = State.New; item.Type = WorkItemType.Bug; foreach (var window in Application.Current.Windows.OfType<Window>().Where(x => !String.IsNullOrWhiteSpace(x.Title))) { var bitmap = UIHelper.TakeSnapshot(window); if (!_tempFolder.Exists()) { _tempFolder = TemporaryManager.CreateFolder(); } var tempFile = _tempFolder.CreateFile(); bitmap.SaveJpeg(tempFile.Path, 30); String title = window.Title; item.Attachments.Add(new Attachment() { Description = title + " Screen Capture", FilePath = tempFile.Path, Name = $"{title}.jpg", }); } return item; } private string[] GetLogFiles(FileLogger logger) { string[] fileEntries = new string[1]; fileEntries[0] = logger.LogFile; string fileName = Path.GetFileNameWithoutExtension(logger.LogFile); int indexPos = fileName.IndexOf(FileLogger.FILE_SET_EXTENSION); if (indexPos > 0) { string extension = Path.GetExtension(logger.LogFile); fileName = fileName.Substring(0, indexPos); fileEntries = Directory.GetFiles(logger.Folder, $"{fileName}*{extension}").Where(x => Path.GetFileName(x).StartsWith(logger.Tag)).OrderBy(x => x.Length).ThenBy(x => x).ToArray(); } return fileEntries; } public void FinalizeBug(WorkItem item) { IAuthenticationProvider auth = TangoIOC.Default.GetInstance<IAuthenticationProvider>(); IStudioApplicationManager app = TangoIOC.Default.GetInstance<IStudioApplicationManager>(); FileLogger appFileLogger = LogManager.Default.RegisteredLoggers.FirstOrDefault(x => x.GetType() == typeof(FileLogger)) as FileLogger; FileLogger embeddedFileLogger = MachineOperator.EmbeddedLogManager.RegisteredLoggers.FirstOrDefault(x => x.GetType() == typeof(FileLogger)) as FileLogger; if (appFileLogger != null) { string[] logFiles = GetLogFiles(appFileLogger); foreach( string file in logFiles) { var appLogFile = _tempFolder.CreateImaginaryFile(); File.Copy(file, appLogFile.Path); item.Attachments.Add(new Attachment() { Description = "Application Log File", FilePath = appLogFile.Path, Name = Path.GetFileName(file), }); } } if (embeddedFileLogger != null && File.Exists(embeddedFileLogger.LogFile)) { string[] logFiles = GetLogFiles(embeddedFileLogger); foreach (string file in logFiles) { var embeddedLogFile = _tempFolder.CreateImaginaryFile(); File.Copy(file, embeddedLogFile.Path); item.Attachments.Add(new Attachment() { Description = "Embedded Log File", FilePath = embeddedLogFile.Path, Name = Path.GetFileName(file), }); } } //Add session log file.. if (MachineOperator.EnableSessionLogFile) { var file = MachineOperator.SessionLogger.LogFile; var sessionLogFile = _tempFolder.CreateImaginaryFile(); File.Copy(file, sessionLogFile.Path); item.Attachments.Add(new Attachment() { Description = "Session Log File", FilePath = sessionLogFile.Path, Name = Path.GetFileName(file), }); } SystemInformationModel sysModel = new SystemInformationModel(); sysModel.ApplicationVersion = app.Version.ToString(); sysModel.EmbeddedVersion = "N/A"; sysModel.HostName = Environment.MachineName; sysModel.UserName = auth.CurrentUser.Contact.FullName; if (app.ConnectedMachine != null) { Machine machine = app.Machine; sysModel.Machine = machine; sysModel.EmbeddedVersion = app.ConnectedMachine.DeviceInformation.Version; sysModel.ConfigurationString = machine.Configuration.Clone().ToJsonString(); if (app.ConnectedMachine.CurrentProcessParameters != null) { sysModel.LoadedProcessParametersString = app.ConnectedMachine.CurrentProcessParameters.ToJsonString(nameof(ProcessParametersTable.ProcessParametersTablesGroup)); } if (app.ConnectedMachine.CurrentHardwareConfiguration != null) { sysModel.LoadedHardwareConfigurationString = app.ConnectedMachine.CurrentHardwareConfiguration.ToJsonString(); } } if (app.Machine != null && app.ConnectedMachine != null && app.ConnectedMachine.DeviceInformation != null) { item.EmbeddedVersion = app.ConnectedMachine.DeviceInformation.Version; item.MachineSerialNumber = app.Machine.SerialNumber; } String html = String.Empty; using (var stream = EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.UI.TFS.SystemInformationTemplate.cshtml")) { StreamReader reader = new StreamReader(stream); html = reader.ReadToEnd(); } item.SystemInformation = CodeGeneration.Helper.Parse(html, sysModel); item.StepsToReproduce = String.Format("<div style=\"white-space:pre\">{0}</div>", item.StepsToReproduce); } private TeamMember GetUserTeamMember() { IAuthenticationProvider auth = TangoIOC.Default.GetInstance<IAuthenticationProvider>(); TeamMember currentUser = Project.Members.SingleOrDefault(x => x.UniqueName.ToLower().Contains(auth.CurrentUser.Email.ToLower())); return currentUser; } } }