Skip to content

Commit

Permalink
added basic automatic update
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Grabarevic committed Feb 27, 2017
1 parent 176517c commit 7dbddb1
Show file tree
Hide file tree
Showing 25 changed files with 736 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.ComponentModel.Composition;
using System.IO;

using Windows.UI.Notifications;

using BuildsAppReborn.Contracts.Models;
using BuildsAppReborn.Contracts.UI.Notifications;

Expand Down Expand Up @@ -41,6 +39,26 @@ public void ShowBuild(IBuild build, Func<IBuild, String> iconProvider)
ToastNotificationManager.CreateToastNotifier(AppId).Show(toast);
}

public void ShowMessage(String title, String message)
{
// Get a toast XML template
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

// Fill in the text elements
var stringElements = toastXml.GetElementsByTagName("text");

stringElements[0].AppendChild(toastXml.CreateTextNode(title));
stringElements[1].AppendChild(toastXml.CreateTextNode(message));
//stringElements[2].AppendChild(toastXml.CreateTextNode();

// Create the toast and attach event listeners
var toast = new ToastNotification(toastXml);
toast.Dismissed += ToastDismissed;

// Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(AppId).Show(toast);
}

#endregion

#region Private Methods
Expand Down
22 changes: 21 additions & 1 deletion BuildsAppReborn.Client/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="BuildsAppReborn.Client.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DeltaCompressionDotNet.MsDelta" publicKeyToken="46b2138a390abf55" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<applicationSettings>
<BuildsAppReborn.Client.Properties.Settings>
<setting name="UpdateCheckUrl" serializeAs="String">
<value>https://github.com/lgrabarevic/BuildsAppReborn</value>
</setting>
</BuildsAppReborn.Client.Properties.Settings>
</applicationSettings>
</configuration>
27 changes: 20 additions & 7 deletions BuildsAppReborn.Client/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
using System.IO;
using System.Linq;
using System.Windows;

using BuildsAppReborn.Client.Properties;
using BuildsAppReborn.Client.ViewModels;
using BuildsAppReborn.Contracts;

using Hardcodet.Wpf.TaskbarNotification;

namespace BuildsAppReborn.Client
Expand All @@ -19,8 +22,10 @@ public partial class App

protected override void OnExit(ExitEventArgs e)
{
if (e.ApplicationExitCode == 0) this.globalSettingsContainer.Save();

this.updateChecker.Stop();
this.buildMonitor.Stop();
this.globalSettingsContainer.Save();
this.notifyIcon.Dispose();
base.OnExit(e);
}
Expand All @@ -32,12 +37,16 @@ protected override void OnStartup(StartupEventArgs e)
EnsureOnlyOneInstance();

var compositionContainer = BuildCompositionContainer();

this.updateChecker = compositionContainer.GetExportedValue<UpdateChecker>();
this.updateChecker.Start();
this.updateChecker.UpdateCheck();
this.globalSettingsContainer = compositionContainer.GetExportedValue<GlobalSettingsContainer>();

this.buildMonitor = compositionContainer.GetExportedValue<IBuildMonitorAdvanced>();
this.buildMonitor.Start(this.globalSettingsContainer.BuildMonitorSettingsContainer, TimeSpan.FromMinutes(1));

