Пример #1
0
 /// <summary>
 /// Initializes a new instance of the GeoFilter class.
 /// </summary>
 /// <param name="relativePath">Relative path applicable to geo filter.
 /// (e.g. '/mypictures', '/mypicture/kitty.jpg', and etc.)</param>
 /// <param name="action">Action of the geo filter, i.e. allow or block
 /// access. Possible values include: 'Block', 'Allow'</param>
 /// <param name="countryCodes">Two letter country codes defining user
 /// country access in a geo filter, e.g. AU, MX, US.</param>
 public GeoFilter(string relativePath, GeoFilterActions action, IList <string> countryCodes)
 {
     RelativePath = relativePath;
     Action       = action;
     CountryCodes = countryCodes;
     CustomInit();
 }
        internal static GeoFilter DeserializeGeoFilter(JsonElement element)
        {
            string           relativePath = default;
            GeoFilterActions action       = default;
            IList <string>   countryCodes = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("relativePath"))
                {
                    relativePath = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("action"))
                {
                    action = property.Value.GetString().ToGeoFilterActions();
                    continue;
                }
                if (property.NameEquals("countryCodes"))
                {
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString());
                    }
                    countryCodes = array;
                    continue;
                }
            }
            return(new GeoFilter(relativePath, action, countryCodes));
        }
Пример #3
0
        ///GENMHASH:3883B65D38EC24BB4F7FD6D5BDD34433:6B89DE41199AB45D2C541D6B3DBC05CC
        public CdnEndpointImpl WithGeoFilter(string relativePath, GeoFilterActions action, Microsoft.Azure.Management.ResourceManager.Fluent.Core.CountryISOCode countryCode)
        {
            var geoFilter = this.CreateGeoFiltersObject(relativePath, action);

            if (geoFilter.CountryCodes == null)
            {
                geoFilter.CountryCodes = new List <string>();
            }
            geoFilter.CountryCodes.Add(countryCode.ToString());
            Inner.GeoFilters.Add(geoFilter);
            return(this);
        }
        internal static string ToSerializedValue(this GeoFilterActions value)
        {
            switch (value)
            {
            case GeoFilterActions.Block:
                return("Block");

            case GeoFilterActions.Allow:
                return("Allow");
            }
            return(null);
        }
Пример #5
0
        public GeoFilter(string relativePath, GeoFilterActions action, IEnumerable <string> countryCodes)
        {
            if (relativePath == null)
            {
                throw new ArgumentNullException(nameof(relativePath));
            }
            if (countryCodes == null)
            {
                throw new ArgumentNullException(nameof(countryCodes));
            }

            RelativePath = relativePath;
            Action       = action;
            CountryCodes = countryCodes.ToList();
        }
Пример #6
0
        ///GENMHASH:79A840C9F24220C8EF02C0B73BAD3C0F:3586CFD7AEFDBFA89168B9EFC6A2C18C
        private GeoFilter CreateGeoFiltersObject(string relativePath, GeoFilterActions action)
        {
            if (Inner.GeoFilters == null)
            {
                Inner.GeoFilters = new List <GeoFilter>();
            }
            var geoFilter = Inner.GeoFilters
                            .FirstOrDefault(s => s.RelativePath.Equals(
                                                relativePath,
                                                System.StringComparison.OrdinalIgnoreCase));

            if (geoFilter == null)
            {
                geoFilter = new GeoFilter();
            }
            else
            {
                Inner.GeoFilters.Remove(geoFilter);
            }
            geoFilter.RelativePath = relativePath;
            geoFilter.Action       = action;
            return(geoFilter);
        }
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="GeoFilterActions" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => GeoFilterActions.CreateFrom(sourceValue);
Пример #8
0
 internal GeoFilter(string relativePath, GeoFilterActions action, IList <string> countryCodes)
 {
     RelativePath = relativePath;
     Action       = action;
     CountryCodes = countryCodes;
 }
Пример #9
0
 public static string ToSerialString(this GeoFilterActions value) => value switch
 {