Remove() public method

public Remove ( object key ) : void
key object
return void
示例#1
0
        public void CountTests()
        {
            var d = new OrderedDictionary();
            Assert.Equal(0, d.Count);

            for (int i = 0; i < 1000; i++)
            {
                d.Add(i, i);
                Assert.Equal(i + 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d.Remove(i);
                Assert.Equal(1000 - i - 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d[(object)i] = i;
                Assert.Equal(i + 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d.RemoveAt(0);
                Assert.Equal(1000 - i - 1, d.Count);
            }
        }
        public void PassingEqualityComparers()
        {
            var eqComp = new CaseInsensitiveEqualityComparer();
            var d1 = new OrderedDictionary(eqComp);
            d1.Add("foo", "bar");
            Assert.Throws<ArgumentException>(() => d1.Add("FOO", "bar"));

            // The equality comparer should also test for a non-existent key 
            d1.Remove("foofoo");
            Assert.True(d1.Contains("foo"));

            // Make sure we can change an existent key that passes the equality comparer
            d1["FOO"] = "barbar";
            Assert.Equal("barbar", d1["foo"]);

            d1.Remove("FOO");
            Assert.False(d1.Contains("foo"));
        }
示例#3
0
		private void Common (OrderedDictionary od)
		{
			Assert.IsNotNull (od.GetEnumerator (), "GetEnumerator");
			Assert.AreEqual (0, od.Count, "Count-0");
			Assert.IsFalse (od.IsReadOnly, "IsReadOnly");
			od.Add ("a", "1");
			Assert.AreEqual (1, od.Count, "Count-1");
			od["a"] = "11";
			Assert.AreEqual ("11", od["a"], "this[string]");
			od[0] = "111";
			Assert.AreEqual ("111", od[0], "this[int]");

			DictionaryEntry[] array = new DictionaryEntry[2];
			od.CopyTo (array, 1);

			Assert.AreEqual ("111", ((DictionaryEntry)array[1]).Value, "CopyTo");
			Assert.AreEqual (1, od.Keys.Count, "Keys");
			Assert.AreEqual (1, od.Values.Count, "Values");
			Assert.IsTrue (od.Contains ("a"), "Contains(a)");
			Assert.IsFalse (od.Contains ("111"), "Contains(111)");

			od.Insert (0, "b", "2");
			Assert.AreEqual (2, od.Count, "Count-2");
			od.Add ("c", "3");
			Assert.AreEqual (3, od.Count, "Count-3");

			OrderedDictionary ro = od.AsReadOnly ();

			od.RemoveAt (2);
			Assert.AreEqual (2, od.Count, "Count-4");
			Assert.IsFalse (od.Contains ("c"), "Contains(c)");

			od.Remove ("b");
			Assert.AreEqual (1, od.Count, "Count-5");
			Assert.IsFalse (od.Contains ("b"), "Contains(b)");

			od.Clear ();
			Assert.AreEqual (0, od.Count, "Count-6");

			Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
			// it's a read-only reference
			Assert.AreEqual (0, od.Count, "Count-7");
		}
        /// <devdoc>
        ///     Metdata filtering is the third stage of our pipeline.  
        ///     In this stage we check to see if the given object is a
        ///     sited component that provides the ITypeDescriptorFilterService
        ///     object.  If it does, we allow the TDS to filter the metadata.
        ///     This will use the cache, if available, to store filtered
        ///     metdata.
        /// </devdoc>
        private static ICollection PipelineFilter(int pipelineType, ICollection members, object instance, IDictionary cache)
        {
            IComponent component = instance as IComponent;
            ITypeDescriptorFilterService componentFilter = null;

            if (component != null)
            {
                ISite site = component.Site;
                if (site != null)
                {
                    componentFilter = site.GetService(typeof(ITypeDescriptorFilterService)) as ITypeDescriptorFilterService;
                }
            }

            // If we have no filter, there is nothing for us to do.
            //
            IList list = members as ArrayList;

            if (componentFilter == null)
            {
                Debug.Assert(cache == null || list == null || !cache.Contains(_pipelineFilterKeys[pipelineType]), "Earlier pipeline stage should have removed our cache");
                return members;
            }

            // Now, check our cache.  The cache state is only valid
            // if the data coming into us is read-only.  If it is read-write,
            // that means something higher in the pipeline has already changed
            // it so we must recompute anyway.
            //
            if (cache != null && (list == null || list.IsReadOnly))
            {
                FilterCacheItem cacheItem = cache[_pipelineFilterKeys[pipelineType]] as FilterCacheItem;
                if (cacheItem != null && cacheItem.IsValid(componentFilter)) {
                    return cacheItem.FilteredMembers;
                }
            }

            // Cache either is dirty or doesn't exist.  Re-filter the members.
            // We need to build an IDictionary of key->value pairs and invoke
            // Filter* on the filter service.
            //
            OrderedDictionary filterTable = new OrderedDictionary(members.Count);
            bool cacheResults;

            switch(pipelineType)
            {
                case PIPELINE_ATTRIBUTES:
                    foreach(Attribute attr in members)
                    {
                        filterTable[attr.TypeId] = attr;
                    }
                    cacheResults = componentFilter.FilterAttributes(component, filterTable);
                    break;

                case PIPELINE_PROPERTIES:
                case PIPELINE_EVENTS:
                    foreach(MemberDescriptor desc in members)
                    {
                        string descName = desc.Name;
                        // We must handle the case of duplicate property names
                        // because extender providers can provide any arbitrary
                        // name.  Our rule for this is simple:  If we find a
                        // duplicate name, resolve it back to the extender
                        // provider that offered it and append "_" + the
                        // provider name.  If the provider has no name,
                        // then append the object hash code.
                        //
                        if (filterTable.Contains(descName)) 
                        {
                            // First, handle the new property.  Because
                            // of the order in which we added extended
                            // properties earlier in the pipeline, we can be 
                            // sure that the new property is an extender.  We
                            // cannot be sure that the existing property
                            // in the table is an extender, so we will 
                            // have to check.
                            //
                            string suffix = GetExtenderCollisionSuffix(desc);
                            Debug.Assert(suffix != null, "Name collision with non-extender property.");
                            if (suffix != null) 
                            {
                                filterTable[descName + suffix] = desc;
                            }

                            // Now, handle the original property.
                            //
                            MemberDescriptor origDesc = (MemberDescriptor)filterTable[descName];
                            suffix = GetExtenderCollisionSuffix(origDesc);
                            if (suffix != null) 
                            {
                                filterTable.Remove(descName);
                                filterTable[origDesc.Name + suffix] = origDesc;
                            }
                        }
                        else 
                        {
                            filterTable[descName] = desc;
                        }
                    }
                    if (pipelineType == PIPELINE_PROPERTIES)
                    {
                        cacheResults = componentFilter.FilterProperties(component, filterTable);
                    }
                    else
                    {
                        cacheResults = componentFilter.FilterEvents(component, filterTable);
                    }
                    break;

                default:
                    Debug.Fail("unknown pipeline type");
                    cacheResults = false;
                    break;
            }

            // See if we can re-use the IList were were passed.  If we can,
            // it is more efficient to re-use its slots than to generate new ones.
            //
            if (list == null || list.IsReadOnly)
            {
                Trace("Pipeline : Filter needs to create member list for {0}", instance.GetType().Name);
                list = new ArrayList(filterTable.Values);
            }
            else
            {
                list.Clear();
                foreach(object obj in filterTable.Values)
                {
                    list.Add(obj);
                }
            }

            // Component filter has requested that we cache these
            // new changes.  We store them as a correctly typed collection
            // so on successive invocations we can simply return.  Note that
            // we always return the IList so that successive stages in the
            // pipeline can modify it.
            //
            if (cacheResults && cache != null)
            {
                ICollection cacheValue;

                switch(pipelineType)
                {
                    case PIPELINE_ATTRIBUTES:
                        Attribute[] attrArray = new Attribute[list.Count];
                        try
                        {
                            list.CopyTo(attrArray, 0);
                        }
                        catch(InvalidCastException)
                        {
                            throw new ArgumentException(SR.GetString(SR.TypeDescriptorExpectedElementType, typeof(Attribute).FullName));
                        }
                        cacheValue = new AttributeCollection(attrArray);
                        break;

                    case PIPELINE_PROPERTIES:
                        PropertyDescriptor[] propArray = new PropertyDescriptor[list.Count];
                        try
                        {
                            list.CopyTo(propArray, 0);
                        }
                        catch(InvalidCastException)
                        {
                            throw new ArgumentException(SR.GetString(SR.TypeDescriptorExpectedElementType, typeof(PropertyDescriptor).FullName));
                        }
                        cacheValue = new PropertyDescriptorCollection(propArray, true);
                        break;

                    case PIPELINE_EVENTS:
                        EventDescriptor[] eventArray = new EventDescriptor[list.Count];
                        try
                        {
                            list.CopyTo(eventArray, 0);
                        }
                        catch(InvalidCastException)
                        {
                            throw new ArgumentException(SR.GetString(SR.TypeDescriptorExpectedElementType, typeof(EventDescriptor).FullName));
                        }
                        cacheValue = new EventDescriptorCollection(eventArray, true);
                        break;

                    default:
                        Debug.Fail("unknown pipeline type");
                        cacheValue = null;
                        break;
                }

                Trace("Pipeline : Filter results being cached for {0}", instance.GetType().Name);

                FilterCacheItem cacheItem = new FilterCacheItem(componentFilter, cacheValue);
                cache[_pipelineFilterKeys[pipelineType]] = cacheItem;
                cache.Remove(_pipelineAttributeFilterKeys[pipelineType]);
            }

            return list;
        }
示例#5
0
        public void RemoveAtTests()
        {
            var d = new OrderedDictionary();

            Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(0));
            Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(-1));
            Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(5));

            Assert.Throws<ArgumentNullException>(() => d.Remove(null));

            for (var i = 0; i < 1000; i++)
            {
                d.Add("foo_" + i, "bar_" + i);
            }
            for (var i = 0; i < 1000; i++)
            {
                d.RemoveAt(1000 - i - 1);
                Assert.Equal(1000 - i - 1, d.Count);
            }
            for (var i = 0; i < 1000; i++)
            {
                d.Add("foo_" + i, "bar_" + i);
            }
            for (var i = 0; i < 1000; i++)
            {
                Assert.Equal("bar_" + i, d[0]);
                d.RemoveAt(0);
                Assert.Equal(1000 - i - 1, d.Count);
            }
        }
