Click here to Skip to main content
15,897,226 members

Rohit Wason - Professional Profile



Summary

    Blog RSS
809
Author
9
Debator
2
Enquirer
9
Organiser
165
Participant
0
Authority
0
Editor
I have been in software development since 1998. In all these years, I have developed special interest in Object-oriented programming methodologies and processes (like UML based development) When not working or thinking about work, I like to spend time with my family (my wife and little daughter). I also try to sweat on a racquetball game once in a while.

Reputation

Weekly Data. Recent events may not appear immediately. For information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

Actions with a green tick can be performed by this member.


 
GeneralDesigning an SQL Builder Pin
Rohit Wason31-Jan-06 8:29
Rohit Wason31-Jan-06 8:29 
GeneralEmbedded xml-resources Pin
Rohit Wason22-Jan-06 13:58
Rohit Wason22-Jan-06 13:58 
I was dragging this one for some time. We wanted to try embedding all our xml-schema and xsl files in the assembly itself.

Now, I had worked with embedded resources before and at first it seemed a simple 2 step thing: mark the file as "embedded resource" and load it from Assembly.GetManifestResourceStream(). This works for simple cases.

The real problem arises when the xslt-files or schemas refer to other files. For example the directive: <xsl:import href="commonTemplates.xsl"/> in a transformation file refers to an external file and when loading the transformation, the engine (one like System.Xml.XmlTransformation) looks for http://commonTemplates.xsl in the current location and loads its definition along with the current transformation-file.

The problem with an embedded xslt-file is, there's no standard way of referring one embedded-xslt into another. So, as in our example, if the embedded xslt-resource had a <xsl:import href="commonTemplates.xsl"/> in it, the engine would still try to look for http://commonTemplates.xsl in the working folder (\bin etc). And, if we need to keep the referred file in the local path, we beat the whole purpose of embeddig the resource in the first place!

The solution comes in the shape of a helpful class provided by the framework - called XmlResolver[^]

This is a pretty useful class that you can inject into the standard xsl-transformation process of XslTransformation class. The design pattern of XMLResolver is such that when passed into the XMLTransformation::Transform[^] call, it is called to resolve references (like URLs) present in the XSL-transformation source. A derived class of XMLResolver called XMLURLResolver[^] is designed specifically for this. Now, what I wanted is to define a new uri-scheme (like http://, ftp:// etc) and be able to use that in my transformations to refer to 'embedded' files - I picked "ref://". To implement the handling of this new schema, we need to extend the XMLURLResolver class:
public class XmlResourceResolver : XmlUrlResolver
{
    ...
}


The second step is to override the GetEntity method:
public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
{
	Stream stream = null;

	switch (absoluteUri.Scheme)
	{
		case "res":
			// Handled res:// scheme requests against
			// a named assembly with embedded resources
			Assembly assembly = null;
			string assemblyfilename = absoluteUri.Host;

			//Assembly-Name
			if (string.Compare(Assembly.GetExecutingAssembly().GetName().Name, assemblyfilename, true) == 0)
			{
				assembly = Assembly.GetExecutingAssembly();
			}
			else if (string.Compare(Assembly.GetEntryAssembly().GetName().Name, assemblyfilename, true) == 0)
			{
				assembly = Assembly.GetEntryAssembly();
			}
			else
			{
			}

			//Resource-Name
			string resourceName = assemblyfilename + "." + absoluteUri.Query.Substring(absoluteUri.Query.IndexOf('?') + 1);

			//The System.URI class converts the supplied URI into all lower case characters by default, 
			//and we need to preserve the case in order to load an embedded resource. So we look for the name
			//(case ignored) in the GetManifestResourceNames array
			resourceName = ResolveResourceName(assembly.GetManifestResourceNames(), resourceName);
			stream = assembly.GetManifestResourceStream(resourceName);

			return stream;

		default:
			//Handle file:// and http:// 
			//requests from the XmlUrlResolver base class
			stream = (Stream)base.GetEntity(absoluteUri, role, ofObjectToReturn);
			return stream;
	}
}


See that last else in the code above? Its left blank because I don't allow for external assemblies being referred to in my project - its either the GetExecutingAssembly() or GetEntryAssembly() that I use.

The ResolveResourceName method makes sure the original names of the resource is kept intact:
private string ResolveResourceName(string[] names, string resourceName)
{
	foreach (string name in names)
	{
		if (String.Compare(name, resourceName, true) == 0)
			return name;
	}

	return null;
}


-- modified at 13:07 Tuesday 31st January, 2006

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.