Skip to content

Commit

Permalink
Fixed setting dialogs and furthe rthings
Browse files Browse the repository at this point in the history
Added basic diagnosticsclient
  • Loading branch information
StefanKert committed Mar 30, 2019
1 parent 28b7bd3 commit 01d54f8
Show file tree
Hide file tree
Showing 42 changed files with 885 additions and 963 deletions.
2 changes: 1 addition & 1 deletion src/BuildVision.Common/AppVersionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Reflection;

Expand Down
4 changes: 4 additions & 0 deletions src/BuildVision.Common/BuildVision.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<None Include="Key.snk" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AppInsights.WindowsDesktop" Version="2.10.17-preview" />
</ItemGroup>

<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="WindowsBase" />
Expand Down
65 changes: 65 additions & 0 deletions src/BuildVision.Common/Diagnostics/DiagnosticsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;

namespace BuildVision.Common.Diagnostics
{
public static class DiagnosticsClient
{
private static bool _initialized;
private static TelemetryClient _client;


public static void Initialize(string apiKey)
{
if (!string.IsNullOrWhiteSpace(apiKey))
{
TelemetryConfiguration.Active.InstrumentationKey = apiKey;
TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = Debugger.IsAttached;
TelemetryConfiguration.Active.TelemetryInitializers.Add(new VersionTelemetry());
TelemetryConfiguration.Active.TelemetryInitializers.Add(new SessionTelemetry());

_initialized = true;

_client = new TelemetryClient();
}
}

public static void OnExit()
{
if (!_initialized) return;

_client.Flush();
// Allow time for flushing:
System.Threading.Thread.Sleep(1000);
}

public static void TrackEvent(string eventName, IDictionary<string, string> properties = null, IDictionary<string, double> metrics = null)
{
if (!_initialized) return;
_client.TrackEvent(eventName, properties, metrics);
}

public static void TrackTrace(string evt)
{
if (!_initialized) return;
_client.TrackTrace(evt);
}

public static void Notify(Exception exception)
{
if (!_initialized) return;

_client.TrackException(exception);
}

public static void TrackPageView(string pageName)
{
if (!_initialized) return;

_client.TrackPageView(pageName);
}
}
}
62 changes: 62 additions & 0 deletions src/BuildVision.Common/Diagnostics/SessionTelemetry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;

namespace BuildVision.Common.Diagnostics
{
class SessionTelemetry : ITelemetryInitializer
{
private readonly string _userName;
private readonly string _operatingSystem = RuntimeInformation.OSDescription?.Replace("Microsoft ", ""); // Shorter description
private readonly string _session = Guid.NewGuid().ToString();

#if STORE
private const string Channel = "store";
#elif NIGHTLY
private const string Channel = "nightly";
#elif CHOCO
private const string Channel = "chocolatey";
#else
private const string Channel = "zip";
#endif


public SessionTelemetry()
{
try
{
using (var hash = SHA256.Create())
{
var hashBytes = hash.ComputeHash(Encoding.UTF8.GetBytes(Environment.MachineName + Environment.UserDomainName + Environment.UserName));
_userName = Convert.ToBase64String(hashBytes);
}
}
catch
{
// No user id
}
}

public void Initialize(ITelemetry telemetry)
{
telemetry.Context.GlobalProperties["Environment"] = Channel;
// Always default to development if we're in the debugger
if (Debugger.IsAttached)
{
telemetry.Context.GlobalProperties["Environment"] = "development";
}

if (_userName != null)
{
telemetry.Context.User.Id = _userName;
}

telemetry.Context.Session.Id = _session;
telemetry.Context.Device.OperatingSystem = _operatingSystem;
}
}
}
25 changes: 25 additions & 0 deletions src/BuildVision.Common/Diagnostics/VersionTelemetry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Linq;
using System.Reflection;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;

namespace BuildVision.Common.Diagnostics
{
class VersionTelemetry : ITelemetryInitializer
{
private readonly string _appVersion;

public VersionTelemetry()
{
_appVersion = typeof(DiagnosticsClient).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
.FirstOrDefault(ama => string.Equals(ama.Key, "CloudBuildNumber", StringComparison.OrdinalIgnoreCase))
?.Value;
}

public void Initialize(ITelemetry telemetry)
{
telemetry.Context.Component.Version = _appVersion;
}
}
}
15 changes: 0 additions & 15 deletions src/BuildVision.Contracts/Models/IBuildProgressViewModel.cs

This file was deleted.

11 changes: 9 additions & 2 deletions src/BuildVision.Exports/Providers/IBuildInformationProvider.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using BuildVision.Contracts;
using BuildVision.Contracts.Models;
using BuildVision.UI.Models;

