private void RemoveSchedulingForInitiative(InternalEventScheduling es)
 {
     if (es?.Initiative is InternalInitiative init)
     {
         scheduledEventsForInitiatives.Remove(init, es);
         if (init.AutoRemove && !scheduledEventsForInitiatives.AnyValues(init))
         {
             // Get rid of an AutoRemove Initiative when there are no more scheduled events referencing it
             scheduledEventsForInitiatives.Clear(init);
             oc.Remove(init);
         }
     }
 }
Esempio n. 2
0
        public void UnLinkGrid()
        {
            if (MyDataBC == null)
            {
                return;
            }
            var mi = myData as INotifyPropertyChanged;

            if (mi != null)
            {
                mi.PropertyChanged -= OnMyGridPropertyChanged;
            }
            var mbc = MyData as IBindableComponent;

            if (mbc != null)
            {
                mbc.DataBindings.Clear();
            }
            for (int i = 0; i < gridRowList.Count; i++)
            {
                var rowdef = gridRowList[i];
                try
                {
                    rowdef.UnLinkRow();
                }
                catch (Exception ex)
                {
                    throw new Exception("UnLinkRow failed: " + rowdef.Name, ex);
                }
            }
            linkedRows.Clear();
            LinkedCells.Clear();
        }
Esempio n. 3
0
 /**
  * Set sharding value for database sharding only.
  *
  * <p>The sharding operator is {@code =}</p>
  *
  * @param value sharding value
  */
 public void SetDatabaseShardingValue(IComparable value)
 {
     databaseShardingValues.Clear();
     tableShardingValues.Clear();
     databaseShardingValues.Add("", value);
     databaseShardingOnly = true;
 }
        public void Clear_RemovesAll()
        {
            sut.Add("a", "c");
            sut.Add("b", "c");
            sut.Clear();

            sut.Should().BeEmpty();
        }
Esempio n. 5
0
 private void Apply(SagaKeysChangedEvent ev)
 {
     keys.Clear();
     foreach (var namePair in ev.Keys)
     {
         keys.AddRange(namePair.Key, namePair.Value);
     }
 }
Esempio n. 6
0
        public void Clear(int size)
        {
            MultiValueDictionary <int, int> dict = CreateMVD(size);

            foreach (var iteration in Benchmark.Iterations)
            {
                MultiValueDictionary <int, int> copyDict = new MultiValueDictionary <int, int>(dict);
                using (iteration.StartMeasurement())
                    copyDict.Clear();
            }
        }
Esempio n. 7
0
        void UpdateTraitsFilter()
        {
            filterTraits.Clear();

            if (listTraits.SelectedIndices.Count > 0)
            {
                foreach (ListViewItem item in listTraits.SelectedItems)
                {
                    filterTraits.AddValue(item.Group.Name, item.Text);
                }
            }
        }
        public void Clear_ShouldRemoveAllValues()
        {
            _target.Add("A", "A");
            _target.Add("A", "B");
            _target.Add("B", "A");
            _target.Add("B", "B");

            _target.Clear();

            var result = _target.ContainsKey("A") || _target.ContainsKey("B");

            Assert.False(result);
        }
Esempio n. 9
0
        public void Dispose()
        {
            var conns = _deviceObservers.Values.SelectMany(c => c).ToList();

            _deviceObservers.Clear();
            if (conns.Any())
            {
                foreach (var c in conns)
                {
                    c.Dispose();
                }
            }
        }
Esempio n. 10
0
 public static void ShouldClear()
 {
     var multiDict = new MultiValueDictionary<string, string>();
     multiDict.AddRange("key2", values2);
     multiDict.AddRange("key1", values1);
     multiDict.Add("key3", "海亀");
     multiDict.Clear();
     IReadOnlyCollection<string> values;
     Assert.IsFalse(multiDict.TryGetValue("海亀", out values));
     Assert.IsFalse(multiDict.TryGetValue("key1", out values));
     Assert.IsFalse(multiDict.TryGetValue("key2", out values));
     Assert.IsFalse(multiDict.TryGetValue("key3", out values));
 }
