Monday, 27 February 2012
MVC Client Side and server Side View Engines
Date Diff in C#
After rereading some of your posts it seams like a better understanding of what .net really is is what is needed for you to find an answer to your question. The DateDiff method that is contained in Microsoft.VisualBasic is not a visual basic method, nor is it a C# method. It is a .net method contained in a .net library. It was created to give programmers who use a language other than VB some of the functionality that is included in VB as part of the runtime. May I suggest reading the wikipedia articles on CLR and CLI:
Common_Language_Runtime
Common_Language_Infrastructure
These, along with the description at the top of this page (List_of_CLI_languages ) which I found useful, should help you solve your problem.
If you are still unsatisifed, then you can always continue along the line of my previous post and just pull Microsofts source code out of Microsoft.VisualBasic.dll and insert it into your own C# code.
http://forums.asp.net/t/1107932.aspx
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/81806efe-f565-4444-8b94-f3332d29efc6/
Wednesday, 22 February 2012
ASP.NET MVC 4 Features
The ASP.NET MVC 4 Beta includes a bunch of great new features and capabilities. Some of the highlights include:
- Bundling and Minification – ASP.NET MVC 4 includes the new bundling and minification support we are also adding to ASP.NET 4.5. These features enable you to build web applications that load faster and feel more responsive to users, by minimizing the number and size of HTTP requests that your pages make. Included with the MVC 4 beta are new “cache busting” helper methods that enable easy proxy caching of bundled files (with automatic invalidation if you change the cached CSS or JavaScript). You can learn more about bundling and minification from my previous blog post about it.
- Database Migrations – ASP.NET MVC 4 includes the new Entity Framework 4.3 release, which includes a bunch of great new features. One of the most eagerly anticipated features it provides is database migration support. This enables you to easily evolve your database schema using a code focused migration approach – and do so while preserving the data within your database. I’ll blog more about this in the future - you can also see a walkthrough of database migrations in this tutorial.
- Web API – ASP.NET MVC 4 includes some fantastic new support for creating “Web APIs”. This enables you to easily create HTTP services and APIs that can be programmatically called from a broad range of clients (ranging from browsers using JavaScript, to native apps on any mobile/client platform). The new Web API support also provides an ideal platform for building RESTful services. I’ll be blogging much more about this support soon – it is really cool, and opens up a bunch of new opportunities.
- Mobile Web – ASP.NET MVC 4 includes new support for building mobile web applications and mobile web sites, and makes it much easier to build experiences that are optimized for phone and tablet experiences. It includes jQuery Mobile, and includes new support for customizing which view templates are used depending upon what type of device is accessing the app.
- Razor Enhancements – ASP.NET MVC 4 includes V2 of our Razor View engine. Razor V2 includes a bunch of juicy enhancements that enable you to make your view templates even cleaner and more concise – including better support for resolving URL references and selectively rendering HTML attributes.
- Async Support and WebSockets – You’ll be able to take advantage of some additional language and runtime capabilities when using ASP.NET MVC 4 with .NET 4.5 and VS 11. Async support is one of the big ones, and the ASP.NET MVC runtime support for this combined with the new C#/VB async language enhancements (which are super elegant and clean) is going to enable you to write incredibly scalable applications. You will also be able to take advantage of the new WebSocket support built-into .NET 4.5 to build applications with even richer browser/server communication.
Sunday, 19 February 2012
JQuery Ajax Call and ASP.net MVC 4.0
| Step | Operation | Bandwidth |
| 1 | Index page first load | 140.7 KB |
| 2 | Click on edit link | |
| 3 | Edit page load | 133.9 KB |
| 4 | Save data on the server | 8 KB |
| 5 | Return to Index | 140.7 KB |
| 423.3 K |
The same operation performed over Ajax with a modal dialog pop-up instead of navigating to an Edit page:
| Step | Operation | Bandwidth |
| 1 | Index page first load | 140.7 KB |
| 2 | Click on edit link | |
| 3 | Edit dialog load | 12.8 KB |
| 4 | Save data on the server | 4 KB |
| 5 | Close dialog and update Index html | 4.1 KB |
| 161.6 KB |
These figures should change when applying Compression and Omission techniques, but the Ajax powered edit operation is more efficient nevertheless.
public JsonResult EditNote(int id)
{
string message = string.Empty;
var note = new TxtNote();
try
{
note = (from x in db.TxtNotes where x.Id == id select x).FirstOrDefault();
}
catch (Exception ex)
{
message = ex.Message;
}
{
Html = this.RenderPartialView("_NoteEdit", note),
Message = message
}, JsonRequestBehavior.AllowGet);
}
<div class="edit-box">
<textarea name="edit-content" id="edit-content" class="edit-textarea" rows="1" maxlength="4000">@Model.Titletextarea><br />
div>
$(".edit-note").live("click", function (e) {
e.preventDefault();
showLoader('Editing note');
var noteId = $(this).attr("id").replace('edit-', '');
var liId = '#bar-' + noteId;
//load note from db and open in dialog
$.ajax({
type: "GET",
url: "TextNotes/EditNote",
data: { id: noteId },
cache: false,
dataType: "json",
success: function (mynote) {
$("#edit-popup").html(mynote.Html);
$("#edit-popup").dialog({
resizable: true,
height: 210,
width: 510,
modal: true,
buttons: {
Save: function () {
var boxval = $("#edit-content").val();
if (!boxval) {
showError("Can't save an empty note");
return;
}
$.ajax({
type: "POST",
url: "TextNotes/SaveNote",
data: { id: noteId, content: boxval },
cache: false,
dataType: "json",
success: function (data) {
if (data.Message) {
showError(data.Message);
} else {
$(liId).replaceWith(data.Html);
$(liId).slideDown("slow");
$("#flash").hide();
$("#edit-popup").dialog("close");
}
}
}); //end save call
}, // end ok button
Cancel: function () {
$("#flash").hide();
$(this).dialog("close");
}
},
close: function () {
$("#flash").hide();
} //end buttons
}); //end modal edit
}
}); //end ajax call
}); //end edit
[ValidateInput(false)]
public JsonResult SaveNote(int id, string content)
{
string message = string.Empty;
var note = new TxtNote();
try
{
note = (from x in db.TxtNotes where x.Id == id select x).FirstOrDefault();
note.Title = content;
db.SaveChanges();
}
catch (Exception ex)
{
message = ex.Message;
}
{
Html = this.RenderPartialView("_NotesList", new List<TxtNote>() { note }),
Message = message
}, JsonRequestBehavior.AllowGet);
}
Previous post: Async operations with jQuery Ajax and Asp.Net MVC
Wednesday, 15 February 2012
Behavior-driven development framework for testing your JavaScript code
BDD for JavaScript
describe("Jasmine", function() { it("makes testing JavaScript awesome!", function() { expect(yourCode).toBeLotsBetter(); }); });Tuesday, 7 February 2012
Aspect-Oriented Programming
When thinking of an object and its relationship to other objects we often think in terms of inheritance. We define some abstract class; let us use a Dog class as an example. As we identify similar classes but with unique behaviors of their own, we often use inheritance to extend the functionality. For instance, if we identified a Poodle we could say a Poodle Is A Dog, so Poodle inherits Dog. So far so good, but what happens when we define another unique behavior later on that we label as an Obedient Dog? Surely not all Dogs are obedient, so the Dog class cannot contain the obedience behavior. Furthermore, if we were to create an Obedient Dog class that inherited from Dog, then where would aPoodle fit in that hierarchy? A Poodle is A Dog, but a Poodle may or may not be obedient; does Poodle, then, inherit from Dog, or does Poodle inherit from Obedient Dog? Instead, we can look at obedience as an aspect that we apply to any type of Dog that is obedient, as opposed to inappropriately forcing that behavior in the Dog hierarchy.
In software terms, aspect-oriented programming allows us the ability to apply aspects that alter behavior to classes or objects independent of any inheritance hierarchy. We can then apply these aspects either during runtime or compile time. It is easier to demonstrate AOP by example then to describe it. To start, though, it is important to define four key AOP terms I will use repeatedly:
- Joinpoint—Well defined points in code that can be identified.
- Pointcut—A way of specifying a Joinpoint by some means of configuration or code.
- Advice—A way of expressing a cross cutting action that needs to occur.
- Mixin—An instance of a class to be mixed in with the target instance of a class to introduce new behavior.
To better understand these terms, think of a joinpoint as a defined point in program flow. A good example of a joinpoint is the following: when code invokes a method, that point at which that invocation occurs is considered the joinpoint. The pointcut allows us to specify or define the joinpoints that we wish to intercept in our program flow. A Pointcut also contains an advice that is to occur when the joinpoint is reached. So if we define a Pointcut on a particular method being invoked, when the invocation occurs or the joinpoint is invoked, it is intercepted by the AOP framework and the pointcut's advice is executed. An advice can be several things, but you should most commonly think of it as another method to invoke. So when we invoke a method with a pointcut, our advice to execute would be another method to invoke. This advice or method to invoke could be on the object whose method was intercepted or on another object that we mixed in. We will explain mixins in further detail later.
Extracted From - http://msdn.microsoft.com/en-us/library/aa288717(v=vs.71).aspx
Microsoft Unveils Microsoft Dynamics CRM Mobile
Microsoft Corp. (Nasdaq “MSFT”) today announced that Microsoft Dynamics CRM will release its next service update in Q2 2012. This service update will deliver the capability for customers to access the complete functionality of Microsoft Dynamics CRM on virtually any device with a new cloud-based, cross-platform, native mobile client service for Windows Phone 7, iPad, iPhone, Android and BlackBerry mobile devices.
“In today’s hyperconnected world, customers need to be able to access their business-critical data on the device of their choice from wherever they are,” said Dennis Michalis, general manager, Microsoft Dynamics CRM. “These advancements, combined with the strength of the Microsoft platform, make Microsoft Dynamics CRM an obvious choice for any business.”
Maintaining Microsoft’s commitment to delivering rapid innovation to customers, the Microsoft Dynamics CRM Q2 2012 service update also includes enhanced social functionality and new enterprise-class features, and adds multiple Web browser options for users, including Internet Explorer, Chrome, Firefox and Safari, running on PC, Macintosh and iPad devices.
Delivering CRM on Virtually Any Mobile Device
Microsoft Dynamics CRM Mobile will deliver customers a fast and familiar experience, helping sales, customer service, marketing and management professionals connect with their customers and each other on multiple mobile devices through a security-enhanced environment. For instance, sales and marketing representatives will now be able to quickly capture and convert leads 24/7 and develop marketing campaigns on the go.
Using the cloud-based, cross-platform, native mobile client service, customers will be able to sync their information and sales pipelines offline, helping them stay connected on the road and on their terms.
Through the power of xRM, the flexible application development framework of Microsoft Dynamics CRM, customers will also be able to easily mobilize their extended CRM applications by having seamless integration between Microsoft Dynamics CRM Mobile and their existing Microsoft Dynamics CRM environment.
Microsoft Dynamics CRM Mobile will be available at a starting price of $30 (U.S.) per user, per month and supports the use of up to three devices per user.
Additional Social Enhancements
Building on the Microsoft Dynamics CRM November 2011 service update, the new release will include more social capabilities with Activity Feeds that give people the ability to like and unlike status updates, improved status filtering, and the capability to view all statuses relating to a particular record view, which will make it even easier for users to stay on top of all relevant customer information to help them be more productive.
Complete information on the Microsoft Dynamics CRM Q2 2012 service update is available in theRelease Preview Guide and a blog post from Michalis on CRM Connection. Those who want to follow and engage with the Microsoft Dynamics CRM Twitter community can do so at @MSDynamicsCRM, using #MSDYNCRM and #crm2011.
About Microsoft Dynamics
Microsoft Dynamics CRM and ERP solutions empower your people to be more productive and your systems to last longer and scale as your business grows, while enabling you to derive the insights necessary to respond quickly in an ever-changing world of business.
About Microsoft
Founded in 1975, Microsoft (Nasdaq “MSFT”) is the worldwide leader in software, services and solutions that help people and businesses realize their full potential.
Note to editors: For more information, news and perspectives from Microsoft, please visit the Microsoft News Center at http://www.microsoft.com/news. Web links, telephone numbers and titles were correct at time of publication, but may have changed. For additional assistance, journalists and analysts may contact Microsoft’s Rapid Response Team or other appropriate contacts listed athttp://www.microsoft.com/news/contactpr.mspx.