Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>Null.</returns>
        public DockingStationEvent Execute()
        {
            Log.Info("PopQueueOperation: Deleting oldest message from iNet upload queue.");

            bool deleted = PersistedQueue.CreateInetInstance().Delete();

            Log.Info("PopQueueOperation:" + (deleted ? "Message deleted." : "No messages to delete."));

            return(null);
        }
        public async Task DequeueTwoItems()
        {
            // Arrange
            PersistedQueue <int> queue = CreatePersistedQueue <int>(inMemoryCapacity: 1);

            queue.Enqueue(0);
            queue.Enqueue(1);

            // Act / Assert
            Assert.Equal(0, await queue.DequeueAsync());
            Assert.Equal(1, await queue.DequeueAsync());
        }
        public async Task Enqueue(int numberOfItems)
        {
            // Arrange
            PersistedQueue <int> queue = CreatePersistedQueue <int>();

            // Act
            for (int i = 0; i < numberOfItems; i++)
            {
                queue.Enqueue(i);
            }

            // Assert
            Assert.Equal(0, await queue.PeekAsync());
        }
        public async Task Dequeue(int numberOfItems)
        {
            // Arrange
            PersistedQueue <int> queue = CreatePersistedQueue <int>();

            for (int i = 0; i < numberOfItems; i++)
            {
                queue.Enqueue(i);
            }

            // Act / Assert
            for (int i = 0; i < numberOfItems; i++)
            {
                Assert.Equal(i, await queue.DequeueAsync());
            }
        }
Exemplo n.º 5
0
        private async Task InMemoryInt()
        {
            IPersistence <int>          persistence = new InMemoryPersistence <int>();
            PersistedQueueConfiguration config      = new PersistedQueueConfiguration {
                MaxItemsInMemory = itemsToKeepInMemory
            };
            PersistedQueue <int> queue = new PersistedQueue <int>(persistence, config);

            for (int i = 0; i < totalItems; i++)
            {
                queue.Enqueue(i);
            }
            for (int i = 0; i < totalItems; i++)
            {
                await queue.DequeueAsync();
            }
        }
