示例#1
0
        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);
        }