|
i got a problem about WMI.
i want use wmi to config my network adapter, such as ip address, subnet mask, etc. and i found some methods of Win32_NetworkAdapterConfiguration class can do this, but they are all enable method, for example, EnableDNS ,it can enable DNS setting and specify dns search order.
THE PROBLEM is how can i DISABLE DNS search, namely , obtain DNS server automatically.
|
|
|
|
|
Ok i am struggling with the factory pattern big time. This pattern seems great if you are creating objects that share all the same properties but i can never find a sample client that uses the specific concrete classes that have different properteries. ( Ok that probably made no sense so here is a sample using generics )
public abstract class Vehicle
{
protected string name;
protected string type;
public Vehicle()
{
}
public Vehicle(string name)
{
this.name = name;
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Type
{
get { return type; }
}
}
// a concrete vehicle
public class Car : Vehicle
{
public Car() : base()
{
}
public Car(string name, string type) : base(name)
{
base.type = type;
}
}
// another concrete vehicle
public class Truck : Vehicle
{
bool 4WD = false;
public Truck() : base()
{
}
public Truck(string name, string type) : base(name)
{
base.type = type;
}
public Engage4WD() // This only exists for a truck
{
4WD = true;
}
}
interface IVehicleFactory
{
T CreateObject<t>(string name) where T : Vehicle, new();
}
public class VehicleFactory : IVehicleFactory
{
public T CreateObject<t>(string name) where T : Vehicle, new()
{
// create instance of Type T where this type derives from Vehicle
T v = new T();
v.Name = name;
return v;
}
}
public class FactoryPatternUsingGenericMethod
{
static void Main(string[] args)
{
IVehicleFactory f = new VehicleFactory();
Car c = f.CreateObject<car>("Kitty");
Truck d = f.CreateObject<truck>("test");
}
}
}
It appears at this point i can get a truck or a car using the factory however what is the benefit of this. This just seems like alot of work when i could have just had a separate truck object and car object inheriting from vehicle and use the new operator without resorting to a factory. Would this not give the same result.
I guess i just can't seem to quite grasp what the big benefit is here for the presentation layer?
Thanks in advance
|
|
|
|
|
The benefit is that you'll have a single point that creates instances of a common base class or interface based on a parameter.
Your class factory should *never* return a Car or a Truck, it should return only Vehicle.
You may argue that this would stop you from using the Engage4WD method from your Truck class. This is because your class inheritance is wrong. A Truck should not derive from a Vehicle, because it does not complies with the Liskov Substitution Principle.
It seems that you're using the flawed "is a" principle for OO design, so, if you don't know LSP yet, please read this document[^] and understand why a Square should not derive from a Rectangle. After reading it, you'll understand why your class factory doesn't help in anything and should return always a base class.
I see dead pixels
Yes, even I am blogging now!
|
|
|
|
|
never heard of the principle, looks like i have some homework. I figured something was wrong, the objects are alike but not enough to work correctly with the inheritance. I'll continue looking at lsp to figure out how i would fix the sample i wrote. It just seems like based on what i've always been told truck would inherit from vehicle because it does share some similar properties.
Thanks
|
|
|
|
|
Daniel Turini wrote: please read this document[^]
That was a really good read.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi there,
I want to make an answering machine with tapi using c# .After connecting , i need to playback a wave file to caller . I tried many way but failed. If anyone know please help me , or give me the code to do that .
Thanks.
|
|
|
|
|
1) Use Google to search for 'TAPI FAQ' there are several GREAT links there.
2) Just as an FYI. You don't exactly use TAPI to play a wave file. TAPIs responsibility ends with giving you a voice handle to a device really.
3) TAPI currently is not great under Managed code. There is a C# interface implementation out there (search on GotDotNet) for it...
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
My Blog[^]
|
|
|
|
|
Now i using VS 2003 and tapi3.x to program.
i think with tapi3 i can play back wave file , but i find that all the sample playback file in MSDN write in C++ . I don't know how to do that in C# .
If you know please help me .
thanks
|
|
|
|
|
And i dont mean a list of processes, like if you had explorer running, looking at drive c, the task name would be DRIVE_C(C , and of course the process would be explorer.
|
|
|
|
|
Hi there!
I'm using the XmlTextReader to parse an XML file. The structure of the file is as follows:
+++
<?xml version="1.0" encoding="utf-8" ?>
<slideshow title="My Slideshow">
<image url="imgurl_1" copyright="copy_1" contact="contact_1">
<en-US>
<title>title_1</title>
<description>desc_1</description>
</en-US>
<de-DE>
<title>titel_1</title>
<description>beschreibung_1</description>
</de-DE>
</image>
</slideshow>
+++
There might be any number of image and language (e.g. fr-FR) nodes in the file.
What I'm trying to do is to find a certain language (e.g. 'de-DE') node. If the node can't be found, I'd like to find a different one (fallback language). But can this be done using the XmlTextReader? I can't seem to figure out how to simply check a node for its title and move on if there is no match. Or do I have to use an entirely different approach?
Thanks in advance and a happy sunday!
/matthias
<br><div style="{width:100%; color:navy; background-color:white;border-top:navy 1pt solid;}"><font size="1">I love deadlines. I like the whooshing sound they make as they fly by. <br>[Douglas Adams]
|
|
|
|
|
Hiya,
XmlTextReader provides a forward-only way of parsing xml documents. This means you don't have random access ability and the means to jump around your xml document. You start at the top and work your way to the end.
With this in mind, if you want a 'fallback' language in your example, you either need to provide this as the last entry in the xml, or else implement a way of parsing which remembers the 'best yet' record from the xml.
Two points about your xml, firstly probably just a typo but the </image> tag doesn't match <img> tag, and secondly you are using the language as the element name <en-US> - this might be better represented as <language name=en-US>.
You can use XmlTextReader.Read() to fetch the next element from the document. Check its NodeType property to determine if it is Element . Then using your xml as it stands you can use the Name property to pick up the element name. From there you can have a boolean flag which you set to tell you're in the right language and can read the title and description.
Hope that makes some sense...
Regards,
Rob Philpott.
|
|
|
|
|
Hi Rob,
thanks for your reply. I've had a look closely last night at the XmlTextReader and figured, that it was not the right thing to use. Switched to the XmlDocument instead for increased flexibility. As for your suggestion to use the language codes (like en-US ) as attribute values, I've done that. Makes perfectly sense.
Thanks for your help! I really appreciated it.
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
I want to set backgroundimage of a MDIForm through coding. So I set it with the help of openfiledialog.
But the problem I m facing is that, it is not in center, the image get "tiled" (many same images on the form) I want only 1 image and it must be in center of the form.
Another problem is that I want to see this BackGroundimage after restarting the application. (I don't want to store the image path in the database)
Please help me out.....
Thanx in advance
--
Harshal Bhakta
Pune
|
|
|
|
|
for the first problem, you will need draw the backgroundimage by yourself, override the paint event and calculate the bounds, draw it
the second, you can write it into registry, when application is starting, check the registry to determine whether the backgroundimage is selected.
|
|
|
|
|
Hi
Thank you for your quick response.
But I m still confused. I want to select the image as a background from the path (openfiledialog), and the image should at the center of the screen.
You wrote "draw the backgroundimage by yourself,override the paint event and calculate the bounds"
can u please tell me the code for it.
Second problem of saving the image: Next time when I run the application I must see the previously set background image. (I don't want to save the path in the database) you suggested abt registry..plz send code also for it.
please help........
|
|
|
|
|
see your email
|
|
|
|
|
i want to make a chronometer connected to the parallel port of the computer and i want to get some help if you have done any projcet like this,i have seen something about this in a forum so i decided to do this for my lesson project.it must iclude these;TLP521-4(Optocoupler), 74LS139 (Decoder), 74LS247(Display driver), 4 anode Display.
i am trying but i dont have enough knowlegde about displays,if you have any please help.
|
|
|
|
|
I can't understand,
If I have two form
One is form1
one is form2
how to set the button in form1 to open form2
|
|
|
|
|
If I understand you correctly, you want a button control on form1 to open form2?
In the Click event of your button, write some code like:
<br />
private void btnOpenForm_Click(object sender, EventArgs e)<br />
{<br />
Form2 myForm = new Form2();<br />
<br />
form2.Show();<br />
<br />
form2.ShowDialog(this);<br />
}<br />
I hope this helps.
Jeff Bramwell
|
|
|
|
|
i want to make a chronometer connected to the parallel port of the computer and i want to get some help if you have done any projcet like this,i have seen something about this in a forum so i decided to do this for my lesson project.it must iclude these;TLP521-4(Optocoupler), 74LS139 (Decoder), 74LS247(Display driver), 4 anode Display.
i am trying but i dont have enough knowlegde about displays,if you have any please help.
|
|
|
|
|
We need to display the data received from a csv stream in HTML format.
For this,we are thinking of importing into a dataset and binding a datagrid to the dataset.
Can someone provide the C# source of exactly how to go about it.
We DO NOT WANT to save the stream into a file,and then read through odbc;we would rather import the stream into a dataset directly
thanks in advance
|
|
|
|
|
If you just want to display it in HTML and don't need the DataGrid , you can do it the old fashioned way and parse the file using these rules.
- Write
<table> to your output stream - While your input stream has characters left:
- Read a line (or to the end) from your input stream.
- Write "" to your output stream.
- Replace all commas not inside a balanced set of quotation marks with
</td><td> .
- Replace all
</td><td>" with </td><td> . - Replace all
"</td><td> with </td><td> . - Replace all
"" with " . - If the first character of the line is
" , remove it. - If the last character of the line is
" , remove it. - Write the modified string to the output stream.
- Write "" to your output stream.
- Write
</table> to your output stream.
Now, you have a table with your CSV in it.
For example, following that replacement rule set with the string 1,2,3,4,"I say""Hello,"" and you don't","Com,ma" , we get the following replacements:
1,2,3,4,"I say""Hello,"" and you don't","Com,ma"
1</td><td>2</td><td>3</td><td>4</td><td>"I say""Hello,"" and you don't"</td><td>"Com,ma"
1</td><td>2</td><td>3</td><td>4</td><td>I say""Hello,"" and you don't"</td><td>Com,ma"
// Replace all "</td><td> with </td><td>.
1</td><td>2</td><td>3</td><td>4</td><td>I say""Hello,"" and you don't</td><td>Com,ma"
// Replace all "" with ".
1</td><td>2</td><td>3</td><td>4</td><td>I say"Hello," and you don't</td><td>Com,ma"
// If the first character of the line is ", remove it.
1</td><td>2</td><td>3</td><td>4</td><td>I say"Hello," and you don't</td><td>Com,ma"
// If the last character of the line is ", remove it.
1</td><td>2</td><td>3</td><td>4</td><td>I say"Hello," and you don't</td><td>Com,ma
"we must lose precision to make significant
statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi Friends
I made a project wich it has a form and I splited the form with 2 panel in the left hand I put a treeview control
Now I want to do these works:
When I click on one of the treeview nodes a related from or frame to that node display on right hand and these forms and frames are different from each other but the problem: there is only 1 method when you click on the treeview: private void treeView1_AfterSelect ( object sender, TreeViewEventArgs e )
I need to decicde on something that indicates which one of tree view nodes is selected.
If any of friends know how can I solve this problem please inform me.
thanks
FS.Hashemi
|
|
|
|
|
F. Hashemi,
Use the e.Node value that is provided by the event parameters. It will give you a reference to the clicked node.
Jeff Bramwell
|
|
|
|
|
I like to do a two-step process here.
1) When you create the TreeNode , set the Tag property with an identifier value that allows you to quickly ascertain the type of the TreeNode clicked. This could be as easy as using an Enum in your code.
2) As the previous poster suggested, use the TreeViewEventArgs.Node property to investigate the recently clicked TreeNode
You can refer to my article Building the CVS Root File Changing Utility here on codeproject.com for examples of using these properties together.
"we must lose precision to make significant
statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|