Esempio n. 11
0
 ///<summary>Restores the light sources that were temporarily removed when UpdateBeforeOpacityChange was called.
 /// (UpdateBeforeOpacityChange MUST be called immediately before changing the opacity.)</summary>
 public void UpdateAfterOpacityChange()
 {
     if (!midOpacityUpdate)
     {
         throw new InvalidOperationException("This method can only be called to finish an opacity update");
     }
     midOpacityUpdate = false;
     foreach (KeyValuePair <Point, int> pair in tempRemovedLights.GetAllKeyValuePairs())
     {
         UpdateBrightnessWithinRadius(pair.Key, pair.Value, 1);
     }
     tempRemovedLights.Clear();
 }
        public void MultiValueDictionaryClearTest()
        {
            MultiValueDictionary <Int32, String> dictionary = new MultiValueDictionary <Int32, String>();

            foreach (KeyValuePair <Int32, List <String> > item in _items)
            {
                dictionary.Add(item.Key, item.Value);
            }

            Assert.AreEqual(10, dictionary.Count());

            dictionary.Clear();
            Assert.AreEqual(0, dictionary.Count());
        }
Esempio n. 13
0
        public static void ShouldClear()
        {
            var multiDict = new MultiValueDictionary <string, string>();

            multiDict.AddRange("key2", values2);
            multiDict.AddRange("key1", values1);
            multiDict.Add("key3", "海亀");
            multiDict.Clear();
            IReadOnlyCollection <string> values;

            Assert.IsFalse(multiDict.TryGetValue("海亀", out values));
            Assert.IsFalse(multiDict.TryGetValue("key1", out values));
            Assert.IsFalse(multiDict.TryGetValue("key2", out values));
            Assert.IsFalse(multiDict.TryGetValue("key3", out values));
        }
        public void ClearingDictionaryShouldResultInCountZero()
        {
            var dict = new MultiValueDictionary <int, string>(() => new HashSet <string>())
            {
                { 1, "one" },
                { 1, "een" },
                { 2, "two" },
                { 2, "twee" },
                { 2, "deux" }
            };

            dict.Clear();

            Assert.Equal(0, dict.Count);
        }
Esempio n. 15
0
 /// <summary>
 /// At end of update dictionary needs to be erased.(?)
 /// </summary>
 /// <param name="gameTime"></param>
 public void update(GameTime gameTime)
 {
     // Go through each collision
     foreach (Tangible key in collisions.Keys)
     {
         foreach (Tangible value in collisions.GetValues(key, false))
         {
             //System.Console.WriteLine("Resolving collision " + key.GetType().Name + " with " + value.GetType().Name + " at " + gameTime.TotalGameTime.TotalMilliseconds);
             key.collide(value, gameTime);
         }
     }
     //System.Console.WriteLine("Before collisions.Count " + collisions.Count);
     collisions.Clear();
     //System.Console.WriteLine("After collisions.Count " + collisions.Count);
 }
Esempio n. 16
0
        internal void CommitDestroy()
        {
            foreach (var child in Transform.Children.ToArray())
            {
                child.GameObject.CommitDestroy();
            }

            foreach (var componentList in _components)
            {
                foreach (var component in componentList.Value)
                {
                    component.InternalRemoved(_registry);
                }
            }

            _components.Clear();

            Destroyed?.Invoke(this);
            InternalDestroyCommitted.Invoke(this);
        }
