Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Category list

Widget Twitter not found.

Root element is missing.X

Updating my using with Windows Live Writer

by Ahmadreza Atighechi 4. August 2010 19:46

I didn't know about this sophisticated application so called “Windows Live Writer”. Actually quiet frequently I was looking for an HTML editor to write my blog post and then update my blog. Because HTML edit which comes with BlogEngine.Net is not easy to use – and its the same problem with all web based HTML editor-. To be honest windows live writer is something more than what I expected.

I was reading an article about AtomPub Using WCF Data, I came across Windows Live Writer which surprisingly supports BlogEngine.Net (Its better to say that BlogEnine.Net supports AtomPub which is protocol for publishing content).

Windows Live Writer easily installed on my machine. After installation completed you will be asked about your blog information and if your blog supports AtomPub then you can continue to enter login information of your blog. With a quick search I found in WiKithat Windows Live Writer supports BlogEngine.Net so I selected “other blog service” option in this form.

What blog service do you use

In next step you’ll be asked about your blog address and username and password.

Add a blog account

For me as a developer it was surprising that Windows Live Writer supports plug-ins. first thing I looked for was SyntaxHighlighter. Yes! . I’s already been developed. there is a project in CodePlex named "SyntaxHighlighter for Windows Live Writer” you can easily download and set it up.

Tags: ,

Blog

How to mess with "click test" facebook application

by Ahmadreza Atighechi 27. July 2010 05:07

 

Couple of days ago I came across a fantastic challenging application in Facebook which is called “click test”. This application measures your click per second and you have to click as much as you can in 10 seconds. For sure in my 130 friend there are many who can click more than me, but I had to do my bests especially a friend of mine (Kambiz) who is not only good at typing and clicking but also good programming. What should I do! should I left the battle or keep challenging? Of course I have to stay in this battle. I tried to score a good click per second but honestly the best I did was about 90 clicks per second which is lower than lots of my friends. 

What is “click test” application? This is a simple but ton that you have to click on with a countdown timer which runs inside browser. Ok, the first thing pops in mind is writing a simple application to simulate clicking on this button. Ohhh, you have to find browser windows handle then use SendMessage with appropriate (wParam, lParam) parameters to simulate clicking on specific area of window. That sounds great. But the fact is I’m more JavaScript and HTML guy than *API* guy. So let Keep It Simple Stupid (KISS).

If you view source of “test” application page you’ll face huge amount of complex source code which is really complicated. At the be ginning I wanted to find the function which is responsible for counting down t from 10 to zero and then increase it but the code is really messy and it takes time to find the function you want. Should I inspect all HTML and Jscript source code? The answer is No

Recently browsers are delivered with quite sophisticated feature for developers. For example Internet Explorer 8 has got famous feature which is called “Developer Tools” and you can activate it by pressing F12. Having pressed F12, nice window will be displayed to help you debug your HTML and JavaScript. 

Ok to find start button you can press Ctrl+B or select Find -> Select element by click. 

Then move your mouse to element that you want inside browse. 

As soon as you move your mouse inside browse you’ll notice that browser mark current element by bordering it. So find start button and then click on it. Gotcha! Developer tools automatically scrolls to input tag related to selected element. You can also scroll horizontally to find “onmouseup” which is actually responsible for counting your clicks. Ok, double click inside onmouseup and then press Ctrl+A to select all body of onmouseup. 

So I can copy this element into clipboard and then paste in notepad. You may also have somthing similar to following:

 

 

fbjs_sandbox.instances.a130168443678744.bootstrap();
return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,130168443678744),function(a130168443678744_event)
{a130168443678744_game.update($FBJS.ref(this).getForm())},130168443678744],new fbjs_event(event));

 

 

Actually this is an event handler and this code runs every time you click on your mouse button. But it’s rather complicated. It calls a function at first and then calls another function. So If I want to change this code I have to find these functions and then change body of them. 

But what if I don’t change any code and just make this event handler to run multiple times per click. That is sound good idea. So let copy and paste event handler for couple of times. But I should notice that second function call has “return” and I have to remove it for my new copies, and just leave it for last one.

 

 