this.notifyIcon = (TaskbarIcon) FindResource("NotifyIcon");
this.notifyIcon = (TaskbarIcon)FindResource("NotifyIcon");
if (this.notifyIcon != null)
{
this.notifyIcon.DataContext = compositionContainer.GetExportedValue<NotifyIconViewModel>();
Expand All @@ -55,8 +64,7 @@ private static CompositionContainer BuildCompositionContainer()
var directoryName = Path.GetDirectoryName(typeof(App).Assembly.Location);
if (directoryName != null)
{
var assemblies = Directory.GetFiles(directoryName, "*.dll").Union(Directory.GetFiles(directoryName, "*.exe"))
.Where(a => !String.Equals(Path.GetFileName(a), "NuGet.Squirrel.dll", StringComparison.InvariantCultureIgnoreCase));
var assemblies = Directory.GetFiles(directoryName, "*.dll").Union(Directory.GetFiles(directoryName, "*.exe")).Where(a => !String.Equals(Path.GetFileName(a), "NuGet.Squirrel.dll", StringComparison.InvariantCultureIgnoreCase) && !String.Equals(Path.GetFileName(a), "Update.exe", StringComparison.InvariantCultureIgnoreCase));

foreach (var assembly in assemblies)
{
Expand All @@ -74,14 +82,17 @@ private static CompositionContainer BuildCompositionContainer()
return new CompositionContainer(catalog, true);
}

private static void EnsureOnlyOneInstance()
#endregion

#region Private Methods

private void EnsureOnlyOneInstance()
{
var currentProcess = Process.GetCurrentProcess();
var count = Process.GetProcesses().Count(p => p.ProcessName == currentProcess.ProcessName);
if (count > 1)
{
// MessageBox.Show("An instance is already running ...");
Current.Shutdown();
Current.Shutdown(-1);
}
}

Expand All @@ -95,6 +106,8 @@ private static void EnsureOnlyOneInstance()

private TaskbarIcon notifyIcon;

private UpdateChecker updateChecker;

#endregion
}
}
48 changes: 35 additions & 13 deletions BuildsAppReborn.Client/BuildsAppReborn.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="DeltaCompressionDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1d14d6e5194e7f4a, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.dll</HintPath>
<Reference Include="DeltaCompressionDotNet, Version=1.1.0.0, Culture=neutral, PublicKeyToken=1d14d6e5194e7f4a, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="DeltaCompressionDotNet.MsDelta, Version=1.0.0.0, Culture=neutral, PublicKeyToken=46b2138a390abf55, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.MsDelta.dll</HintPath>
<Reference Include="DeltaCompressionDotNet.MsDelta, Version=1.1.0.0, Culture=neutral, PublicKeyToken=46b2138a390abf55, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.MsDelta.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="DeltaCompressionDotNet.PatchApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3e8888ee913ed789, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.PatchApi.dll</HintPath>
<Reference Include="DeltaCompressionDotNet.PatchApi, Version=1.1.0.0, Culture=neutral, PublicKeyToken=3e8888ee913ed789, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.PatchApi.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dragablz, Version=0.0.3.186, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -76,19 +76,19 @@
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Squirrel, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand All @@ -99,8 +99,8 @@
<HintPath>..\packages\Prism.Core.6.2.0\lib\net45\Prism.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.1.6.2\lib\Net45\Splat.dll</HintPath>
<Reference Include="Splat, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.2.0.0\lib\Net45\Splat.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Squirrel, Version=1.5.2.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -134,6 +134,9 @@
<Compile Include="Converter\BuildStatusToImageConverter.cs" />
<Compile Include="Converter\BuildStatusToSolidColorBrushForegroundConverter.cs" />
<Compile Include="Converter\BuildStatusToSolidColorBrushBackgroundConverter.cs" />
<Compile Include="Converter\MinutesToTimeSpanConverter.cs" />
<Compile Include="Interfaces\IHasDataContext.cs" />
<Compile Include="Interfaces\ISubSettingsControl.cs" />
<Compile Include="Properties\GlobalAssemblyInfo.cs" />
<Compile Include="Converter\BuildTimeToElapsedTimeConverter.cs" />
<Compile Include="Converter\FallBackNulltoLoadingConverter.cs" />
Expand All @@ -144,6 +147,9 @@
<Compile Include="SampleData\SampleBuildDefinition.cs" />
<Compile Include="SampleData\SampleDataGenerator.cs" />
<Compile Include="SampleData\SampleProject.cs" />
<Compile Include="UpdateChecker.cs" />
<Compile Include="ViewModels\GeneralSettingsViewModel.cs" />
<Compile Include="ViewModels\SettingsViewModel.cs" />
<Compile Include="Views\BuildsStatusView.xaml.cs">
<DependentUpon>BuildsStatusView.xaml</DependentUpon>
</Compile>
Expand All @@ -157,6 +163,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\GeneralSettingsControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ServerSettingsControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\SettingsView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -165,6 +179,12 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Views\GeneralSettingsControl.xaml.cs">
<DependentUpon>GeneralSettingsControl.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ServerSettingsControl.xaml.cs">
<DependentUpon>ServerSettingsControl.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SettingsView.xaml.cs">
<DependentUpon>SettingsView.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down Expand Up @@ -200,7 +220,9 @@
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BuildsAppReborn.Contracts.UI\BuildsAppReborn.Contracts.UI.csproj">
Expand Down
36 changes: 36 additions & 0 deletions BuildsAppReborn.Client/Converter/MinutesToTimeSpanConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace BuildsAppReborn.Client.Converter
{
internal class MinutesToTimeSpanConverter : IValueConverter
{
#region Implementation of IValueConverter

public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
{
if (value is TimeSpan)
{
var ts = (TimeSpan) value;
return ts.TotalMinutes;
}

return Binding.DoNothing;
}

public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture)
{
// ToDo: proper string parsing
if (value is Int32)
{
var minutes = (Int32) value;
return TimeSpan.FromMinutes(minutes);
}

return Binding.DoNothing;
}

#endregion
}
}
29 changes: 24 additions & 5 deletions BuildsAppReborn.Client/GlobalSettingsContainer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.ComponentModel.Composition;
using System.IO;

