|
<<relatively new="" to="" webservices="" so="" bear="" with="" me="">>
the idea is this, read a recorset into XML object (in C# webservice), VB6 app calls the service gets passed the object thn uses XMLHTTP to read it.
OK problem is i have no idea how to pass it?, i can read XMLHTTP (in VB), and prob. populate XML in C# but the middle?(passing, not wanting to use xml file at all) - can anyone help ?
|
|
|
|
|
Hello,
I am looking for a way in C# to be able to programatically build a list of available classes in the applcation that I can search the list and execute a desired class method based on a passed parameter to the program. I could do this by building a case statement with all available classes, but would like it to be more dynamic.
Thanks
|
|
|
|
|
Hi!
You can try this code snippit, I think it's what you want to do. I made this type of thing before for a Java proggie, and it was even easier in C#! Good Luck!
A few runs look like:
------------------------------
RunArbitraryClasss.exe RunArbitraryClasss.NonRunnableClass arg1 arg2
Unhandled Exception: System.Exception: A class was specified that is not subclassed from ValidRunnableClass!
at RunArbitraryClasss.RunArbitraryClasss.Run(String[] args) in c:\source\automation\runarbitraryclasss\runarbitraryclasss.cs:line 53
at RunArbitraryClasss.RunArbitraryClasss.Main(String[] args) in c:\source\automation\runarbitraryclasss\runarbitraryclasss.cs:line 20
------------------------------
RunArbitraryClasss.exe RunArbitraryClasss.RunnableClass arg1 arg2
I'm a runnable class: arg1 arg2
Here's the source!
--------------------------------------------------------------
using System;
using System.Reflection;
namespace RunArbitraryClasss
{
class RunArbitraryClasss
{
[STAThread]
static int Main(string[] args)
{
RunArbitraryClasss oRunArbitraryClasss = new RunArbitraryClasss();
return(oRunArbitraryClasss.Run(args));
}
public int Run(string[] args)
{
Type [] aTypes = System.Reflection.Assembly.GetExecutingAssembly().GetTypes();
foreach(Type oCurrType in aTypes)
{
if(oCurrType.ToString() == args[0] && oCurrType.IsSubclassOf(Type.GetType("RunArbitraryClasss.ValidRunnableClass")))
{
ConstructorInfo ci = oCurrType.GetConstructor(Type.EmptyTypes);
ValidRunnableClass vrc = (ValidRunnableClass) ci.Invoke(null);
string [] passArgs = new string [args.Length - 1];
int i = 0;
for(i = 1; i < args.Length; i++)
{
passArgs[i - 1] = args[i];
}
return(vrc.Run(passArgs));
}
}
throw new Exception("A class was specified that is not subclassed from ValidRunnableClass!");
}
}
abstract class ValidRunnableClass
{
abstract public int Run(string [] args);
}
class RunnableClass : ValidRunnableClass
{
public override int Run(string [] args)
{
Console.Write("I'm a runnable class:");
foreach(string tempStr in args)
Console.Write(" {0}", tempStr);
return(0);
}
}
class NonRunnableClass
{
public int Run(string [] args)
{
Console.Write("I'm a NON-runnable class:");
foreach(string tempStr in args)
Console.Write(" {0}", tempStr);
return(0);
}
}
}
Nick.
|
|
|
|
|
This worked on returning the class names. I now have populated a string collection with the names of the matching classes. In doing so, I ran into another question. If I have several classes that have a method of .execute(), how can I create an instance and call the .execute of the function that matches the function name that is in the string collection? for example:
public class MyTestFuction
{
public void Execute()
{
// do something here
}
}
string s = "MyTestFuction"
if (s == "MyTestFuction")
{
//How to use the string name to
//call the matching class
s ????? .Execute();
}
|
|
|
|
|
Take another look at ValidRunnableClass. It's an abstract class which exposes one method, Run(). If you change your example above a hair, to look like:
public class MyTestFuction : ValidRunnableClass
{
// Change the Execute call to match the Run() method in ValidRunnableClass.
public override void Run(string [] args)
{
// do something here
}
}
Now, you have a class that has a common interface. You can add more classes at will, without having to add any switch/cases at all. Next, to cause the execution check my example again:
Type [] aTypes = System.Reflection.Assembly.GetExecutingAssembly().GetTypes();
foreach(Type oCurrType in aTypes)
{
if(oCurrType.ToString() == args[0] && oCurrType.IsSubclassOf(Type.GetType("RunArbitraryClasss.ValidRunnableClass")))
{
// Get the constructor for the class to invoke the run method on.
ConstructorInfo ci = oCurrType.GetConstructor(Type.EmptyTypes);
// Create an instance of the class that is derived from
// ValidRunnableClass. This will give us our prototype for invoking the
// Run method on the subclass.
ValidRunnableClass vrc = (ValidRunnableClass) ci.Invoke(null);
// Drop the first arg from the args list.
string [] passArgs = new string [args.Length - 1];
int i = 0;
for(i = 1; i < args.Length; i++)
{
passArgs[i - 1] = args[i];
}
// Execute the target class.
return(vrc.Run(passArgs));
}
}
throw new Exception("A class was specified that is not subclassed from ValidRunnableClass!");}
First, you create an instance of the ValidRunnableClass interface from a System.Type object. You do this with the System.Type.GetConstructor() function. Then, you use the ConstructorInfo.Invoke() method to create a ValidRunnableClass object. Then, you call the Run() method on the ValidRunnableClass which does your work. Because you extended MyTestFunction from ValidRunnableClass, it will call the proper method in MyTestFunction automatically!
Ok, I think you should be able to make it go from here.
Good luck!
Nick.
|
|
|
|
|
is this what you want??
testButton1.Image = Image.FromFile(path);
Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning
Mark Twain
Get your facts first, and then you can distort them as much as you please
Mark Twain
|
|
|
|
|
I'm not sure if you want to load the icon at run time or design time. At design time, you can obviously simply add it through the visual studio designer. At run time you have a couple of options:
1:
You can populate an image list at design time with any images you need for your button and associate them through the button's imagelist property. You can then change the button's icon at run time by simply changing the ImageIndex property to the correct image in the ImageList.
2:
You can pull icons from your assembly if they are compiled as an embeded resource. Right click on your project and choose Add Existing Item. Browse to the icon you want to add (You may need to change the Files of Type drop down to Image Files), and select open. The icon is now in your project, go to its properties and change the Build Action to Embedded Resource. You can now access this icon at runtime with the following code:
using System.Drawing;
...
System.IO.Stream strm = this.GetType().Assembly.GetManifestResourceStream(IconPath);
Icon i = new Icon(strm);
However, to assign this to the Image property of your button, you will need to convert to a bitmap, as it does not accept icons at run time, do this as follows:
using System.Drawing;
...
System.IO.Stream strm = this.GetType().Assembly.GetManifestResourceStream(IconPath);
Icon i = new Icon(strm);
Bitmap b = i.ToBitmap();
One thing to be careful of regardless of the method you choose is to make sure that you have the correct settings for the TextAlign & ImageAlign properties of the button, otherwise the text & image may overlap.
Hope this is useful.
|
|
|
|
|
I am trying to download a intel hex file to target system with serial communication.
I do not know how to write in C# a code to send lines until the end of file.
I can send an entire hex file to commPort but I get problen with <cr> and <lf>
of my hex file in the end of line of hex file.
I have a pesode code below written in pascal may be it help to anderstand my problem. Whith this code I have no problem to download a hex file.
i: integer;
line: string;
for i:= 1 to length(line) do
begin
code..
sndbyte(ord(line[i]));
end;
sndbyte(13); <cr>
sndbyte(10); <lf>
I will be very thankful if you could help me to write this code with C#.
Salam
|
|
|
|
|
i was wondering if it was possible for me to close a messagebox that is open from within my program...the messagebox is opened on a seperate threat...so my progress bar can still keep progressing. When the progress bar is done...reguardless of weather or not the user selected Yes or No i want the message box to close.... is it possible to close it?
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
One thread is doing work and another thread shows the progress of the work in a Form, am I right?
If so, the thread doing the work could simply kill the form's Close() method when finished.
|
|
|
|
|
well the main thread is doing the progress...when the user clicks a button (cancel) it opens up a message box on its own thread. i just was wondering if it was possible for me to close the message box...even after the Show Method was already called apon.
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
Well, if the messagebox is running on a different thread, just kill off the thread using
Thread.Abort()
Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning
Mark Twain
Get your facts first, and then you can distort them as much as you please
Mark Twain
|
|
|
|
|
Hello all,
Quick problem. I've got a Bitmap.
Bitmap bit = new Bitmap(this.GetType(),"bitmap.bmp");
This loads the bitmap ok. Now, I wanna add some text to it and save the added text to the bitmap itself for later use. I can't use OnPaint or anything like that.
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "But a fresh install - it's like having clean sheets" - C. Maunder Lounge 3 Mar '03
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
Jonny Newman wrote:
Now, I wanna add some text to it and save the added text to the bitmap itself for later use.
By "save it for later use", do you mean physically save it back to disk in the file or just modify it for late use in the currently running instance of your program? I do not think you can modify a resource and then save it back into the executable or DLL on the fly. But I suppose I could be wrong, it has happened before
If you only wish to modify for use during the current instance and lose all changes when you shut your app down, you can use the Graphics class and its paint methods.
Example:
Bitmap bit = new Bitmap(this.GetType(),"bitmap.bmp");
using(Graphics g = Graphics.FromImage(bit))
{
g.DrawString("Some String Here",myFont,myBrush,myPointF);
}
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Nathan Blomquist wrote:
If you only wish to modify for use during the current instance and lose all changes when you shut your app down, you can use the Graphics class and its paint methods.
Thats the one I meant
Nathan Blomquist wrote:
g.DrawString("Some String Here",myFont,myBrush,myPointF);
This doesn't work, I don't know why....it only load up the original bitmap...
Rectangle rect = new Rectangle(this.Location.X + 87,this.Location.Y + 11,150,36);
string show = author.ToString();
g.DrawString(show,new Font("Arial",13),new SolidBrush(Color.Red),rect);
...
this.img = bit;
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "But a fresh install - it's like having clean sheets" - C. Maunder Lounge 3 Mar '03
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
Never mind, i've fixed it now.
Cheers anyway.
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "But a fresh install - it's like having clean sheets" - C. Maunder Lounge 3 Mar '03
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
In our application, we use system environment variables in our project properties in order to redirect our output files. It is done this way so not every developer and the build machine are bound to have the same absolute path.
We do this, for C++ projects, the following way: In the Project Properties, we set Configuration Properties -> General -> Output Directory to $(MyBuildDir)\Debug, for instance, and MyBuildDir resolves to c:\MyBuilds. This works very well with C++ projects, using VS.NET.
Recently, we added a C# project to our build process for this application. But setting the Ouput Directory with an environment variable, the environment variable does not get expanded and it creates a directory literally named $(MyBuidDir)\Debug under the project directory and puts the files there.
Why does this does not work like with VC++.NET? Is it because environment variables don't work with C# builds?
|
|
|
|
|
Hi Michel,
have you found a solution? We're facing the same problem
Regards
Thomas
Disclaimer: Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.
|
|
|
|
|
in my application i would like to get the PID of the current process, does any one know how i can do this?
Thanks
Tim
|
|
|
|
|
System.Diagnostics.GetCurrentProcess().Id
|
|
|
|
|
i dont have GetCurrentProcess in the Diagnostics namespace.
Any ideas why its not there? am i calling it from the wrong place?
|
|
|
|
|
System.Diagnostics.Process.GetCurrentProcess().Id
|
|
|
|
|
Thanks very much thats got it
|
|
|
|
|
I have the Struct:
public struct Base
{
public string Name;
public string Phone;
}
public struct Operator
{
public int ID;
public Base[] OperatorData;
}
I want to populate a repeater with 2 collumns(Nome,Phone).
The following code doesn´t work.
rpt.DataSource = Operator.Dados;
rpt.DataBind();
In aspNet
<%# DataBinder.Eval(Container.DataItem,"Name") %>
<%# DataBinder.Eval(Container.DataItem,"Phone") %>
Please, help me.
How can I populate the repeater with a array of Struct ?
Thanks.
Pablo Rodrigo
|
|
|
|
|
(Hello Paresh! I'm sure you will answer...)
For simple things, DataBinding is a cool thing; Now I saw that there is a easy property to bind a DataSource with a key in the datatable:
list.DataSource=m_workset.Projekte;
list.DisplayMember="projekttext";
list.ValueMember="projektid";
Looks good but I didn't find how to get then this Value out of an item - say by double-click on an item.
Does anybody knows hot to get this valuemember out of an listboxitem?
Thanks!
Stefan
|
|
|
|