Example #1
0
        /// <summary>
        /// Gets next sequential id for the specified key.
        /// </summary>
        /// <param name="IdKey"></param>
        /// <returns></returns>
        public int GetNextID(string idKey)
        {
            lock (this)
            {
                //fetching cache if not done already
                if (currentIds == null)
                {
                    FillCache();
                }

                if (idmaps.ContainsKey(idKey))
                {
                    if (currentIds[idKey] >= idmaps[idKey].Idvalue)
                    {
                        //getting next id range
                        idmaps[idKey].Idvalue += idOffset;
                        UpdateIdmap(idmaps[idKey]);
                    }
                }
                else
                {
                    //adding new entry if not exist any
                    var newIdmap = new Idmap();
                    newIdmap.Idkey   = idKey;
                    newIdmap.Idvalue = idOffset * 2;
                    AddIdmap(newIdmap);
                    idmaps.Add(idKey, newIdmap);
                    currentIds.Add(idKey, idOffset);
                }
                currentIds[idKey]++;
                return(currentIds[idKey]);
            }
        }
Example #2
0
 public virtual void UpdateIdmap(Idmap idmap)
 {
     this.repo.Update(idmap);
     if (logger.IsEnabled(LogLevel.Trace))
     {
         logger.LogTrace($"Idmap Updated;  ThreadId: {Thread.CurrentThread.ManagedThreadId}, IdMap:\n {ObjectDumper.Dump(idmap)}");
     }
 }