Esempio n. 1
0
        /// <summary>
        /// Is the requesting in the audience group?
        /// </summary>
        /// <param name="callingClient">GatedClient</param>
        /// <param name="requiredClient">RequiredClient</param>
        /// <returns>true if the calling client is in required client audience group, false otherwise</returns>
        private static bool IsInAudienceGroup(GatedClient callingClient, RequiredClient requiredClient)
        {
            if (string.IsNullOrWhiteSpace(requiredClient.AudienceGroup))
            {
                // Return true because AudienceGroup check is not needed
                return(true);
            }

            if (callingClient.AudienceGroups.Count == 0)
            {
                return(false);
            }

            RequiredApplication requiredApplication;

            if (callingClient.AppCode != null &&
                requiredClient.Overrides.TryGetValue(callingClient.AppCode, out requiredApplication) &&
                !string.IsNullOrWhiteSpace(requiredApplication.AudienceGroup))
            {
                // App Override
                if (callingClient.AudienceGroups.Contains(requiredApplication.AudienceGroup, StringComparer.OrdinalIgnoreCase))
                {
                    return(true);
                }

                return(false);
            }
            else
            {
                // ClientVersion
                if (callingClient.AudienceGroups.Contains(requiredClient.AudienceGroup, StringComparer.OrdinalIgnoreCase))
                {
                    return(true);
                }

                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Is the requesting client version in range?
        /// </summary>
        /// <param name="client">GatedClient</param>
        /// <param name="requiredClient">RequiredClient</param>
        /// <returns>true if the client version is in required client version range, false otherwise</returns>
        private static bool IsVersionInRange(GatedClient client, RequiredClient requiredClient)
        {
            if (client.Version == null)
            {
                return(false);
            }

            RequiredApplication requiredApplication;

            if (client.AppCode != null &&
                requiredClient.Overrides.TryGetValue(client.AppCode, out requiredApplication))
            {
                if (requiredApplication.VersionRanges.Count > 0)
                {
                    // VersionRanges of application
                    foreach (ProductVersionRange range in requiredApplication.VersionRanges)
                    {
                        if (range.Min <= client.Version && range.Max >= client.Version)
                        {
                            return(true);
                        }
                    }

                    return(false);
                }

                // Between MinVersion and MaxVersion of application
                if ((requiredApplication.MinVersion != null && requiredApplication.MinVersion > client.Version) ||
                    (requiredApplication.MaxVersion != null && requiredApplication.MaxVersion <= client.Version))
                {
                    return(false);
                }

                return(true);
            }
            else
            {
                if (requiredClient.VersionRanges.Count > 0)
                {
                    // VersionRanges of platform
                    foreach (ProductVersionRange range in requiredClient.VersionRanges)
                    {
                        if (range.Min <= client.Version && range.Max >= client.Version)
                        {
                            return(true);
                        }
                    }

                    return(false);
                }

                // Between MinVersion and MaxVersion of platform
                if ((requiredClient.MinVersion != null && requiredClient.MinVersion > client.Version) ||
                    (requiredClient.MaxVersion != null && requiredClient.MaxVersion <= client.Version))
                {
                    return(false);
                }

                return(true);
            }
        }