示例#6
0
        public void RemoveTests()
        {
            var d = new OrderedDictionary();

            // should work
            d.Remove("asd");

            Assert.Throws<ArgumentNullException>(() => d.Remove(null));

            for (var i = 0; i < 1000; i++)
            {
                d.Add("foo_" + i, "bar_" + i);
            }
            for (var i = 0; i < 1000; i++)
            {
                Assert.True(d.Contains("foo_" + i));
                d.Remove("foo_" + i);
                Assert.False(d.Contains("foo_" + i));
                Assert.Equal(1000 - i - 1, d.Count);
            }
        }
示例#7
0
        private void playQueueContents(OrderedDictionary queueToPlay, Boolean isImmediateMessages)
        {
            long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            List<String> keysToPlay = new List<String>();
            List<String> soundsProcessed = new List<String>();
            lock (queueToPlay)
            {
                foreach (String key in queueToPlay.Keys)
                {
                    QueuedMessage queuedMessage = (QueuedMessage)queueToPlay[key];
                    if (queuedMessage.dueTime <= milliseconds)
                    {
                        if ((queuedMessage.abstractEvent == null || queuedMessage.abstractEvent.isClipStillValid(key)) &&
                            !keysToPlay.Contains(key) && (!queuedMessage.gapFiller || playGapFillerMessage()) &&
                            (queuedMessage.expiryTime == 0  || queuedMessage.expiryTime > milliseconds))
                        {
                            keysToPlay.Add(key);
                        }
                        else
                        {
                            Console.WriteLine("Clip " + key + " is not valid");
                            soundsProcessed.Add(key);
                        }
                    }
                }
                if (keysToPlay.Count > 0)
                {
                    Boolean oneOrMoreEventsEnabled = false;
                    if (keysToPlay.Count == 1 && clipIsPearlOfWisdom(keysToPlay[0]) && hasPearlJustBeenPlayed())
                    {
                        Console.WriteLine("Rejecting pearl of wisdom " + keysToPlay[0] +
                            " because one has been played in the last " + minTimeBetweenPearlsOfWisdom + " seconds");
                        soundsProcessed.Add(keysToPlay[0]);
                    }
                    else
                    {
                        foreach (String eventName in keysToPlay)
                        {
                            if ((eventName.StartsWith(QueuedMessage.compoundMessageIdentifier) &&
                                ((QueuedMessage)queuedClips[eventName]).isValid) || enabledSounds.Contains(eventName))
                            {
                                oneOrMoreEventsEnabled = true;
                            }
                        }
                    }

                    if (oneOrMoreEventsEnabled)
                    {
                        openRadioChannelInternal();
                        soundsProcessed.AddRange(playSounds(keysToPlay, isImmediateMessages));
                    }
                    else
                    {
                        Console.WriteLine("All events are disabled");
                    }
                    // only close the channel if we've processed the entire queue
                    /*Console.WriteLine("Can we close? " + !isImmediateMessages + ", " + soundsProcessed.Count + ", " + keysToPlay.Count);
                    if (!isImmediateMessages && soundsProcessed.Count == keysToPlay.Count && !holdChannelOpen)
                    {
                        closeRadioInternalChannel();
                    }*/
                    Console.WriteLine("finished playing");
                }
                foreach (String key in soundsProcessed)
                {
                    Console.WriteLine("Removing {0} from queue", key);
                    queueToPlay.Remove(key);
                }
            }
        }