Esempio n. 17
0
 private static void RefreshServices()
 {
     ServiceCacheLock.EnterWriteLock();
     ServiceCacheTime = DateTime.Now;
     ServiceCache.Clear();
     ServiceCacheByPID.Clear();
     foreach (ServiceController sc in ServiceController.GetServices())
     {
         ServiceInfo info = new ServiceInfo(sc);
         if (!ServiceCache.ContainsKey(sc.ServiceName)) // should not happen but in case
         {
             ServiceCache.Add(sc.ServiceName, info);
         }
         if (info.LastKnownPID != -1)
         {
             ServiceCacheByPID.Add(info.LastKnownPID, info);
         }
     }
     // this takes roughly 30 ms
     ServiceCacheLock.ExitWriteLock();
 }
Esempio n. 18
0
        public static void Init()
        {
            db.CreateTable <DBWord>();
            db.CreateTable <DBMeaning>();
            db.CreateTable <DBTranslation>();

            words.Clear(); means.Clear(); eles.Clear();
            WrongCount = 0;
            foreach (var w in db.Table <DBWord>())
            {
                var s = w.ToStat();
                words.Add(s, w.Id);
                eles.Add(s);
                if (s.wrong > 0)
                {
                    WrongCount += s.wrong;
                }
                WrongCount++;
            }
            foreach (var m in db.Table <DBMeaning>())
            {
                var s = m.ToStat();
                means.Add(s, m.Id);
                eles.Add(s);
                if (s.wrong > 0)
                {
                    WrongCount += s.wrong;
                }
                WrongCount++;
            }
            e2c.Clear(); c2e.Clear();
            foreach (var t in db.Table <DBTranslation>())
            {
                e2c.Add(t.Wid, t.Mid);
                c2e.Add(t.Mid, t.Wid);
            }
            updTimeAll = updTimeDetail = DateTime.Now.Ticks;
        }
Esempio n. 19
0
        public static Automaton NfaToDfa(Automaton nfa, out MultiValueDictionary<State, State> dfaStatesToNfa)
        {
            var dfa = new Automaton();
            dfa.CaptureNames = nfa.CaptureNames;
            var dfaStartState = dfa.AddState();
            dfa.StartState = dfaStartState;
            var nfaTransitionsToDfa = new MultiValueDictionary<Transition, Transition>();
            var transitionClasses = new List<Transition>();
            var mergeStates = new HashSet<State>();
            dfaStatesToNfa = new MultiValueDictionary<State, State>();
            dfaStatesToNfa.Add(dfaStartState, nfa.StartState);
            //不动点算法,不能使用 foreach!
            for(int i = 0; i < dfa.States.Count; ++i)
            {
                var curDfaState = dfa.States[i];
                var nfaStates = dfaStatesToNfa[curDfaState];
                foreach(var nfaState in nfaStates)
                {
                    foreach(var outTransition in nfaState.Output)
                    {
                        if (!nfaTransitionsToDfa.Values.SelectMany(transitions => transitions).Contains(outTransition))
                        {
                            transitionClasses.Add(outTransition);
                            nfaTransitionsToDfa.Add(outTransition, outTransition);
                        }
                    }
                }

                foreach(var transitionClass in transitionClasses)
                {
                    var nfaTransitions = nfaTransitionsToDfa[transitionClass];
                    foreach(var nfaTransition in nfaTransitions)
                    {
                        var state = nfaTransition.End;
                        if (!mergeStates.Contains(state))
                            mergeStates.Add(state);
                    }

                    mergeStates.OrderBy(state => state);

                    //mergeStates 是候选的一个 DFA 状态。在这之前,还需要判断:这个候选状态是否已经存在于 DFA 中了?
                    //var isContained = dfaStatesToNfa.Values.Contains((IReadOnlyCollection<State>)mergeStates);
                    State newDfaState = null;
                    foreach(var dfaState in dfaStatesToNfa.Keys)
                    {
                        var prevNfaStates = dfaStatesToNfa[dfaState];
                        if (prevNfaStates.Count == mergeStates.Count &&
                            prevNfaStates.SequenceEqual(mergeStates))
                        {
                            newDfaState = dfaState;
                            break;
                        }
                    }
                    if(newDfaState == null)
                    {
                        newDfaState = dfa.AddState();
                        dfaStatesToNfa.AddRange(newDfaState, mergeStates);
                        newDfaState.IsFinalState = mergeStates.Any(state => state.IsFinalState);
                    }

                    var dfaTransition = dfa.AddTransition(curDfaState, newDfaState, transitionClass.TransitionType);
                    dfaTransition.Capture = transitionClass.Capture;
                    dfaTransition.Range = transitionClass.Range;
                    dfaTransition.Index = transitionClass.Index;
                    mergeStates.Clear();
                }
                transitionClasses.Clear();
                nfaTransitionsToDfa.Clear();
            }

            return dfa;
        }
