|
I looked in the object browswer but it shows me all the classes and i have to go thru every class and check the derived class to see if it implements that class... too time consuming.. has to be a beter way.. unless there is another way to do it using objct browser
|
|
|
|
|
Are you looking to find this out at runtime, or at design time? If it is at design time and you are using VS, just right click on the base class and do a "Find All References", then look for "xxx : BaseClass" results
Jeff
|
|
|
|
|
Over looked the simples thing... your suggestion did work.. Thanks. ANy luck with the form dialog?
|
|
|
|
|
Hola-
---===The Background===---
So here's the problem I'm running into. I'm throwing out a UDP packet from my machine to a subnet broadcast address. Once the packet is broadcast over the subnet, a series of cool little devices we used in our hardware called DigiConnect MEs (ethernet to serial converters - www.digi.com) read the packet, realize that it's a device discovery request, and then proceed to each send a packet back to my machine detailing their firmware version, IP, etc.
The first part is fine. I'm sending out over UDP, and when I use SharpPCap to get raw access and just sniff out any UDP packets, I find that, yes, the devices on the network are responding and sending packets back to me.
However, I'm trying to transition anyway from SharpPcap on the recieve end to allow for abstraction. Plus, SharpPcap doesn't support the network card in my laptop, which is annoying the heck out of me. =D
---===The Problem===---
The devices on the network respond to the same port on my machine that sent the packet to the broadcast address. I'm not sure if I have this reconfigured correctly to recieve it.
UdpClient u = new UdpClient("224.0.5.128", 2362);
byte[] packet3 = new byte[] {68, 73, 71, 73, 0, 1, 0, 6, 255, 255, 255, 255, 255, 255 };
int port = ((IPEndPoint)u.Client.LocalEndPoint).Port;
IPEndPoint recvpt = new IPEndPoint(System.Net.IPAddress.Any, 0);
u.Send(packet3, packet3.Length);
byte[] data = u.Receive(ref recvpt);
u.Close();
Thanks in advance for any help.
|
|
|
|
|
Heres an interesing (I hope) question
The short version of the question:
Is it possible to cast an instance of a WebService reference to an custom interface (the webservice contains the methods as defined in the interface)
The long version:
I have an application framework that consists of the following key components:
(A) Client API
(B) Server WebService
(C) Server Remoting Listener / Application
In runtime, the Client API pushes requests onto the Server WebService, which inturn pushes them onto the Server Remoting Listener / Application.
So as an example the Client API exposes a DoSomething method which calls the DoSomething web service method, which calls the DoSomething Server Remoting Listener / Application method, the return value of which is returned back up the tree.
In order to maintain a degree of control (and for remoting) all of these components use a common interface, i.e.
public interface IFrameworkMethods
{
int DoSomething();
}
The reason for all these degrees of seperation is that typically all three components are on different devices to split the load across the enterprise. For reasons of policy connectivity from client to server farm must be across HTTP however within the farm I can use remoting. All decisions that cannot be changed.
Now heres the question:
Under some configurations the Client API and Server Remoting Listener / Application are on the same device. As such it seems sensible to not take the performance hit of performing a HTTP post to localhost, and to push the requests directly onto the local listener.
In the first run of the code, I simply did something like this:
public int DoSomething()
{
int resultCode = 0;
if (directRemotingAvailable)
{
resultCode = remotingObject.DoSomething();
}
else
{
resultCode = webServiceObject.DoSomething();
}
return resultCode;
}
This obviously works, but this API exposes alot of methods so it is alot of if/else and bloat. Which got me thinking, I am using the interface for remoting, so why not use the interface defintion for the webservice as well.
So my Client API method now looks something like this:
public int DoSomething()
{
IFrameworkMethods obj = GetInterface();
int resultCode = obj.DoSomething();
}
private IFrameworkMethods GetInterface()
{
IFrameworkMethods obj = null;
if (configIsRemoting)
{
}
else
{
FrameworkMethodsWebService ws = new FrameworkMethodsWebService()
}
}
As you may have seen the problem I have surrounds the fact that I cannot cast/convert an instance of the FrameworkMethodsWebService to an interface of IFrameworkMethods . Which is fair enough, at the end of the day, they are entirely different objects.
So the question is based on this architecture can this be done somehow? and if so please prod me in the right direction.
-- modified at 11:54 Friday 12th October, 2007
|
|
|
|
|
MrEyes wrote: Is it possible to cast an instance of a WebService reference to an custom interface (the webservice contains the methods as defined in the interface)
What methods it exposes has nothing to do with what "type" it is. You can only cast an object to a type that it is or implements in the case of interfaces, period.
I strongly urge you to study software development material until you gain a more comprehensive understanding of fundamental concepts like this one before you develop production software.
|
|
|
|
|
led mike wrote: I strongly urge you to study software development material until you gain a more comprehensive understanding of fundamental concepts like this one before you develop production software.
Great piece of advice, however serves absolutely no purpose beyond hobbiests, classrooms and virgin standalone projects. When working in the real world of a preexisting production application framework that is currently deployed to around a 15 thousand servers, over a 200 thousand clients and has prooved to be extremely reliable and profitable, I find that rewriting and redeploying is, shall we say, a tad stupid.
There are many ways to meet a development challenge, unforutunalty many professional developers loose sight of the fact that they exist to serve end users not their own foibles and technical curiosity. As long as the result meets requirements and specifications and is supportable, usable, maintainable and scalable; I absolutley don't care if its architecture doesnt meet the current flavour of the day.
Bottom line, rant over, I have found a solution, it works.
Of to read some books, maybe, hmmm, The very Hungry Caterpillar
P.S. For anybody who is interested the solution is to create a wrapper around the webservice object that also uses the interface. When the WS interface is needed the main worker class creates/reuses an instance of the WS wrapper/proxy that can now be cast to the interface type and called using the same code that calls the remoting interface. Logic must exist within the wrapper/proxy to set initial params (i.e. url, timeout etc)
|
|
|
|
|
MrEyes wrote: P.S. For anybody who is interested the solution is
So the solution wasn't casting the WebService object to the interface because of what I stated, right?
MrEyes wrote: Bottom line, rant over
MrEyes wrote: I absolutley don't care if its architecture doesnt meet the current flavour of the day.
What did my post have to do with architecture?
|
|
|
|
|
I just installed VS 2005 on my Vista Machine and when the project runs it doesn't allow me to break point. Inside visual studios it is sitting ready to be run again. Does anyone know how I can get get the debugger to work. Thanks a million.
|
|
|
|
|
Are you running VS with administrator rights?
Me: Can you see the "up" arrow?
User:Errr...ummm....no.
Me: Can you see an arrow that points upwards?
User: Oh yes, I see it now!
-Excerpt from a support call taken by me, 08/31/2007
|
|
|
|
|
Thanks Martin. That did the trick.
|
|
|
|
|
You're welcome.
Me: Can you see the "up" arrow?
User:Errr...ummm....no.
Me: Can you see an arrow that points upwards?
User: Oh yes, I see it now!
-Excerpt from a support call taken by me, 08/31/2007
|
|
|
|
|
I would like to display a custom message box form as a modal dialog by calling Form.ShowDialog(this). However, I would like to make this call from a separate thread in my main class. Currently when I do this, upon exiting the second form (which is displayed correctly), my entire application locks up. I have put some sample code below which illustrates the problem...
public class MainForm : Form {
...
private void Button1_Click(object sender, EventArgs e) {
new Thread(new ThreadStart(showModalDialogThread)).Start();
}
private void showModalDialogThread() {
ModalDialog myDialog = new ModalDialog();
myDialog.ShowDialog(this); // freezes the application on close event
}
}
public class ModalDialog : Form { ... }
Thanks ahead of time to anyone who can help,
Jeff
|
|
|
|
|
You can't show a modal dialog for your application on a separate thread. Because you are passing "this" in as the parent windows, the message box must be created and shown on the same thread that the parent window was created on.
What exactly are you trying to accomplish?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I currently have a threaded process that loads a file in the background, but it shows dialogs in a number of situations using the "MessageBox.Show(this, ...)" method (works as expected) to notify the user of progress/errors. However, a few of the dialogs present messages that are far too long to show in a standard MessageBox, so I made a new class called MessageBoxExtended, which looks and feels identical to the built-in MessageBox, with similar parameters and everything. On my class I have a static method (Show) that you can send the same parameters as in MessageBox.Show. However, when I call my static method (MessageBoxExtended.Show(this, message, caption)) from the same place I called the other, I get complete lock-up when I try to close my dialog. Since the built-in MessageBox works fine for this, I don't understand why there is no way for me to implement the same functionality. I tried to use owner.Invoke() within my MessageBoxExtended.Show() method, but that freezes up on loading. Any other ideas, or are you certain there is no way to do this?
Jeff
|
|
|
|
|
I would suggest that you create delegates/events to accomplish this. for example:
to show progress :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
Import imp = new Import();
public Form1()
{
InitializeComponent();
imp.ProgressChanged += new ProgressChangedEventHandler(imp_ProgressChanged);
}
protected void imp_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.progressBar1.Maximum = e.Total;
this.progressBar1.Value = e.CurrentProgress;
}
private void button1_Click(object sender, EventArgs e)
{
Thread thrd = new Thread(new ThreadStart(imp.Start));
thrd.Start();
}
}
}
//Your Delegate
public delegate void ProgressChangedEventHandler(object sender, ProgressChangedEventArgs e);
//Your ProgressChangedEventArgs event
public class ProgressChangedEventArgs : EventArgs
{
//Fields
private int _currentProgress;
private int _total;
//Constructors
public ProgressChangedEventArgs(int currentProgress, int total)
{
this._currentProgress = currentProgress;
this._total = total;
}
//Properties
public int CurrentProgress
{
get { return this._currentProgress; }
}
public int Total
{
get { return this._total; }
}
}
//Import Class
public class Import
{
//Events
public ProgressChangedEventHandler ProgressChanged;
//Method
public void Start()
{
int tot = 1000;
for (int i = 0; i < tot; i++)
{
OnProgressChanged(this, new ProgressChangedEventArgs(i, tot));
Thread.Sleep(100);
}
}
//Event Method
protected void OnProgressChanged(object sender, ProgressChangedEventArgs e)
{
ISynchronizeInvoke sync = (ISynchronizeInvoke)this.ProgressChanged.Target;
if (sync.InvokeRequired) {
ProgressChangedEventHandler tmp = new ProgressChangedEventHandler(OnProgressChanged);
object[] args ={ sender, e };
sync.Invoke(tmp, args);
return;
}
if (ProgressChanged != null)
ProgressChanged(sender, e);
}
}
-- modified at 13:28 Friday 12th October, 2007
|
|
|
|
|
OK. I have come up with a painful, yet operable, solution. In every single static "Show" method that could get called in my MessageBoxExtended class, I do the following...
public static DialogResult Show(IWin32Window owner, ...) {
Control parent = owner as Control;
if (parent != null && parent.InvokeRequired) {
return (DialogResult)parent.Invoke(new SpecificDelegate(MessageBoxExtended.Show),
new object[] { parent, ... });
} else {
return (new MessageBoxExtended(...)).ShowDialog(owner);
}
}
Every "..." in the previous (and following) code is filled in with identical arguments with what is passed in. This works, but I am confused why the following does not...
public static DialogResult Show(IWin32Window owner, ...) {
Control parent = owner as Control;
MessageBoxExtended mbe = new MessageBoxExtended(...);
if (parent != null && parent.InvokeRequired) {
return (DialogResult)parent.Invoke(new ShowDialogDelegate(mbe.ShowDialog),
new object[] { parent });
} else {
return (new MessageBoxExtended(...)).ShowDialog(owner);
}
}
Does anyone have any insight as to why the hell the first method works as expected but the second freezes?! My head feels like it is about to explode (and I am sad becuase I have to add like 50 delegates to my class)!
Jeff (More confused than I have ever been)
|
|
|
|
|
Hi Jeff,
Since Controls are not thread-safe, the basic rule is: the thread that creates a Control
is the only thread that is allowed to access the Control (with the exception of a few
members such as InvokeRequired and Invoke).
Since most often all Controls are related (part of Form.Controls, parent to each other, etc),
this normally means only one (the main) thread will create and access Controls.
the first method is OK.
the second fails because another thread creates mbe, then asks the creator of owner
(probably the main thread) to access mbe.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
That makes perfect sense! Thank you very much for the straightforward and descriptive answer! My head hurts less now. I sure wish that I could just do overloaded methods like in C++ (with default values) so I only had to make one change instead of like 200. Thanks for the advice in the following post as well.
Jeff
|
|
|
|
|
One more thing, you don't need as many delegates as MessageBox.Show() has overloads.
Within your MessageBoxExtended class you could map most of them onto the most powerful one,
then let that one perform the InvokeRequired/Invoke stuff.
And you could shortcircuit that for the most popular overload(s) adding some delegates and
code again to improve performance, although this is probably irrelevant since MessageBoxes
typically block your thread anyway until the user decides to close them.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I need some help getting base data from an object.
Here is the code that I am using:
l_oAttributes = type.GetCustomAttributes(true);<br />
<br />
foreach (Attribute attribute in l_oAttributes)<br />
{<br />
Object l_oTest = l_oAttributes[0];<br />
}
etc etc...
The information I need is in the base of the l_oTest (ie ColumeID and such), how can I access this information?
Thanks
|
|
|
|
|
RussBus wrote: how can I access this information
I guess l_oTest is a type other than Object so you need to cast it and then access it's public members, or am I missing something?
|
|
|
|
|
Do I cast it as the type of attribute it is? How would I do this?
|
|
|
|
|
If you know the base type of l_oTest, simply convert it to that type...
KnownBaseType kt = l_oTest as KnownBaseType;
if (kt != null) {
// Do Something
}
If you don't know what the base type is, but you know you want to get or set the value of some property, use reflection...
using System.Reflection;
...
PropertyInfo pi = l_oTest.GetType().BaseType.GetProperty("PropertyName");
if (pi.CanRead) {
PropertyReturnType result = (PropertyReturnType)pi.GetGetMethod().Invoke(l_oTest, null);
}
Is this what you need?
Jeff
|
|
|
|
|
I still don't get the value.
I want to get the value for ColumnID, when I use you code I get ColumnID but not the value for it.
|
|
|
|
|