示例#8
0
        private bool HandleCommand(string commandName) {
            DataSourceView view = null;

            if (IsDataBindingAutomatic) {
                view = GetData();
                if (view == null) {
                    throw new HttpException(SR.GetString(SR.View_DataSourceReturnedNullView, ID));
                }
            }
            else {
                return false;
            }

            if (!view.CanExecute(commandName)) {
                return false;
            }
            
            OrderedDictionary values = new OrderedDictionary();
            OrderedDictionary keys = new OrderedDictionary();

            ExtractRowValues(values, true /*includeReadOnlyFields*/, false /*includePrimaryKey*/);
            foreach (DictionaryEntry entry in DataKey.Values) {
                keys.Add(entry.Key, entry.Value);
                if (values.Contains(entry.Key)) {
                    values.Remove(entry.Key);
                }
            }

            view.ExecuteCommand(commandName, keys, values, HandleCommandCallback);
            return true;
        }
示例#9
0
        private bool HandleCommand(ListViewItem item, int itemIndex, string commandName) {
            DataSourceView view = null;

            if (IsDataBindingAutomatic) {
                view = GetData();
                if (view == null) {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.ListView_NullView, ID));
                }
            }
            else {
                return false;
            }

            if (!view.CanExecute(commandName)) {
                return false;
            }

            ListViewDataItem dataItem = item as ListViewDataItem;
            if (itemIndex < 0 && dataItem == null) {
                throw new InvalidOperationException(AtlasWeb.ListView_InvalidCommand);
            }

            OrderedDictionary values = new OrderedDictionary();
            OrderedDictionary keys = new OrderedDictionary();
            if (item != null) {
                ExtractItemValues(values, item, false /*includePrimaryKey*/);
            }

            if (DataKeys.Count > itemIndex) {
                foreach (DictionaryEntry entry in DataKeys[itemIndex].Values) {
                    keys.Add(entry.Key, entry.Value);
                    if (values.Contains(entry.Key)) {
                        values.Remove(entry.Key);
                    }
                }
            }
            
            view.ExecuteCommand(commandName, keys, values, HandleCommandCallback);
            return true;
        }
        private static ICollection PipelineFilter(int pipelineType, ICollection members, object instance, IDictionary cache)
        {
            bool flag;
            IComponent component = instance as IComponent;
            ITypeDescriptorFilterService filterService = null;
            if (component != null)
            {
                ISite site = component.Site;
                if (site != null)
                {
                    filterService = site.GetService(typeof(ITypeDescriptorFilterService)) as ITypeDescriptorFilterService;
                }
            }
            IList list = members as ArrayList;
            if (filterService == null)
            {
                return members;
            }
            if ((cache != null) && ((list == null) || list.IsReadOnly))
            {
                FilterCacheItem item = cache[_pipelineFilterKeys[pipelineType]] as FilterCacheItem;
                if ((item != null) && item.IsValid(filterService))
                {
                    return item.FilteredMembers;
                }
            }
            OrderedDictionary attributes = new OrderedDictionary(members.Count);
            switch (pipelineType)
            {
                case 0:
                    foreach (Attribute attribute in members)
                    {
                        attributes[attribute.TypeId] = attribute;
                    }
                    flag = filterService.FilterAttributes(component, attributes);
                    break;

                case 1:
                case 2:
                    foreach (MemberDescriptor descriptor in members)
                    {
                        string name = descriptor.Name;
                        if (attributes.Contains(name))
                        {
                            string extenderCollisionSuffix = GetExtenderCollisionSuffix(descriptor);
                            if (extenderCollisionSuffix != null)
                            {
                                attributes[name + extenderCollisionSuffix] = descriptor;
                            }
                            MemberDescriptor member = (MemberDescriptor) attributes[name];
                            extenderCollisionSuffix = GetExtenderCollisionSuffix(member);
                            if (extenderCollisionSuffix != null)
                            {
                                attributes.Remove(name);
                                attributes[member.Name + extenderCollisionSuffix] = member;
                            }
                        }
                        else
                        {
                            attributes[name] = descriptor;
                        }
                    }
                    if (pipelineType == 1)
                    {
                        flag = filterService.FilterProperties(component, attributes);
                    }
                    else
                    {
                        flag = filterService.FilterEvents(component, attributes);
                    }
                    break;

                default:
                    flag = false;
                    break;
            }
            if ((list == null) || list.IsReadOnly)
            {
                list = new ArrayList(attributes.Values);
            }
            else
            {
                list.Clear();
                foreach (object obj2 in attributes.Values)
                {
                    list.Add(obj2);
                }
            }
            if (flag && (cache != null))
            {
                ICollection is2;
                switch (pipelineType)
                {
                    case 0:
                    {
                        Attribute[] array = new Attribute[list.Count];
                        try
                        {
                            list.CopyTo(array, 0);
                        }
                        catch (InvalidCastException)
                        {
                            throw new ArgumentException(SR.GetString("TypeDescriptorExpectedElementType", new object[] { typeof(Attribute).FullName }));
                        }
                        is2 = new AttributeCollection(array);
                        break;
                    }
                    case 1:
                    {
                        PropertyDescriptor[] descriptorArray = new PropertyDescriptor[list.Count];
                        try
                        {
                            list.CopyTo(descriptorArray, 0);
                        }
                        catch (InvalidCastException)
                        {
                            throw new ArgumentException(SR.GetString("TypeDescriptorExpectedElementType", new object[] { typeof(PropertyDescriptor).FullName }));
                        }
                        is2 = new PropertyDescriptorCollection(descriptorArray, true);
                        break;
                    }
                    case 2:
                    {
                        EventDescriptor[] descriptorArray2 = new EventDescriptor[list.Count];
                        try
                        {
                            list.CopyTo(descriptorArray2, 0);
                        }
                        catch (InvalidCastException)
                        {
                            throw new ArgumentException(SR.GetString("TypeDescriptorExpectedElementType", new object[] { typeof(EventDescriptor).FullName }));
                        }
                        is2 = new EventDescriptorCollection(descriptorArray2, true);
                        break;
                    }
                    default:
                        is2 = null;
                        break;
                }
                FilterCacheItem item2 = new FilterCacheItem(filterService, is2);
                cache[_pipelineFilterKeys[pipelineType]] = item2;
                cache.Remove(_pipelineAttributeFilterKeys[pipelineType]);
            }
            return list;
        }