Esempio n. 20
0
    public void Rebuild( )
    {
        //Debug.Log( "Rebuilding Uni2D Asset Table..." );

        m_oAtlasGUIDSpritePrefabGUIDsMultiDict.Clear( );
        m_oTextureGUIDAtlasGUIDsMultiDict.Clear( );
        m_oTextureGUIDClipGUIDsMultiDict.Clear( );
        m_oTextureGUIDSpritePrefabGUIDsMultiDict.Clear( );

        m_oAtlasPathGUIDDict.Clear( );
        m_oClipPathGUIDDict.Clear( );

        // Iterate project's assets
        string[] rAssetPaths = AssetDatabase.GetAllAssetPaths( );

        int   iAssetCount      = rAssetPaths.Length;
        float fInvAssetCount   = 1.0f / (float)iAssetCount;
        int   iProcessedAssets = 0;

        try
        {
            foreach (string rPath in rAssetPaths)
            {
                EditorUtility.DisplayProgressBar("Uni2D - Asset Table Rebuilding Progress",
                                                 iProcessedAssets + " out of " + iAssetCount + " asset(s) processed...",
                                                 fInvAssetCount * iProcessedAssets);

                Object rAssetObject = null;

                // Might be an atlas or a clip
                if (rPath.EndsWith(".prefab"))
                {
                    rAssetObject = AssetDatabase.LoadAssetAtPath(rPath, typeof(Uni2DTextureAtlas));
                    if (rAssetObject != null)                           // It's an atlas
                    {
                        Uni2DTextureAtlas rAtlasAsset = (Uni2DTextureAtlas)rAssetObject;
                        string            rAtlasGUID  = AssetDatabase.AssetPathToGUID(rPath);

                        foreach (string rTextureGUID in rAtlasAsset.GetTextureGUIDs( ))
                        {
                            this.AddAtlasUsingTexture(rAtlasGUID, rTextureGUID);
                        }

                        m_oAtlasPathGUIDDict.Add(rPath, rAtlasGUID);

                        rAtlasAsset = null;
                        EditorUtility.UnloadUnusedAssets( );
                    }

                    rAssetObject = AssetDatabase.LoadAssetAtPath(rPath, typeof(Uni2DAnimationClip));
                    if (rAssetObject != null)                           // It's an animation clip
                    {
                        Uni2DAnimationClip rAnimationClipAsset = (Uni2DAnimationClip)rAssetObject;
                        string             rAnimationClipGUID  = AssetDatabase.AssetPathToGUID(rPath);

                        foreach (string rTextureGUID in rAnimationClipAsset.GetAllFramesTextureGUIDs( ))
                        {
                            this.AddClipUsingTexture(rAnimationClipGUID, rTextureGUID);
                        }

                        m_oClipPathGUIDDict.Add(rPath, rAnimationClipGUID);

                        rAnimationClipAsset = null;
                        EditorUtility.UnloadUnusedAssets( );
                    }

                    rAssetObject = AssetDatabase.LoadAssetAtPath(rPath, typeof(GameObject));
                    if (rAssetObject != null)                           // It's a sprite prefab
                    {
                        GameObject    rPrefabAsset            = (GameObject)rAssetObject;
                        string        rPrefabGUID             = AssetDatabase.AssetPathToGUID(rPath);
                        Uni2DSprite[] rSpritePrefabComponents = rPrefabAsset.GetComponentsInChildren <Uni2DSprite>(true);

                        foreach (Uni2DSprite rSpritePrefabComponent in rSpritePrefabComponents)
                        {
                            Uni2DEditorSpriteSettings rSpriteSettings = rSpritePrefabComponent.SpriteSettings;

                            this.AddSpritePrefabUsingTexture(rPrefabGUID, rSpriteSettings.textureContainer.GUID);

                            if (rSpriteSettings.atlas != null)
                            {
                                this.AddSpritePrefabUsingAtlas(rPrefabGUID, Uni2DEditorUtils.GetUnityAssetGUID(rSpriteSettings.atlas));
                            }
                        }

                        rPrefabAsset            = null;
                        rSpritePrefabComponents = null;
                        EditorUtility.UnloadUnusedAssets( );
                    }
                }

                ++iProcessedAssets;
            }
        }
        finally
        {
            this.Save( );

            EditorUtility.UnloadUnusedAssets( );

            EditorUtility.SetDirty(this);
            EditorUtility.ClearProgressBar( );
        }

        //Debug.Log( "Uni2D Asset Table Rebuild: Done." );
    }
