Beispiel #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);
        }
Beispiel #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();
     }
 }
Beispiel #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);
        }
Beispiel #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);
            }
        }
Beispiel #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);
        }
Beispiel #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));
            }
        }
Beispiel #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);
            }
        }
Beispiel #8
0
 public static bool GetByValue(int srid, out SridItem item)
 {
     return(TryGetByValue(srid, out item));
 }