fbjs_sandbox.instances.a130168443678744.bootstrap(); fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,130168443678744),function(a130168443678744_event) {a130168443678744_game.update($FBJS.ref(this).getForm())},130168443678744],new fbjs_event(event)); 
fbjs_sandbox.instances.a130168443678744.bootstrap();fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,130168443678744),function(a130168443678744_event) {a130168443678744_game.update($FBJS.ref(this).getForm())},130168443678744],new fbjs_event(event)); 
fbjs_sandbox.instances.a130168443678744.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,130168443678744),function(a130168443678744_event) {a130168443678744_game.update($FBJS.ref(this).getForm())},130168443678744],new fbjs_event(event));

 

 

As you see I copied all code for three times and left return just for last call. It means my clicks will be tripled and I can register 150 clicks just for 50. It’s good. So let’s copy this code back to onmouseup element it is ready for testing. 

Enjoy it!

Tags: ,

Blog

WEBCAMPS Sydney Day 1 / Part 2

by Ahmadreza Atighechi 9. July 2010 05:59

 

As first day continued Scott and James tried to demonstrate Microsoft ASP.net 4.0 and MVC 2. Same question about ASP.Net was asked and was answered. Fellows was worried about replacement of ASP.Net with MVC 2 and as it was answered and like before Scott and James defined that ASP.Net is not going to be replaced by MVC. It is just a new approach of implementing web applications and depending on website structure and content websites could either be implemented by ASP.Net 4.0 or MVC 2.

Couple of new project templates has been added to Visual Studio 2010 and in web. One of them is “ASP.NET Web Application”. When a new ASP.NET Web Application is created visual studio automatically creates folder and files which are needed for a simple application. This type of project unlike previous web application is not an empty project and contains necessary files and folders to create a simpl e application.

This template includes Microsoft ASP.NET Membership Provider and if SQL Server Express is installed on developer machine this type of project is automatically configured for ASP.NET Membership provider which connects to SQL Express. This type of Web application is similar to ASP.Net application because the theme and style looks like default theme of ASP.Net MVC Application. Good news is Micros oft has added jQuery to ASP.Net web application and ASP.Net MVC 2 Web application templates.

I think one of best features of MVC is its testability and on top of that you can change test framework of testing if you want. I’ve find some good articles and posts about adding customized test framework for testing MVC 2 projects. How to: Add a Custom MVC Test Framework in Visual Studio and a post about NUnit Template for ASP.NET MVC 2 .

Presenters created a new MVC2 Web application and for beginning they created a project without database just to keep it simple. View, Mode was discussed in this session and they talked about partial views and templates. I wanted to describe creating templates in MVC 2 but I found a good sample in Microsoft that helps to understand how to create templates in MVC. Following is link to EditorFor extension method. On the bottom of page you can find a link to Template Helper Sample.

For describing model part of MVC a virtual project was defined named Plan My Night. It was a simple application to plan night. They described model and controller by creating a simple database and entity model to implement Plan My Night. During implementation o f Plan My Night they described partial views editor templates. For editor templates there is a good sample to create an editor template for datetime inputs called MVC2 Editor Template with date and time.

They combined sample with newly introduced feature called jQuery Templates Data Linking. You can find a complete sample in ScottGu’s Blog. Another cool feature of visual studio which is really useful is Dynamic JavaScript Intellisense in VS 2010. Not only client items in win form can be identified by intellisense of VS 2010 but also items which are being created by developer during development can be identified in VS 2010 like following picture. 1000 items with TestDev prefix is added to window object. Exactly after while command you all TestDiv0 to TestDiv1000 is added to suggestion list.

During the presentation Scott wanted to use a trick to cause a crash for visual studio 2010 (It was on purpose). He changed “while” condition to an infinite while condition and he expected VS to crash when suggestion list was being opened, but visual studio is clever enough and calculates list until certain amount of millisecond and if it’s going to be time consuming visual studio just ignores rest of computing and jump over next statement. There is a good post in ScottGu’s Blog about JS Intellisense and its improvements.

Other feature which was discussed in webcamps was about Web.config transformation and packaging and deployment of web application SQL server. There is a good clip about Web.Config transformation in channel9 about Web Deployment and Web.Config.

 Rest of presentation was about IIS extensions which are available on http://www.iis.net/download and can be downloaded and installed by Web Platform Installer. Among those extensions SEO Toolkit was fantastic which was shown by Scott.

At the end of presentation fellows were asked to pitch their ideas for next day. Following are some of projects and people voted for them .

My Noisy Neighbour (I voted this project)

RaceDay Commander

MongoDB Management Studio

Due Date – lightweight task-tracking for uni students

Address Book Lookup

