private void UseRecentConnection(RecentConnection obj)
        {
            if (obj is RecentRemoteQueueConnection)
            {
                var rc = (RecentRemoteQueueConnection)obj;
                OpenRemoteQueue(rc);
                return;
            }

            if (obj is RecentRemoteQueueManagerConnection)
            {
                var rc = (RecentRemoteQueueManagerConnection)obj;
                OpenRemoteQueueManager(rc);
                return;
            }

            if (obj is RecentQueueConnection)
            {
                var rc = (RecentQueueConnection)obj;
                OpenLocalQueue(rc);
                return;
            }

            if (obj is RecentQueueManagerConnection)
            {
                var rc = (RecentQueueManagerConnection)obj;
                OpenLocalQueueManager(rc);
                return;
            }
        }
        public static RecentConnectionConfigElement ConvertFromModel(RecentConnection rc)
        {
            if (rc is RecentRemoteQueueConnection)
            {
                return(new RecentRemoteQueueConnectionConfigElement((RecentRemoteQueueConnection)rc));
            }

            if (rc is RecentRemoteQueueManagerConnection)
            {
                return(new RecentRemoteConnectionConfigElement((RecentRemoteQueueManagerConnection)rc));
            }

            if (rc is RecentQueueConnection)
            {
                return(new RecentQueueConnectionConfigElement((RecentQueueConnection)rc));
            }

            if (rc is RecentQueueManagerConnection)
            {
                return(new RecentConnectionConfigElement((RecentQueueManagerConnection)rc));
            }

            throw new NotSupportedException("Invalid RecentConnection type");
        }
        private void AddRecentConnection(IQueue q, IRecentQueueConnection previous)
        {
            RecentConnection data = null;

            if (previous != null)
            {
                if (q.QueueManager.ConnectionProperties.IsLocal)
                {
                    var temp = previous as RecentQueueConnection;
                    if (temp != null)
                    {
                        if (temp.QueueManagerName == q.QueueManager.Name &&
                            temp.QueueName == q.Name)
                        {
                            data = temp;
                        }
                    }
                }
                else
                {
                    var temp = previous as RecentRemoteQueueConnection;
                    if (temp != null)
                    {
                        if (temp.QueueManagerName == q.QueueManager.Name &&
                            temp.QueueName == q.Name &&
                            temp.HostName == q.QueueManager.ConnectionProperties.HostName &&
                            temp.Port == q.QueueManager.ConnectionProperties.Port &&
                            temp.Channel == q.QueueManager.ConnectionProperties.Channel &&
                            (temp.UserId ?? "") == (q.QueueManager.ConnectionProperties.UserId ?? ""))
                        {
                            data = temp;
                        }
                    }
                }
            }
            if (data == null)
            {
                if (q.QueueManager.ConnectionProperties.IsLocal)
                {
                    data = new RecentQueueConnection
                    {
                        QueueManagerName = q.QueueManager.Name,
                        QueueName        = q.Name
                    };
                }
                else
                {
                    data = new RecentRemoteQueueConnection
                    {
                        QueueManagerName = q.QueueManager.Name,
                        QueueName        = q.Name,
                        HostName         = q.QueueManager.ConnectionProperties.HostName,
                        Port             = q.QueueManager.ConnectionProperties.Port,
                        Channel          = q.QueueManager.ConnectionProperties.Channel
                    };
                    if (!string.IsNullOrEmpty(q.QueueManager.ConnectionProperties.UserId))
                    {
                        ((RecentRemoteQueueConnection)data).UserId = q.QueueManager.ConnectionProperties.UserId;
                    }
                }
            }
            UserSettings.AddRecentConnection(data);
        }
        private void AddRecentConnection(IQueueManager qm, IObjectNameFilter filter, IRecentConnection previous)
        {
            RecentConnection data = null;

            if (previous != null)
            {
                if (qm.ConnectionProperties.IsLocal)
                {
                    var temp = previous as RecentQueueManagerConnection;
                    if (temp != null)
                    {
                        if (temp.QueueManagerName == qm.Name &&
                            FilterEquals(temp, filter))
                        {
                            data = temp;
                        }
                    }
                }
                else
                {
                    var temp = previous as RecentRemoteQueueManagerConnection;
                    if (temp != null)
                    {
                        if (temp.QueueManagerName == qm.Name &&
                            FilterEquals(temp, filter) &&
                            temp.HostName == qm.ConnectionProperties.HostName &&
                            temp.Port == qm.ConnectionProperties.Port &&
                            temp.Channel == qm.ConnectionProperties.Channel &&
                            (temp.UserId ?? "") == (qm.ConnectionProperties.UserId ?? ""))
                        {
                            data = temp;
                        }
                    }
                }
            }
            if (data == null)
            {
                if (qm.ConnectionProperties.IsLocal)
                {
                    data = new RecentQueueManagerConnection
                    {
                        QueueManagerName = qm.Name
                    };
                    if (filter is StaticQueueList)
                    {
                        ((RecentQueueManagerConnection)data).QueueList = new List <string>(((StaticQueueList)filter).Names);
                    }
                    else
                    {
                        ((RecentQueueManagerConnection)data).ObjectNamePrefix = filter?.NamePrefix?[0];
                    }
                }
                else
                {
                    data = new RecentRemoteQueueManagerConnection
                    {
                        QueueManagerName = qm.Name,
                        HostName         = qm.ConnectionProperties.HostName,
                        Port             = qm.ConnectionProperties.Port,
                        Channel          = qm.ConnectionProperties.Channel,
                        UserId           = qm.ConnectionProperties.UserId
                    };
                    if (filter is StaticQueueList)
                    {
                        ((RecentRemoteQueueManagerConnection)data).QueueList = new List <string>(((StaticQueueList)filter).Names);
                    }
                    else
                    {
                        ((RecentRemoteQueueManagerConnection)data).ObjectNamePrefix = filter?.NamePrefix?[0];
                    }
                    if (!string.IsNullOrWhiteSpace(qm.ConnectionProperties.UserId))
                    {
                        ((RecentRemoteQueueManagerConnection)data).UserId = qm.ConnectionProperties.UserId;
                    }
                }
            }
            UserSettings.AddRecentConnection(data);
        }