public override void Apply(T ruleContext) { ProfileKeyDefinition pkd = AnalyticsManager.GetProfileKeyDefinitionById(new Guid(Context.Database.GetItem(ProfileKeyId.ToString()).ID.ToString())); ProfileDefinition pd = AnalyticsManager.GetProfileDefinitionById(pkd.ProfileDefinitionId); if (pd != null) { ProfileKeyData pkItem = AnalyticsTracker.Current.Data.Profiles.GetProfile(pd.Name).GetProfileKey(pkd.Name); if (pkItem != null) { AnalyticsManager.UpdateProfileKey(pkItem.ProfileKeyId, pkItem.Value * Int32.Parse(Multiplier)); } } }
private double GetProfileKeyValue() { Func <ProfileData, bool> predicate = null; Func <ProfileKeyData, bool> func2 = null; AnalyticsTracker current = AnalyticsTracker.Current; if (current == null) { return(0.0); } Guid sessionId = current.CurrentSession.GetSessionId(); if (sessionId == Guid.Empty) { return(0.0); } ProfileKeyResult profileKeyResult = GetProfileKeyResult(sessionId, new Guid(ProfileKeyId)); if ((profileKeyResult.ProfileId == Guid.Empty) || (profileKeyResult.ProfileKeyId == Guid.Empty)) { return(0.0); } if (current.Data != null) { if (predicate == null) { predicate = p => p.ProfileId == profileKeyResult.ProfileId; } ProfileData source = current.Data.Profiles.FirstOrDefault(predicate); if (source != null) { if (func2 == null) { func2 = profileKeyData => profileKeyData.ProfileKeyId == profileKeyResult.ProfileKeyId; } ProfileKeyData data2 = source.FirstOrDefault(func2); if (data2 != null) { int num = source.Sum((ProfileKeyData profileKeyData) => profileKeyData.Value); bool changed = source.Aggregate(source.Changed, (current1, data3) => current1 | data3.Changed); profileKeyResult.Count = changed ? (source.Count + 1) : source.Count; profileKeyResult.Total = num; profileKeyResult.Value = data2.Value; } } } string str = profileKeyResult.ProfileType ?? string.Empty; switch (str.ToLower()) { case "sum": return(profileKeyResult.Value); case "percentage": return((profileKeyResult.Value * 100.0) / (profileKeyResult.Total)); case "average": return((profileKeyResult.Value) / ((double)profileKeyResult.Count)); } return(profileKeyResult.Value); }