Beispiel #1
0
        public static void HandleRemove(MooNetClient client, bnet.protocol.friends.GenericFriendRequest request)
        {
            var removee = AccountManager.GetAccountByPersistentID(request.TargetId.Low);
            var remover = client.Account;

            var removeeAsFriend = bnet.protocol.friends.Friend.CreateBuilder().SetId(removee.BnetAccountID).Build();
            var removerAsFriend = bnet.protocol.friends.Friend.CreateBuilder().SetId(remover.BnetAccountID).Build();

            var removed = Friends.Remove(remover.BnetAccountID.Low, removeeAsFriend);

            if (!removed)
            {
                Logger.Warn("No friendship mapping between {0} and {1}", remover.BnetAccountID.Low, removeeAsFriend);
            }
            removed = Friends.Remove(removee.BnetAccountID.Low, removerAsFriend);
            if (!removed)
            {
                Logger.Warn("No friendship mapping between {0} and {1}", removee.BnetAccountID.Low, removerAsFriend);
            }
            RemoveFriendshipFromDB(remover, removee);

            var notifyRemover = bnet.protocol.friends.FriendNotification.CreateBuilder().SetTarget(removeeAsFriend).Build();

            client.MakeTargetedRPC(FriendManager.Instance, () =>
                                   bnet.protocol.friends.FriendsNotify.CreateStub(client).NotifyFriendRemoved(null, notifyRemover, callback => { }));

            if (removee.IsOnline)
            {
                var notifyRemovee = bnet.protocol.friends.FriendNotification.CreateBuilder().SetTarget(removerAsFriend).Build();
                removee.LoggedInClient.MakeTargetedRPC(FriendManager.Instance, () =>
                                                       bnet.protocol.friends.FriendsNotify.CreateStub(removee.LoggedInClient).NotifyFriendRemoved(null, notifyRemovee, callback => { }));
            }
        }
        public void Remove()
        {
            MultiDictionary<string, string> dictionary = new MultiDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            dictionary.Add("x", "x1");
            dictionary.Add("x", "x2");
            dictionary.Add("y", "y1");

            Assert.Equal(true, dictionary.Remove("x", "x1"));

            Assert.Equal(2, dictionary.KeyCount);
            Assert.Equal(2, dictionary.ValueCount);

            Assert.Equal(true, dictionary.Remove("x", "x2"));

            Assert.Equal(1, dictionary.KeyCount);
            Assert.Equal(1, dictionary.ValueCount);

            Assert.Equal(true, dictionary.Remove("y", "y1"));

            Assert.Equal(0, dictionary.KeyCount);
            Assert.Equal(0, dictionary.ValueCount);

            dictionary.Add("x", "x1");
            dictionary.Add("x", "x2");

            Assert.Equal(true, dictionary.Remove("x", "x2"));

            Assert.Equal(1, dictionary.KeyCount);
            Assert.Equal(1, dictionary.ValueCount);
        }
        public void Remove()
        {
            MultiDictionary <string, string> dictionary = new MultiDictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            dictionary.Add("x", "x1");
            dictionary.Add("x", "x2");
            dictionary.Add("y", "y1");

            Assert.Equal(true, dictionary.Remove("x", "x1"));

            Assert.Equal(2, dictionary.KeyCount);
            Assert.Equal(2, dictionary.ValueCount);

            Assert.Equal(true, dictionary.Remove("x", "x2"));

            Assert.Equal(1, dictionary.KeyCount);
            Assert.Equal(1, dictionary.ValueCount);

            Assert.Equal(true, dictionary.Remove("y", "y1"));

            Assert.Equal(0, dictionary.KeyCount);
            Assert.Equal(0, dictionary.ValueCount);

            dictionary.Add("x", "x1");
            dictionary.Add("x", "x2");

            Assert.Equal(true, dictionary.Remove("x", "x2"));

            Assert.Equal(1, dictionary.KeyCount);
            Assert.Equal(1, dictionary.ValueCount);
        }
Beispiel #4
0
        public void Test_Remove_Key_Failure()
        {
            var dictionary = new MultiDictionary <int, string> {
                { 3, "sun" }, { 2, "two" }, { 3, "three" }
            };

            Assert.AreEqual(false, dictionary.Remove(1));
            Assert.AreEqual(false, dictionary.Remove(4));
        }
