Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variation name #15

Merged
merged 4 commits into from
Sep 14, 2023
Merged
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
9 changes: 6 additions & 3 deletions Flagship.Tests/FsFlag/FlagMetadataTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FlagMetadataTest
[TestMethod()]
public void ToJson()
{
var metadata = new FlagMetadata("CampaignId", "VariationGroupId", "VariationId", true, "", null);
var metadata = new FlagMetadata("CampaignId", "VariationGroupId", "VariationId", true, "", null, "CampaignName", "VariaitonGroupName", "VariationName");

var metadataJson = new Dictionary<string, object>()
{
Expand All @@ -24,7 +24,10 @@ public void ToJson()
["variationId"] = "VariationId",
["isReference"] = true,
["campaignType"] = "",
["slug"] = null
["slug"] = null,
["campaignName"] = "CampaignName",
["variationGroupName"] = "VariaitonGroupName",
["variationName"] = "VariationName",
};
Assert.AreEqual(metadata.ToJson(), JsonConvert.SerializeObject(metadataJson));
}
Expand All @@ -33,7 +36,7 @@ public void ToJson()
public void EmptyMetadata()
{
Assert.AreEqual(JsonConvert.SerializeObject(FlagMetadata.EmptyMetadata()),
JsonConvert.SerializeObject(new FlagMetadata("","","", false,"", null)));
JsonConvert.SerializeObject(new FlagMetadata("","","", false,"", null, "", "", "")));
}
}
}
4 changes: 2 additions & 2 deletions Flagship.Tests/FsFlag/FlagTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async public Task FlagTest()
EnvId = "envID"
};

var metadata = new FlagMetadata(flagDTO.CampaignId, flagDTO.VariationGroupId, flagDTO.VariationId, flagDTO.IsReference, flagDTO.CampaignType, flagDTO.Slug);
var metadata = new FlagMetadata(flagDTO.CampaignId, flagDTO.VariationGroupId, flagDTO.VariationId, flagDTO.IsReference, flagDTO.CampaignType, flagDTO.Slug, flagDTO.CampaignName, flagDTO.VariationGroupName, flagDTO.VariationName);

var trackingManagerMock = new Mock<Api.ITrackingManager>();
var decisionManagerMock = new Mock<Decision.IDecisionManager>();
Expand Down Expand Up @@ -129,7 +129,7 @@ public void FlagNullTest()
var defaultValue = "defaultString";
var flag = new Flag<string>("key", visitorMock.Object, defaultValue);

var metadata = new FlagMetadata("", "", "", false, "", null);
var metadata = new FlagMetadata("", "", "", false, "", null, "", "", "");

var resultMeta = flag.Metadata;

Expand Down
4 changes: 2 additions & 2 deletions Flagship.Tests/FsVisitor/DefaultStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public void GetFlagMetadataFailedTest()
const string functionName = "flag.metadata";
var defaultStrategy = new DefaultStrategy(visitorDelegate);

var metadata = new FsFlag.FlagMetadata("CampaignId", "variationGroupId", "variationId", false, "", null);
var metadata = new FsFlag.FlagMetadata("CampaignId", "variationGroupId", "variationId", false, "", null, "CampaignName", "VariationGroupName", "VariationName");
var resultatMetadata = defaultStrategy.GetFlagMetadata(metadata, "key", false);

Assert.AreEqual(JsonConvert.SerializeObject(FsFlag.FlagMetadata.EmptyMetadata()), JsonConvert.SerializeObject(resultatMetadata));
Expand All @@ -388,7 +388,7 @@ public void GetFlagMetadataTest()
const string functionName = "flag.metadata";
var defaultStrategy = new DefaultStrategy(visitorDelegate);

var metadata = new FsFlag.FlagMetadata("CampaignId", "variationGroupId", "variationId", false, "", null);
var metadata = new FsFlag.FlagMetadata("CampaignId", "variationGroupId", "variationId", false, "", null, "CampaignName", "VariationGroupName", "VariationName");
var resultatMetadata = defaultStrategy.GetFlagMetadata(metadata, "key", true);

Assert.AreEqual(JsonConvert.SerializeObject(metadata), JsonConvert.SerializeObject(resultatMetadata));
Expand Down
4 changes: 3 additions & 1 deletion Flagship/Api/BatchingPeriodicCachingStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ public async override Task SendBatch(CacheTriggeredBy batchTriggeredBy = CacheTr

var hitKeysToRemove = new List<string>();

foreach (var item in HitsPoolQueue)
var HitsPoolQueueClone = HitsPoolQueue.ToList();

foreach (var item in HitsPoolQueueClone)
{
if ((DateTime.Now - item.Value.CreatedAt).TotalMilliseconds >= Constants.DEFAULT_HIT_CACHE_TIME)
{
Expand Down
4 changes: 4 additions & 0 deletions Flagship/Decision/BucketingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ virtual public async void SendContextAsync(VisitorDelegateAbstract visitor)
var campaign = GetMatchingVisitorVariationGroup(item.VariationGroups, visitor, item.Id, item.Type);
if (campaign != null)
{
campaign.Name = item.Name;
campaigns.Add(campaign);
}
}
Expand All @@ -210,6 +211,7 @@ protected Model.Campaign GetMatchingVisitorVariationGroup(IEnumerable<VariationG
Id = campaignId,
Variation = variation,
VariationGroupId = item.Id,
VariationGroupName = item.Name,
Type = campaignType
};
}
Expand Down Expand Up @@ -252,6 +254,7 @@ protected Model.Variation GetVariation(VariationGroup variationGroup, VisitorDel
Id = newVariation.Id,
Modifications = newVariation.Modifications,
Reference = newVariation.Reference,
Name = newVariation.Name,
};
}
}
Expand All @@ -264,6 +267,7 @@ protected Model.Variation GetVariation(VariationGroup variationGroup, VisitorDel
Id = item.Id,
Modifications = item.Modifications,
Reference = item.Reference,
Name = item.Name,
};
}
}
Expand Down
61 changes: 33 additions & 28 deletions Flagship/Decision/DecisionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,54 @@ internal abstract class DecisionManager : IDecisionManager
protected bool _isPanic = false;

