MessageQueueCriteria 类

定义

当执行查询时使用 MessageQueue 类的 GetPublicQueues() 方法筛选消息队列。Filters message queues when performing a query using the MessageQueue class's GetPublicQueues() method.

public ref class MessageQueueCriteria
public class MessageQueueCriteria
type MessageQueueCriteria = class
Public Class MessageQueueCriteria
继承
MessageQueueCriteria

示例

下面的示例循环访问消息队列,并显示在最后一天中创建并且存在于计算机 "MyComputer" 上的每个队列的路径。The following example iterates through message queues and displays the path of each queue that was created in the last day and that exists on the computer "MyComputer".

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:

   // Iterates through message queues and displays the
   // path of each queue that was created in the last
   // day and that exists on the computer "MyComputer". 
   void ListPublicQueuesByCriteria()
   {
      UInt32 numberQueues = 0;
      
      // Specify the criteria to filter by.
      MessageQueueCriteria^ myCriteria = gcnew MessageQueueCriteria;
      myCriteria->MachineName = "MyComputer";
      myCriteria->CreatedAfter = DateTime::Now.Subtract( TimeSpan(1,0,0,0) );
      
      // Get a cursor into the queues on the network.
      MessageQueueEnumerator^ myQueueEnumerator = MessageQueue::GetMessageQueueEnumerator( myCriteria );
      
      // Move to the next queue and read its path.
      while ( myQueueEnumerator->MoveNext() )
      {
         
         // Increase the count if priority is Lowest.
         Console::WriteLine( myQueueEnumerator->Current->Path );
         numberQueues++;
      }

      
      // Handle no queues matching the criteria.
      if ( numberQueues == 0 )
      {
         Console::WriteLine( "No public queues match criteria." );
      }

      return;
   }

};

int main()
{
   
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;
   
   // Output the count of Lowest priority messages.
   myNewQueue->ListPublicQueuesByCriteria();
   return 0;
}

using System;
using System.Messaging;

namespace MyProject
{
    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //		
        // This example uses a cursor to step through the
        // message queues and list the public queues on the
        // network that specify certain criteria.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Output the count of Lowest priority messages.
            myNewQueue.ListPublicQueuesByCriteria();
                        
            return;
        }

        //**************************************************
        // Iterates through message queues and displays the
        // path of each queue that was created in the last
        // day and that exists on the computer "MyComputer".
        //**************************************************
        
        public void ListPublicQueuesByCriteria()
        {
            uint numberQueues = 0;
            
            // Specify the criteria to filter by.
            MessageQueueCriteria myCriteria = new
                MessageQueueCriteria();
            myCriteria.MachineName = "MyComputer";
            myCriteria.CreatedAfter = DateTime.Now.Subtract(new
                TimeSpan(1,0,0,0));

            // Get a cursor into the queues on the network.
            MessageQueueEnumerator myQueueEnumerator =
                MessageQueue.GetMessageQueueEnumerator(myCriteria);

            // Move to the next queue and read its path.
            while(myQueueEnumerator.MoveNext())
            {
                // Increase the count if priority is Lowest.
                Console.WriteLine(myQueueEnumerator.Current.Path);
                numberQueues++;
            }

            // Handle no queues matching the criteria.
            if (numberQueues == 0)
            {
                Console.WriteLine("No public queues match criteria.");
            }

            return;
        }
    }
}
Imports System.Messaging

 
Public Class MyNewQueue


        '
        ' Provides an entry point into the application.
        '		 
        ' This example uses a cursor to step through the
        ' message queues and list the public queues on the
        ' network that specify certain criteria.
        

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue()

            ' Output the count of Lowest priority messages.
            myNewQueue.ListPublicQueuesByCriteria()

            Return

        End Sub


        
        ' Iterates through message queues and displays the
        ' path of each queue that was created in the last
        ' day and that exists on the computer "MyComputer". 
        

        Public Sub ListPublicQueuesByCriteria()

            Dim numberQueues As Int32 = 0

            ' Specify the criteria to filter by.
            Dim myCriteria As New MessageQueueCriteria()
            myCriteria.MachineName = "MyComputer"
            myCriteria.CreatedAfter = DateTime.Now.Subtract(New _
                TimeSpan(1, 0, 0, 0))


            ' Get a cursor into the queues on the network.
            Dim myQueueEnumerator As MessageQueueEnumerator = _
                MessageQueue.GetMessageQueueEnumerator(myCriteria)

            ' Move to the next queue and read its path.
            While myQueueEnumerator.MoveNext()
                ' Increase the count if the priority is Lowest.
                Console.WriteLine(myQueueEnumerator.Current.Path)
                numberQueues += 1
            End While

            ' Handle no queues matching the criteria.
            If numberQueues = 0 Then
                Console.WriteLine("No queues match the criteria.")
            End If

            Return

        End Sub

