Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
feat: Sentry context (#237)
Browse files Browse the repository at this point in the history
* Payload creating has runtime detection
* Context is built lazily on first event
* Root context is closed per event to avoid sys calls required to build it
* .NET Framework 4.7.1 added to support NET Standard 2.0 paths (RuntimeInformation)
* Warnings over obsolete calls removed from test projects
* Nancy targets net471 also
* Json.NET indirect reference to Nancy
* fix: Context loaded on SentryEvent
  • Loading branch information
bruno-garcia committed Apr 20, 2018
1 parent 7caf688 commit 4130daa
Show file tree
Hide file tree
Showing 53 changed files with 1,813 additions and 80 deletions.
4 changes: 2 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ var version = isTravis ? "0.0.1" : gitVersion.NuGetVersion;
var artifactsDir = Directory("./artifacts");
var outputDir = Directory("./build");

var dotnetFrameworks = IsRunningOnWindows() ? new [] { "net45", "net40", "netstandard2.0" } : new string[] { };
var dotnetFrameworks = IsRunningOnWindows() ? new [] { "net471", "net45", "net40", "netstandard2.0" } : new string[] { };
// net35 can't be build by dotnet - https://github.com/Microsoft/msbuild/issues/1333
var msBuildFrameworks = IsRunningOnWindows() ? new [] { "net35" } : new [] { "net45", "net40", "net35", "netstandard2.0" };
var msBuildFrameworks = IsRunningOnWindows() ? new [] { "net35" } : new [] { "net471", "net45", "net40", "net35", "netstandard2.0" };

var frameworks = dotnetFrameworks.Union(msBuildFrameworks).ToList();

Expand Down
13 changes: 0 additions & 13 deletions src/CommonConfigurations.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,4 @@
<OutputPath>..\..\..\build\$(Configuration.Split("-")[0])</OutputPath>
<IntermediateOutputPath>..\..\..\build\obj\$(Configuration.Split("-")[0])\</IntermediateOutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net35'">
<DefineConstants>$(DefineConstants);net35</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net40'">
<DefineConstants>$(DefineConstants);net40</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net45'">
<DefineConstants>$(DefineConstants);net45</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<DefineConstants>$(DefineConstants);netstandard2.0</DefineConstants>
</PropertyGroup>
</Project>
18 changes: 18 additions & 0 deletions src/SharpRaven.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ Global
Debug-net35|Any CPU = Debug-net35|Any CPU
Debug-net40|Any CPU = Debug-net40|Any CPU
Debug-net45|Any CPU = Debug-net45|Any CPU
Debug-net471|Any CPU = Debug-net471|Any CPU
Debug-netstandard2.0|Any CPU = Debug-netstandard2.0|Any CPU
Release|Any CPU = Release|Any CPU
Release-net35|Any CPU = Release-net35|Any CPU
Release-net40|Any CPU = Release-net40|Any CPU
Release-net45|Any CPU = Release-net45|Any CPU
Release-net471|Any CPU = Release-net471|Any CPU
Release-netstandard2.0|Any CPU = Release-netstandard2.0|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
Expand All @@ -65,6 +67,8 @@ Global
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Debug-net40|Any CPU.Build.0 = Debug-net40|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Debug-net45|Any CPU.ActiveCfg = Debug-net45|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Debug-net45|Any CPU.Build.0 = Debug-net45|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Debug-net471|Any CPU.ActiveCfg = Debug-net45|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Debug-net471|Any CPU.Build.0 = Debug-net45|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Debug-netstandard2.0|Any CPU.ActiveCfg = Debug-netstandard2.0|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Debug-netstandard2.0|Any CPU.Build.0 = Debug-netstandard2.0|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -75,6 +79,8 @@ Global
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Release-net40|Any CPU.Build.0 = Release-net40|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Release-net45|Any CPU.ActiveCfg = Release-net45|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Release-net45|Any CPU.Build.0 = Release-net45|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Release-net471|Any CPU.ActiveCfg = Release-net45|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Release-net471|Any CPU.Build.0 = Release-net45|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Release-netstandard2.0|Any CPU.ActiveCfg = Release-netstandard2.0|Any CPU
{CC80A2E1-AE39-44DE-8DA3-4EEF42F90FB1}.Release-netstandard2.0|Any CPU.Build.0 = Release-netstandard2.0|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -85,6 +91,8 @@ Global
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Debug-net40|Any CPU.Build.0 = Debug-net40|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Debug-net45|Any CPU.ActiveCfg = Debug-net45|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Debug-net45|Any CPU.Build.0 = Debug-net45|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Debug-net471|Any CPU.ActiveCfg = Debug-net45|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Debug-net471|Any CPU.Build.0 = Debug-net45|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Debug-netstandard2.0|Any CPU.ActiveCfg = Debug-netstandard2.0|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Release|Any CPU.Build.0 = Release|Any CPU
Expand All @@ -94,6 +102,8 @@ Global
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Release-net40|Any CPU.Build.0 = Release-net40|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Release-net45|Any CPU.ActiveCfg = Release-net45|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Release-net45|Any CPU.Build.0 = Release-net45|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Release-net471|Any CPU.ActiveCfg = Release-net45|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Release-net471|Any CPU.Build.0 = Release-net45|Any CPU
{E1DBEBBF-9448-4D99-B378-2B8CF1629F31}.Release-netstandard2.0|Any CPU.ActiveCfg = Release-netstandard2.0|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand All @@ -102,6 +112,8 @@ Global
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug-net40|Any CPU.Build.0 = Debug-net40|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug-net45|Any CPU.ActiveCfg = Debug-net45|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug-net45|Any CPU.Build.0 = Debug-net45|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug-net471|Any CPU.ActiveCfg = Debug-net45|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug-net471|Any CPU.Build.0 = Debug-net45|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug-netstandard2.0|Any CPU.ActiveCfg = Debug-netstandard2.0|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release|Any CPU.Build.0 = Release|Any CPU
Expand All @@ -110,6 +122,8 @@ Global
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release-net40|Any CPU.Build.0 = Release-net40|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release-net45|Any CPU.ActiveCfg = Release-net45|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release-net45|Any CPU.Build.0 = Release-net45|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release-net471|Any CPU.ActiveCfg = Release-net45|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release-net471|Any CPU.Build.0 = Release-net45|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release-netstandard2.0|Any CPU.ActiveCfg = Release-netstandard2.0|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand All @@ -118,6 +132,8 @@ Global
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug-net40|Any CPU.Build.0 = Debug-net40|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug-net45|Any CPU.ActiveCfg = Debug-net45|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug-net45|Any CPU.Build.0 = Debug-net45|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug-net471|Any CPU.ActiveCfg = Debug-net45|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug-net471|Any CPU.Build.0 = Debug-net45|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug-netstandard2.0|Any CPU.ActiveCfg = Debug-netstandard2.0|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release|Any CPU.Build.0 = Release|Any CPU
Expand All @@ -126,6 +142,8 @@ Global
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release-net40|Any CPU.Build.0 = Release-net40|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release-net45|Any CPU.ActiveCfg = Release-net45|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release-net45|Any CPU.Build.0 = Release-net45|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release-net471|Any CPU.ActiveCfg = Release-net45|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release-net471|Any CPU.Build.0 = Release-net45|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release-netstandard2.0|Any CPU.ActiveCfg = Release-netstandard2.0|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
Expand Down
9 changes: 9 additions & 0 deletions src/SharpRaven.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_WHILE_BRACES_STYLE/@EntryValue">ONLY_FOR_MULTILINE</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_CONSTRUCTOR_INITIALIZER_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_EMBEDDED_STATEMENT_ON_SAME_LINE/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_LINQ_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/REDUNDANT_THIS_QUALIFIER_STYLE/@EntryValue">USE_FOR_FIELD</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SIMPLE_EMBEDDED_STATEMENT_STYLE/@EntryValue">LINE_BREAK</s:String>
Expand Down Expand Up @@ -629,9 +633,14 @@ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF S
<s:Boolean x:Key="/Default/Environment/GenerateMru/SortByName/=Properties/@EntryIndexedValue">False</s:Boolean>
<s:Boolean x:Key="/Default/Environment/GenerateMru/SortByName/=ReadProperties/@EntryIndexedValue">False</s:Boolean>
<s:String x:Key="/Default/Environment/Hierarchy/PsiConfigurationSettingsKey/LocationType/@EntryValue">TEMP_FOLDER</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpFileLayoutPatternsUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EXml_002ECodeStyle_002EFormatSettingsUpgrade_002EXmlMoveToCommonFormatterSettingsUpgrade/@EntryIndexedValue">True</s:Boolean>
Expand Down
5 changes: 2 additions & 3 deletions src/app/SharpRaven.Nancy/SharpRaven.Nancy.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45;net40</TargetFrameworks>
<TargetFrameworks>net471;net45;net40</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>

<PackageId>SharpRaven.Nancy</PackageId>
Expand All @@ -24,7 +24,7 @@
<ProjectReference Include="..\SharpRaven\SharpRaven.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net40' or '$(TargetFramework)' == 'net45'">
<ItemGroup Condition="'$(TargetFramework)' == 'net40' or '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net471'">
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
Expand All @@ -33,7 +33,6 @@

<ItemGroup>
<PackageReference Include="Nancy" Version="1.4.3" />
<PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
</ItemGroup>

<ItemGroup>
Expand Down
147 changes: 147 additions & 0 deletions src/app/SharpRaven/Data/Context/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#region License

// Copyright (c) 2014 The Sentry Team and individual contributors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// 3. Neither the name of the Sentry nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#endregion

using System;
using System.Diagnostics;
using System.Reflection;

using Newtonsoft.Json;

using SharpRaven.Utilities;

namespace SharpRaven.Data.Context
{
/// <summary>
/// Describes the application.
/// </summary>
/// <remarks>
/// As opposed to the runtime, this is the actual application that
/// was running and carries meta data about the current session.
/// </remarks>
/// <seealso href="https://docs.sentry.io/clientdev/interfaces/contexts/"/>
public class App
{
/// <summary>
/// Version-independent application identifier, often a dotted bundle ID.
/// </summary>
[JsonProperty(PropertyName = "app_identifier", NullValueHandling = NullValueHandling.Ignore)]
public string Identifier { get; set; }
/// <summary>
/// Formatted UTC timestamp when the application was started by the user.
/// </summary>
[JsonProperty(PropertyName = "app_start_time", NullValueHandling = NullValueHandling.Ignore)]
public DateTimeOffset? StartTime { get; set; }
/// <summary>
/// Application specific device identifier.
/// </summary>
[JsonProperty(PropertyName = "device_app_hash", NullValueHandling = NullValueHandling.Ignore)]
public string Hash { get; set; }
/// <summary>
/// String identifying the kind of build, e.g. testflight.
/// </summary>
[JsonProperty(PropertyName = "build_type", NullValueHandling = NullValueHandling.Ignore)]
public string BuildType { get; set; }
/// <summary>
/// Human readable application name, as it appears on the platform.
/// </summary>
[JsonProperty(PropertyName = "app_name", NullValueHandling = NullValueHandling.Ignore)]
public string Name { get; set; }
/// <summary>
/// Human readable application version, as it appears on the platform.
/// </summary>
[JsonProperty(PropertyName = "app_version", NullValueHandling = NullValueHandling.Ignore)]
public string Version { get; set; }
/// <summary>
/// Internal build identifier, as it appears on the platform.
/// </summary>
[JsonProperty(PropertyName = "app_build", NullValueHandling = NullValueHandling.Ignore)]
public string Build { get; set; }

/// <summary>
/// The application AssemblyName used to report Version and Name
/// </summary>
/// <remarks>
/// If no value is set, the entry assemby's name will be used, if possible.
/// When not available, a best effort to locate the entrypoint will be made by walking up the stack
/// </remarks>
[JsonIgnore]
public static AssemblyName ApplicationName { get; set; }

/// <summary>
/// Clones this instance
/// </summary>
/// <returns></returns>
internal App Clone()
{
return new App
{
Build = this.Build,
Version = this.Version,
Name = this.Name,
BuildType = this.BuildType,
Hash = this.Hash,
Identifier = this.Identifier,
StartTime = this.StartTime
};
}

/// <summary>
/// Creates an App instance while loading relevant data at runtime
/// </summary>
/// <returns>An instance if any property was successfuly set or null otherwise.</returns>
internal static App Create()
{
try
{
var app = new App();

var asm = ApplicationName ?? EntryAssemblyNameLocator.GetAssemblyName();
if (asm != null)
{
app.Name = asm.Name;
app.Version = asm.Version?.ToString();
}

using (var proc = Process.GetCurrentProcess())
{
app.StartTime = proc.StartTime.ToUniversalTime();
}

return app;
}
catch (Exception e)
{
SystemUtil.WriteError(e);
return null;
}
}

}
}
Loading

0 comments on commit 4130daa

Please sign in to comment.