public FlagshipConfig Config { get; set; }
public bool IsPanic {
get => _isPanic;
protected set {
public bool IsPanic
{
get => _isPanic;
protected set
{
_isPanic = value;
StatusChange?.Invoke(_isPanic ? FlagshipStatus.READY_PANIC_ON : FlagshipStatus.READY);
}
}

public HttpClient HttpClient { get ; set ; }
public HttpClient HttpClient { get; set; }

public DecisionManager(FlagshipConfig config, HttpClient httpClient)
{
Config = config;
Config = config;
HttpClient = httpClient;
}

abstract public Task<ICollection<Campaign>> GetCampaigns(VisitorDelegateAbstract visitor);

public Task<ICollection<FlagDTO>> GetFlags(ICollection<Campaign> campaigns)
{
return Task.Factory.StartNew(() =>
{
ICollection<FlagDTO> flags = new Collection<FlagDTO>();
foreach (var campaign in campaigns)
{
foreach (var item in campaign.Variation.Modifications.Value)
{
var flag = new FlagDTO()
{
Key = item.Key,
CampaignId = campaign.Id,
VariationGroupId = campaign.VariationGroupId,
VariationId = campaign.Variation.Id,
IsReference = campaign.Variation.Reference,
Value = item.Value,
CampaignType = campaign.Type,
Slug = campaign.Slug
};
flags.Add(flag);
}
}
return flags;
});
return Task.Factory.StartNew(() =>
{
ICollection<FlagDTO> flags = new Collection<FlagDTO>();
foreach (var campaign in campaigns)
{
foreach (var item in campaign.Variation.Modifications.Value)
{
var flag = new FlagDTO()
{
Key = item.Key,
CampaignId = campaign.Id,
CampaignName = campaign.Name,
VariationGroupId = campaign.VariationGroupId,
VariationGroupName = campaign.VariationGroupName,
VariationId = campaign.Variation.Id,
VariationName = campaign.Variation.Name,
IsReference = campaign.Variation.Reference,
Value = item.Value,
CampaignType = campaign.Type,
Slug = campaign.Slug
};
flags.Add(flag);
}
}
return flags;
});
}
}
}
6 changes: 3 additions & 3 deletions Flagship/Enums/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ internal static class Constants
/// </summary>
public const int REQUEST_TIME_OUT = 2000;

public const string BASE_API_URL = "https://decision.flagship.io/v2/";
public const string BASE_API_URL = "https://staging-decision.flagship.io/v2/"; // "https://decision.flagship.io/v2/";

public const string HIT_API_URL = "https://ariane.abtasty.com";

public const string HIT_EVENT_URL = "https://events.flagship.io/";

public const string BUCKETING_API_URL = "https://cdn.flagship.io/{0}/bucketing.json";
public const string BUCKETING_API_URL = "https://cdn-staging.flagship.io/{0}/bucketing.json";

public const string BUCKETING_API_CONTEXT_URL = "https://decision.flagship.io/v2/{0}/events";

public const string SEND_CONTEXT_EVENT = "sendContextEvent";

public const string SDK_VERSION = "3.1.1";
public const string SDK_VERSION = "3.1.2";

public const string FLAGSHIP_SDK = "Flagship SDK";