End Class

注解

MessageQueue类提供了许多方法,使用这些方法可以筛选网络上公用队列的搜索。The MessageQueue class provides a number of methods that enable you to filter your search for public queues on the network. 按队列标签、类别或服务器位置进行筛选的特定方法为 GetPublicQueuesByLabelGetPublicQueuesByCategoryGetPublicQueuesByMachineSpecific methods for filtering by queue label, category, or server location are the GetPublicQueuesByLabel, GetPublicQueuesByCategory, and GetPublicQueuesByMachine.

MessageQueueCriteria与方法一起使用时,类 GetPublicQueues 允许您优化筛选器。The MessageQueueCriteria class, when used with the GetPublicQueues method, allows you to refine your filter. 您可以指定不是通过一种 GetPublicQueuesBy * 方法或多个条件专门解决的搜索条件。You can specify search criteria not specifically addressed through one of the GetPublicQueuesBy* methods, or by multiple criteria. 您可以将实例传递给方法,以便进行 MessageQueueCriteria GetPublicQueues 搜索,例如,队列创建或修改时间、队列所在的计算机、队列标签或类别或这些属性的任意组合。You can pass a MessageQueueCriteria instance into the GetPublicQueues method in order to search, for example, by queue creation or modification times, the computer the queue resides on, the queue label or category, or any combination of these properties.

按多个属性进行筛选时,通过将 AND 运算符应用于属性集来撰写条件。When filtering by multiple properties, the criteria are composed by applying the AND operator to the set of properties. 因此,当您将属性的值与属性一起指定时,您需要在 CreatedAfter 指定的时间之后、在 MachineName 特定计算机上创建的所有队列。Thus, when you specify a value for the CreatedAfter property together with the MachineName property, you are asking for all queues that were created after a specified time and that reside on a specific computer.

设置任何属性时,设置属性的方法还会设置一个标志,用于指示该属性应包含在所生成的筛选器中。When you set any property, the method that sets the property also sets a flag to indicate that it should be included in the filter you are building. 不能从搜索筛选器中删除单独的属性。You cannot remove individual properties from the search filter. 相反,您可以通过调用从筛选器中删除所有属性 ClearAll ,然后将您要生成的属性设置为搜索筛选器。Instead, you remove all properties from the filter by calling ClearAll, and then set the properties that you do want to build into the search filter. ClearAll 将所有属性重置为 "未设置" 默认状态。ClearAll resets all properties into a "not set" default state.

必须先设置属性,然后才能尝试读取它;否则,将引发异常。You must set a property before trying to read it; otherwise, an exception is thrown.

构造函数

MessageQueueCriteria()

初始化 MessageQueueCriteria 类的新实例。Initializes a new instance of the MessageQueueCriteria class.

属性

Category

获取或设置作为网络中队列的筛选依据的类别。Gets or sets the category by which to filter queues in the network.

CreatedAfter

获取或设置队列创建日期和时间的下限,以此作为筛选网络上的队列的依据。Gets or sets the lower boundary of the queue creation date and time by which to filter queues on the network.

CreatedBefore

获取或设置队列创建日期和时间的上限,以此作为筛选网络上的队列的依据。Gets or sets the upper boundary of the queue creation date and time by which to filter queues on the network.

Label

获取或设置作为网络中队列的筛选依据的标签。Gets or sets the label by which to filter queues in the network.

MachineName

获取或设置作为网络中队列的筛选依据的计算机名。Gets or sets the computer name by which to filter queues in the network.

ModifiedAfter

获取或设置队列修改日期和时间的下限,以此作为筛选网络上的队列的依据。Gets or sets the lower boundary of the queue modification date and time by which to filter queues on the network.

ModifiedBefore

获取或设置队列修改日期和时间的上限,以此作为筛选网络上的队列的依据。Gets or sets the upper boundary of the queue modification date and time by which to filter queues on the network.

方法

ClearAll()

清除置入筛选器的所有属性,并将所有属性值设为“未设置”状态。Clears all properties from being built into a filter and puts all property values into a "not set" state.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