Esempio n. 21
0
 public void Clear(int size)
 {
     MultiValueDictionary<int, int> dict = CreateMVD(size);
     foreach (var iteration in Benchmark.Iterations)
     {
         MultiValueDictionary<int, int> copyDict = new MultiValueDictionary<int, int>(dict);
         using (iteration.StartMeasurement())
             copyDict.Clear();
     }
 }
Esempio n. 22
0
 internal void Clear()
 {
     _indicesCoverage.Clear();
 }
 public void Reset() => _roomsConnections.Clear();
Esempio n. 24
0
 public void Clear() => _dict.Clear();
Esempio n. 25
0
        /// <summary>
        /// Initialize the <see cref="NntpArticleBuilder"/> from the given <see cref="NntpArticle"/>.
        /// All properties are overwritten.
        /// </summary>
        /// <param name="article">The <see cref="NntpArticle"/> to initialize the <see cref="NntpArticleBuilder"/> with.</param>
        /// <returns>The <see cref="NntpArticleBuilder"/> so that additional calls can be chained.</returns>
        public NntpArticleBuilder InitializeFrom(NntpArticle article)
        {
            messageId = null;
            from      = null;
            subject   = null;

            headers.Clear();
            body.Clear();
            groups.Clear();

            foreach (KeyValuePair <string, ICollection <string> > header in article.Headers)
            {
                foreach (string value in header.Value)
                {
                    switch (header.Key)
                    {
                    case NntpHeaders.MessageId:
                        // skip additional messageid's
                        break;

                    case NntpHeaders.From:
                        if (from == null)
                        {
                            from = value;
                        }
                        break;

                    case NntpHeaders.Subject:
                        if (subject == null)
                        {
                            subject = value;
                        }
                        break;

                    case NntpHeaders.Date:
                        if (dateTime == null)
                        {
                            if (DateTimeOffset.TryParseExact(value, dateFormat, CultureInfo.InvariantCulture,
                                                             DateTimeStyles.None, out DateTimeOffset headerDateTime))
                            {
                                dateTime = headerDateTime;
                            }
                        }
                        break;

                    case NntpHeaders.Newsgroups:
                        // convert group header to list of groups, do not add as header
                        AddGroups(value);
                        break;

                    default:
                        headers.Add(header.Key, value);
                        break;
                    }
                }
            }

            body.AddRange(article.Body);
            messageId = article.MessageId;

            return(this);
        }