Expand Down
2 changes: 1 addition & 1 deletion Flagship/Flagship.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Authors>Flagship Team</Authors>
<Company>ABTasty</Company>
<Product>Flagship</Product>
<Version>3.1.1</Version>
<Version>3.1.2</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<PackageProjectUrl>https://github.com/flagship-io/flagship-dotnet-sdk</PackageProjectUrl>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Expand Down
6 changes: 5 additions & 1 deletion Flagship/FsFlag/Flag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public IFlagMetadata Metadata
get
{
var flagDTO = _visitorDelegateAbstract.Flags?.FirstOrDefault(x => x.Key == _key);
var metadata = new FlagMetadata(flagDTO?.CampaignId ?? "", flagDTO?.VariationGroupId ?? "", flagDTO?.VariationId ?? "", flagDTO?.IsReference ?? false, flagDTO?.CampaignType ?? "", flagDTO?.Slug);
var metadata = new FlagMetadata(flagDTO?.CampaignId ?? "",
flagDTO?.VariationGroupId ?? "",
flagDTO?.VariationId ?? "", flagDTO?.IsReference ?? false, flagDTO?.CampaignType ?? "", flagDTO?.Slug,
flagDTO?.CampaignName??"", flagDTO?.VariationGroupName??"", flagDTO?.VariationName??""
);
if (flagDTO == null)
{
return metadata;
Expand Down
16 changes: 14 additions & 2 deletions Flagship/FsFlag/FlagMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,26 @@ public class FlagMetadata : IFlagMetadata
[JsonProperty("slug")]
public string Slug { get; set; }

internal FlagMetadata(string campaignId, string variationGroupId, string variationId, bool isReference, string campaignType, string slug)
[JsonProperty("campaignName")]
public string CampaignName { get; set; }

[JsonProperty("variationGroupName")]
public string VariationGroupName { get; set; }

[JsonProperty("variationName")]
public string VariationName { get; set; }

internal FlagMetadata(string campaignId, string variationGroupId, string variationId, bool isReference, string campaignType, string slug, string campaignName, string variationGroupName, string variaitonName)
{
CampaignId = campaignId;
VariationGroupId = variationGroupId;
VariationId = variationId;
IsReference = isReference;
CampaignType = campaignType;
Slug = slug;
CampaignName = campaignName;
VariationGroupName = variationGroupName;
VariationName = variaitonName;
}

public string ToJson()
Expand All @@ -44,7 +56,7 @@ public string ToJson()

internal static IFlagMetadata EmptyMetadata()
{
return new FlagMetadata("", "", "", false, "", null);
return new FlagMetadata("", "", "", false, "", null, "", "", "");
}

}
Expand Down
4 changes: 3 additions & 1 deletion Flagship/FsFlag/IFlagMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ namespace Flagship.FsFlag
public interface IFlagMetadata
{
string CampaignId { get; }
string CampaignName { get; }
string VariationGroupId { get; }
string VariationGroupName { get; }
string VariationName { get; }
string VariationId { get; }
bool IsReference { get; }
string CampaignType { get; }

string Slug { get; }
string ToJson();
}
Expand Down
2 changes: 1 addition & 1 deletion Flagship/FsVisitor/DefaultStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected override async Task SendActivate(FlagDTO flag, object defaultValue = n
FlagValue = flag.Value,
FlagDefaultValue = defaultValue,
VisitorContext = Visitor.Context,
FlagMetadata = new FlagMetadata(flag.CampaignId, flag.VariationGroupId, flag.VariationId, flag.IsReference, flag.CampaignType, flag.Slug)
FlagMetadata = new FlagMetadata(flag.CampaignId, flag.VariationGroupId, flag.VariationId, flag.IsReference, flag.CampaignType, flag.Slug, flag.CampaignName, flag.VariationGroupName, flag.VariationName)
};
await TrackingManager.ActivateFlag(activate);
}
Expand Down
2 changes: 2 additions & 0 deletions Flagship/Model/Bucketing/Campaign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Flagship.Model.Bucketing
public class Campaign
{
public string Id { get; set; }

public string Name { get; set; }
public string Type { get; set; }
public string Slug { get; set; }
public IEnumerable<VariationGroup> VariationGroups { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Flagship/Model/Bucketing/Variation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Flagship.Model.Bucketing
public class Variation
{
public string Id { get; set; }
public string Name { get; set; }
public bool Reference { get; set; }
public int Allocation { get; set; }
public Modifications Modifications { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions Flagship/Model/Bucketing/VariationGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Flagship.Model.Bucketing
public class VariationGroup
{
public string Id { get; set; }

public string Name { get; set; }
public TargetingContainer Targeting { get; set; }
public IEnumerable<Variation> Variations { get; set; }
}
Expand Down
4 changes: 4 additions & 0 deletions Flagship/Model/Campaign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ public class Campaign
/// </summary>
public string Id { get; set; }

public string Name { get; set; }

public string Slug { get; set; }

/// <summary>
/// The variation group ID (scenario)
/// </summary>
public string VariationGroupId { get; set; }

public string VariationGroupName { get; set; }

/// <summary>
/// The variation assigned for the visitor
/// </summary>
Expand Down
9 changes: 7 additions & 2 deletions Flagship/Model/FlagDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ public class FlagDTO
public string Key { get; set; }
public string CampaignId { get; set; }

public string VariationGroupId { get; set; }
public string CampaignName { get; set; }

public string VariationGroupId { get; set; }

public string VariationGroupName { get; set; }

public string VariationId { get; set; }

public string VariationName { get; set; }

public bool IsReference { get; set; }

public object Value { get; set; }

public string CampaignType { get; set; }
public string Slug { get; set; }

}
}
5 changes: 5 additions & 0 deletions Flagship/Model/Variation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ public class Variation
/// </summary>
public string Id { get; set; }

/// <summary>
///
/// </summary>
public string Name { get; set; }

/// <summary>
/// Is Reference
/// </summary>
Expand Down