using System.Linq;
using BuildsAppReborn.Contracts.Models;
using BuildsAppReborn.Infrastructure;

Expand All @@ -15,8 +15,16 @@ internal class GlobalSettingsContainer

public GlobalSettingsContainer()
{
this.settingsFilePath = Path.Combine(Consts.ApplicationUserProfileFolder, "settings.json");
BuildMonitorSettingsContainer = SettingsContainer<BuildMonitorSettings>.Load(this.settingsFilePath);
this.buildMonitorSettingsFilePath = Path.Combine(Consts.ApplicationUserProfileFolder, "buildMonitorSettings.json");
this.generalSettingsFilePath = Path.Combine(Consts.ApplicationUserProfileFolder, "generalSettings.json");

BuildMonitorSettingsContainer = SettingsContainer<BuildMonitorSettings>.Load(this.buildMonitorSettingsFilePath);
this.generalSettingsContainer = SettingsContainer<GeneralSettings>.Load(this.generalSettingsFilePath);

if (!this.generalSettingsContainer.Any())
{
this.generalSettingsContainer.Add(new GeneralSettings());
}
}

#endregion
Expand All @@ -25,20 +33,31 @@ public GlobalSettingsContainer()

public SettingsContainer<BuildMonitorSettings> BuildMonitorSettingsContainer { get; }

/// <summary>
/// Gets the general settings.
/// </summary>
/// <value>
/// The general settings.
/// </value>
public GeneralSettings GeneralSettings => this.generalSettingsContainer.Single();

#endregion

#region Public Methods

public void Save()
{
BuildMonitorSettingsContainer.Save(this.settingsFilePath);
BuildMonitorSettingsContainer.Save(this.buildMonitorSettingsFilePath);
this.generalSettingsContainer.Save(this.generalSettingsFilePath);
}

#endregion

#region Private Fields

private String settingsFilePath;
private String buildMonitorSettingsFilePath;
private SettingsContainer<GeneralSettings> generalSettingsContainer;
private String generalSettingsFilePath;

#endregion
}
Expand Down
13 changes: 13 additions & 0 deletions BuildsAppReborn.Client/Interfaces/IHasDataContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace BuildsAppReborn.Client.Interfaces
{
public interface IHasDataContext
{
#region Public Properties

Object DataContext { get; set; }

#endregion
}
}
2 changes: 1 addition & 1 deletion BuildsAppReborn.Client/Interfaces/ISettingsView.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BuildsAppReborn.Client.Interfaces
{
public interface ISettingsView
public interface ISettingsView : IHasDataContext
{
}
}
Loading

0 comments on commit 7dbddb1

Please sign in to comment.