Esempio n. 26
0
        public static Automaton NfaToDfa(Automaton nfa, out MultiValueDictionary <State, State> dfaStatesToNfa)
        {
            var dfa = new Automaton();

            dfa.CaptureNames = nfa.CaptureNames;
            var dfaStartState = dfa.AddState();

            dfa.StartState = dfaStartState;
            var nfaTransitionsToDfa = new MultiValueDictionary <Transition, Transition>();
            var transitionClasses   = new List <Transition>();
            var mergeStates         = new HashSet <State>();

            dfaStatesToNfa = new MultiValueDictionary <State, State>();
            dfaStatesToNfa.Add(dfaStartState, nfa.StartState);
            //不动点算法,不能使用 foreach!
            for (int i = 0; i < dfa.States.Count; ++i)
            {
                var curDfaState = dfa.States[i];
                var nfaStates   = dfaStatesToNfa[curDfaState];
                foreach (var nfaState in nfaStates)
                {
                    foreach (var outTransition in nfaState.Output)
                    {
                        if (!nfaTransitionsToDfa.Values.SelectMany(transitions => transitions).Contains(outTransition))
                        {
                            transitionClasses.Add(outTransition);
                            nfaTransitionsToDfa.Add(outTransition, outTransition);
                        }
                    }
                }

                foreach (var transitionClass in transitionClasses)
                {
                    var nfaTransitions = nfaTransitionsToDfa[transitionClass];
                    foreach (var nfaTransition in nfaTransitions)
                    {
                        var state = nfaTransition.End;
                        if (!mergeStates.Contains(state))
                        {
                            mergeStates.Add(state);
                        }
                    }

                    mergeStates.OrderBy(state => state);

                    //mergeStates 是候选的一个 DFA 状态。在这之前,还需要判断:这个候选状态是否已经存在于 DFA 中了?
                    //var isContained = dfaStatesToNfa.Values.Contains((IReadOnlyCollection<State>)mergeStates);
                    State newDfaState = null;
                    foreach (var dfaState in dfaStatesToNfa.Keys)
                    {
                        var prevNfaStates = dfaStatesToNfa[dfaState];
                        if (prevNfaStates.Count == mergeStates.Count &&
                            prevNfaStates.SequenceEqual(mergeStates))
                        {
                            newDfaState = dfaState;
                            break;
                        }
                    }
                    if (newDfaState == null)
                    {
                        newDfaState = dfa.AddState();
                        dfaStatesToNfa.AddRange(newDfaState, mergeStates);
                        newDfaState.IsFinalState = mergeStates.Any(state => state.IsFinalState);
                    }

                    var dfaTransition = dfa.AddTransition(curDfaState, newDfaState, transitionClass.TransitionType);
                    dfaTransition.Capture = transitionClass.Capture;
                    dfaTransition.Range   = transitionClass.Range;
                    dfaTransition.Index   = transitionClass.Index;
                    mergeStates.Clear();
                }
                transitionClasses.Clear();
                nfaTransitionsToDfa.Clear();
            }

            return(dfa);
        }
