MessageQueueCriteria Klasa

Definicja

Filtruje kolejki komunikatów podczas wykonywania zapytania przy użyciu MessageQueue metody klasy GetPublicQueues() .

public ref class MessageQueueCriteria
public class MessageQueueCriteria
type MessageQueueCriteria = class
Public Class MessageQueueCriteria
Dziedziczenie
MessageQueueCriteria

Przykłady

Poniższy przykład wykonuje iterację po kolejkach komunikatów i wyświetla ścieżkę każdej kolejki, która została utworzona w ostatnim dniu i która istnieje na komputerze "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

Uwagi

Klasa MessageQueue udostępnia szereg metod, które umożliwiają filtrowanie wyszukiwania kolejek publicznych w sieci. Konkretne metody filtrowania według etykiety kolejki, kategorii lub lokalizacji serwera to GetPublicQueuesByLabel, GetPublicQueuesByCategoryi GetPublicQueuesByMachine.

Klasa MessageQueueCriteria , gdy jest używana z metodą , umożliwia uściślenie filtru GetPublicQueues . Można określić kryteria wyszukiwania, które nie zostały specjalnie uwzględnione za pomocą jednej z GetPublicQueuesBymetod * lub według wielu kryteriów. Wystąpienie można przekazać MessageQueueCriteria do GetPublicQueues metody w celu wyszukania, na przykład przez czas tworzenia lub modyfikacji kolejki, komputer, na którym znajduje się kolejka, etykieta kolejki lub kategoria albo dowolna kombinacja tych właściwości.

Podczas filtrowania według wielu właściwości kryteria składają się przez zastosowanie AND operatora do zestawu właściwości. W związku z tym, po określeniu CreatedAfter wartości właściwości wraz z MachineName właściwością, pytasz o wszystkie kolejki, które zostały utworzone po określonym czasie i które znajdują się na określonym komputerze.

Po ustawieniu dowolnej właściwości metoda ustawiania właściwości ustawia również flagę, aby wskazać, że powinna zostać uwzględniona w filtrze, który tworzysz. Nie można usunąć poszczególnych właściwości z filtru wyszukiwania. Zamiast tego usuwasz wszystkie właściwości z filtru, wywołując metodę ClearAll, a następnie ustawiasz właściwości, które chcesz utworzyć w filtrze wyszukiwania. ClearAll resetuje wszystkie właściwości do stanu domyślnego "nie ustawiono".

Musisz ustawić właściwość przed próbą jej odczytania; w przeciwnym razie zgłaszany jest wyjątek.

Konstruktory

MessageQueueCriteria()

Inicjuje nowe wystąpienie klasy MessageQueueCriteria.

Właściwości

Category

Pobiera lub ustawia kategorię, według której mają być filtrowane kolejki w sieci.

CreatedAfter

Pobiera lub ustawia dolną granicę daty i godziny tworzenia kolejki, według której mają być filtrowane kolejki w sieci.

CreatedBefore

Pobiera lub ustawia górną granicę daty i godziny tworzenia kolejki, według której mają być filtrowane kolejki w sieci.

Label

Pobiera lub ustawia etykietę, za pomocą której mają być filtrowane kolejki w sieci.

MachineName

Pobiera lub ustawia nazwę komputera, za pomocą którego należy filtrować kolejki w sieci.

ModifiedAfter

Pobiera lub ustawia dolną granicę daty i godziny modyfikacji kolejki, według której mają być filtrowane kolejki w sieci.

ModifiedBefore

Pobiera lub ustawia górną granicę daty i godziny modyfikacji kolejki, według której mają być filtrowane kolejki w sieci.

Metody

ClearAll()

Czyści wszystkie właściwości z wbudowanego w filtr i umieszcza wszystkie wartości właściwości w stanie "nie ustawiono".

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też