|
Hi Mark. There are some articles on attributes here on CodeProject that you may want to check out (do a search for "attributes"). I particularly liked this one from sadaf alvi
http://www.codeproject.com/csharp/attributes.asp[^]
I haven't tried it, but it seems reasonable that an Attribute could be created at runtime... how would it be applied? I see the GetCustomAttributes method, but nothing to set them...
|
|
|
|
|
Actually, you cannot create attributes at runtime. They represent meta-data, or data that describes data (the compiled code). They are set only by the compiler for the particular source file.
However, there are a couple ways around this. The first it so emit an assembly (see System.Reflection.Emit ) and attribute a emitted class with attributes before compiling the assembly.
The second way is to implement ICustomTypeDescriptor . For the most part, most methods can use the appropriate overloaded TypeDescriptor method that takes a bool dictating whether or not to query for said interface (that way, while you still have to implement every method, you don't have to write any custom code when you don't need to). In your implementation of ICustomTypeDescriptor.GetAttributes , return a custom set of attribute classes.
Implementing ICustomTypeDescriptor is only useful when something uses the TypeDescriptor class (or something else that uses it, like the PropertyGrid component - we the interface to custom some of this stuff in a runtime grid in our app). Of course, a class of yours could query for it, too, but usually the TypeDescriptor is sufficient.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Interesting, Heath. Good info
|
|
|
|
|
Thanks for that Heath, very useful information. At least I can rest assured that I was not being that Stupid when I asked the question...
|
|
|
|
|
the obsolete attrib is hardcoded into the compiler..
and so is the strongname key attribs and everything else that can raise compile errors..
you cannot create your own attribs that does the same..
//Roger
|
|
|
|
|
Hi anybody knows how to get the IP address of my DSL modem passing through
linksys router using .net framework in C# ????
Thanks
|
|
|
|
|
If you're linksys has the latest BIOS update, you could use the UPnP interface to query the external IP address. You'll need to find more information about UPnP in MSDN or download the SDK from the same site. There's far too much to cover on a broad topic here.
Another way - somewhat of a hack - would be to create a new process (see System.Diagnostics.Process ) to start tracert.exe and redirect its stdout. The second hop should be the IP address of your linksys's external interface. This only works if it allows pings out if firewalled.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi
I am trying to do the same. As someone suggested me to use a feature in my linksys router but mine doesn't have it. Anyway, there are several ways but I did:
1. Create a simple html page which records(using script php, java, asp..) client IP and display it on the page. This page will be hosted somewhere outside your linksys router. example: http://www.somedomain.com/ip.html which will display string IP=111.112.114.115. Your code will go to that page and grab the text and parse for IP.
and Here is the code in C#
Regex regexp = new Regex("IP=[0-9]+.[0-9]+.[0-9]+.[0-9]+");
WebRequest request = WebRequest.Create("http://www.somedomain.com/ip.html");
WebResponse response = request.GetResponse();
StreamReader rd = new StreamReader(response.GetResponseStream());
string content = rd.ReadToEnd();
string myip = regexp.Match(content).ToString();
then you can split the string and get IP only.
2. The second way is to login your linksys router and go to http://192.168.1.1/status.htm
and then seach for wan IP but I still have problem with the login.
|
|
|
|
|
Thanks a lot for the reply.
I see we are at the same level.
I prefere the second option because i find kind
of useless to read the IP of the wan from outside.
I thought the same as you and I have the problem
for the login too.
I'd like to query the router with a command,
but I don't know how.
I think with a CISCO you can do it like the
old HAYES AT command of the analog modems style.
But with linksys..... ?????
Thanks I will work on the login to the 192.168.1.1 address
|
|
|
|
|
|
I chatted with the Customer support of Linksys. It seams they don't want to reveal the paramenters to login. But i think i found a guy didn't know i was talking about
http://192.168.1.1/Gozila.cgi?usrName=admin&Passwd=xxxx
but still not sure because I don't know the exact name of the parameters.
Anyhow I Copy / Modified this code from a program fount in codeproject
and I got some results.
It seems like something is not working right: when i start the program
I can even log in with the hotmail login. Maybe it just look to the password
and not the login name or I think the linksys accept any authenticated users of windows or something like that.
This is the code:
using System;
using System.Diagnostics;
using System.Drawing;
using System.Collections;
using System.IO;
using System.ComponentModel;
using System.Windows.Forms;
using mshtml;
using SHDocVw;
using System.Text.RegularExpressions;
using System.Data.OleDb;
namespace TestIENavigate
{
///
/// Summary description for Form1.
///
public class form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button butNavigate;
private System.Windows.Forms.TextBox txtDisplay;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
private InternetExplorer m_browser;
public form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.butNavigate = new System.Windows.Forms.Button();
this.txtDisplay = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// butNavigate
//
this.butNavigate.Location = new System.Drawing.Point(320, 368);
this.butNavigate.Name = "butNavigate";
this.butNavigate.Size = new System.Drawing.Size(120, 23);
this.butNavigate.TabIndex = 0;
this.butNavigate.Text = "Navigate";
this.butNavigate.Click += new System.EventHandler(this.butNavigate_Click);
//
// txtDisplay
//
this.txtDisplay.Location = new System.Drawing.Point(8, 8);
this.txtDisplay.Multiline = true;
this.txtDisplay.Name = "txtDisplay";
this.txtDisplay.Size = new System.Drawing.Size(768, 352);
this.txtDisplay.TabIndex = 1;
this.txtDisplay.Text = "";
//
// form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(784, 395);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtDisplay,
this.butNavigate});
this.Name = "form1";
this.Text = "IE Navigate";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new form1());
}
private void butNavigate_Click(object sender, System.EventArgs e)
{
txtDisplay.Text = "";
m_browser = new InternetExplorer();
txtDisplay.Text = explorerRead("http://192.168.1.1/Status.htm",m_browser);
}
private string explorerRead(string web_page_address,InternetExplorer ie)
{
System.Object nullObject = 0;
System.Object nullObjStr = "";
try
{
ie.Navigate(web_page_address,ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);
}
catch(Exception e)
{
return null;
}
int ctr = 0;
while( ie.ReadyState!=tagREADYSTATE.READYSTATE_COMPLETE )
{
Application.DoEvents();
System.Threading.Thread.Sleep(100);
if(++ctr > 25)
{
return null;
}
}
// extract and return the text contents of the retrieved page
return (ie.Document as IHTMLDocument2).body.outerText;
}
}
}
DON'T forget to add references to .net components and COM
Microsoft.mshtml (.net)
AsxSHDocVw
SHDocVw
When you run the program the login dialog will pop-up.
Once you login and your program is running you will not to login again.
I hope this help and maybe we can go little bit further.
Thanks
|
|
|
|
|
hiiiii all...
i'm developing a web site...and my manager wanna prevent any user form certain country from accessing the (or loggon )site....example( anyone from Canada or Congo or any other country)...is there anyway to do this ??....
thx in advance
|
|
|
|
|
Hi,
With the help of "Country-to-IP Address Mappings Compiled", you can block any user by getting its IP address and matching it with against the IP in the above listing.
I hope the following link will help you.
http://www.arson-network.com/index.php?class=tutorial&subargs=75
Best of luck.
|
|
|
|
|
Hi,
I am running into a problem when trying to use the Z Buffer in my d3d app. I have code that looks similar to this…
device.Clear(ClearFlags.Target, System.Drawing.Color.Black, 1.0f, 0);
//Begin the scene
device.BeginScene();
But whenever I change it to something like this
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.Black, 1.0f, 0);
//Begin the scene
device.BeginScene();
I get an error and the D3d dll throws an “error in application” exception. Does anyone have any idea on what could be causing this problem?
-Art
|
|
|
|
|
Is that the best exception you get? Have you tried putting the BeginScene call in a try/catch block and seeing if you get something more descriptive?
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Alternatively to the other poster, you could try a little thing called "debugging" (it seems to be a quickly dying "craze") and use VS.NET's extensive debugger to view everything relevant to that exception (by examining the exception's properties and the state of objects around it). At the very least, it would give more information that could help the CP community help you. Besides, debugging is as important as actually writing the code in any application that does more than print "Hello, world" to the console or a window.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
hi,
I'm trying to use a string declared in a file called Settings.cs
public class Settings : System.Windows.Forms.Form<br />
{<br />
public string folderName
<br />
protected int iTCPPort;<br />
in another file called registry.cs
<br />
private void MainRegSetKey()<br />
{<br />
RegistryKey hRegistryKey = Registry.CurrentUser.CreateSubKey("Vortex");<br />
<br />
hRegistryKey.SetValue("Download_Destination",Settings.foldername);<br />
<br />
return true;<br />
In the SetValue function I can't assign foldername, have I to declare a new istance of Settings doing Settings s = new Settings(); ?
thanks in advance
Paolo Ponzano
|
|
|
|
|
Paolo Ponzano wrote:
In the SetValue function I can't assign foldername, have I to declare a new istance of Settings doing Settings s = new Settings(); ?
Yes, that's one way. The other solution is to declare folderName as a static field:
public static string folderName;
Regards,
Alvaro
Can I ask you a question?
|
|
|
|
|
I'm now just starting to deal with resources in .NET and I have a few important questions:
1. Say I just created a new C# Windows project inside VS.NET (called Test). I switch to Windows Explorer and manually copy a bitmap file (Foo.bmp) into the folder where the project files are located. I switch back to VS.NET and add Foo.bmp to the project. I change its BuildAction to EmbedAsResource. How do I access the file in the program? Is there a hidden .resources file somehow added to the assembly where files like Foo.bmp are embedded into?
2. What's the benefit of a .resources file? From working with SharpDevelop, I've noticed that they can contain strings, images, and just about anything, and that each resource is referenced by name. When would you add an image file (Foo.bmp) to a .resources file instead of directly as another project file?
3. Please explain the BuildActions. What's the difference between EmbedAsResource and Compile? When would I want to compile a resource?
4. What's the difference between a .resources and .resx file?
As you can see, I'm pretty confused with all this resource stuff. In VC6, you always had a .rc file which would compile to a .res that had all the resources embedded. Now in VS.NET it seems like .resources are only necessary for strings. Image files can be added directly into the project. But how are those accessed?...
I need to have all these issues cleared up. If anyone can also point me to a good site that clears it all up, I'd really appreciate it.
Thanks!
Alvaro
Can I ask you a question?
|
|
|
|
|
Alvaro,
I can answer a couple of your questions. I too am having resource problems that have had me stumped for a week.
Answers:
2) A .resources file is just a container for resources. You can embed a .resources file into your application or leave it external. The benifit of having all your resources in the one file is you can have multiple versions of it eg. one containg English strings and one containg German, or for containg different icon/bitmap sets (to skin your app). Allows you to change your icons etc easily as they are all kept in one spot.
3) If you hit F1 while the build action combo box is highlighted the .NET help has a good explanation. But for easy refference: EmbedAsResource included the resource as part of the compiled EXE or DLL. Compile makes the compiler process the resource when you compile your project. You might get a few errors if you try to compile a BMP or .Resx file etc. Content includes the resource as an external file. None does as it states, nothing.
4) A .resx file is an XML wrapped resource file. It is converted to a .resources file when the project is compiled.
My problem is a slightly older thread "Retrieving an icon from an embedded resx". I have some code in my post that my help answer your first question. If anyone could help it would be greatly appreciated.
Regards,
Scott.
|
|
|
|
|
Scott,
I really appreciate you taking the time to answer my questions. For a while I thought no one would.
I did a Google search for "resource files in .NET" and found this[^] link, which answered my first question. So the code required for accessing an image file that is embedded in the app is:
Image image = Image.FromStream(GetType().Assembly.GetManifestResourceStream("DefaultNamespace.Name.bmp"));
Regards,
Alvaro
Can I ask you a question?
|
|
|
|
|
I'm working on a WinForms app and need to embed an instance of MS Excel in a WinForm window. We did this in VB6, but it's quirky because we don't know Win32 API programming very well. I've got a sample of this, but don't see a way to post it along with this message.
If I get a good solution to the problem, I'd like post an article on the topic for all to use.
Can anyone offer help with this?
|
|
|
|
|
Wrap the API call to SetParent and pass it the handle to the window you want to act as a parent ...
HWND SetParent( HWND hWndChild, HWND hWndNewParent );
This function exists in User32.dll
D.
|
|
|
|
|
Hello
I have a WebService (Java) and client -SmartDevice App (c#).
It´s a similar example that i have.
In WS I have a class: MyData. This class have 3 properties: Name, Address and tlf. I have method that send an object array (MyData[]) of this to client.But when I call this method and return de object the client (SmartDevice App) catch an Exception.(System.WebException - Soap.Protocol)
The web reference is Ok.
The text of error/exception: "format "arrayofdata" not exist in http://webservice".
Can´t send object-array to client from ws??
How can I serialize data in compactFramework??
How can I send a group of data from ws to client??
Thank for your help.
|
|
|
|
|
Hi all,
I understand that a that Hashtable can be used as a datasource for a datagrid. I also understand that my Hashtable needs to implement IList.
Can anyone show me a little code snippet to do this please. I want both the Hashtable key and value to be visible in the datagrid.
Thanks,
Rob
|
|
|
|