Esempio n. 27
0
        public virtual void BasicOperationsTest()
        {
            var    data    = new MultiValueDictionary <TKey, TValue>();
            var    key0    = NextKey();
            var    key1    = NextKey();
            var    value00 = NextValue();
            var    value01 = NextValue();
            var    value10 = NextValue();
            var    value11 = NextValue();
            TValue v;

            TValue[] vs;
            var      xvs = new List <TValue>();

            // single key, single value
            data.Add(key0, value00);
            Assert.True(data.ContainsKey(key0));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value00)));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value01)));
            Assert.True(data.TryGetValue(key0, out v));
            Assert.Equal(value00, v);
            Assert.True(data.TryGetValues(key0, out vs));
            Assert.NotNull(vs);
            Assert.Single(vs, v);
            xvs.Clear();
            Assert.True(data.TryGetValues(key0, xvs));
            Assert.Single(xvs, v);
            var count = data.Count;

            Assert.Equal(1, count);
            count = data.Count();
            Assert.Equal(1, count);
            Assert.Single(data.Keys, key0);
            data.Clear();
            Assert.Empty(data);
            // single key, two values (added separately)
            data.Add(key0, value00);
            data.Add(key0, value01);
            Assert.True(data.ContainsKey(key0));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value00)));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value01)));
            Assert.True(data.TryGetValue(key0, out v));
            Assert.True(EqualityComparer <TValue> .Default.Equals(value00, v) || EqualityComparer <TValue> .Default.Equals(value01, v));
            Assert.True(data.TryGetValues(key0, out vs));
            Assert.NotNull(vs);
            Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue> {
                value00, value01
            }));
            xvs.Clear();
            Assert.True(data.TryGetValues(key0, xvs));
            count = xvs.Count;
            Assert.Equal(2, count);
            Assert.Contains(value00, xvs);
            Assert.Contains(value01, xvs);
            count = data.Count;
            Assert.Equal(2, count);
            count = data.Count();
            Assert.Equal(2, count);
            Assert.Single(data.Keys, key0);
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Remove(new KeyValuePair <TKey, TValue>(key0, value00)));
            count = data.Count;
            Assert.Equal(1, count);
            count = data.Count();
            Assert.Equal(1, count);
            data.Add(key0, value00);
            Assert.Equal(2, data.Remove(key0));
            Assert.Empty(data);
            // single key, two values (added as enumerable)
            data.Add(key0, value00, value01);
            Assert.True(data.ContainsKey(key0));
            Assert.True(data.TryGetValue(key0, out v));
            Assert.True(EqualityComparer <TValue> .Default.Equals(value00, v) || EqualityComparer <TValue> .Default.Equals(value01, v));
            Assert.True(data.TryGetValues(key0, out vs));
            Assert.NotNull(vs);
            Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue> {
                value00, value01
            }));
            count = data.Count;
            Assert.Equal(2, count);
            count = data.Count();
            Assert.Equal(2, count);
            Assert.Single(data.Keys, key0);
            data.Set(key0, value01);
            count = data.Count;
            Assert.Equal(1, count);
            count = data.Count();
            Assert.Equal(1, count);
            data.Set(key0, value00, value01);
            Assert.Equal(2, data.Remove(key0));
            Assert.Empty(data);
            // single key, two values (added as keyvalue pairs)
            ((ICollection <KeyValuePair <TKey, TValue> >)data).Add(new KeyValuePair <TKey, TValue>(key0, value00));
            ((ICollection <KeyValuePair <TKey, TValue> >)data).Add(new KeyValuePair <TKey, TValue>(key0, value01));
            Assert.True(data.ContainsKey(key0));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value00)));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value01)));
            Assert.True(data.TryGetValue(key0, out v));
            Assert.True(EqualityComparer <TValue> .Default.Equals(value00, v) || EqualityComparer <TValue> .Default.Equals(value01, v));
            Assert.True(data.TryGetValues(key0, out vs));
            Assert.NotNull(vs);
            Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue> {
                value00, value01
            }));
            count = data.Count;
            Assert.Equal(2, count);
            count = data.Count();
            Assert.Equal(2, count);
            Assert.Single(data.Keys, key0);
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Remove(new KeyValuePair <TKey, TValue>(key0, value00)));
            count = data.Count;
            Assert.Equal(1, count);
            count = data.Count();
            Assert.Equal(1, count);
            data.Add(key0, value00);
            Assert.Equal(2, data.Remove(key0));
            Assert.Empty(data);
            // two keys, two values (added separately)
            data.Add(key0, value00);
            data.Add(key0, value01);
            data.Add(key1, value10);
            data.Add(key1, value11);
            Assert.True(data.ContainsKey(key0));
            Assert.True(data.ContainsKey(key1));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value00)));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value01)));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key1, value10)));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key1, value11)));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key1, value00)));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key1, value01)));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value10)));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value11)));
            Assert.True(data.TryGetValue(key0, out v));
            Assert.True(EqualityComparer <TValue> .Default.Equals(value00, v) || EqualityComparer <TValue> .Default.Equals(value01, v));
            Assert.True(data.TryGetValues(key0, out vs));
            Assert.NotNull(vs);
            Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue> {
                value00, value01
            }));
            xvs.Clear();
            Assert.True(data.TryGetValues(key0, xvs));
            count = xvs.Count;
            Assert.Equal(2, count);
            Assert.Contains(value00, xvs);
            Assert.Contains(value01, xvs);
            Assert.True(data.TryGetValue(key1, out v));
            Assert.True(EqualityComparer <TValue> .Default.Equals(value10, v) || EqualityComparer <TValue> .Default.Equals(value11, v));
            Assert.True(data.TryGetValues(key1, out vs));
            Assert.NotNull(vs);
            Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue> {
                value10, value11
            }));
            xvs.Clear();
            Assert.True(data.TryGetValues(key1, xvs));
            count = xvs.Count;
            Assert.Equal(2, count);
            Assert.Contains(value10, xvs);
            Assert.Contains(value11, xvs);
            count = data.Count;
            Assert.Equal(4, count);
            count = data.Count();
            Assert.Equal(4, count);
            Assert.True(HashSet <TKey> .CreateSetComparer().Equals(new HashSet <TKey>(data.Keys), new HashSet <TKey> {
                key0, key1
            }));
            count = data.Keys.Count();
            Assert.Equal(2, count);
            Assert.Equal(2, data.Remove(key0));
            count = data.Count;
            Assert.Equal(2, count);
            count = data.Count();
            Assert.Equal(2, count);
            data.Clear();
            Assert.Empty(data);
        }