namespace BuildVision.Exports.Providers
{
public interface IBuildInformationProvider
{
void BuildFinished(IEnumerable<IProjectItem> projects, bool success, bool canceled);
void BuildStarted(uint dwAction);
ObservableCollection<IProjectItem> GetBuildingProjects();
void ProjectBuildStarted(IProjectItem projectItem, BuildActions buildAction);
void ProjectBuildFinished(BuildActions buildAction, string projectIdentifier, bool succeess, bool canceled);
void ReloadCurrentProjects();
void ResetCurrentProjects();
void BuildFinished(bool success, bool canceled);
void BuildStarted(BuildActions buildAction);
void BuildUpdate();
void ResetBuildInformationModel();
IBuildInformationModel GetBuildInformationModel();
Expand Down
16 changes: 0 additions & 16 deletions src/BuildVision.Exports/Providers/IBuildingProjectsProvider.cs

This file was deleted.

10 changes: 5 additions & 5 deletions src/BuildVision.Exports/Sevices/IBuildService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace BuildVision.Exports.Services
using BuildVision.UI.Models;

namespace BuildVision.Exports.Services
{
public interface IBuildService
{
void ShowGridColumnsSettingsPage();
void ShowGeneralSettingsPage();
void BuildSolution();
void CleanSolution();
void RebuildSolution();
void CancelBuildSolution();
void ProjectCopyBuildOutputFilesToClipBoard();
void RaiseCommandForSelectedProject();
void ProjectCopyBuildOutputFilesToClipBoard(IProjectItem projItem);
void RaiseCommandForSelectedProject(IProjectItem projectItem, int command);
}
}
10 changes: 10 additions & 0 deletions src/BuildVision.Exports/Sevices/ITaskBarInfoService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using BuildVision.Contracts;

namespace BuildVision.Exports.Services
{
public interface ITaskBarInfoService
{
void ResetTaskBarInfo(bool ifTaskBarProgressEnabled = true);
void UpdateTaskBarInfo(BuildState buildState, BuildScopes buildScope, int projectsCount, int finishedProjects);
}
}
11 changes: 9 additions & 2 deletions src/BuildVision.UI/BuildVision.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@
<Compile Include="Controls\Indicators\WarningProjectsIndicator.cs" />
<Compile Include="Controls\Indicators\WarningsIndicator.cs" />
<Compile Include="Converters\BooleanToHiddenConverter.cs" />
<Compile Include="Converters\InProgressToBoolConverter.cs" />
<Compile Include="Converters\InProgressToCollapsedConverter.cs" />
<Compile Include="Converters\InProgressToVisibleConverter.cs" />
<Compile Include="Converters\StateIconKeyToIconConverter.cs" />
<Compile Include="Enums\ResetTaskBarItemInfoCondition.cs" />
<Compile Include="Helpers\SortDescription.cs" />
<Compile Include="Models\SortDescription.cs" />
<Compile Include="Enums\SortOrder.cs" />
<Compile Include="Enums\WindowState.cs" />
<Compile Include="Helpers\WindowStateAction.cs" />
<Compile Include="Models\WindowStateAction.cs" />
<Compile Include="IPackageSettingsProvider.cs" />
<Compile Include="Settings\Models\BaseGridColumnSettings.cs" />
<Compile Include="Settings\Models\BuildMessagesSettings.cs" />
Expand Down Expand Up @@ -372,9 +373,15 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="AppInsights.WindowsDesktop">
<Version>2.10.17-preview</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.14.0">
<Version>14.3.25407</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Commands\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
18 changes: 4 additions & 14 deletions src/BuildVision.UI/Components/ControlView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<converters:InProgressToCollapsedConverter x:Key="InProgressToCollapsedConverter" />
<converters:InProgressToVisibleConverter x:Key="InProgressToVisibleConverter" />

<converters:InProgressToBoolConverter x:Key="InProgressToBoolConverter" />

</ResourceDictionary>
</UserControl.Resources>
Expand Down Expand Up @@ -115,26 +115,16 @@
HorizontalAlignment="Stretch"
MinWidth="66"
ToolTip="{x:Static res:Resources.CancelBuildSolutionButtonTooltip}"
IsEnabled="False"
IsEnabled="{Binding BuildInformationModel.CurrentBuildState, Converter={StaticResource InProgressToBoolConverter}}"
Visibility="{Binding BuildInformationModel.CurrentBuildState, Converter={StaticResource InProgressToVisibleConverter}}">

<customButtons:BuildActionButton.Content>
<StackPanel Orientation="Horizontal">
<ContentControl Template="{StaticResource CancelBuildSolutionIcon}" />
<TextBlock Margin="2,0,0,0" Text="{x:Static res:Resources.CancelBuildSolutionButtonCaption}" />
</StackPanel>
</customButtons:BuildActionButton.Content>

<customButtons:BuildActionButton.Style>
<Style TargetType="{x:Type customButtons:BuildActionButton}">
<Style.Triggers>
<DataTrigger Binding="{Binding BuildInformationModel.CurrentBuildState}" Value="{x:Static contracts:BuildState.InProgress}">
<Setter Property="customButtons:BuildActionButton.Visibility" Value="Visible" />
<Setter Property="customButtons:BuildActionButton.IsEnabled" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</customButtons:BuildActionButton.Style>

</customButtons:BuildActionButton>

</WrapPanel>
Expand Down
22 changes: 22 additions & 0 deletions src/BuildVision.UI/Converters/InProgressToBoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Globalization;
using System.Windows.Data;
using BuildVision.Contracts;

namespace BuildVision.UI.Converters
{
[ValueConversion(typeof(BuildState), typeof(bool))]
public class InProgressToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var buildState = (BuildState)value;
return buildState == BuildState.InProgress;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
8 changes: 5 additions & 3 deletions src/BuildVision.UI/DataGrid/DataGridContentControlColumn.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
Expand All @@ -9,9 +9,11 @@ public class DataGridContentControlColumn : DataGridBoundColumn
{
protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
{
ContentControl contentControl = (cell != null) ? (cell.Content as ContentControl) : null;
var contentControl = (cell != null) ? (cell.Content as ContentControl) : null;
if (contentControl == null)
{
contentControl = new ContentControl();
}

contentControl.ClipToBounds = true;
contentControl.SnapsToDevicePixels = true;
Expand All @@ -26,4 +28,4 @@ protected override FrameworkElement GenerateEditingElement(DataGridCell cell, ob
throw new InvalidOperationException();
}
}
}
}
Loading

0 comments on commit 01d54f8

Please sign in to comment.