Rhino.Queues.Storage.QueueStorage.Global C# (CSharp) Method

Global() public method

public Global ( Action action ) : void
action Action
return void
        public void Global(Action<GlobalActions> action)
        {
            var shouldTakeLock = usageLock.IsReadLockHeld == false;
            try
            {
                if (shouldTakeLock)
                    usageLock.EnterReadLock();
                using (var qa = new GlobalActions(instance, columnsInformation, database, Id, configuration))
                {
                    action(qa);
                }
            }
            finally
            {
                if(shouldTakeLock)
                    usageLock.ExitReadLock();
            }
        }

Usage Example

        public void MovesMessageToOutgoingFromHistory()
        {
            using (var qf = new QueueStorage("test.esent"))
            {
                qf.Initialize();
                qf.Global(actions =>
                {
                    actions.CreateQueueIfDoesNotExists("test");
                    actions.Commit();
                });

                var testMessage = new MessagePayload
                {
                    Data = new byte[0],
                    Headers = new NameValueCollection(),
                };

                qf.Global(actions =>
                {
                    Guid transactionId = Guid.NewGuid();
                    actions.RegisterToSend(new Endpoint("localhost", 0),
                        "test",
                        null,
                        testMessage,
                        transactionId);
                    actions.MarkAsReadyToSend(transactionId);
                    actions.Commit();
                });

                qf.Send(actions =>
                {
                    Endpoint endpoint;
                    var msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, out endpoint);
                    var bookmark = actions.MarkOutgoingMessageAsSuccessfullySent(msgs[0].Bookmark);
                    actions.RevertBackToSend(new[] { bookmark });

                    msgs = actions.GetMessagesToSendAndMarkThemAsInFlight(int.MaxValue, int.MaxValue, out endpoint);
                    Assert.NotEmpty(msgs);
                    actions.Commit();
                });

                qf.Global(actions =>
                {
                    var messages = actions.GetSentMessages();
                    Assert.Empty(messages);
                    actions.Commit();
                });
            }
        }
All Usage Examples Of Rhino.Queues.Storage.QueueStorage::Global