private void AttachOutgoingLink(AttachContext attachContext, Source source) { IEntity entity = _entityLookup.Find(source.Address); if (entity == null) { attachContext.Complete(new Error(ErrorCode.NotFound) { Description = "Entity not found." }); _logger.LogError($"Could not attach outgoing link to non-existing entity '{source.Address}'."); return; } DeliveryQueue queue = entity.DeliveryQueue; if (queue == null) { attachContext.Complete(new Error(ErrorCode.NotFound) { Description = "Queue not found." }); _logger.LogError($"Could not attach outgoing link to non-existing queue '{source.Address}'."); return; } var outgoingLinkEndpoint = new OutgoingLinkEndpoint(queue); attachContext.Complete(outgoingLinkEndpoint, 0); _logger.LogDebug($"Attached outgoing link to queue '{source.Address}'."); }
private static int GetNumberOfMessagesInDeliveryQueue() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); DeliveryQueue queue = application.GlobalObjects.DeliveryQueue; Status status = application.Status; string messages = status.UndeliveredMessages; if (messages.Length < 4) { return(0); } string[] messageList = status.UndeliveredMessages.Split('\n'); int count = 0; foreach (string message in messageList) { if (message.Length < 4) { continue; } string recipients = message.Split('\t')[3]; string[] recipientList = recipients.Split(','); count += recipientList.Length; } return(count); }
public async Task Process_CompleteSuccessfully_WhenOutgoingLinkQueueFound() { const string linkName = "abcd"; const string entity = "entity"; ISecurityContext securityContext = Substitute.For <ISecurityContext>(); IEntityLookup entityLookup = Substitute.For <IEntityLookup>(); ILoggerProvider loggerProvider = Substitute.For <ILoggerProvider>(); Entities.IEntity fakeEntity = Substitute.For <Entities.IEntity>(); var deliveryQueue = new DeliveryQueue(); var linkProcessor = new LinkProcessor(securityContext, entityLookup, loggerProvider); entityLookup.Find(Arg.Any <string>()).Returns(fakeEntity); securityContext.IsAuthorized(Arg.Any <Connection>()).Returns(true); fakeEntity.DeliveryQueue.Returns(deliveryQueue); Session session = await TestAmqpHost.OpenAndLinkProcessorAsync(linkProcessor); try { var receiver = new ReceiverLink(session, linkName, entity); deliveryQueue.Enqueue(new Delivery(new Message { Properties = new Properties { MessageId = "msgid6746" } })); Message message = await receiver.ReceiveAsync(); message.Properties.MessageId.ShouldBe("msgid6746"); } finally { await session.Connection.CloseAsync(); } }
public new void SetUp() { _queue = _application.GlobalObjects.DeliveryQueue; _status = _application.Status; // add an account to send from _account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); }
void initFormOperations() { dg_AllQueues.Items.Clear(); foreach (DeliveryQueueModel item in DeliveryQueue.getAllNotDeliveredMappedToDeliveryQueueModel()) { dg_AllQueues.Items.Add(item); } }
private void btn_Delivered(object sender, RoutedEventArgs e) { if (dg_AllQueues.SelectedItem != null) { DeliveryQueueModel dmq = (DeliveryQueueModel)dg_AllQueues.SelectedItem; DeliveryQueue.updateStatus(dmq.Id); initFormOperations(); } }
public void Dequeue_ThrowsWhenNoDeliveryInQueueWithinTimeout() { var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1)); var queue = new DeliveryQueue(); Action action = () => queue.Dequeue(cts.Token); action.ShouldThrow <OperationCanceledException>(); }
public void Enqueue_SetsMessageSequence() { var message = new Message(); var queue = new DeliveryQueue(); queue.Enqueue(new Delivery(message)); message.MessageAnnotations[(Symbol)"x-opt-sequence-number"].ShouldBe(1L); }
private void btn_Canceled(object sender, RoutedEventArgs e) { if (dg_AllQueues.SelectedItem != null) { DeliveryQueueModel dmq = (DeliveryQueueModel)dg_AllQueues.SelectedItem; Sale.deleteASaleById(dmq.SaleId); DeliveryQueue.deleteById(dmq.Id); initFormOperations(); } }
public void Enqueue_AddsDeliveryToQueue() { var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(50)); var delivery = new Delivery(new Message()); var queue = new DeliveryQueue(); queue.Enqueue(delivery); queue.Dequeue(cts.Token).ShouldBeSameAs(delivery.Message); }
public void Process_DoesNotProcessDeliveryIfItDoesntExist() { var message = new Message(); message.InitializePrivateProperty("Delivery"); ListenerLink link = Construct.Uninitialized <ListenerLink>(); MessageContext messageContext = Construct.ForPrivate <MessageContext>(link, message); var queue = new DeliveryQueue(); Should.NotThrow(() => queue.Process(messageContext)); }
public void Enqueue_GetsFirstInsertedItem() { var delivery1 = new Delivery(new Message()); var delivery2 = new Delivery(new Message()); var queue = new DeliveryQueue(); queue.Enqueue(delivery1); queue.Enqueue(delivery2); queue.Dequeue(CancellationToken.None).ShouldBeSameAs(delivery1.Message); }
public void Dispose_CanBeCalledMultipleTimes() { var queue = new DeliveryQueue(); Should.NotThrow(() => { queue.Dispose(); queue.Dispose(); queue.Dispose(); }); }
public void Dispose_DisposesQueue() { var delivery = new Delivery(new Message()); var queue = new DeliveryQueue(); queue.Dispose(); Should.Throw <ObjectDisposedException>(() => queue.Enqueue(delivery)); Should.Throw <ObjectDisposedException>(() => queue.Dequeue(CancellationToken.None)); Should.Throw <ObjectDisposedException>(() => queue.Process(null)); }
internal void OnSubscribe(Emitter <T> source, DeliveryPolicy policy) { if (this.source != null) { throw new InvalidOperationException("This receiver is already connected to a source emitter."); } this.source = source; this.policy = policy; var combinedPolicy = this.policy.Merge(this.scheduler.GlobalPolicy); this.awaitingDelivery = new DeliveryQueue <T>(combinedPolicy, this.cloner); }
public async Task Enqueue_SetsUniqueMessageForSimultaniousDeliveries() { var queue = new DeliveryQueue(); Message[] messages = Enumerable.Range(1, 16).Select(_ => new Message()).ToArray(); IEnumerable <Task> enqueueTasks = messages .Select(message => Task.Run(() => queue.Enqueue(new Delivery(message)))); await Task.WhenAll(enqueueTasks); var sequenceIds = messages .Select(message => (long)message.MessageAnnotations[(Symbol)"x-opt-sequence-number"]) .ToArray(); sequenceIds.ShouldBeUnique(); }
internal void OnSubscribe(Emitter <T> source, bool allowSubscribeWhileRunning, DeliveryPolicy policy) { if (this.source != null) { throw new InvalidOperationException("This receiver is already connected to a source emitter."); } if (!allowSubscribeWhileRunning && (this.pipeline.IsRunning || source.Pipeline.IsRunning)) { throw new InvalidOperationException("Attempting to connect a receiver to an emitter while pipeline is already running. Make all connections before running the pipeline."); } this.source = source; this.policy = policy; this.awaitingDelivery = new DeliveryQueue <T>(policy, this.cloner); }
private void btn_Search(object sender, RoutedEventArgs e) { if (cb_Name.SelectedValue != null) { if (dp_from.SelectedDate != null && dp_to.SelectedDate != null) { DateTime tempFromDate = Convert.ToDateTime(dp_from.SelectedDate); DateTime tempToDate = Convert.ToDateTime(dp_to.SelectedDate); DateTime fromDate = Convert.ToDateTime(tempFromDate.ToShortDateString() + " 12:00:00 AM"); DateTime toDate = Convert.ToDateTime(tempToDate.ToShortDateString() + " 11:59:59 PM"); int deliveryBoyId = (int)cb_Name.SelectedValue; int ammount = DeliveryQueue.getAmmountOfDeliveryOfaBoyWithDate(deliveryBoyId, fromDate, toDate); lbl_Total.Content = ammount; } } }
public void Process_ProcessesDelivery() { var message = new Message(); message.InitializePrivateProperty("Delivery"); ListenerLink link = Construct.Uninitialized <ListenerLink>(); MessageContext messageContext = Construct.ForPrivate <MessageContext>(link, message); var delivery = new Delivery(message); var queue = new DeliveryQueue(); queue.Enqueue(delivery); queue.Dequeue(CancellationToken.None); queue.Process(messageContext); delivery.Processed.ShouldNotBeNull(); }
private bool SendObject(DeliveryQueue p) { searchRes.Clear(); searchString = p.objectUUID; if (searchRes.Count <= 0) { instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Product not found '" + searchString + "' for user '" + p.userUUID + "'", ChatBufferTextStyle.Error); return(false); } if (searchRes.Count > 1) { instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": More then one product found for '" + searchString + "'", ChatBufferTextStyle.Error); return(false); } var inv = searchRes[0] as InventoryItem; if (inv == null) { instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Product found, but not an inventory item", ChatBufferTextStyle.Error); return(false); } Dictionary <string, string> param = new Dictionary <string, string>(); param.Add("id", p.id); var str = this.RequestVendor("SETDELIVERED", param); if (str != "Delivered|1") { instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Product found, but user " + p.userUUID + " might not have enough funds", ChatBufferTextStyle.Normal); // a message to the user would be helpful later return(false); } instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": SETDELIVERED: " + str, ChatBufferTextStyle.StatusBlue); inv.Permissions.NextOwnerMask = (PermissionMask)p.nextperm; client.Inventory.RequestUpdateItem(inv); client.Inventory.RequestFetchInventory(inv.UUID, inv.OwnerID); Manager.GiveItem(inv.UUID, inv.Name, inv.AssetType, OpenMetaverse.UUID.Parse(p.userUUID), false); instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": PRODUCT '" + searchRes[0].Name + "' SENT TO " + p.userUUID, ChatBufferTextStyle.StatusBlue); return(true); }
public void HandleClosingMessage() { // Create a delivery policy specifying a maximum queue size of 1 var deliveryPolicy = new DeliveryPolicy <int>( 1, 1, null, null, false, guaranteeDelivery: value => value == 2, // only guarantee message value is 2 "TestDeliveryPolicy"); var deliveryQueue = new DeliveryQueue <int>(deliveryPolicy, RecyclingPool.Create <int>()); // Enqueue a closing message - message should be queued deliveryQueue.Enqueue( Message.Create(0, DateTime.UtcNow, DateTime.UtcNow, 0, int.MaxValue), // closing message null,
private List <DeliveryQueue> parseResponse(string content) { List <DeliveryQueue> queue = new List <DeliveryQueue>(); if (String.IsNullOrEmpty(content)) { return(queue); } try { System.Reflection.PropertyInfo[] propertyInfos = typeof(DeliveryQueue).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); string field_separator = "|"; var lines = content.Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string l in lines) { int lastPos = 0; var deliveryQ = new DeliveryQueue(); foreach (System.Reflection.PropertyInfo pInfo in propertyInfos) { var nextPos = l.IndexOf(field_separator, lastPos); if (nextPos > -1) { object o = Convert.ChangeType(l.Substring(lastPos, nextPos - lastPos), pInfo.PropertyType); pInfo.SetValue(deliveryQ, o, null); } lastPos = nextPos + 1; } queue.Add(deliveryQ); } } catch (Exception ex) { instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Failed to read DeliveryQ - " + ex.Message, ChatBufferTextStyle.Error); } return(queue); }
internal void OnSubscribe(Emitter <T> source, bool allowSubscribeWhileRunning, DeliveryPolicy <T> policy) { if (this.Source != null) { throw new InvalidOperationException("This receiver is already connected to a source emitter."); } if (!allowSubscribeWhileRunning && (this.pipeline.IsRunning || source.Pipeline.IsRunning)) { throw new InvalidOperationException("Attempting to connect a receiver to an emitter while pipeline is already running. Make all connections before running the pipeline."); } if (source.Pipeline != this.pipeline) { throw new InvalidOperationException("Receiver cannot subscribe to an emitter from a different pipeline. Use a Connector if you need to connect emitters and receivers from different pipelines."); } this.Source = source; this.DeliveryPolicy = policy; this.awaitingDelivery = new DeliveryQueue <T>(policy, this.Recycler); this.pipeline.DiagnosticsCollector?.PipelineElementReceiverSubscribe(this.pipeline, this.element, this, source, this.DeliveryPolicy.Name); }
public static void DeleteMessagesInQueue() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); DeliveryQueue queue = application.GlobalObjects.DeliveryQueue; Status status = application.Status; string[] messages = status.UndeliveredMessages.Split('\n'); foreach (string message in messages) { if (message.Length < 10) { continue; } string[] info = message.Split('\t'); int id = Convert.ToInt32(info[0]); queue.Remove(id); } application.SubmitEMail(); }
private List<DeliveryQueue> parseResponse(string content) { List<DeliveryQueue> queue = new List<DeliveryQueue>(); if (String.IsNullOrEmpty(content)) return queue; try { System.Reflection.PropertyInfo[] propertyInfos = typeof(DeliveryQueue).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); string field_separator = "|"; var lines = content.Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string l in lines) { int lastPos = 0; var deliveryQ = new DeliveryQueue(); foreach (System.Reflection.PropertyInfo pInfo in propertyInfos) { var nextPos = l.IndexOf(field_separator, lastPos); if (nextPos > -1) { object o = Convert.ChangeType(l.Substring(lastPos, nextPos - lastPos), pInfo.PropertyType); pInfo.SetValue(deliveryQ, o, null); } lastPos = nextPos + 1; } queue.Add(deliveryQ); } } catch (Exception ex) { instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Failed to read DeliveryQ - " + ex.Message, ChatBufferTextStyle.Error); } return queue; }
private bool SendObject(DeliveryQueue p) { searchRes.Clear(); searchString = p.objectUUID; if (searchRes.Count <= 0) { instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Product not found '" + searchString + "' for user '" + p.userUUID + "'", ChatBufferTextStyle.Error); return false; } if (searchRes.Count > 1) { instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": More then one product found for '" + searchString + "'", ChatBufferTextStyle.Error); return false; } var inv = searchRes[0] as InventoryItem; if (inv == null) { instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Product found, but not an inventory item", ChatBufferTextStyle.Error); return false; } Dictionary<string, string> param = new Dictionary<string, string>(); param.Add("id", p.id); var str = this.RequestVendor("SETDELIVERED", param); if (str != "Delivered|1") { instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Product found, but user " + p.userUUID + " might not have enough funds", ChatBufferTextStyle.Normal); // a message to the user would be helpful later return false; } instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": SETDELIVERED: " + str, ChatBufferTextStyle.StatusBlue); inv.Permissions.NextOwnerMask = (PermissionMask)p.nextperm; client.Inventory.RequestUpdateItem(inv); client.Inventory.RequestFetchInventory(inv.UUID, inv.OwnerID); Manager.GiveItem(inv.UUID, inv.Name, inv.AssetType, OpenMetaverse.UUID.Parse(p.userUUID), false); instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": PRODUCT '" + searchRes[0].Name + "' SENT TO " + p.userUUID, ChatBufferTextStyle.StatusBlue); return true; }
/// <summary> /// /// </summary> /// /// <param name="context"></param> /// public override void Invoke(ExchangeRuntime runtime) { if (runtime.Abort) { runtime.Continue(); return; } Stopwatch timer = new Stopwatch(); timer.Start(); List<long> prospects = runtime.GetData(ExchangeRuntime.DISTRIBUTIONS) as List<long>; DistributionEvent @event = new DistributionEvent(this.GetType().Name); if (prospects != null) { foreach (long prospect in prospects) { DeliveryQueue queue = new DeliveryQueue(); queue.AdvertiserId = prospect; queue.Disposition = "PENDING"; queue.LeadId = runtime.GetLead().Id; ExchangeService.SaveDeliveryQueue(queue); @event.Advertisers.Add(prospect); } } timer.Stop(); @event.ElapsedTime = timer.ElapsedMilliseconds; runtime.AddStrategyEvent(@event); runtime.Continue(); }