Beispiel #5
0
    public void Unlisten <T>(Action <T> listener)
    {
        if (!actionMap.ContainsKey(listener))
        {
            return;
        }

        readListeners.Remove(typeof(T), actionMap[listener]);
        actionMap.Remove(listener);
    }
        /// <summary>
        /// Fires the events registered for given watcher.
        /// </summary>
        /// <param name="watcher">The watcher.</param>
        /// <param name="path">The path.</param>
        private static void fireEvents(FileSystemWatcher watcher, string path)
        {
            _watchers.Remove(path);
            watcher.Dispose();

            var eventsCopy = _registeredActions.Get(path).ToArray();

            foreach (var evt in eventsCopy)
            {
                _registeredActions.Remove(path, evt);

                evt();
            }
        }
Beispiel #7
0
        /// <summary>
        /// Clears the errors for a property.
        /// </summary>
        /// <param name="propertyName">The name of th property for which to clear errors.</param>
        /// <example>
        ///     container.ClearErrors("SomeProperty");
        /// </example>
        public void ClearErrors(string propertyName)
        {
            var name = propertyName ?? string.Empty;

            if (!_validationResults.Remove(name))
            {
                return;
            }

            if (_raiseErrorsChanged != null)
            {
                _raiseErrorsChanged(name);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool Remove(KeyT key)
        {
            bool bReturn = false;

            m_LockMultiDictionary.EnterWriteLock();
            {
                bReturn = m_MultiDictionary.Remove(key);

                m_bIsValueChange = true;
            }
            m_LockMultiDictionary.ExitWriteLock();

            return(bReturn);
        }
Beispiel #9
0
        public void DeleteEvents(string titleToDelete)
        {
            string title   = titleToDelete.ToLower();
            int    removed = 0;

            foreach (var eventToRemove in orderedByTitle[title])
            {
                removed++;
                orderedByTitle.Remove(eventToRemove);
            }

            orderedByTitle.Remove(title);

            messages.EventDeleted(removed);
        }
Beispiel #10
0
        public void RemoveNonExistent()
        {
            MultiDictionary <string, string> dictionary = new MultiDictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            dictionary.Add("x", "x1");
            dictionary.Add("x", "x2");
            dictionary.Add("y", "y1");

            Assert.Equal(false, dictionary.Remove("z", "y1"));
            Assert.Equal(false, dictionary.Remove("x", "y1"));
            Assert.Equal(false, dictionary.Remove("y", "y2"));

            Assert.Equal(2, dictionary.KeyCount);
            Assert.Equal(3, dictionary.ValueCount);
        }
        /// <summary>
        /// Adds the room to the construction and clears the open list of invalid entries.
        /// </summary>
        /// <param name="room"></param>
        private void CommitRoom(ProceduralRoom room)
        {
            // Add to the construction
            m_construction.AddRoom(room);

            foreach (var mount in room.MountPoints)
            {
                var attach = mount.AttachedTo;
                if (attach == null)
                {
                    m_openMountPoints.Enqueue(mount);
                    continue;
                }
                // Clear the open list of invalid entries
                foreach (var other in m_possibleRooms[mount])
                {
                    other.InFactor--;
                    if (other.InFactor == 0)
                    {
                        m_openRooms.Remove(other.Key);
                    }
                }
                m_possibleRooms.Remove(mount);
            }
            m_openRooms.Remove(new RoomKey(room.Transform, room.Part));
        }
Beispiel #12
0
        public void CanGetKeyCounts()
        {
            MultiDictionary <int, int, int> sums = new MultiDictionary <int, int, int>();

            const int MAX_X = 10;
            const int MAX_Y = 10;

            for (int i = 0; i < MAX_X; i++)
            {
                for (int j = 0; j < MAX_Y; j++)
                {
                    sums.Add(i, j, (i * 100) + j);
                }
            }

            int total = MAX_X * MAX_Y;

            Assert.AreEqual(total, sums.Keys.Count);


            // Now we will drop all of the items in the Dictionary...
            int removeCount = 0;

            for (int i = 0; i < MAX_X; i++)
            {
                for (int j = 0; j < MAX_Y; j++)
                {
                    sums.Remove(i, j);
                    removeCount++;
                    Assert.AreEqual(total - removeCount, sums.Keys.Count);
                }
            }
        }
        public void RemoveWithFirstKey(K1 key1)
        {
            if (!firstKeyDictionary.ContainsKey(key1))
            {
                throw new ArgumentException("Invalid key");
            }

            firstKeyDictionary.Remove(key1);
            ICollection <K2> key2 = firstSecondKeyDictionary[key1];

            foreach (var item in key2)
            {
                secondKeyDictionary.Remove(item);
                bothKeysDictionary.Remove(GetCompositeKey(key1, item));
            }
        }
Beispiel #14
0
        public void CanRemoveValues()
        {
            MultiDictionary <int, int, int> sums = new MultiDictionary <int, int, int>();

            const int MAX  = 10;
            int       half = MAX / 2;

            for (int i = 0; i < MAX; i++)
            {
                sums.Add(i, i, i);
            }
            Assert.AreEqual(MAX, sums.Values.Count);

            // Remove the first half of the items.  The actual contents of the values list will be compared when we are done.
            for (int i = 0; i < half; i++)
            {
                sums.Remove(i, i);
            }

            Assert.AreEqual(half, sums.Values.Count);
            for (int i = 0; i < half; i++)
            {
                Assert.AreEqual(i + half, sums[i + half, i + half]);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Resolves concepts that were waiting for this concept to be resolved.
        /// </summary>
        private void MarkResolvedConcept(ConceptDescription resolved)
        {
            _logger.Trace(() => "New concept with resolved references: " + resolved.Key);

            _resolvedConcepts.Add(resolved.Concept);
            _resolvedConceptsByKey.Add(resolved.Key, resolved.Concept);
            foreach (var index in _dslModelIndexes)
            {
                index.Add(resolved.Concept);
            }

            List <UnresolvedReference> unresolvedReferences;

            if (_unresolvedConceptsByReference.TryGetValue(resolved.Key, out unresolvedReferences))
            {
                foreach (var unresolved in unresolvedReferences)
                {
                    if (unresolved.Dependant.UnresolvedDependencies <= 0)
                    {
                        throw new FrameworkException($"Internal error while resolving references of '{unresolved.Dependant.Concept.GetUserDescription()}'."
                                                     + $" The concept has {unresolved.Dependant.UnresolvedDependencies} unresolved dependencies,"
                                                     + $" but it is marked as unresolved dependency to '{unresolved.ReferencedStub.GetUserDescription()}'.");
                    }

                    unresolved.Member.SetMemberValue(unresolved.Dependant.Concept, resolved.Concept);

                    if (--unresolved.Dependant.UnresolvedDependencies == 0)
                    {
                        MarkResolvedConcept(unresolved.Dependant);
                    }
                }

                _unresolvedConceptsByReference.Remove(resolved.Key);
            }
        }
Beispiel #16
0
            public string DeleteProductsByNameAndProducer(string productAndProducer)
            {
                if (!this.productsByNameAndProducer.ContainsKey(productAndProducer))
                {
                    return(notFound);
                }
                else
                {
                    HashSet <Product> productsToDelete = new HashSet <Product>(this.productsByNameAndProducer[productAndProducer]);
                    int           productsCount        = productsToDelete.Count;
                    StringBuilder sb = new StringBuilder();
                    foreach (var product in productsToDelete)
                    {
                        sb.Append(product.Name);
                        sb.Append(product.Producer);
                        productsByName.Remove(product.Name, product);
                        productsByPrice.Remove(product.Price, product);
                        productsByNameAndProducer.Remove(sb.ToString(), product);
                        productsByProducer.Remove(product.Producer, product);
                        sb = new StringBuilder();
                    }

                    return(string.Format("{0} products deleted", productsCount));
                }
            }
        /// <summary>
        /// Updates the command process.
        /// </summary>
        /// <param name="tokens">The tokens.</param>
        private static void UpdateCommandProcess(string line)
        {
            string[] urls   = line.Split(';');
            string   oldUrl = urls[0].Trim();
            string   newUrl = urls[1].Trim();

            if (contentUrls.ContainsKey(oldUrl))
            {
                int count = 0;//contentUrls[oldUrl].Count;
                foreach (var item in contentUrls[oldUrl].ToArray())
                {
                    contents.Remove(item.Title, item);
                    item.Url = newUrl;
                    contents.Add(item.Title, item);
                    count++;
                    contentUrls.Add(item.Url, item);
                }
                contentUrls.Remove(oldUrl);

                sb.AppendLine(count + " items updated");
            }
            else
            {
                sb.AppendLine("0 items updated");
            }
        }
Beispiel #18
0
    static string DeleteProducts(string[] parameters)
    {
        int result = 0;

        if (parameters.Length == 1)
        {
            var matchedProducts = productsByProducer[parameters[0]];

            foreach (var product in matchedProducts)
            {
                productsByName.Remove(product.Name, product);
                productsByNameAndProducer.Remove(
                    new Tuple <string, string>(product.Name, product.Producer),
                    product
                    );
                productsByPrice.Remove(product.Price, product);
            }

            result = matchedProducts.Count;
            productsByProducer.Remove(parameters[0]);
        }

        else if (parameters.Length == 2)
        {
            var nameAndProducer = new Tuple <string, string>(parameters[0], parameters[1]);

            var matchedProducts = productsByNameAndProducer[nameAndProducer];

            foreach (var product in matchedProducts)
            {
                productsByName.Remove(product.Name, product);
                productsByProducer.Remove(product.Producer, product);
                productsByPrice.Remove(product.Price, product);
            }

            result = matchedProducts.Count;
            productsByNameAndProducer.Remove(nameAndProducer);
        }

        if (result == 0)
        {
            return("No products found");
        }

        return(string.Format("{0} products deleted", result));
    }
Beispiel #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="nTriggerID"></param>
 public void RemoveAIEvent(BaseAIEvent aiEventInfo)
 {
     Monitor.Enter(m_LockAIEvent);
     {
         m_AIEvent.Remove(aiEventInfo.AIEventType, aiEventInfo);
     }
     Monitor.Exit(m_LockAIEvent);
 }
 /// <summary>
 /// Deletes a Triple from the Colleciton.
 /// </summary>
 /// <param name="t">Triple to remove.</param>
 /// <remarks>Deleting something that doesn't exist has no effect and gives no error.</remarks>
 protected internal override bool Delete(Triple t)
 {
     if (_triples.Remove(t))
     {
         RaiseTripleRemoved(t);
         return(true);
     }
     return(false);
 }
Beispiel #21
0
        public void Test_Remove_Last_Key()
        {
            var dictionary = new MultiDictionary <int, string> {
                { 3, "sun" }
            };

            Assert.AreEqual(1, dictionary.Count);
            Assert.AreEqual(true, dictionary.Remove(3));
            Assert.AreEqual(0, dictionary.Count);
        }
Beispiel #22
0
        public void Test_Dictionary_RemoveValue()
        {
            MultiDictionary <int, string> dictionary = new MultiDictionary <int, string> {
                { 1, "one" }, { 1, "ich" }
            };

            dictionary.Remove(1, "one");
            Assert.AreEqual(true, dictionary.Contains(1, "ich"));
            Assert.AreEqual(false, dictionary.Contains(1, "one"));
        }
Beispiel #23
0
 private static void RemoveEachProduct(ICollection <Product> productsToRemove)
 {
     foreach (var p in productsToRemove.ToList())
     {
         productsByName.Remove(p.Name, p);
         productsByPrice.Remove(p.Price, p);
         productsByProducer.Remove(p.Producer, p);
         productsByNameAndProducer.Remove(p.Name + "-" + p.Producer, p);
     }
 }
Beispiel #24
0
        public void Test_Dictionary_RemoveKey()
        {
            MultiDictionary <int, string> dictionary = new MultiDictionary <int, string> {
                { 1, "one" }, { 2, "two" }
            };

            dictionary.Remove(1);
            Assert.AreEqual(true, dictionary.ContainsKey(2));
            Assert.AreEqual(false, dictionary.ContainsKey(1));
        }
        /// <summary>
        /// Handler fired whenever component is removed.
        /// </summary>
        /// <param name="assembly">Assembly where component has been defined.</param>
        /// <param name="removedComponent">Information about removed component.</param>
        private void _onComponentRemoved(AssemblyProvider assembly, ComponentInfo removedComponent)
        {
            _assemblyComponents.Remove(assembly, removedComponent);
            _components.Remove(removedComponent.ComponentType);

            if (ComponentRemoved != null)
            {
                ComponentRemoved(removedComponent);
            }
        }
Beispiel #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        public int RemoveAll(Predicate <KeyT, ValueT> match)
        {
            MultiDictionary <KeyT, ValueT> tempMultiDictionary = m_MultiDictionary;

            if (tempMultiDictionary.Count <= 0)
            {
                return(0);
            }

            List <KeyValuePair <KeyT, ValueT> > removeList = new List <KeyValuePair <KeyT, ValueT> >(tempMultiDictionary.Count);

            foreach (KeyValuePair <KeyT, ICollection <ValueT> > keyValuePair in tempMultiDictionary)
            {
                foreach (ValueT valueItem in keyValuePair.Value)
                {
                    if (match(keyValuePair.Key, valueItem) == true)
                    {
                        removeList.Add(new KeyValuePair <KeyT, ValueT>(keyValuePair.Key, valueItem));
                    }
                }
            }

            if (removeList.Count <= 0)
            {
                return(0);
            }

            int iRemoveCount = 0;

            MultiDictionary <KeyT, ValueT> newMultiDict = null;
            MultiDictionary <KeyT, ValueT> oldMultiDict = null;

            do
            {
                iRemoveCount = 0;

                oldMultiDict = m_MultiDictionary;

                newMultiDict = new MultiDictionary <KeyT, ValueT>(m_AllowDuplicateValues);
                foreach (var item in oldMultiDict)
                {
                    newMultiDict.AddMany(item.Key, item.Value);
                }

                foreach (KeyValuePair <KeyT, ValueT> keyValuePair in removeList)
                {
                    if (newMultiDict.Remove(keyValuePair.Key, keyValuePair.Value) == true)
                    {
                        iRemoveCount++;
                    }
                }
            } while (Interlocked.CompareExchange <MultiDictionary <KeyT, ValueT> >(ref m_MultiDictionary, newMultiDict, oldMultiDict) != oldMultiDict);

            return(iRemoveCount);
        }
Beispiel #27
0
        public void RemoveKeyValuePass()
        {
            MultiDictionary <int, string> dictionary = new MultiDictionary <int, string>
            {
                { 2, "three" },
                { 1, "three" }
            };

            dictionary.Remove(2, "three");
            Assert.AreEqual(1, dictionary.Count);
        }
Beispiel #28
0
 /// <summary>
 /// 卸载模块
 /// </summary>
 /// <param name="factory"></param>
 private void UninstallModule(IRtpModuleFactory factory)
 {
     if (_modulesIndex.TryGetValue(factory, out var modules))
     {
         foreach (var module in modules)
         {
             module.Uninstall(this);
         }
         _modulesIndex.Remove(factory);
     }
 }
    public void RemoveEntity(Entity entity)
    {
        if (entity is Actor)
        {
            var actor = entity as Actor;
            _infoToActorMapping.Remove(actor.Info, actor);
        }

        _typeToEntityMapping.Remove(entity.GetType(), entity);
        _factionToEntityMapping.Remove(entity.FactionId, entity);
    }
Beispiel #30
0
        public void Remove_KeyValue_Success()
        {
            var multiDictionary = new MultiDictionary <int, string>
            {
                { 1, "one" },
                { 1, "ich" },
            };

            multiDictionary.Remove(1, "one");
            Assert.AreEqual(1, multiDictionary.Count);
        }
Beispiel #31
0
        public void Test_Remove_Value()
        {
            var dictionary = new MultiDictionary <int, string> {
                { 3, "sun" }, { 2, "two" }, { 3, "three" }
            };

            Assert.AreEqual(3, dictionary.Count);
            Assert.AreEqual(true, dictionary.Remove(3, "sun"));
            Assert.AreEqual(2, dictionary.Count);
            Assert.AreEqual(true, dictionary.ContainsKey(3));
        }
        public void Empty()
        {
            MultiDictionary<string, string> dictionary = new MultiDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            Assert.Equal(0, dictionary.KeyCount);
            Assert.Equal(0, dictionary.ValueCount);

            Assert.Equal(false, dictionary.Remove("x", "y"));

            foreach (string value in dictionary["x"])
            {
                Assert.True(false);
            }
        }
        public void RemoveNonExistent()
        {
            MultiDictionary<string, string> dictionary = new MultiDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            dictionary.Add("x", "x1");
            dictionary.Add("x", "x2");
            dictionary.Add("y", "y1");

            Assert.Equal(false, dictionary.Remove("z", "y1"));
            Assert.Equal(false, dictionary.Remove("x", "y1"));
            Assert.Equal(false, dictionary.Remove("y", "y2"));

            Assert.Equal(2, dictionary.KeyCount);
            Assert.Equal(3, dictionary.ValueCount);
        }
        public void MixedAddRemove()
        {
            MultiDictionary<string, string> dictionary = new MultiDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            dictionary.Add("x", "x1");
            dictionary.Remove("x", "x1");
            dictionary.Add("x", "x1");
            dictionary.Add("x", "x1");
            dictionary.Add("x", "x1");
            dictionary.Remove("x", "x1");
            dictionary.Remove("x", "x1");
            dictionary.Remove("x", "x1");
            dictionary.Add("x", "x2");

            Assert.Equal(1, dictionary.KeyCount);
            Assert.Equal(1, dictionary.ValueCount);

            List<string> values = Helpers.MakeList<string>(dictionary["x"]);

            Assert.Equal(1, values.Count);
            Assert.Equal("x2", values[0]);
        }
 private static void DeleteEvents(string command)
 {
     var events = new MultiDictionary<string, Event>(true);  ///added that to make it stop crashing too
     string title = command.Substring("DeleteEvents".Length + 1);
     events.Remove(title); 
 }