Exemple #1
0
        internal static DirectoryQueueMessage BuildMessage(IActorMessage msg)
        {
            DirectoryQueueMessage cloudMessage = new DirectoryQueueMessage();

            byte[] msgBytes = TempSerialization.GetBytes <MsgType>(msg);
            cloudMessage.SetMessageContent(msgBytes);
            return(cloudMessage);
        }
Exemple #2
0
 internal static void AddMessageProperties(DirectoryQueue queue, DirectoryQueueMessage cloudMessage, IStorageQueuePropertiesProvider props)
 {
     if (null == props || (null == props.TimeToLive && null == props.InitialVisibilityDelay))
     {
         queue.AddMessage(cloudMessage);
     }
     else
     {
         queue.AddMessage(cloudMessage, props.TimeToLive, props.InitialVisibilityDelay);
     }
 }
Exemple #3
0
        internal static void SerializeAndSend(IActorMessage msg, DirectoryQueue queue)
        {
            // Add the message to the azure queue
            DirectoryQueueMessage cloudMessage = BuildMessage(msg);

            AddMessageProperties(queue, cloudMessage, (msg is IStorageQueuePropertiesProvider) ? (msg as IStorageQueuePropertiesProvider): null);

            if (null != msg.Status)
            {
                msg.Status?.SetResult(new QueuedDirectoryMessage(cloudMessage));
            }
        }
Exemple #4
0
        internal static void SerializeAndSend(IActorMessage msg, DirectoryQueue queue, string msgString)
        {
            DirectoryQueueMessage cloudMessage = new DirectoryQueueMessage();

            cloudMessage.SetMessageContent(msgString);
            AddMessageProperties(queue, cloudMessage, (msg is IStorageQueuePropertiesProvider) ? (msg as IStorageQueuePropertiesProvider) : null);

            if (null != msg.Status)
            {
                msg.Status?.SetResult(new QueuedDirectoryMessage(cloudMessage));
            }
        }
 public void DeleteMessage(DirectoryQueueMessage msg)
 {
     try
     {
         this.AcquireLock();
         System.Diagnostics.Debug.WriteLine("Delete Message");
         msg.Delete();
     }
     finally
     {
         this.ReleaseLock();
     }
 }
        public DirectoryQueueMessage GetMessage(TimeSpan?retrieveVisibilityTimeout = null)
        {
            if (!System.IO.Directory.Exists(this.queuePath))
            {
                return(null);
            }

            try
            {
                this.AcquireLock();
                System.Diagnostics.Debug.WriteLine("Get Message");
                string msgpath = null;
                System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(this.queuePath);
                foreach (var t in dInfo.GetFileSystemInfos($"*{msgExtension}").OrderBy(p => p.CreationTime))
                {
                    if ((t.Attributes & System.IO.FileAttributes.Hidden) != System.IO.FileAttributes.Hidden)
                    {
                        msgpath = t.FullName;
                    }
                }

                if (null == msgpath)
                {
                    return(null);
                }

                DirectoryQueueMessage nextMessage = DirectoryQueueMessage.FromQueueFile(msgpath);

                System.Diagnostics.Debug.WriteLine(msgpath);

                // NOTE: we release the lock after we have the message because we update the visibility for the file
                nextMessage.DequeueCount++;
                nextMessage.Hide(retrieveVisibilityTimeout);
                nextMessage.Store(); // make sure dequeue count has been stored correctly.

                return(nextMessage);
            }
            finally
            {
                this.ReleaseLock();
            }
        }
        public void AddMessage(DirectoryQueueMessage msg, TimeSpan?timeToLive, TimeSpan?initialVisibilityDelay)
        {
            try
            {
                this.AcquireLock();
                System.Diagnostics.Debug.WriteLine("Add Message");

                // set the msg name;
                string fileNameAndPath = System.IO.Path.Combine(this.queuePath, DateTime.Now.Ticks.ToString("0000000000") + msgExtension);
                while (System.IO.File.Exists(fileNameAndPath))
                {
                    fileNameAndPath = System.IO.Path.Combine(this.queuePath, DateTime.Now.Ticks.ToString("0000000000") + msgExtension);
                }

                msg.SetTimeToLive(timeToLive);
                msg.SetInitialVisibilityDelay(initialVisibilityDelay);
                msg.LocalPathToQueuedMessage = fileNameAndPath;
                msg.Store();
            }
            finally
            {
                this.ReleaseLock();
            }
        }
Exemple #8
0
        public IActorMessage GetMessage()
        {
            if (!recieveMessagesOnly)
            {
                throw new OperatorCannotRecieveMessagesException();
            }

            if (null != hangUp)
            {
                return(hangUp);
            }

            try
            {
                // Get the next message off of the azure queue
                DirectoryQueueMessage next = this.queue.GetMessage(this.retrieveVisibilityTimeout);

                if (null == next)
                {
                    return(null);
                }

                if (next.DequeueCount > maxDequeueCount)
                {
                    if (null != this.deadLetterQueue)
                    {
                        deadLetterQueue.AddMessage(next);
                    }
                    queue.DeleteMessage(next);
                    return(null);
                }

                IActorMessage msg = null;
                if (typeof(MsgType) == typeof(string))
                {
                    msg = next.AsString.ToActorMessage();
                }
                else if (typeof(MsgType) == typeof(byte[]))
                {
                    msg = next.AsBytes.ToActorMessage();
                }
                else
                {
                    byte[] msgBytes = next.AsBytes;
                    var    t        = Telegraph.Instance.Ask(new DeserializeMessage <IActorMessage>(msgBytes));
                    msg = t.Result as IActorMessage;
                }

                if (null == msg.Status)
                {
                    msg.Status = new TaskCompletionSource <IActorMessage>();
                }

                msg.Status.Task.ContinueWith(p => queue.DeleteMessage(next));
                return(msg);
            }
            catch (Exception ex)
            {
                Exception foundEx = null;
                var       handler = this.FindExceptionHandler(_exceptionTypeToHandler, ex, out foundEx);

                if (null != handler)
                {
                    handler.Invoke(foundEx);
                }
                return(null);
            }
        }
 public void AddMessage(DirectoryQueueMessage msg)
 {
     this.AddMessage(msg, null, null);
 }