I voted for first project “My Noisy Neighbour” and in second day I had to join to a group of people to develop this web application based on what we’d learned in first day. In the next post I’m going to describe what was our project was and what had happened.

Tags: , , , ,

Blog

WEBCAMPS Sydney Day 1 / Part 1

by Ahmadreza Atighechi 7. June 2010 01:39

 

WEBCAMP was a 2 days event that provides a chance to learn and build projects based on Microsoft Web Platform. WEBCAMPS is held in different cities around the word and I had chance to participate in Sydney WEBCAMP event in 28 and 29 of May 2010. Interesting point is performers of this event in Sydney were Scott Hanselman and James Senior who I really wanted to be in one of their presentations specially Scott that you’ll never be tired in a conference in case Scott is one of presenters.

This presentation is held on Powerhouse museum in Ultimo.  Seminar star ted at 9:00 and in day one approximately 400 attendees was in event. However, in day 2 number of attendee had dropped sharply to less than half of day one. But that was predictable because day 2 you could participate in lab or build your own application or even participate in a group to develop an application based on what you’ve learned in first day.

 

 

 

 

Day 1 Contents:

Day 1 started with introduction of Microsoft Web platform installer.

Microsoft Web Platform Installer or Web PI is a free installation application which based on your requirements installs services, frameworks, tools or databases you need to install a specific application. Web PI helps you prevent redundant task which is common in installation different project. Web PI check you system and depending on your machine configuration suggest Framework, Servers, Databases and available applications. By aid of Microsoft Web PI you can install Web application like DotNetNuke or Umbraco CMS or even Jumla! The good point is some application like Jumla is php based and Web PI know their installation requirements and install selected program based on setting. No need to say that depending of operating system and system Web PI suggest different set of application. 

In day 1 James Senior tried to install Umbraco CMS in demo Umbraco CMS with database and other requirements was installed on demo machine.

Good point is Web PI installs on a machine as well as IIS and user can run it repeatedly to configure server and installed application and components.

In day 1 presentation has slides to justify that MVC is not a replacement for Microsoft web solution and MVC is just another approach for web development. ASP.Net MVC is an open source project done by Microsoft and you can find it here. 

As the seminar continued one of features of ASP.Net 4.0 was introduced named “ASP.Net Dynamic Data Entities Web Application” Or “ASP.Net Dynamic Data Linq to SQL Web Application”. The first one uses entity framework for data layer but second uses Linq to SQL as data layer. 

As far as I remember these two ASP.Net Extension projects was introduced by Visual Studio 2008 SP1 in 2008. Here is some useful videos for creating and customizing Dynamic Data web applications.

http://www.asp.net/dynamicdata

These project types are useful for creating administration pages from scratch. All you need to do is create your database and relations. Create a project type either Entity of Linq to SQL and select entities you want. Suddenly you find that All CRUD (Create/Remove/Update/Delete) of your entities is created in user friendly URL by using “DynamicDataRoute” class.

Following is steps to create an administration web site for Northwind in less than 2 minutes:

1. Create a new web project type Asp.net Dynamic Data Entities Web application.

2. Copy Nothwind Database files (MDF and LDF) in APP_DATA folder.

3. Right click on project and new data item type ADO.Net Entity Data Model.

4. In wizard form select “Generate from database” item.

5. And then select NORTWIND as data connection.

6. Select tables you want to be added to Entity Data Mod and then click finish.

7. Open Global.asax and then remark line starting with DefaultModel change this line as follow.

 

DefaultModel.RegisterContext(typeof(NorthwindEntities), new ContextConfiguration() { ScaffoldAllTables = true });

 

8. Press F5 and run the application.

 

Simple, Easy and beautiful, It’s a good solution for quick data administration generation. And the good thing is all templates are editable and you can change them.

Tags: , ,

Blog

Value type property and C# compilation error

by Ahmadreza Atighechi 28. November 2009 21:48

Two days ago a question was asked in StackOverflow.com and I found this question so good to prepare a post. I want to explain this question:

Petr asked: I do not understand why there is Control.padding.all which is int and according to hint there is set as well as get but I cannot set it (Control.Padding.All=5)? I would be grateful for explanation.

For example when you want to set

	textBox1.Padding.All = 5;

You will get this compiling error: Cannot modify the return value of 'System.Windows.Forms.TextBoxBase.Padding' because it is not a variable

 

 

