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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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;
}
}
}
|