Servicestack Markdown NoRender Master Layout Page, Render partial content

Hi Guys, I am dealing with the Client End for a project that I am working on and the Client is written purely in HTML5 and Javascript with some CSS3 magic. Now we are using ServiceStack and Markdown templating engine as our Web service and Content providers. So you know that when calling a specific service the output can be any of the following JSON HTML XML CSV JSV   The above are really handy when you want to load your javascript Grid, or display content as HTML. Now if we think about the bigger picture we have couple of things when the output is returned as HTML. First consider this from Markdown Docs Once the appropriate view is executed it's output is stored in the **'Body'** variable and is merged with its static website template. The rules for finding the appropriate master website template is simple: It's the first **default.shtml** page it can find, looking first in its current working directory then recursively up the directory hierarchy until it finds one. The view is merged with the static website template by replacing all **<--@VarName-->** with variables generated by the page (i.e. in ScopeArgs). i.e. the executed output of the View is stored in the **Body** variable and is embedded in the static website template by replacing all **<--@Body-->** found. Advertisement   That's good that the View is processed and merged to the Master website template what what about if we don't want that default action to happen? Ok so this is what you can you. Its called Bare HTML return So for instance if you are accessing a page like localhost/yourwebservice/param (which kicks the default merge with Master them)  then you can change the URL to this localhost/yourwebservice/param?format=html.bare This will override the Fusion of MD template to the Master template. Now there are some scenarios where you will want to select a custom Master … [Read more...]

servicestack default web index page

Hi Guys, So the project we started as of today I am taking care of web side of things. So may be with occasional posts on PHP I will be writing few posts on Javascript, Webservices and ServiceStack. I am not going to explain what ServiceStack is. You are here because you already know about it. In this post I am going to show you how to set Index page after you setup your ServiceStack successfully. By default when you browse you are shown metadata page. This is because you haven't set the default redirect path to your default page (Web service). I would use Page because that falls in line with web terminology. So generally you dont want users to see your metadata page if you're planning to open your software to browsers. Here is what I did The main configuration is made in the app host Configure method. I believe you have access to that CS file. in your configure method add this line So my Configure method looked like this Advertisement   Because I am using markdown templates I will define a Index.md file which for me has nothing but "Hello world" in there. Make sure that Property "Copy to Output Directory" has value "Copy Always" Now lets check what my Index.cs file looks like Nothing much just return whatever is in there in my Index.md file that will be parsed automatically. So now when I try to browse my webservice as HTML I see Hello World on my screen rather than metdata page that highlights what web services are available. I have left some room for you to improve. My motive was to give you insight on what variable we need to set to change the default metadata page load to something else. In my next post I am going to explain how you can disable metadata altogether. I hope that helps. Cheers,   Advertisement … [Read more...]

c# http post

G'day Fellas, Many a times we have to do a HTTP POST to one of our websites either to push something or to push and get something in return.   Below is the code that I use to make such calls. c# code     You can put this code inside a function of your say Util class and reuse this code again and again.   I hope this helps   Cheers   … [Read more...]

[Solved] c# Multiple filters or File extensions with Directory.GetFiles()

Hi Guys, So I had this problem where I wanted to get Files with extensions .js and .css.   As you know that Directory.GetFiles() does not support multiple filters but there are many ways you can get it to work. Whatever you do just be aware that processing a large set of files under a directory and sub directories has memory and performance issues associated with it. Below is a faster way to search files that are returned by Directory.GetFiles() with SearchOption set to AllDirectories Pre-requisite for this method is LINQ First I declare an array with extensions that I want my GetFiles method to absorb and return all files that ends with extensions provided in the below array. Now I declare a static method called GetFiles definition is shown below   Now I will use the above function as shown below The above will print all files that ends with .sln and .suo as shown below E:\Dropbox\projects\jcpl\jcpl.sln E:\Dropbox\projects\jcpl\jcpl.suo Just as a side note. Above is what I use all the time. But this is not the only method and this method will require you to use LINQ. With Older .NET framework where there is not support for LINQ this method will not work. So I rely on the method given below I Hope this helps Cheers! … [Read more...]

jcmin – A Javascript and CSS minimizer using Google Closure and YUI Compressor

