Пример #1
0
        public void SetLocations(List <Location> locations)
        {
            foreach (var location in locations)
            {
                if (location == null || string.IsNullOrWhiteSpace(location.Site) || string.IsNullOrWhiteSpace(location.Code))
                {
                    continue;
                }

                m_SiteToLocation.AddOrUpdate(location.Site, location, (site, loc) => (loc.Number < location.Number) ? location : loc);

                var znum = ZNumber.Parse(location.Code);

                m_CountryIDToMaxChar.AddOrUpdate(location.ISO, znum, (iso, num) => (num < znum) ? znum : num);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="site">100018P1348D2</param>
        /// <returns></returns>
        public Location GetLocation(string site)
        {
            Location location = null;

            if (m_SiteToLocation.TryGetValue(site, out location))
            {
                lock (location)
                {
                    location.NextNumber();
                    return(location);
                }
            }
            else
            {
                var iso = Tools.TryParseCountryID(site);
                if (!iso.HasValue)
                {
                    throw new FaultException("Cannot find CountryID");
                }

                ZNumber zNumber = null;

                lock (zNumber = m_CountryIDToMaxChar.GetOrAdd(iso.Value, new ZNumber()))
                {
                    zNumber.Increase();

                    location = new Location()
                    {
                        ISO = iso.Value, Code = zNumber.ToString(), Site = site
                    };
                    location.NextNumber();

                    m_SiteToLocation[site] = location;
                    return(location);
                }
            }
        }