Following example is an implementation of this error:

    public class ARAControl 
    { 
        public ARAPadding Padding { get; set; } 
    }
    public struct ARAPadding 
    { 
        public int All { get; set; } 
    }

If you use this you'll get mentioned error:

	ARAControl control = new ARAControl(); 
	control.Padding.All = 10;

And why this compiling error happens. It hapens because structure is a value type. By setting this property you first call get Method. "Property Get" will return a copy of ARAPadding, so it is a value type and C# will detect out mistake and prevent compiling.

 

Tags:

Blog

LINQ-To-SQL Uses magic ROW_NUMBER() function

by Ahmadreza Atighechi 5. August 2009 23:39

Recently I founded that LINQ-To-SQL Uses magic ROW_NUMBER() function. ROW_NUMBER() function is a magic function which was added in SQL Server 2005. Microsoft put this function in version 2005 so that developers will not take it for granted and appreciate it. ROW_NUMBER "returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition".

ROW_NUMBER() Syntax:

ROW_NUMBER ( )     OVER ( [ <partition_by_clause> ] <order_by_clause> )

 

For example following query add a number field which is partitioned by ProductID (reset on new ProductID) in descending order on UnitPrice * OrderQty.

 

        SELECT ROW_NUMBER() 
        OVER (Partition by ProductID ORDER BY UnitPrice * OrderQty DESC) AS ROWNUM,* 
        FROM Sales.SalesOrderDetail 
    

 

ROW_NUMBER() helps programmer to select specified amount of rows within a select command. This feature commonly used in paging. Following example returns @P1th to @P2th rows which list is ordered by ProductId.

 

SELECT * FROM
SELECT *, ROW_NUMBER() OVER (ORDER BY ProductID) AS ROWNUMBER 
FROM Sales.SalesOrderDetail) AS ALLDATA
WHERE ALLDATA.ROWNUMBER  BETWEEN @P1 and @P2

 

Skip() and Take()LINQ-To-SQL functions generate ROW_NUMBER syntax in query result. I created a LINQ-TO-SQL dbml file on AdventureWorks. I selected SalesOrderDetail as Data Class.

 

 

            AdventureWorksDataContext advDC = new AdventureWorksDataContext();
 
            IQueryable orderDetails = advDC.SalesOrderDetails.OrderBy(f => f.SalesOrderDetailID)
                                                             .Skip(20).Take(10);
 
            foreach (SalesOrderDetail orderDetail in orderDetails)
                Console.WriteLine(orderDetail.ProductID);
            Console.ReadLine();

 

Above code generates following SQL for orderDetails:

 

 {SELECT [t1].[SalesOrderID], [t1].[SalesOrderDetailID], [t1].[CarrierTrackingNumber], [t1].[OrderQty], [t1].[ProductID], [t1].[SpecialOfferID], [t1].[UnitPrice], [t1].[UnitPriceDiscount], [t1].[LineTotal], [t1].[rowguid], [t1].[ModifiedDate]
FROM (
    SELECT ROW_NUMBER() OVER (ORDER BY [t0].[SalesOrderDetailID]) AS [ROW_NUMBER], [t0].[SalesOrderID], [t0].[SalesOrderDetailID], [t0].[CarrierTrackingNumber], [t0].[OrderQty], [t0].[ProductID], [t0].[SpecialOfferID], [t0].[UnitPrice], [t0].[UnitPriceDiscount], [t0].[LineTotal], [t0].[rowguid], [t0].[ModifiedDate]
    FROM [Sales].[SalesOrderDetail] AS [t0]
    ) AS [t1]
WHERE [t1].[ROW_NUMBER] BETWEEN @p0 + 1 AND @p0 + @p1
ORDER BY [t1].[ROW_NUMBER]
}

 

As you see, Skip and Take functions interpreted as ROW_NUMBER() function.

kick it on DotNetKicks.com

Tags: ,

Blog

Migrating to BlogEngine.net

by Ahmadreza Atighechi 24. June 2009 16:12

 Finally, I've decided to convert my weblog engine from Graffiti CMS to BlogEngine. Moving to BlogEngine doesn't mean weakness of Graffiti blogging engine or indicating any problem. But after surveying BlogEngine and comparing to current version of Graffity CMS I've found lots of features more sophisticated than Graffiti and in my opinion blogEngine is handier. Although you can full features here but in my opinion following features are cool and convincing to migrate:

 

  • Easy installation
  • Cool widgets
  • Advanced comment system (Supporting Nested reply)
  • Cool themes (more themes are available on web)
  • Supporting ping service
  • Static pages

 

 