Esempio n. 28
0
        private void IndexBalances(ChainBase chain, string checkpointName, Func <uint256, Transaction, uint256, BlockHeader, int, IEnumerable <OrderedBalanceChange> > extract)
        {
            SetThrottling();
            BlockingCollection <OrderedBalanceChange[]> indexedEntries = new BlockingCollection <OrderedBalanceChange[]>(100);

            var tasks = CreateTaskPool(indexedEntries, (entries) => Index(entries.Select(e => e.ToEntity()), this.Configuration.GetBalanceTable()), 30);

            using (IndexerTrace.NewCorrelation("Import balances " + checkpointName + " to azure started").Open())
            {
                this.Configuration.GetBalanceTable().CreateIfNotExists();
                var buckets = new MultiValueDictionary <string, OrderedBalanceChange>();

                using (var storedBlocks = Enumerate(checkpointName, chain))
                {
                    foreach (var block in storedBlocks)
                    {
                        foreach (var tx in block.Block.Transactions)
                        {
                            var txId = tx.GetHash();
                            try
                            {
                                var entries = extract(txId, tx, block.BlockId, block.Block.Header, block.Height);

                                foreach (var entry in entries)
                                {
                                    buckets.Add(entry.PartitionKey, entry);
                                    var bucket = buckets[entry.PartitionKey];
                                    if (bucket.Count == 100)
                                    {
                                        indexedEntries.Add(bucket.ToArray());
                                        buckets.Remove(entry.PartitionKey);
                                    }
                                }

                                if (storedBlocks.NeedSave)
                                {
                                    foreach (var kv in buckets.AsLookup().ToArray())
                                    {
                                        indexedEntries.Add(kv.ToArray());
                                    }
                                    buckets.Clear();
                                    tasks.Stop();
                                    storedBlocks.SaveCheckpoint();
                                    tasks.Start();
                                }
                            }
                            catch (Exception ex)
                            {
                                IndexerTrace.ErrorWhileImportingBalancesToAzure(ex, txId);
                                throw;
                            }
                        }
                    }

                    foreach (var kv in buckets.AsLookup().ToArray())
                    {
                        indexedEntries.Add(kv.ToArray());
                    }
                    tasks.Stop();
                    storedBlocks.SaveCheckpoint();
                }
            }
        }