?
Solved

Interface Switch Form1?

Posted on 2013-01-19
9
Medium Priority
?
298 Views
Last Modified: 2013-01-26
I have the following code on Form1 to use one of two Queue interfaces. I currently use this code to switch between queues. My 'Proposed Switching' class does choose the correct queue interface, I just cannot call the interface methods like Enqueue(), Dequeue(), Peek(), etc... Help!

[Form1 code]          
        private MsmqSwitch _mqueue = new MsmqSwitch();

         private void btnLogin_Click(object sender, EventArgs e)
        {
            QueueType queueType;

            if (rbtRegularQueue.Checked)
                queueType = QueueType.NonTransactional;
            else
                queueType = QueueType.Transactional;

            _mqueue.Login(queueType, queueString);
        }

        private void btnSendMsg_Click(object sender, EventArgs e)
        {         
             _mqueue.Enqueue(txtMessage.Text, "message label here"); //Cannot Call 'Enqueue'
        }

Open in new window


[Switching class]
 

public enum QueueType { NonTransactional = 1, Transactional = 2 };

  public class MsmqSwitch : IMsmQueue, IMsmQueueTrans
  {
        IMsmQueue _mqueue;
        IMsmQueueTrans _mqueueTrans;

        public MessageQueue Login(QueueType QueueType, string queueString)
        {
            switch (QueueType)
            {
                case QueueType.NonTransactional:
                    _mqueue = new MsmQueue(queueString);
                    return (MessageQueue)_mqueue;
                    
                case QueueType.Transactional:
                    _mqueueTrans = new MsmQueueTrans(queueString);
                    return (MessageQueue)_mqueueTrans;                                 
            }
            return null;
        }
    }

Open in new window

0
Comment
Question by:pointeman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38797081
The MessageQueue class (.NET) does not contain IMsmQueue or IMsmQueueTrans. thus the reason your code does not work.
Change your switch class as follows: (only if MsmQueue and MsmQueueTrans are subclasses of MessageQueue)
public class MsmqSwitch : IMsmQueue, IMsmQueueTrans  
  {
        MessageQueue _mqueue;
        MessageQueue _mqueueTrans;

        public MessageQueue Login(QueueType QueueType, string queueString)
        {
            switch (QueueType)
            {
                case QueueType.NonTransactional:
                    _mqueue = new MsmQueue(queueString);
                    return _mqueue;
                    
                case QueueType.Transactional:
                    _mqueueTrans = new MsmQueueTrans(queueString);
                    return _mqueueTrans;                                 
            }
            return null;
        }
    }

Open in new window

0
 

Author Comment

by:pointeman
ID: 38797125
Yea, I know. Those are my classes which use MessageQueue class. I need to switch between the two interfaces I built.
0
 

Author Comment

by:pointeman
ID: 38797131
I've been reading about loosely coupled interface programming although not sure it apples here.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38797802
I'm not even sure how that would compile. Your MsmqSwitch class proclaims to implement the IMsmQueue and IMsmQueueTrans interfaces, but you haven't shown anything that would indicate you did implement such. Is this the complete code for the MsmqSwitch class?
0
 

Author Comment

by:pointeman
ID: 38798387
Yea, the IMsmQueue and IMsmQueueTrans are part my first idea. I forgot to remove them from on cut-n-paste. I'm trying to build a component for .net usage. There are two Interfaces (which you noticed), each performs very well, just need a way to swap them and still access each methods. Also trying to eliminate unnecessary code.
0
 

Accepted Solution

by:
pointeman earned 0 total points
ID: 38799500
0
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38799551
Unless IMsmQueue and IMsmQueueTrans or its classes have a base interface or class, you can not use your current code as is.
Please post IMsmQueue and IMsmQueueTrans and their respective class declarations (I only need propertiies and method signatures)
0
 

Author Comment

by:pointeman
ID: 38801656
0
 

Author Closing Comment

by:pointeman
ID: 38821804
Example 2 is a perfect answer if using nearly identical Interfaces like me. Take a look...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question