|
I don't want to execute the files, I want to process them. Unfortunately you can't rely on file extensions when dealing with the web. I can use a .asp, .pl, .php, etc to return any type (not just an HTML document). This is why it is so important that I use dynamic casting.
Also, I need to do more than just store information about the document. I need to process each type of document differently (hence the specialized child classes). So, for example, if it's an HTML document, I want to run an HTML parser on it or check the validity of its links. If it's a GIF, I may want to process its formatting or read its internal comments. However, it's not really the specific processing I have a question about - I need to know how to cast a parent object to an inherited child object without knowing the specific type at design time.
|
|
|
|
|
I did something like this on a project. My solution was a variation of the GoF Bridge design pattern. The idea is to separate the abstraction (the base WebDocument class) from its implementation (child classes of WebDocument).
1. Make WebDocument an abstract class, so it can't be instantiated. Add a method that child classes must override that will be called to process themselves (i.e. Process). Create a static factory method on WebDocument to instantiate an the appropriate handler class. You'll need to pass some information into the method so the class can decide which to create (the HTTP header, etc.).
public abtract class WebDocument
{
protected HttpRequest Request;
public static WebDocument CreateInstance(HttpRequest r)
{
switch r.ContentType
{
case "text/html":
return new HtmlDocument(r)
break;
...
}
}
public abstract void Process()
}
2. Create a class for each document type you need to handle (PDF, Word, etc.) that inherits from WebDocument. Create something like UnhandledDocument to process documents that you don't currently support.
public class HtmlDocument : WebDocument
{
public HtmlDocument(HttpRequest r)
{
this.Request = r;
}
public override void Process()
{
// do something with this.Request
}
}
3. Write client code something like this:
HttpRequest req = HttpContext.Current.Request;
WebDocument d = WebDocument.CreateInstance(req);
d.Process();
Can you see how the abstraction (WebDocument) is separated from an implementation (HtmlDocument)? Supporting new document types is as easy as creating the implementation class and adding it into CreateInstance, and will affect no other code. The client doesn't know or need to know the instance type. All it is responsible for is getting an instance of WebDocument to process a request.
Hope this helps. It certainly helped me!
|
|
|
|
|
Thank you CBoland!
This is very helpful. I didn't want to resort to the switch or if-then-else statements to pick a type (which is why I was asking about dynamic casting), however, it looks like very clean code, and I may end up doing it this way.
I'll probably modify the static "CreateInstance()" method to check for plugins which implement the new IWebDocument interface. This way I (or other developers on the project) can easily distribute updates for old versions, while new version can simply add another line to the switch statement.
|
|
|
|
|
See what you are saying. Ok if you are going that route, may I suggest that the generic version that falls out of all other known documents store the data in a byte array from the stream, that way at least it can just reproduce the data as it was by replaying the stream, but still implement the interface as per whatever spec u give it.
|
|
|
|
|
Hi,
I'm building an app that has to send large amounts of binary data - 700Mb and up to a remote copy of this app. The format of the data doesn't really matter as long as the method is fast, efficiant, and fairly easy to use outside .NET like in Java reimplementationas. I've looked at Socket.Send(Byte[], Int32, Int32, SocketFlags) , but I'm not sure that putting a 700Mb buffer into that function would be such a good idea!? Is it necessary to split the thing up? can .NET help me with this so I don't have to reinvent the wheel? Or is there a better way of sending/downloading data altogether?
Any answers would be much appreciated.
*¨¨`)
¸¸.·´ ¸.·*¨¨`)
(¸¸.·* ¸ .·*
¸¸.·*
(¸¸.~~> Joel Holdsworth.
|
|
|
|
|
Joel,
You will definitely want to break it into chunks, and, with that much data, you will probably want to put some error-recovery around it to restart the download if something bad happens. I suggest include some sort of identifier (ie filename) and the chunk number with each chunk.
Chunking also allows the remote app to display some sort of progress bar as the data comes across, which tends to be pretty useful.
|
|
|
|
|
The below is to resolve the url by username and password and read the xml source from the this url. However, I get error like this : "401 error Unauthorized ...". Can you see where is the problem?
XmlTextReader reader = new XmlTextReader
"http://testurl.com/01/02/myXML.xml");
NetworkCredential nc = new NetworkCredential
("username","password","testurl.com");
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = nc;
reader.XmlResolver= resolver;
|
|
|
|
|
Your dtd may go elsewhere - anything not referred to locally in the dtd will be allowed, externally (different url) may be prohibited by policy.
/**********************************
Paul Evans, Dorset, UK.
Personal Homepage "EnjoySoftware" @
http://www.enjoysoftware.co.uk/
**********************************/
|
|
|
|
|
What does it mean? I did not use any dtd. (or i misunderstood)
|
|
|
|
|
C# :
process[] ps = Process.GetProcessByName();
error: process index is shut
what can i do ?
|
|
|
|
|
Look up the error in the MSDN?
Sorry that wasn't helpful. You seem to have abrivated the error a little though.
/**********************************
Paul Evans, Dorset, UK.
Personal Homepage "EnjoySoftware" @
http://www.enjoysoftware.co.uk/
**********************************/
|
|
|
|
|
Dear friends I have a following problem.
Please help.
We have a desktop application which simply reads data from xl file and insert it in database. This data insertion is implemented in one method and the address of this method is given to one thread. Then therad is started to call this method.
Up to this it is working fine.
The problem is when we run application first time it properly inserts data in database.
But when i try to run it again, it does not insert data.
It says thread is already running.
Actually this application sends a request to remote server and run the script which inserts data into database. This is working for our local server. i.e. when we treat our local server as remote one it properly inserts data. But when we try it with remote one first time it inserts and after that does not work.
Please help..
Tough Times never lasts but
Tough people do!
|
|
|
|
|
Ensure you have actually got something ending the previous thread, and something reacting in your main app that sets the current thread ref to nothing when it exits.
Also passing references to objects across threads is a bit dodgy, look into syncronisation - things like gates and semiphore may serve you well.
/**********************************
Paul Evans, Dorset, UK.
Personal Homepage "EnjoySoftware" @
http://www.enjoysoftware.co.uk/
**********************************/
|
|
|
|
|
A recently posted message on this board has this guide
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkwalkthroughcreatingsimplemultithreadedcomponenetwithvisualc.asp
/**********************************
Paul Evans, Dorset, UK.
Personal Homepage "EnjoySoftware" @
http://www.enjoysoftware.co.uk/
**********************************/
|
|
|
|
|
Paul,
My problem is solved. I have used join method after starting the thread it is working fine for me.
Thanks for your concerns...
Regards..
Amol
Tough Times never lasts but
Tough people do!
|
|
|
|
|
Regards everybuddy,
What shoud I do with my created control so that it doesn't obey it's container opacity value and be independent of it?
perhaps I should override some method?
Thanks for any note,
-nSun
---
"Art happens when you least expect it"
|
|
|
|
|
It depends on how your parent control is drawing. If it's invisible it won't even bother calling children under some circumstances.
Probably look into overriding the paint - although I think the opacity thing is a window attribute.
/**********************************
Paul Evans, Dorset, UK.
Personal Homepage "EnjoySoftware" @
http://www.enjoysoftware.co.uk/
**********************************/
|
|
|
|
|
I thank you for replying and I know its a prolem with my knowledge but I couldn't use your post to find anything I can implement in action.
what you mean by "It depends on how your parent control is drawing"? parant is a form that I can put my control on its surface, now if I decreese this form's opacity my control gets transparent too, I wan't it reserve its opacity.
I need more info or some tutorial link
Thanks again
-nSun
---
"Art happens when you least expect it"
|
|
|
|
|
Hello.
I have a TextBox and I want , for instance, that when the user press the key "." the textbox displays a ",".´
I have a handler for KeyPress event and I know how to detect when the user pressed the key "." but I don-t know what I have to do to change it to the desired key value.
Any ideas ?
Thanks.
|
|
|
|
|
I might be wrong, but why don't you call a javascript function on keypress of the textbox and pick up the text entered in the textbox and upon finding the "." character, replace it with the desired character and put the text back in the textbox.
Cheers,
Rahul
I do not understand what I do. For what I want to do I do not do, but what I hate I do. - Romans 7:15
|
|
|
|
|
|
Is there an equivalent for Java WeakHashMap() class in C#?
Thanks
--------
Dave
|
|
|
|
|
Hi,
Supposed my program wants to grab a html page in my router and parse for the wan IP address. What should I do to send username and password to handle authentication? Particularly, My linksys router pop up a small window to ask for username and password if I access to 192.168.1.1.
thanks.
|
|
|
|
|
|
You may find that the router always does that, even if you supply credentials as http://user:password@192.168.1.1, since it may not parse them itself, but simply run a page.
Steve S
|
|
|
|