Exemplo n.º 1
0
        private static bool WithingWriteLock_TryRegisterId <T>(SridItem item, T value) where T : Enum
        {
            if (_catalog[item.SRID] != item)
            {
                throw new InvalidOperationException();
            }

            int n = GetIdType <T>();

            while (_dicts.Count <= n)
            {
                _dicts.Add(null);
            }

            if (_dicts[n] == null)
            {
                _dicts[n] = new Dictionary <T, SridItem>();
            }

            if (_dicts[n].Contains(value))
            {
                return(false);
            }

            _dicts[n].Add(value, item);
            item.SetId(n, value);
            return(true);
        }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="item"></param>
 /// <param name="value"></param>
 public static void RegisterId <T>(SridItem item, T value)
     where T : struct, Enum
 {
     if (!TryRegisterId(item, value))
     {
         throw new InvalidOperationException();
     }
 }
Exemplo n.º 3
0
        private static SridItem WithinWriteLock_Register(CoordinateReferenceSystem crs, int withSrid)
        {
            SridItem added = new SridItem(withSrid, crs);

            _registered.Add(crs, added);
            _catalog.Add(withSrid, added);

            return(added);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the SRID item by id
        /// </summary>
        /// <param name="srid"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        /// <exception cref="IndexOutOfRangeException"></exception>
        /// <exception cref="ArgumentException"></exception>
        public static bool TryGetByValue(int srid, out SridItem item)
        {
            using (_rwl.WithReadLock())
            {
                if (_catalog.TryGetValue(srid, out item))
                {
                    return(true);
                }

                item = null;
                return(false);
            }
        }
Exemplo n.º 5
0
        static SridItem WithinWriteLock_Register(CoordinateReferenceSystem crs)
        {
            while (_catalog.ContainsKey(_nextId))
            {
                _nextId--;
            }

            SridItem added = new SridItem(_nextId, crs);

            _registered.Add(crs, added);
            _catalog.Add(_nextId, added);

            return(added);
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool TryRegisterId <T>(SridItem item, T value)
            where T : Enum
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            if (!_catalog.TryGetValue(item.SRID, out var vv) || !ReferenceEquals(vv, item))
            {
                throw new ArgumentOutOfRangeException(nameof(item));
            }

            using (_rwl.WithWriteLock())
            {
                return(WithingWriteLock_TryRegisterId(item, value));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public static bool TryGetById <T>(T key, out SridItem item)
            where T : struct, Enum
        {
            item = null;
            using (_rwl.WithReadLock())
            {
                int n = GetIdType <T>();

                if (n >= _dicts.Count)
                {
                    return(false);
                }

                IReadOnlyDictionary <T, SridItem> dict = (IReadOnlyDictionary <T, SridItem>)_dicts[n];

                if (dict?.TryGetValue(key, out item) ?? false)
                {
                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 8
0
 public static bool GetByValue(int srid, out SridItem item)
 {
     return(TryGetByValue(srid, out item));
 }