示例#11
0
		public void ReadOnly_Remove ()
		{
			OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
			od.Remove ("a");
		}
示例#12
0
        public void AsReadOnly_AttemptingToModifyDictionary_Throws()
        {
            OrderedDictionary orderedDictionary = new OrderedDictionary().AsReadOnly();
            Assert.Throws<NotSupportedException>(() => orderedDictionary[0] = "value");
            Assert.Throws<NotSupportedException>(() => orderedDictionary["key"] = "value");
 
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Add("key", "value"));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Insert(0, "key", "value"));
 
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Remove("key"));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.RemoveAt(0));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Clear());
        }
示例#13
0
        private void playQueueContents(OrderedDictionary queueToPlay, Boolean isImmediateMessages)
        {
            long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            List<String> keysToPlay = new List<String>();
            List<String> soundsProcessed = new List<String>();

            Boolean oneOrMoreEventsEnabled = false;
            lock (queueToPlay)
            {
                int willBePlayedCount = queueToPlay.Count;
                foreach (String key in queueToPlay.Keys)
                {
                    QueuedMessage queuedMessage = (QueuedMessage)queueToPlay[key];
                    if (isImmediateMessages || queuedMessage.dueTime <= milliseconds)
                    {
                        Boolean messageHasExpired = queuedMessage.expiryTime != 0 && queuedMessage.expiryTime < milliseconds;
                        Boolean messageIsStillValid = queuedMessage.isMessageStillValid(key, crewChief.currentGameState);
                        Boolean queueTooLongForMessage = queuedMessage.maxPermittedQueueLengthForMessage != 0 && willBePlayedCount > queuedMessage.maxPermittedQueueLengthForMessage;
                        if ((isImmediateMessages || !keepQuiet || queuedMessage.playEvenWhenSilenced) && queuedMessage.canBePlayed &&
                            messageIsStillValid && !keysToPlay.Contains(key) && !queueTooLongForMessage && !messageHasExpired)
                        {
                            keysToPlay.Add(key);
                        }
                        else
                        {
                            if (!messageIsStillValid)
                            {
                                Console.WriteLine("Clip " + key + " is not valid");
                            }
                            else if (messageHasExpired)
                            {
                                Console.WriteLine("Clip " + key + " has expired");
                            }
                            else if (queueTooLongForMessage)
                            {
                                List<String> keysToDisplay = new List<string>();
                                foreach (String keyToDisplay in queueToPlay.Keys)
                                {
                                    keysToDisplay.Add(keyToDisplay);
                                }
                                Console.WriteLine("Queue is too long to play clip " + key + " max permitted items for this message = "
                                    + queuedMessage.maxPermittedQueueLengthForMessage + " queue: " + String.Join(", ", keysToDisplay));
                            }
                            else if (!queuedMessage.canBePlayed)
                            {
                                Console.WriteLine("Clip " + key + " has some missing sound files");
                            }
                            soundsProcessed.Add(key);
                            willBePlayedCount--;
                        }
                    }
                }
                if (keysToPlay.Count > 0)
                {
                    if (keysToPlay.Count == 1 && clipIsPearlOfWisdom(keysToPlay[0]))
                    {
                        if (hasPearlJustBeenPlayed())
                        {
                            Console.WriteLine("Rejecting pearl of wisdom " + keysToPlay[0] +
                                " because one has been played in the last " + minTimeBetweenPearlsOfWisdom + " seconds");
                            soundsProcessed.Add(keysToPlay[0]);
                        }
                        else if (disablePearlsOfWisdom)
                        {
                            Console.WriteLine("Rejecting pearl of wisdom " + keysToPlay[0] +
                                   " because pearls have been disabled for the last phase of the race");
                            soundsProcessed.Add(keysToPlay[0]);
                        }
                    }
                    else
                    {
                        oneOrMoreEventsEnabled = true;
                    }
                }
            }
            Boolean wasInterrupted = false;
            if (oneOrMoreEventsEnabled)
            {
                // block for immediate messages...
                if (isImmediateMessages)
                {
                    lock (queueToPlay)
                    {
                        openRadioChannelInternal();
                        soundsProcessed.AddRange(playSounds(keysToPlay, isImmediateMessages, out wasInterrupted));
                    }
                }
                else
                {
                    // for queued messages, allow other messages to be inserted into the queue while these are being read
                    openRadioChannelInternal();
                    soundsProcessed.AddRange(playSounds(keysToPlay, isImmediateMessages, out wasInterrupted));
                }
            }
            else
            {
                soundsProcessed.AddRange(keysToPlay);
            }
            if (soundsProcessed.Count > 0)
            {
                lock (queueToPlay)
                {
                    foreach (String key in soundsProcessed)
                    {
                        if (queueToPlay.Contains(key))
                        {
                            queueToPlay.Remove(key);
                        }
                    }
                }
            }
            if (queueHasDueMessages(queueToPlay, isImmediateMessages) && !wasInterrupted && !isImmediateMessages)
            {
                Console.WriteLine("There are " + queueToPlay.Count + " more events in the queue, playing them...");
                playQueueContents(queueToPlay, isImmediateMessages);
            }
        }
