Skip to content

Commit

Permalink
Merge pull request #29 from Moesif/fix-multitargeting
Browse files Browse the repository at this point in the history
Fix:Null pointer due to no sample rate
  • Loading branch information
dgilling authored Jun 8, 2020
2 parents 4a38db2 + 94d7dfc commit e7e8c95
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions Moesif.Middleware/Helpers/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public class AppConfig
public int getSamplingPercentage(Api.Http.Response.HttpStringResponse config, string userId, string companyId)
{
// Get sampling percentage
if (config == null)
{
return 100;
}

var userDefaultRate = new object();

Expand All @@ -96,12 +100,12 @@ public int getSamplingPercentage(Api.Http.Response.HttpStringResponse config, st
? ApiHelper.JsonDeserialize<Dictionary<string, object>>(companyDefaultRate.ToString())
: null;

if (!string.IsNullOrEmpty(userId) && userSampleRate.Count > 0 && userSampleRate.ContainsKey(userId))
if (userSampleRate != null && !string.IsNullOrEmpty(userId) && userSampleRate.Count > 0 && userSampleRate.ContainsKey(userId))
{
return Int32.Parse(userSampleRate[userId].ToString());
}

if (!string.IsNullOrEmpty(companyId) && companySampleRate.Count > 0 && companySampleRate.ContainsKey(companyId))
if (companySampleRate != null && !string.IsNullOrEmpty(companyId) && companySampleRate.Count > 0 && companySampleRate.ContainsKey(companyId))
{
return Int32.Parse(companySampleRate[companyId].ToString());
}
Expand Down
2 changes: 1 addition & 1 deletion Moesif.Middleware/Moesif.Middleware.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Moesif.Middleware</id>
<version>1.1.4</version>
<version>1.1.5</version>
<title>MoesifMiddleware</title>
<authors>Moesif</authors>
<owners>Moesif</owners>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private async Task LogEventAsync(EventRequestModel event_request, EventResponseM
try
{
// If available, get sampling percentage based on config else default to 100
samplingPercentage = config != null ? appConfig.getSamplingPercentage(config, userId, companyId): 100;
samplingPercentage = appConfig.getSamplingPercentage(config, userId, companyId);

Random random = new Random();
double randomPercentage = random.NextDouble() * 100;
Expand Down
4 changes: 2 additions & 2 deletions Moesif.Middleware/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.4")]
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]

0 comments on commit e7e8c95

Please sign in to comment.