diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-04-24 19:05:53 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-04-24 19:05:53 +0300 |
| commit | 97e45f70267d961168b77b149022b94022e0e199 (patch) | |
| tree | 89bf6c1c893ab099ef99690d155a0855ba8a9d92 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs | |
| parent | 8046598cb1439b66a8d6e556a61b715fc859a6b0 (diff) | |
| download | Tango-97e45f70267d961168b77b149022b94022e0e199.tar.gz Tango-97e45f70267d961168b77b149022b94022e0e199.zip | |
Working on reporting...
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs new file mode 100644 index 000000000..27b257e61 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using Tango.BL.Entities; +using Tango.Core.DI; +using Tango.Core.Helpers; +using Tango.Integration.Operation; +using Tango.Logging; +using Tango.MachineStudio.Common.Authentication; +using Tango.MachineStudio.Common.StudioApplication; +using Tango.SharedUI.Helpers; +using Tango.TFS; + +namespace Tango.MachineStudio.UI.TFS +{ + public class TeamFoundationServiceExtendedClient : TeamFoundationServiceClient + { + public Project Project { get; private set; } + + private bool _isInitialized; + public bool IsInitialized + { + get { return _isInitialized; } + private set { _isInitialized = value; RaisePropertyChangedAuto(); } + } + + public TeamFoundationServiceExtendedClient(string collectionURL, string userName, string personalToken) : base(collectionURL, userName, personalToken) + { + + } + + public Task<WorkItem> UploadWorkItem(WorkItem workItem) + { + return UploadWorkItem(Project, workItem); + } + + public void Initialize() + { + Task.Factory.StartNew(() => + { + if (!IsInitialized) + { + Project = GetProject("Tango").Result; + IsInitialized = true; + } + }); + } + + 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 = Project.Members.SingleOrDefault(x => x.UniqueName.ToLower().Contains(auth.CurrentUser.Email.ToLower())); + item.CreatedBy = currentUser; + item.ChangedBy = currentUser; + item.AuthorizedAs = currentUser; + + item.FoundInBuild = app.Version; + item.Priority = Priority.Priority3; + item.Severity = Severity.Medium; + item.State = State.New; + item.Type = WorkItemType.Bug; + + var bitmap = UIHelper.TakeSnapshot(MainWindow.Instance); + String filePath = PathHelper.GetTempFilePath(); + bitmap.SaveJpeg(filePath, 30); + + item.Attachments.Add(new Attachment() + { + Description = "Screen Capture", + FilePath = filePath, + Name = "Screen Capture.jpg", + }); + + 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 appLogFile = PathHelper.GetTempFilePath(); + File.Copy(appFileLogger.LogFile, appLogFile); + + item.Attachments.Add(new Attachment() + { + Description = "Application Log File", + FilePath = appLogFile, + Name = Path.GetFileName(appFileLogger.LogFile), + }); + } + + if (embeddedFileLogger != null && File.Exists(embeddedFileLogger.LogFile)) + { + String embeddedLogFile = PathHelper.GetTempFilePath(); + File.Copy(appFileLogger.LogFile, embeddedLogFile); + + item.Attachments.Add(new Attachment() + { + Description = "Embedded Log File", + FilePath = embeddedLogFile, + Name = Path.GetFileName(embeddedFileLogger.LogFile), + }); + } + + SystemInformationModel sysModel = new SystemInformationModel(); + sysModel.ApplicationVersion = app.Version; + sysModel.EmbeddedVersion = "Fake Version"; + sysModel.HostName = Environment.MachineName; + sysModel.UserName = auth.CurrentUser.Contact.FullName; + + if (app.ConnectedMachine != null) + { + Machine machine = app.ConnectedMachine.Machine; + + sysModel.Machine = machine; + + MachineDesigner.Views.MainView machineView = new MachineDesigner.Views.MainView(); + machineView.Width = 1280; + machineView.Height = 1100; + machineView.PanelColumnDefinition.Width = new System.Windows.GridLength(0); + machineView.stackHeader.Visibility = Visibility.Collapsed; + machineView.Background = System.Windows.Media.Brushes.White; + machineView.DataContext = new MachineDesigner.ViewModels.MainViewVM() { SelectedMachine = machine, Configuration = machine.Configuration }; + + String configImageFile = PathHelper.GetTempFilePath(); + machineView.RenderToFile(configImageFile, System.Drawing.Imaging.ImageFormat.Jpeg, new System.Windows.Size(machineView.Width, machineView.Height), 100); + + item.Attachments.Add(new Attachment() + { + Description = "Machine Configuration", + FilePath = configImageFile, + Name = "Machine Configuration.jpg" + }); + + sysModel.ConfigurationString = machine.Configuration.CloneConfiguration().ToJsonString(); + } + + 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); + + return item; + } + } +} |
