IQueueSpecifier GetQueueInfo(string queueName)
        {
            var qPath = _parent.GetQueuePath(_exchangeName, queueName);

            var qMtx = FDMessageBus.GetQueueMutex(_exchangeName, queueName);

            using (qMtx)
            {
                if (qMtx.Wait(TimeSpan.FromSeconds(120)))
                {
                    var di = new DirectoryInfo(qPath);
                    if (!di.Exists)
                    {
                        return(null);
                    }

                    var fi = new FileInfo(Path.Combine(qPath, "routes.json"));
                    if (fi.Exists)
                    {
                        using (var sr = fi.OpenText())
                        {
                            var text = sr.ReadToEnd();
                            var mqd  = JsonConvert.DeserializeObject <MessageQueueDeclaration>(text);
                            return(new FDQueueSpecifier(mqd));
                        }
                    }
                }
            }


            return(null);
        }
        public IExchangeSpecifier DeleteQueue(string queueName)
        {
            var qPath  = _parent.GetQueuePath(_exchangeName, queueName);
            var qMtx   = FDMessageBus.GetQueueMutex(_exchangeName, queueName);
            var exPath = _parent.GetExchangePath(_exchangeName);
            var exMtx  = FDMessageBus.GetExchangeMutex(_exchangeName);

            using (exMtx)
                using (qMtx)
                {
                    if (exMtx.Wait(TimeSpan.FromSeconds(30)) && qMtx.Wait(TimeSpan.FromSeconds(30)))
                    {
                        var di = new DirectoryInfo(qPath);
                        if (!di.Exists)
                        {
                            return(this);
                        }

                        di.Delete(true);
                    }
                }
            return(this);
        }
        public IExchangeSpecifier DeclareQueue(string queueName, params string[] boundRoutes)
        {
            var qPath  = _parent.GetQueuePath(_exchangeName, queueName);
            var qMtx   = FDMessageBus.GetQueueMutex(_exchangeName, queueName);
            var exPath = _parent.GetExchangePath(_exchangeName);
            var exMtx  = FDMessageBus.GetExchangeMutex(_exchangeName);

            using (exMtx)
                using (qMtx)
                {
                    if (exMtx.Wait(TimeSpan.FromSeconds(30)) && qMtx.Wait(TimeSpan.FromSeconds(30)))
                    {
                        var di = new DirectoryInfo(qPath);
                        if (di.Exists)
                        {
                            return(this);
                        }
                        di.Create();

                        var fi = new FileInfo(Path.Combine(qPath, "routes.json"));
                        using (var sw = fi.CreateText())
                        {
                            var q = new MessageQueueDeclaration {
                                Name = queueName
                            };
                            q.Bindings.AddRange(boundRoutes);
                            var text = JsonConvert.SerializeObject(q);
                            sw.Write(text);
                            sw.Flush();
                            sw.Close();
                        }
                    }
                }


            return(this);
        }