Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Collector.Common.Correlation.sln
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.13
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4651B83D-ABF7-487E-A591-D1E0C2EA8002}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Collector.Common.Correlation", "src\Collector.Common.Correlation\Collector.Common.Correlation.csproj", "{A794B639-9F10-4373-9D22-7CA7EFE9007F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FD38999E-F777-403C-BF30-E21F847846EE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Collector.Common.Correlation", "src\Collector.Common.Correlation\Collector.Common.Correlation.csproj", "{A794B639-9F10-4373-9D22-7CA7EFE9007F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Collector.Common.Correlation.UnitTest", "test\Collector.Common.Correlation.UnitTest\Collector.Common.Correlation.UnitTest.csproj", "{4FE38F50-DE1B-4B70-AC63-11BD18DA1CC8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Collector.Common.Correlation.AspNet", "src\Collector.Common.Correlation.AspNet\Collector.Common.Correlation.AspNet.csproj", "{D5EE331C-6342-4E29-8B86-EE43A61CB648}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Collector.Common.Correlation.AspNet", "src\Collector.Common.Correlation.AspNet\Collector.Common.Correlation.AspNet.csproj", "{D5EE331C-6342-4E29-8B86-EE43A61CB648}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Collector.Common.Correlation.AspNet.Samples", "src\Collector.Common.Correlation.AspNet.Samples\Collector.Common.Correlation.AspNet.Samples.csproj", "{35630115-A6B7-4AE4-8D6C-E9B144B627A1}"
EndProject
Expand Down Expand Up @@ -47,4 +47,7 @@ Global
{D5EE331C-6342-4E29-8B86-EE43A61CB648} = {4651B83D-ABF7-487E-A591-D1E0C2EA8002}
{35630115-A6B7-4AE4-8D6C-E9B144B627A1} = {4651B83D-ABF7-487E-A591-D1E0C2EA8002}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DC2083DC-8F3B-402C-B93D-C9B37B7DD946}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Collector.Common.Correlation.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_USER_LINEBREAKS/@EntryValue">True</s:Boolean>
<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_ACCESSORHOLDER_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ON_SINGLE_LINE/@EntryValue">True</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_TYPE_CONSTRAINTS_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_WHILE_ON_NEW_LINE/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/REDUNDANT_THIS_QUALIFIER_STYLE/@EntryValue">DO_NOT_USE</s:String>
Expand Down Expand Up @@ -468,7 +470,11 @@
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<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_002ECSharpUseContinuousIndentInsideBracesMigration/@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_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_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
<AssemblyName>Collector.Common.Correlation.AspNet.Samples</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>12.0</OldToolsVersion>
<UseIISExpress>true</UseIISExpress>
<Use64BitIISExpress />
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -109,6 +121,25 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349C5851-65DF-11DA-9384-00065B846F21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:49813/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<Copyright>Copyright © 2017</Copyright>
<Description>Package for managing correlation ids and correlation states in a asp.net application.</Description>
<Authors>Team Heimdal, Team Nohm, Team Houdini</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public IEnumerable<KeyValuePair<string, object>> GetCorrelationValues()
return httpContext.Items[CorrelationValueDictionaryKey] as ConcurrentDictionary<string, object> ?? new ConcurrentDictionary<string, object>();
}

public object GetValue(string name)
=> HttpContext.Current.Items.Contains(name) ? HttpContext.Current.Items[name] : null;

public T GetValue<T>(string name)
where T : class
=> GetValue(name) as T;

public static void Enable()
{
CorrelationState.Use(new HttpContextCorrelationState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public bool TryAddOrUpdateCorrelationValue(string name, object value)
}

public IEnumerable<KeyValuePair<string, object>> GetCorrelationValues() => CorrelationValues.Value;

public object GetValue(string name) =>
CorrelationValues.Value != null && CorrelationValues.Value.TryGetValue(name, out var value) ? value : null;

public T GetValue<T>(string name)
where T : class =>
GetValue(name) as T;

}
}
#endif
15 changes: 15 additions & 0 deletions src/Collector.Common.Correlation/CallerContextCorrelationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ private static bool HasActiveCorrelationSession()
{
return CallContext.LogicalGetData(CORRELATION_ID) != null;
}

public object GetValue(string name)
{
var values = CallContext.LogicalGetData(CORRELATION_VALUES) as ConcurrentDictionary<string, object>;

object value;

return values != null && values.TryGetValue(name, out value) ? value : null;
}

public T GetValue<T>(string name)
where T : class
{
return GetValue(name) as T;
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>2.0.0</Version>
<Version>2.1.0</Version>
<Copyright>Copyright © 2017</Copyright>
<Description>Package for managing correlation ids and correlation states.</Description>
<Authors>Team Heimdal, Team Nohm, Team Houdini</Authors>
Expand Down
12 changes: 12 additions & 0 deletions src/Collector.Common.Correlation/CorrelationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ public static IEnumerable<KeyValuePair<string, object>> GetCorrelationValues()
return Enumerable.Empty<KeyValuePair<string, object>>();
}

/// <summary>
/// Gets the value associated with the name in the correlation state.
/// <param name="name">The name of the value. If the name don´t exist it will return null.</param>
/// </summary>
public static T GetCorrelationValue<T>(string name) where T : class
{
return CorrelationStates
.OrderBy(x => x.Priority)
.Select(x => x.GetValue<T>(name))
.FirstOrDefault(x => x != null);
}

/// <summary>
/// If you jump across several different threads using different threading methods (as in WPF threading and async await nested) then you can manually resyncronize the correlation state.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions src/Collector.Common.Correlation/ICorrelationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ public interface ICorrelationState
bool TryAddOrUpdateCorrelationValue(string name, object value);

IEnumerable<KeyValuePair<string, object>> GetCorrelationValues();

object GetValue(string name);

T GetValue<T>(string name) where T : class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public IEnumerable<KeyValuePair<string, object>> GetCorrelationValues()
return correlationDictionary;
}

public object GetValue(string name) =>
correlationDictionary.TryGetValue(name, out var value) ? value : null;

public T GetValue<T>(string name)
where T : class =>
GetValue(name) as T;

private static bool HasActiveCorrelationSession()
{
if (threadId == null)
Expand Down