示例#14
0
        private void playQueueContents(OrderedDictionary queueToPlay, Boolean isImmediateMessages)
        {
            long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            List<String> keysToPlay = new List<String>();
            List<String> soundsProcessed = new List<String>();

            Boolean oneOrMoreEventsEnabled = false;
            if (queueToPlay.Count > 0)
            {
                Console.WriteLine("Processing queue of " + queueToPlay.Count + " event(s)");
            }
            lock (queueToPlay)
            {
                foreach (String key in queueToPlay.Keys)
                {
                    QueuedMessage queuedMessage = (QueuedMessage)queueToPlay[key];
                    if (isImmediateMessages || queuedMessage.dueTime <= milliseconds)
                    {
                        if ((isImmediateMessages || !keepQuiet) &&
                            (queuedMessage.abstractEvent == null || queuedMessage.abstractEvent.isClipStillValid(key)) &&
                            !keysToPlay.Contains(key) && (!queuedMessage.gapFiller || playGapFillerMessage(queueToPlay)) &&
                            (queuedMessage.expiryTime == 0 || queuedMessage.expiryTime > milliseconds))
                        {
                            keysToPlay.Add(key);
                        }
                        else
                        {
                            Console.WriteLine("Clip " + key + " is not valid");
                            soundsProcessed.Add(key);
                        }
                    }
                }
                if (keysToPlay.Count > 0)
                {
                    if (keysToPlay.Count == 1 && clipIsPearlOfWisdom(keysToPlay[0]) && hasPearlJustBeenPlayed())
                    {
                        Console.WriteLine("Rejecting pearl of wisdom " + keysToPlay[0] +
                            " because one has been played in the last " + minTimeBetweenPearlsOfWisdom + " seconds");
                        soundsProcessed.Add(keysToPlay[0]);
                    }
                    else
                    {
                        foreach (String eventName in keysToPlay)
                        {
                            if ((eventName.StartsWith(QueuedMessage.compoundMessageIdentifier) &&
                                ((QueuedMessage)queueToPlay[eventName]).isValid) || enabledSounds.Contains(eventName))
                            {
                                oneOrMoreEventsEnabled = true;
                            }
                        }
                    }
                }
                if (queueToPlay.Count > 0 && keysToPlay.Count == 0)
                {
                    Console.WriteLine("None of the " + queueToPlay.Count + " message(s) in this queue is due or valid");
                }
            }
            Boolean wasInterrupted = false;
            if (oneOrMoreEventsEnabled)
            {
                // block for immediate messages...
                if (isImmediateMessages)
                {
                    lock (queueToPlay)
                    {
                        openRadioChannelInternal();
                        soundsProcessed.AddRange(playSounds(keysToPlay, isImmediateMessages, out wasInterrupted));
                    }
                }
                else
                {
                    // for queued messages, allow other messages to be inserted into the queue while these are being read
                    openRadioChannelInternal();
                    soundsProcessed.AddRange(playSounds(keysToPlay, isImmediateMessages, out wasInterrupted));
                }
            }
            else
            {
                soundsProcessed.AddRange(keysToPlay);
            }
            if (soundsProcessed.Count > 0)
            {
                lock (queueToPlay)
                {
                    foreach (String key in soundsProcessed)
                    {
                        if (queueToPlay.Contains(key))
                        {
                            queueToPlay.Remove(key);
                        }
                    }
                }
            }
            if (queueHasDueMessages(queueToPlay, isImmediateMessages) && !wasInterrupted && !isImmediateMessages)
            {
                Console.WriteLine("There are " + queueToPlay.Count + " more events in the queue, playing them...");
                playQueueContents(queueToPlay, isImmediateMessages);
            }
        }
 private bool HandleCommand(string commandName)
 {
     DataSourceView data = null;
     if (base.IsBoundUsingDataSourceID)
     {
         data = this.GetData();
         if (data == null)
         {
             throw new HttpException(System.Web.SR.GetString("View_DataSourceReturnedNullView", new object[] { this.ID }));
         }
     }
     else
     {
         return false;
     }
     if (!data.CanExecute(commandName))
     {
         return false;
     }
     OrderedDictionary fieldValues = new OrderedDictionary();
     OrderedDictionary keys = new OrderedDictionary();
     this.ExtractRowValues(fieldValues, true, false);
     foreach (DictionaryEntry entry in this.DataKey.Values)
     {
         keys.Add(entry.Key, entry.Value);
         if (fieldValues.Contains(entry.Key))
         {
             fieldValues.Remove(entry.Key);
         }
     }
     data.ExecuteCommand(commandName, keys, fieldValues, new DataSourceViewOperationCallback(this.HandleCommandCallback));
     return true;
 }