Permalink
Browse files

Added update available notifications

Closes #10
  • Loading branch information...
1 parent 2fae6d0 commit 66818116808d6429f23762120a1f41400f9ca286 @citizenmatt citizenmatt committed Jan 18, 2013
@@ -0,0 +1,19 @@
+using System;
+using System.Xml.Serialization;
+using JetBrains.UI.Updates;
+using JetBrains.VSIntegration.Updates;
+
+namespace JetBrains.ReSharper.Plugins.NuGet.Updates
+{
+ [XmlType]
+ [XmlRoot("PluginLocalInfo")]
+ [Serializable]
+ public class PluginLocalEnvironmentInfo
+ {
+ [XmlElement]
+ public UpdateLocalEnvironmentInfoVs LocalEnvironment = new UpdateLocalEnvironmentInfoVs();
+
+ [XmlElement]
+ public UpdateLocalEnvironmentInfo.VersionSubInfo PluginVersion = new UpdateLocalEnvironmentInfo.VersionSubInfo();
+ }
+}
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using JetBrains.Application;
+using JetBrains.DataFlow;
+using JetBrains.UI.Updates;
+using JetBrains.VSIntegration.Updates;
+using System.Linq;
+
+namespace JetBrains.ReSharper.Plugins.NuGet.Updates
+{
+ [ShellComponent]
+ public class UpdatesNotifier
+ {
+ public UpdatesNotifier(Lifetime lifetime, UpdatesManager updatesManager)
+ {
+ var uri = new Uri("https://raw.github.com/JetBrains/resharper-nuget/master/updates.xslt");
+ var category = updatesManager.Categories.AddOrActivate("NuGetSupport", uri);
+ category.CustomizeLocalEnvironmentInfo.Advise(lifetime, args =>
+ {
+ // We can customise the local environment info that the xslt will be applied to
+ // It should be an instance of UpdateLocalEnvironmentInfo, bail out early if it's
+ // not. The only reason it wouldn't be is if someone has got hold of the "NuGetSupport"
+ // category and subscribed to the CustomizeLocalEnvironmentInfo signal. Unlikely.
+ if (!(args.Out is UpdateLocalEnvironmentInfoVs))
+ return;
+
+ // Set the data the xslt will be applied against. Pass in the current environment,
+ // in case we ever need it, but really, we only care about the current version
+ args.Out = new PluginLocalEnvironmentInfo
+ {
+ LocalEnvironment = args.Out as UpdateLocalEnvironmentInfoVs,
+ PluginVersion = new UpdateLocalEnvironmentInfo.VersionSubInfo(GetThisVersion())
+ };
+ });
+
+ RemoveStaleUpdateNotification(category);
+ }
+
+ private static Version GetThisVersion()
+ {
+ var assembly = typeof(UpdatesNotifier).Assembly;
+ return assembly.GetName().Version;
+ }
+
+ private static void RemoveStaleUpdateNotification(UpdatesCategory category)
+ {
+ // ReSharper downloads and evaluates the xslt on a regular basis (every 24 hours),
+ // but doesn't re-evaluate it after an install (it doesn't know when something is
+ // installed!) so if there's a reminder to download this or an older version, remove it
+ var thisVersion = GetThisVersion();
+ var updateInfo = category.UpdateInfos.FirstOrDefault(container => new Version(container.Data.ProductVersion) <= thisVersion);
+ if (updateInfo != null)
+ category.UpdateInfos.Remove(updateInfo);
+ }
+ }
+}
@@ -65,11 +65,18 @@
<Compile Include="NuGetApi.cs" />
<Compile Include="NuGetModuleReferencer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Updates\PluginLocalEnvironmentInfo.cs" />
+ <Compile Include="Updates\UpdatesNotifier.cs" />
<Compile Include="VsServiceMapExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <Content Include="..\..\updates.xslt">
+ <Link>updates.xslt</Link>
+ </Content>
+ </ItemGroup>
<PropertyGroup>
<ReSharperSdkTargets Condition=" '$(ReSharperSdkTargets)' == '' ">$(MSBuildExtensionsPath)\JetBrains\ReSharper.SDK\v6.1</ReSharperSdkTargets>
</PropertyGroup>
@@ -48,10 +48,12 @@
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="PresentationCore" />
+ <Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
+ <Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
@@ -65,15 +67,22 @@
<Compile Include="NuGetApi.cs" />
<Compile Include="NuGetModuleReferencer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Updates\PluginLocalEnvironmentInfo.cs" />
+ <Compile Include="Updates\UpdatesNotifier.cs" />
<Compile Include="VsServiceMapExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <Content Include="..\..\updates.xslt">
+ <Link>updates.xslt</Link>
+ </Content>
+ </ItemGroup>
<PropertyGroup>
<ReSharperSdkTargets Condition=" '$(ReSharperSdkTargets)' == '' ">$(MSBuildExtensionsPath)\JetBrains\ReSharper.SDK\v7.1</ReSharperSdkTargets>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(ReSharperSdkTargets)\Plugin.Targets" />
<Import Project="resharper-nuget-debugging.proj" />
-</Project>
+</Project>
View
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:msxsl="urn:schemas-microsoft-com:xslt"
+ exclude-result-prefixes="msxsl">
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <!-- This is the latest version available -->
+ <xsl:variable name="LatestMajor" select="1" />
+ <xsl:variable name="LatestMinor" select="1" />
+ <xsl:variable name="LatestBuild" select="0" />
+
+ <!-- Match the PluginLocalInfo element created by serialising the data from the category -->
+ <xsl:template match="/PluginLocalInfo">
+ <UpdateInfos>
+ <xsl:variable name="InstalledMajor" select="PluginVersion/@Major" />
+ <xsl:variable name="InstalledMinor" select="PluginVersion/@Minor" />
+ <xsl:variable name="InstalledBuild" select="PluginVersion/@Build" />
+
+ <!-- If we have a new version, add an <UpdateInfo /> element to tell ReSharper a new version is ready -->
+ <xsl:if test="($InstalledMajor &lt; $LatestMajor) or ($InstalledMajor = $LatestMajor and $InstalledMinor &lt; $LatestMinor) or ($InstalledMajor = $LatestMajor and $InstalledMinor = $LatestMinor and $InstalledBuild &lt; $LatestBuild)">
+
+ <UpdateInfo>
+ <InformationUri>https://github.com/JetBrains/resharper-nuget/wiki/Release-Notes</InformationUri>
+ <Title>
+ <xsl:value-of select="concat('NuGet Support for ReSharper ', $LatestMajor, '.', $LatestMinor, '.', $LatestBuild, ' Released')"/>
+ </Title>
+ <Description>A minor upgrade is available.</Description>
+ <DownloadUri>???</DownloadUri>
+ <CompanyName>JetBrains</CompanyName>
+ <ProductName>NuGet Support</ProductName>
+ <ProductVersion><xsl:value-of select="concat($LatestMajor, '.', $LatestMinor, '.', $LatestBuild, '.0')"/></ProductVersion>
+ <PriceTag />
+ <IsFree>true</IsFree>
+ </UpdateInfo>
+
+ </xsl:if>
+ </UpdateInfos>
+ </xsl:template>
+
+</xsl:stylesheet>

0 comments on commit 6681811

Please sign in to comment.