Tuesday, June 18, 2013

Passing Date parametere from Javascript to WCF

Having a service method that accepts two parameters will look like this:

public class ServiceRequest
    Nullable<DateTime> DateTimeFrom { get; set; }
    Nullable<DateTime> DateTimeTo { get; set; }

public interface IService
    [WebInvoke(UriTemplate = "getServiceCall", Method = "POST")]
    ServResponse GetBusinessObjects(ServiceRequest filter);
Now, To start calling this method we need to construct a Json data representing the parameters.
      var fromDate = new Date(2013, 06, 18);
      var toDate = new Date();

      var datavar = {
            DateTimeFrom: fromDate.toMSJSON(),
            DateTimeTo: toDate.toMSJSON()
      var parameters = JSON.stringify(datavar); 

But, before calling the toMSJSON on date object we need to define it as follows:

// Let Date type be compatible for Microsoft WCF
Date.prototype.toMSJSON = function () {
/// <summary>Let Date type be compatible for Microsoft WCF.</summary>
var date = '/Date(' + this.getTime()  + '-0000)/';

Getting DateTime from WCF

// convert WCF date to Javascript
String.prototype.DateWCF = function () {
    /// <summary>convert string into Date</summary>
    var matches = this.match(/\/Date\(([0-9]+)(?:.*)\)\//);
    if (matches)
        return new Date(parseInt(matches[1]));
Notice that when you use a date in javascript it is representing your local date based on the settings on your systemn and browser. As a result you might pass different notation to WCF. For example, my broweser has an timezone offset of -120 minutes. So when I ask to convert 06/20/2013 02:10:04 I see 2013-06-20T00:10:04.000Z which is perfectly normal because that represents the same exact time as I meant on my browser. Thus WCF will get the correct date aswell.

Friday, April 5, 2013

Minify js and css files in Visual Studio 2012

Finally we got an integrated tool in VS2012 that does the jobin Solution Explorer:
Web Essentials
You can enable this tool using the Extensions And Updates from the TOOLS menu.

  1. First, right-click on the css file and from the Web Essentials context menu choose to Minify CSS Files. This will ensure that with every build it will generate the accompanying .min.css file too.
  2. Make sure you have the Web.Release.config beside your web.config
  3. In your .aspx or .master file put an if statement to figure out if this is running on your debug mode or release mode:
 <% if (HttpContext.Current.IsDebuggingEnabled) { %>
    <link href="/css/MyFile.css" rel="stylesheet" type="text/css"></link>
  <%} else {%>
    <link href="/css/MyFile.min.css" rel="stylesheet" type="text/css"></link>
  <%} %>

Wednesday, March 27, 2013

Do more with less

You can do more with less by reducing your design to its essence, and solving for distractions,
not discoverability. Create a clean and purposeful experience by leaving only the most relevant
elements on screen so people can be immersed in the content.

  • Be great at something instead of mediocre at many things.
  • Put content before chrome.
  • Be visually focused and direct, letting people get immersed in what they love, and they will explore the rest.
  • Inspire confidence in users. 

Desktop browsers have quite a lot of chrome (menus, options, status bars, and so on) that is
only sometimes useful. Typically, however, users open a browser to see a webpage, not to
interact with the browser. Moving commands off the browser chrome and into the app bar or
into charms helps users focus on what they care about.

Copied from Windows 8 User Experience Guidelines

Passed 70-480 exam

Yesterday morning I passed the exam in very short time (about an hour).
Amazingly, most of the questions were very familiar and the hints people provided earlier has been very helpful.

  • http://moustafa-arafa.blogspot.nl/2012/12/study-material-for-programming-html5.html
  • http://geekswithblogs.net/WTFNext/archive/2012/10/08/exam-70-480-study-material-programming-in-html5-with-javascript-and.aspx
  • http://www.techexams.net/forums/microsoft-developers-certifications/79076-70-480-programming-html5-javascript-css3.html
And a magor help from ExamCollection:

Thursday, February 28, 2013

Finds Close Points by Distance

In this example I am trying to find the distance between the locations in a table and a given point. When I found the distance I will return thee result filtered by a allegible distance.
-- =============================================
-- Author:		Asghar Panahy
-- Create date: 28-Feb-2013
-- Description:	Zoekt objecten binnen bereik van gegeven punt
-- =============================================
ALTER PROCEDURE [dbo].[BereikbareObjecten] 
	-- Add the parameters for the stored procedure here
	@orig_lat REAL , 
	@orig_lng REAL,
	@binnenMeter integer
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.

	-- Select your SRID wisely. Don't follow me.
	-- select * from sys.spatial_reference_systems 
	-- where spatial_reference_id in (4937, 4258, 4326, 4269)
	DECLARE @SRID as int = 4326;
	DECLARE @orig geography;
	SET @orig = geography::Point(@orig_lat, @orig_lng, @SRID);
	SELECT  *,CONVERT(INT,  @orig.STDistance( geography::Point([object].[Latitude], [object].[Longitude], @SRID))) As [Distance]
	  INTO #MyTempTable
	  FROM [Object]  
	SELECT * FROM #MyTempTable 
         WHERE [Distance] <= @binnenMeter 
         ORDER BY [Distance]

Thursday, January 24, 2013

putting images into one bigger file to improve newtork performance and thus page-load

Getting all icons in one file requires some handy works to layout the pictures in both css and html.
I recently put some sample buttons and logo using the one is implemented by YouTube and is available here.