Exemplo n.º 6
0
        protected override void OnStart()
        {
            // Upon startup, see if there's anything already queued.
            try
            {
                bool isEmpty = PersistedQueue.CreateInetInstance().IsEmpty();
                Log.Info(string.Format("{0}.OnStart: IsEmpty={1}", Name, isEmpty));
                PendingUploads = isEmpty == false;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            // Since we pull from the message queue and upload to iNet in the 'background',
            // there's no reason to run at a high/normal priority.
            Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
        }
        public void Count(int numberOfItems)
        {
            // Arrange
            PersistedQueue <int> queue = CreatePersistedQueue <int>();

            for (int i = 0; i < numberOfItems; i++)
            {
                queue.Enqueue(i);
            }

            // Act / Assert
            for (int i = 0; i < numberOfItems; i++)
            {
                Assert.Equal(numberOfItems - i, queue.Count);
                queue.DequeueAsync();
            }
            Assert.Empty(queue);
        }
Exemplo n.º 8
0
 public void IterationSetup()
 {
     if (useLargeData)
     {
         largePersistence = new NosqlPersistence <LargeData>(PersistenceFilePath);
         PersistedQueueConfiguration config = new PersistedQueueConfiguration {
             MaxItemsInMemory = itemsToKeepInMemory
         };
         largeQueue = new PersistedQueue <LargeData>(largePersistence, config);
     }
     else
     {
         smallPersistence = new NosqlPersistence <int>(PersistenceFilePath);
         PersistedQueueConfiguration config = new PersistedQueueConfiguration {
             MaxItemsInMemory = itemsToKeepInMemory
         };
         smallQueue = new PersistedQueue <int>(smallPersistence, config);
     }
 }
        public void GetEnumerator(int numberOfItems)
        {
            // Arrange
            PersistedQueue <int> queue = CreatePersistedQueue <int>();

            for (int i = 0; i < numberOfItems; i++)
            {
                queue.Enqueue(i);
            }

            // Act / Assert
            int expected = 0;

            foreach (int item in queue)
            {
                Assert.Equal(expected, item);
                expected++;
            }
        }
Exemplo n.º 10
0
 public void Setup(string queueName, DataStore store)
 {
     _testData       = TestData.ForIntegrationTests(store);
     _persistedQueue = new PersistedQueue <ComplexType>(
         queueName, _testData.Context);
 }
Exemplo n.º 11
0
        /// <summary>
        /// This method implements the thread start for this service.
        /// </summary>
        protected override void Run()
        {
            // For logging, keep track of number of items found on queue, which of
            // those successfully uploaded, and which that were ignored/skipped.
            int queuedCount = 0, uploadedCount = 0, ignoredCount = 0;

            InetUploader inetUploader = null;

            try
            {
                PersistedQueue inetQueue = PersistedQueue.CreateInetInstance();

                while (true)
                {
                    if (!Runnable())   // Keep sending until the message queue is empty or we're stopped/paused.
                    {
                        break;
                    }

                    try
                    {
                        Log.Trace(">INET: Checking for non-empty queue.");

                        bool isEmpty = inetQueue.IsEmpty();

                        if (isEmpty)
                        {
                            Log.Trace(">INET: No data in upload queue.");
                            PendingUploads = false;
                            break;
                        }

                        Log.Debug(">INET: Retrieving queued item....");

                        // Get the oldest object on the queue (the object is not removed).
                        object queObject = inetQueue.Peek();

                        if (queObject == null)
                        {
                            Log.Debug(">INET: No data in upload queue.");
                            PendingUploads = false;
                            break;
                        }

                        PendingUploads = true;

                        string deviceLocation = string.Empty;

                        object wsParmObject = null;

                        queuedCount++;

                        QueueData queueData = null;
                        try
                        {
                            queueData = (QueueData)queObject;

                            double kB = (double)queueData.WebServiceParameterSize / 1024.0d; // convert bytes to kilobytes
                            Log.Debug(string.Format(">INET: {0} ({1},\"{2}\",{3}), {4} KB)...",
                                                    queueData, queueData.Id, Log.DateTimeToString(queueData.Timestamp), queueData.InetAccountNum, kB.ToString("f1")));

                            wsParmObject = queueData.WebServiceParameter;
                        }
                        catch (Exception e)
                        {
                            // If this failed, then something was on the queue which
                            // was not the right type.  Could have been old data.
                            // Just ignore it.
                            ignoredCount++;
                            Log.Debug(">INET: " + e.ToString());

                            // If debug build, DO NOT delete poison data. We need to keep
                            // it so that we can investigate what's wrong with it.
#if DEBUG
                            Log.Debug(">INET: Found non-conforming data on queue: ");
                            Log.Debug(">INET: " + queObject.ToString());
                            break;
#else
                            Log.Debug(">INET: Found non-conforming data on queue. Purging it:");
                            Log.Debug(">INET: " + queObject.ToString());
                            //_msmqTransaction.Commit();
                            inetQueue.Delete(queueData.Id);
                            continue;
#endif
                        }

                        // We don't instantiate iNet until we know we need it And, if we make it
                        // to here, then that's now.  We then will continue to re-use it for the duration
                        // that we remain in the loop.
                        if (inetUploader == null)
                        {
                            inetUploader = new InetUploader();
                        }

                        string errorCode = inetUploader.Upload(wsParmObject, queueData.Label, queueData.InetAccountNum);

                        // On any error, just break out and we'll retry on next iteration of Run().
                        // The intent is that if there's some network issue, or we're just offline,
                        // then we watn to let some time pass for the issue to clear up or to go back online.
                        if (errorCode != string.Empty)
                        {
                            break;
                        }

                        // Now that we've successfully uploaded it to iNet, we can remove it from the queue
                        Log.Debug(string.Format(">INET: Deleting uploaded {0} from queue.", queueData));
                        inetQueue.Delete(queueData.Id);

                        uploadedCount++;
                    }
                    // catch
                    catch (Exception ex1)
                    {
                        Log.Debug(">INET: Exception caught, - " + ex1.ToString());
                    }
                } // end-while !empty queue
            }
            finally
            {
                if (inetUploader != null)
                {
                    inetUploader.Dispose();
                }
            }

            if (queuedCount > 0)
            {
                Log.Debug(">INET: Finished. " + queuedCount + " found in queue, " + uploadedCount + " uploaded, " + ignoredCount + " ignored");
            }
        }