Hi Guys, I am working on relatively medium to enterprise size project where we have 70+ javascript and 20+ css files plus libraries we use. I had this problem where I just want to minimize all files at once or individually using YUI compressor and Google Closure. I couldn't find anything that utilizes both and do compression without making API calls. Thus I end up developing jcmin for myself which mean Jaspreet Chahal's a Monster :) Just kidding. It actually means Javascript CSS  Minimizer I didn't do anything fancy I thought this util can help someone who want simple command line rather than remembering all the little things provided by individual compilers. jcmin is in Beta. Not the actual compilers (Closure and YUI Compressor) but jcmin.  Important: jcmin is not a compiler itself. You can say jcmin is a wrapper to YUI compressor and Google Closure and it only does basic stuff. I can add more Advance things  if you like this util and want more control. As I said I developed this util for myself and I am kinda sharing it. If you end up finding it useful then consider donating or atleast a backlink to this page will much appreciated.   Pre-requisites .NET Framework >= 2.0 Recommended: java.exe in System environment path. Advantages of using this util Gives you option to choose between Google Closure and YUI Compressor You can minimize files under your directories You can even re curse through your directory and minimize files inside subdirectories. This util will form an equivalent structure at target directory. No need to goto separate compilers for Javascript and CSS this util do it both by firing appropriate compiler for a given file type. See Errors thrown by respective compiler. Comes with IKVM so if you dont have java installed compilers still work (I recommend to install it and put java.exe in Environment Path) You can skip any number of file by their name or even part of … [Read more...]

c# how to programmatically execute exe and wait till it finish execution

Hi Guys, So in my process of developing a util that utilizes "A well known javascript compressor" to compress javascript files. I came across where I had a need to run Java.exe from my c# application. You must be aware of Process class under System.Diagnostics package. We will be utilizing Process class to execute java from command line and keep the window hidden and also stop the flow of program until called EXE finishes execution   If this solution can be improved please leave you comments but I guess its pretty much standard using c# libraries so can't go wrong with that This is how I did it finally.   Important piece of information in above code is start.CreateNoWindow = true, by default this value is false, When you set it to true, then  you are directing your program that keep the called program hidden. When you call WaitForExit on  the process it sets the period of time to wait for the associated process to exit, and blocks the current thread of execution until the time has elapsed or the process has exited. Read more here about WaitForExit  http://msdn.microsoft.com/en-us/library/system.diagnostics.process.waitforexit.aspx … [Read more...]

c# Run exe programmatically with console window hidden

Hi Guys, So in my process of developing basic applications using c# I finally came across where I had a need to run Java.exe from my c# application with target command window hidden.   If this solution can be improved please leave you comments but I guess its pretty much standard using c# libraries so can't go wrong with that This is how I did it finally.   Important piece of information in above code is start.CreateNoWindow = true, by default this value is false Read more about it here http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.createnowindow.aspx … [Read more...]

jctree documentation

jcTree Documentation In this post I will show you how to use jcTree.exe to create a Javascript enabled tree from your command line. First up lets check out the command help as shown below Download this Utility from this URL http://jaspreetchahal.org/jctree-a-c-tool-to-create-jquery-javascript-enabled-folder-or-directory-tree-and-output-to-html-file/ I am not going to explain what each switch does but I am going to narrate couple of use cases Create a tree from Directory structure and save it to index.html under a given target folder Create a tree from Directory structure and save it to index.html under a given target folder with TXT files only and apply classic jsTree theme to it with verbose mode. Test Directory Structure C:\cutils\JCRSBackup.exe C:\cutils\License.txt C:\cutils\print.txt C:\cutils\Readme.txt C:\cutils\RackSpaceWindowsClient C:\cutils\RackSpaceWindowsClient\License.txt Scenario 1 Assuming the above directory structure exists lets create a tree for above directory structure and store it in c:\demo folder. One good thing about this Util is that if the target folder does not exist it will create it automatically The command shell> jctree -source=c:\cutils -target=c:\demo screenshot When you run the above command "demo" folder will be created with index.html inside it. Notice that jsTree will also be copied to the destination folder. This is a requirement. Without it your tree will only be a unordered HTML list. Lets check out the browser output So we get nice tree and each node is a link to the file itself. From here on you can do whatever you like with your newly created file. Scenario 2 Assuming the directory structure is the same as in Scenario 1 use the command below The command shell> jctree -source=c:\cutils -target=c:\demo -v -theme=classic -filetypes=*.txt screenshot When you run the above command "demo" folder will be created with index.html inside it. Notice that … [Read more...]

c# how to create XML without XML tag using XMLDocument and XMLWriter

Hi Guys, I had this problem where I just wanted to create a XML file without a XML tag. Frankly I was just creating a HTML snippet which I needed to embed in some other file. I am not going to show you all that code but instead I will show you the important bits. Below is the code that you should be looking for to create a XML file without XML tag. So we are using XMLDocument class to create a XML document. I am just using file name to include .html because that fit my scenario. Feel free to change it to any other extension. Above code will produce the output file with contents below Important thing in the above code is utilizing XmlWriterSettings class and putting OmitXmlDeclaration property to false. Make sure that you also set ConformanceLevel to Fragment, by default it is set to Document and when XMLWriter is outputting a document it always will include XML tag. Lets omit XmlWriterSettings from the above code to make it equivalent to the code below   Above code will now output file called somefile.html with following contents I hope this helps … [Read more...]