Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added package ID & Version to metadata

  • Loading branch information...
commit 517a7a51607613922a56cd38ea117f56de1496a2 1 parent 306b0b1
@nikmd23 nikmd23 authored
View
41 source/Glimpse.Core/Extensibility/NuGetPackageAttribute.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Linq;
+using System.Reflection;
+
+namespace Glimpse.Core.Extensibility
+{
+ [AttributeUsage(AttributeTargets.Assembly)]
+ public class NuGetPackageAttribute : Attribute
+ {
+ private string Id { get; set; }
+ private string Version { get; set; }
+
+ public NuGetPackageAttribute() : this(null, null) { }
+ public NuGetPackageAttribute(string id) : this(id, null) { }
+ public NuGetPackageAttribute(string id, string version)
+ {
+ Id = id;
+ Version = version;
+ }
+
+ public string GetId(Assembly assembly)
+ {
+ if (!string.IsNullOrEmpty(Id))
+ return Id;
+
+ return Id = assembly.GetName().Name;
+ }
+
+ public string GetVersion(Assembly assembly)
+ {
+ if (!string.IsNullOrEmpty(Version))
+ return Version;
+
+ var infoVersion = assembly.GetCustomAttributes(typeof (AssemblyInformationalVersionAttribute), false).Cast<AssemblyInformationalVersionAttribute>().SingleOrDefault();
+ if (infoVersion != null)
+ return Version = infoVersion.InformationalVersion;
+
+ return Version = assembly.GetName().Version.ToString();
+ }
+ }
+}
View
3  source/Glimpse.Core/Framework/GlimpseMetadata.cs
@@ -13,11 +13,14 @@ public GlimpseMetadata()
{"paging", "NEED TO IMPLMENT RESOURCE Pager"},//TODO: Implement resource
{"tab", "NEED TO IMPLMENT RESOURCE test-popup.html"},//TODO: Implement resource
};
+
+ Packages = new Dictionary<string, string>();
}
public string Version { get; set; }
public IDictionary<string,PluginMetadata> Plugins { get; set; }
public IDictionary<string,string> Resources { get; set; }
+ public IDictionary<string,string> Packages { get; set; }
}
public class PluginMetadata
View
12 source/Glimpse.Core/Framework/GlimpseRuntime.cs
@@ -333,6 +333,18 @@ private void PersistMetadata()
pluginMetadata[tab.GetType().FullName] = metadataInstance;
}
+ foreach(var assembly in AppDomain.CurrentDomain.GetAssemblies())
+ {
+ var nugetPackage = assembly.GetCustomAttributes(typeof (NuGetPackageAttribute), false).Cast<NuGetPackageAttribute>().SingleOrDefault();
+ if (nugetPackage == null)
+ continue;
+
+ var version = nugetPackage.GetVersion(assembly);
+ var id = nugetPackage.GetId(assembly);
+
+ metadata.Packages[id] = version;
+ }
+
var resources = metadata.Resources;
var endpoint = Configuration.ResourceEndpoint;
var logger = Configuration.Logger;
View
1  source/Glimpse.Core/Glimpse.Core.csproj
@@ -86,6 +86,7 @@
<Compile Include="Extensibility\IConfigurable.cs" />
<Compile Include="Extensibility\IParameterValueProvider.cs" />
<Compile Include="Extensibility\IPrivilegedResource.cs" />
+ <Compile Include="Extensibility\NuGetPackageAttribute.cs" />
<Compile Include="Extensibility\ResourceParameterMetadata.cs" />
<Compile Include="Extensibility\TimerResult.cs" />
<Compile Include="Extensibility\IAlternateImplementation.cs" />
View
3  source/Glimpse.Core/SerializationConverter/GlimpseMetadataConverter.cs
@@ -12,7 +12,8 @@ public override object Convert(GlimpseMetadata metadata)
{
{"version", metadata.Version},
{"plugins", metadata.Plugins},
- {"resources", metadata.Resources}
+ {"resources", metadata.Resources},
+ {"packages", metadata.Packages},
};
}
}
View
4 source/Glimpse.Mvc3/Properties/AssemblyInfo.cs
@@ -1,6 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using Glimpse.Core.Extensibility;
[assembly: ComVisible(false)]
[assembly: Guid("751c5691-28de-4b8d-ba4d-dde77a91efa9")]
@@ -17,4 +18,5 @@
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0-rc")] //Used to specify the NuGet version number at build time
-[assembly: InternalsVisibleTo("Glimpse.Test.Mvc3")]
+[assembly: InternalsVisibleTo("Glimpse.Test.Mvc3")]
+[assembly: NuGetPackage]

2 comments on commit 517a7a5

@avanderhoorn

Is it possible to alter GlimpseRuntime.cs so that the json snippet would look like this?

...
"version":[ { name: 'Glimpse', version: '0.83' }, { name: 'Glimpse.Elmah', version: '0.9.2' } ],
...

I'm happy if we want to rename "version" to "packages", but the rest of the structure is easier for me to consume and a little more flexible if we need to include extra data.

@nikmd23
Owner
Please sign in to comment.
Something went wrong with that request. Please try again.