ServiceStack adding to allowed File extensions

Hi Guys, We had a weird problem at work where our font files won't load. One of my colleague Dr. Overton who is working on web services using Service stack for one of our project showed me what the problem was. Now I am 80% web guy and 20% applications. So for once I was like ok its something to do with configurations. That turned out to be true By default these extensions are allowed   [geshi lang="csharp" nums="1" target="_self" ] [crayon-66913476b2764201479792/] As you can see that AllowFileExtensions is just a Collection Object property (which we can add extensions to) under class EndPointHostConfig So within your AppHost.cs file  where you are creating EndpointHostConfig config object as shown below [crayon-66913476b2768830123611/] After this declaration just add required extensions. In our case we want to process few font files that won't work otherwise without these changes [geshi lang="csharp" nums="1" target="_self" ] [crayon-66913476b276a363327664/]   Advertisement   Much thanks to Dr Overton to figure this out.   I hope this helps someone Cheers … [Read more...]

jcResizerCmd – A Free Bulk Image Resizer and watermarker Command Line Software

Hi Guys, Why I did this is a short story that I can share here, I downloaded a free pack of icons in PNG format, now all of them were really good. The number of icons in icon pack was roughly just over 200. Now I wanted them to be 24x24 pixels. I know that I could have done some CSS magic and bring the size down to 24x24 but I thought may be I haven't done anything in C# in a while so why not see how difficult it will be to create a command line tool that just do resizing and watermarking on the images. I did couple of hours reading turn out to be that It actually simple to manipulate Images in .NET with all the classes such as Image, Bitmap, Graphics available to assist me. SO I thought well the reason is there so lets start. I quickly assembled the requirement of what I wanted and started coding. Now I have touched c# after a while so it took me couple of hours to get used to using DOT (.) rather than (->) that I use in PHP for Object manipulations and use. Ok so I know this could not be the best of the util available but I think I did just enough to convince anyone or primarily myself that its a sharable FREE product that could be handy tool for some. I did lot of readings on Image manipulations with .NET so hopefully this tool is just reflection of my readings. When I started to write this tool, it just started with Resizing an Image (v0.9) but then I thought may be watermarking can also be done in Image iteration loop then why not introduce that too. I am doing a website just for this util because I think it could be a helpful tool. So more documentation and usage example will be available from there. Alright enough of chit chat lets start by looking at this util now. jcResizerCmd - A command line util.   How to use it Here is the command structure   Ok so as you can see that there are few options available thats all I needed. May be I should think of adding image rotation angle too. But I thought that may not be … [Read more...]

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 template. … [Read more...]

servicestack turn off metadata

Hi Guys, In this brief post I am going to show you how to disable or turn off metadata completely. 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   EnableFeatures = Feature.Csv | Feature.CustomFormat | Feature.Html | Feature.Json | Feature.Markdown , // you can add more features here but don't add metadata, I have enable few because I need those. This can be done another way but I find this method clear   So my Configure method looked like this [crayon-66913476b2f3d460635705/] I hope this helps Cheers, Advertisement … [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 [crayon-66913476b3037271040101/] [crayon-66913476b3039175307076/] So my Configure method looked like this [crayon-66913476b303a789492696/] Advertisement   Because I am using markdown templates I will define a 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   [crayon-66913476b303b796132985/] Nothing much just return whatever is in there in my 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 [geshi lang="csharp" nums="1" target="_self" ] [crayon-66913476b3247284348546/]     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   [sam_ad id="54" codes="true"] … [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. [geshi lang="csharp" nums="1" target="_self" ] [crayon-66913476b334c625526561/] Now I declare a static method called GetFiles definition is shown below [geshi lang="csharp" nums="1" target="_self" ] [crayon-66913476b334f693374788/]   Now I will use the above function as shown below [geshi lang="csharp" nums="1" target="_self" ] [crayon-66913476b3350794093533/] The above will print all files that ends with .sln and .suo as shown below [crayon-66913476b3351164981565/] 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 [crayon-66913476b3352515805046/] 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 their name. … [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. [geshi lang="csharp" nums="1" target="_self" ] [crayon-66913476b362f241492097/]   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 … [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. [geshi lang="csharp" nums="1" target="_self" ] [crayon-66913476b371b066768372/]   Important piece of information in above code is start.CreateNoWindow = true, by default this value is false Read more about it here … [Read more...]