Tags:

Blog

Code contracts (Part 2): Creating my first project with code contracts

by Ahmadreza Atighechi 22. May 2009 04:35

 

I downloaded code contracts from here. After installing code contract, I tried to create my first project with code contracts. I created new console project name CodeContractTest . I added reference to Microsoft.Contracts library which is appeared in .Net references after installation.

I wrote following code this is clearly compiled without any warning.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using System.Diagnostics;

namespace CodeContractTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Swap(new string[] { "Code", "Contract" }, 1, 4);
        }
        static void Swap(string[] arr, int item1, int item2)
        {
            string temp;
            temp = arr[item1];
            arr[item1] = arr[item2];
            arr[item2] = temp;
        }

    }

}

 

However, after running this application we will encounter with IndexOutOfRangeException. This is occurred because illegal parameter in Swap method call.

Let take a look at new feature added to Visual Studio 2008. I open properties window of project. New tab is added named "Code Contracts". I checked "Perform Static Contract Checking" and "Implicit Array Bound Obligations". If I rebuild project new warnings and message will be appeared in Error window.

 

Four warnings are about Array access and four suggestion message plus one summary message.

 

In order to improve code and get rid of warnings I should add preconditions in swap method. I added four line of precondition which assure item1 , item2 is in array boundary. I used Contract class and Requires static method which is used for preconditions it has two overloads first overload has a bool parameter. We can use this method to explicitly define the conditions of input parameters.

        static void Swap(string[] arr, int item1, int item2)
        {
            Contract.Requires(item1 < arr.Length);
            Contract.Requires(item1 >= 0);
            Contract.Requires(item2 < arr.Length);
            Contract.Requires(item2 >= 0);
            string temp;
            temp = arr[item1];
            arr[item1] = arr[item2];
            arr[item2] = temp;
        }

After rebuilding project new warning is appeared. It shows that one of contract precondition rules is broken.

If I change the swap with proper input parameters after rebuilding project warning messages will be disappeared.

 

            Swap(new string[] { "Code", "Contract" }, 0, 1);

If I check "Implicit Non-Null Obligation" on code contracts tab of property window building application will be face with new warning "contracts: Possible use of a null array 'arr'"

 

Swap method should be called with non-null array parameter. This is another contract that should be added to preconditions. So I changed Swap method as follow.

       static void Swap(string[] arr, int item1, int item2)
        {
            Contract.Requires(arr != null);
            Contract.Requires(item1 < arr.Length);
            Contract.Requires(item1 >= 0);
            Contract.Requires(item2 < arr.Length);
            Contract.Requires(item2 >= 0);
            string temp;
            temp = arr[item1];
            arr[item1] = arr[item2];
            arr[item2] = temp;
        }

In this case developer of Swap method define contract for input parameters and there is no need to swap caller know all swap code in order to prevent bad parameter calling.

You can download code from here

 

kick it on DotNetKicks.com

 

Tags:

Blog

Visual Studio trick: Adding namespace

by Ahmadreza Atighechi 20. May 2009 05:17

 

A few days ago I saw a clip of PDC 2008 about MVC .Net which is great concept. It was performed by Phil Haack. In this video Phil shows a trick of Visual studio which is very useful.

Most of the time during application development you want use a class which its name space has not been included. Guess what should you do? Oh yes ! You should type name space completely or leave current line and go to top of class adding appropriate "using" statement get back to your line of code. Surprisingly there is a trick in visual studio 2008 (I tested in visual studio 2008). If reference of class included in project you can Type class name completely at the same time a tooltip bar will be appeared under your class name. At the same time press Ctrl+. (dot). A menu will be appeared which offers you two options. First option will add using statement at the top of code class file. Second option will insert full class name including name space.

 

 

kick it on DotNetKicks.com

Tags:

Blog

Axum

by Ahmadreza Atighechi 13. May 2009 01:06

Axum has been released in Microsoft DevLabs

What is Axum:

Axum is a language that builds upon the architecture of the Web and principles of isolation, actors, and message-passing to increase application safety, responsiveness, scalability, and developer productivity.

Axum aims to validate a safe and productive parallel programming model for .NET.

you can find more inforamtion about Axum here

And here is Axum blog

Tags:

Blog

The information on this web site is provided "AS IS" with no warranties, and confers no rights.

Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen