internal Dictionary <Guid, AmDbStateInfo> GetAllDbStatesFromClusdb(IClusterDB clusdb)
        {
            Dictionary <Guid, AmDbStateInfo> dictionary = new Dictionary <Guid, AmDbStateInfo>();

            if (!DistributedStore.Instance.IsKeyExist("ExchangeActiveManager\\DbState", null))
            {
                return(dictionary);
            }
            IEnumerable <Tuple <string, RegistryValueKind> > valueInfos = clusdb.GetValueInfos("ExchangeActiveManager\\DbState");

            if (valueInfos != null)
            {
                foreach (Tuple <string, RegistryValueKind> tuple in valueInfos)
                {
                    string item  = tuple.Item1;
                    string value = clusdb.GetValue <string>("ExchangeActiveManager\\DbState", item, string.Empty);
                    Guid   guid;
                    if (!string.IsNullOrEmpty(value) && Guid.TryParse(item, out guid))
                    {
                        AmDbStateInfo value2 = AmDbStateInfo.Parse(guid, value);
                        dictionary.Add(guid, value2);
                    }
                }
            }
            return(dictionary);
        }
        private int RemoveItemsFromClusdb(string objectName, IClusterDB clusdb, string keyName, bool isDeleteKey, IEnumerable <Guid> collection, Func <string, string> nameGenerator = null, int batchSize = 200)
        {
            if (!DistributedStore.Instance.IsKeyExist(keyName, null))
            {
                return(0);
            }
            int num  = 0;
            int num2 = 0;
            HashSet <string> hashSet = new HashSet <string>(collection.Select(delegate(Guid id)
            {
                string text2 = id.ToString();
                if (nameGenerator != null)
                {
                    return(nameGenerator(text2));
                }
                return(text2);
            }));

            num2 = hashSet.Count;
            try
            {
                if (isDeleteKey)
                {
                    IEnumerable <string> subKeyNames = clusdb.GetSubKeyNames(keyName);
                    hashSet.IntersectWith(subKeyNames);
                }
                else
                {
                    IEnumerable <string> other = from vi in clusdb.GetValueInfos(keyName)
                                                 select vi.Item1;
                    hashSet.IntersectWith(other);
                }
            }
            catch (Exception ex)
            {
                ReplayCrimsonEvents.ClusdbPeriodicCleanupFailed.Log <string, string>(objectName, ex.ToString());
                return(0);
            }
            if (hashSet.Count == 0)
            {
                return(0);
            }
            int       num3      = 0;
            int       num4      = 0;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            foreach (IEnumerable <string> enumerable in hashSet.Batch(batchSize))
            {
                num++;
                int num5 = 0;
                try
                {
                    using (IClusterDBWriteBatch clusterDBWriteBatch = clusdb.CreateWriteBatch(keyName))
                    {
                        foreach (string text in enumerable)
                        {
                            num5++;
                            if (isDeleteKey)
                            {
                                clusterDBWriteBatch.DeleteKey(text);
                            }
                            else
                            {
                                clusterDBWriteBatch.DeleteValue(text);
                            }
                        }
                        clusterDBWriteBatch.Execute();
                        num3 += num5;
                    }
                }
                catch (Exception ex2)
                {
                    num4++;
                    ReplayCrimsonEvents.ClusdbCleanupBatchOperationFailed.Log <string, string, string, bool, int, int, int, int>(objectName, ex2.Message, keyName, isDeleteKey, num, num5, num2, hashSet.Count);
                }
            }
            long elapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            ReplayCrimsonEvents.ClusdbPeriodicCleanupCompleted.Log <string, string, int, string, int, int, long>(objectName, keyName, num3, isDeleteKey ? "Key" : "Property", num, num4, elapsedMilliseconds);
            return(num3);
        }