Showing posts with label Learning. Show all posts
Showing posts with label Learning. Show all posts

Wednesday, 15 February 2017

Resharper shorcut cheat sheet

Quite by chance today I stumbled across a new way to learn Resharper shortcuts.

In visual studio, when editing a file, tap the ctrl key three times in quick succession. This brings up the cheat sheet

clip_image002

Then hold down the Ctrl key, Shift Key, or Alt Key when the dialog is open, and you'll see what short cuts are applicable to the development pane that you're in

clip_image002[4]

Monday, 2 February 2015

MVC / Jquery unobtrusive validation

http://www.devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-1

Also for how do attach a new client side method to unobtrusive validation e.g.

jQuery.validator.unobtrusive.adapters.add(adapterName, [params], fn);

see this article...

http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html

 

Note: For any element a in your <form>, you can do this to figure out what validation is attached to the containing <form> for that element...


$.data(a.form, "validator").settings.rules

e.g.

$.data(a.form, "validator").settings.rules.MiddleInitial
Object {maxlength: "1", __dummy__: true}

$.data(a.form, "validator").settings.messages.MiddleInitial
Object {maxlength: "The middle initial must be a single charater"}

Wednesday, 21 May 2014

BrowserLink and other new VS 2013 features

Perhaps the most significant enhancement to creating web applications in Visual Studio for many years. Check out how you can edit your pages in line in the browser, and it updates the source code back in visual studio directly, using the new BrowserLink feature...

http://www.asp.net/visual-studio/overview/2013/visual-studio-2013-web-editor-features-browser-link

More features worth a look are all listed under the parent page here...

http://www.asp.net/visual-studio/overview/2013

Thursday, 5 December 2013

Cross platform mobile development in C#

http://blog.xamarin.com/microsoft-and-xamarin-partner-globally/

Microsoft Virtual Academy - ASP.NET MVC

I’ve just got into the Microsoft Virtual Academy, and I have to say it has a wealth of up to date, excellent training videos.

http://www.microsoftvirtualacademy.com/Content/ViewContent.aspx?et=4099&m=4093&ct=19601#?fbid=_Oyn-vcRqgr

Razor syntax escape characters…

image

Html anti forgery token..

http://blog.stevensanderson.com/2008/09/01/prevent-cross-site-request-forgery-csrf-using-aspnet-mvcs-antiforgerytoken-helper/

ASP.NET MVC 4 Content Map

http://www.asp.net/mvc/overview/getting-started/aspnet-mvc-content-map

Script including - always use the longhand version for the <script></script> tag, otherwise your script file will not be downloading to the client browser

JSBin.com - http://jsbin.com/ a fantastic javscript, jquery, html and css online playground like jsfiddle.net and plnkr.co. The nice thing about this one though is that you can download the entire finished article file as a single html page.

What's coming in ASP.NET - www.asp.net/vnext

Signed nightly builds of asp.net vnext - https://aspnetwebstack.codeplex.com/

Getting started with web api - http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

Web API 2 (video) - http://channel9.msdn.com/Events/Build/2013/3-504

Tuesday, 23 July 2013

Unit of work pattern in WCF

See here for an example of how to implement a unit of work pattern in WCF (using Unity).

http://blogs.5dlabs.it/post/2012/05/23/Implementing-Repository-and-UnitOfWork-patterns-in-a-WCF-service-using-Unity.aspx

public class CustomServiceHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
  {
return new CustomServiceHost(serviceType, baseAddresses);
  }
}

public class CustomServiceHost : ServiceHost
{
static IUnityContainer _container;
static CustomServiceHost()
  {
    _container = new UnityContainer();
    _container.RegisterType<ICompanyRepository, CompanyRepository>();
    _container.RegisterType<IUnitOfWork, DbUnitOfWork>();
    _container.RegisterType<SVCContext>(new ServiceInstanceLifeTimeManager());
  }
public CustomServiceHost(Type serviceType, params Uri[] : base(serviceType, baseAddresses)
  {
  }
protected override void ApplyConfiguration()
  {
base.ApplyConfiguration();
    Description.Behaviors.Add(_container.Resolve<UnityServiceBehavior>());
  }
}

public class UnityServiceBehavior : BehaviorExtensionElement , IServiceBehavior
{
IUnityContainer _container;
public UnityServiceBehavior(IUnityContainer container) : base()
  {
    _container = container;
  }
public void AddBindingParameters(ServiceDescription serviceDescription,
ServiceHostBase serviceHostBase,
Collection<ServiceEndpoint> endpoints,
BindingParameterCollection bindingParameters)
  {
  }
public void ApplyDispatchBehavior(ServiceDescription serviceDescription,
ServiceHostBase serviceHostBase)
  {
Type serviceType = serviceDescription.ServiceType;
IInstanceProvider instanceProvider = new UnityInstanceProvider(_container, serviceType);
foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
    {
foreach (EndpointDispatcher endpointDispatcher in dispatcher.Endpoints)
      {
        endpointDispatcher.DispatchRuntime.InstanceProvider = instanceProvider;
        endpointDispatcher.DispatchRuntime.MessageInspectors.Add(
new UnitOfWorkMessageInspector(_container)
        );
      }
    }
  }
public void Validate(ServiceDescription serviceDescription,
ServiceHostBase serviceHostBase)
  {
  }
public override Type BehaviorType
  {
get { return this.GetType(); }
  }
protected override object CreateBehavior()
  {
return this;
  }
}

public class UnityInstanceProvider : IInstanceProvider
{
IUnityContainer _container;
Type _serviceType;
public UnityInstanceProvider(IUnityContainer container, Type serviceType)
  {
    _container = container;
    _serviceType = serviceType;
  }
public object GetInstance(InstanceContext instanceContext, Message message)
  {
return _container.Resolve(_serviceType);
  }
public object GetInstance(InstanceContext instanceContext)
  {
return this.GetInstance(instanceContext, null);
  }
public void ReleaseInstance(InstanceContext instanceContext, object instance)
  {
  }
}

 

 

public interface IUnitOfWork
{
void Commit();
}

public class DbUnitOfWork : IUnitOfWork
{
SVCContext _context;
public DbUnitOfWork(SVCContext context)
  {
    _context = context;
  }
public void Commit()
  {
    _context.SaveChanges();
  }
}

 

public class UnitOfWorkMessageInspector : IDispatchMessageInspector
{
IUnityContainer _container;
public UnitOfWorkMessageInspector(IUnityContainer container)
  {
    _container = container;
  }
public object AfterReceiveRequest(ref Message request, IClientChannel channel,
InstanceContext instanceContext)
  {
return _container.Resolve<IUnitOfWork>();
  }
public void BeforeSendReply(ref Message reply, object correlationState)
  {
    ((IUnitOfWork)correlationState).Commit();
  }
}

Thursday, 17 January 2013

Project Silk for all your HTML web application needs

A colleague of mine pointed out this white paper article that Microsoft have kindly put together, which appears to be a full overview on how to construct a web site in this day an age.

"Guidance for building cross-browser web applications with a focus on client-side interactivity. These applications take advantage of the latest web standards like HTML5, CSS3 and ECMAScript 5 along with modern web technologies such as jQuery, Internet Explorer 9, and ASP.NET MVC3"

http://silk.codeplex.com/

You can also download it all in pdf format from the following link

http://www.microsoft.com/en-us/download/details.aspx?id=27290

Wednesday, 31 October 2012

Beware the perils of Javascript

These two links are definitely worth a read I think...

http://oreilly.com/javascript/excerpts/javascript-good-parts/bad-parts.html

and especially…

http://oreilly.com/javascript/excerpts/javascript-good-parts/awful-parts.html

e.g.

Semicolon Insertion

JavaScript has a mechanism that tries to correct faulty programs by automatically inserting semicolons. Do not depend on this. It can mask more serious errors.

It sometimes inserts semicolons in places where they are not welcome. Consider the consequences of semicolon insertion on thereturn statement. If a return statement returns a value, that value expression must begin on the same line as the return:

return

{

status: true

};

This appears to return an object containing a status member. Unfortunately, semicolon insertion turns it into a statement that returns undefined. There is no warning that semicolon insertion caused the misinterpretation of the program. The problem can be avoided if the { is placed at the end of the previous line and not at the beginning of the next line:

return {

status: true

};

Wednesday, 26 September 2012

JavaScript dates are zero based for month part

It appears that JS treats dates as zero indexed on the month part when you construct them in the format new Date("yyyy", "MM", "dd")

clip_image001

Wednesday, 18 July 2012

Client side tools for Phone development

These are the client side tools that have just been mentioned for developing responsive web applications for mobile platform today on http://live.aspconf.net/ 

image

Frameworks to learn for SPAs

If you're thinking of building single page applications in future, then you will need to learn the following frameworks for sure..

image

Monday, 9 July 2012

Knockout.js learning

I've come across this great site for helping you to get to grips with the basics of creating some excellent user interfaces in javascript and HTML5.

http://learn.knockoutjs.com/

image

If anything, it's great just for using the editor for quick checking of HTML in a preview mode using the Run functionality on the left hand side...

image

Monday, 25 June 2012

Using Apache benchmark to load test your web site

You can download the apache web server, then simply look inside the zip file for ab.exe.

E.g. to load test your site with 10 concurrent requests use the following command line...

>ab.exe -n 10 -c 10 http://localhost/mywebsite

For more information see 8.15mins into this video link...

http://channel9.msdn.com/Events/TechDays/Techdays-2012-the-Netherlands/2287

Friday, 18 May 2012

Microsoft MVC Best Practices

http://wiki.asp.net/page.aspx/1014/aspnet-mvc-best-practices

The ASP.NET MVC is becoming more and more popular each day.  As the application grows in size so does the maintenance nightmare.  Following are some of the better practices, that if followed, may help maintain our application and also provides a means of scalability as the demand increases.  Feel free to add/update practices/tips as required.

Do note that this checklist are just for quick reference and are not detailed materials and can be used as a quick reference.  

  1. Isolate Controllers
    Isolate the controllers from dependencies on HttpContext, data access classes, configuration, logging etc.  Isolation could be achieved by creating wrapper classes and using an IOC container for passing in these dependencies
  2. IoC Container
    Use an IoC container to manage all external dependencies  The following are some of the well known containers/framework.
    1. Ninject
    2. Autofac
    3. StructureMap
    4. Unity Block
    5. Castle Windsor

  3. No "magic strings"
    Never use magic string in your code.   More to come on this.
  4. Create a ViewModel for each view
    Create a specialized ViewModel for each view.  The role of ViewModel should only be databinding.  It should not contain any presentation logic.
  5. HtmlHelper
    For generating view html use HtmlHelper.  If  the current HtmlHelper is not sufficient extend it using extension methods.  This will keep the design in check.
  6. Action Methods
    Decorate your action methods with appropriate verbs like Get or Post as applicable.
  7. Caching
    Decorate your most used action methods with OutputCache attribute.

  8. Controller and Domain logic
    Try to keep away domain logic from controller.  Controller should only be responsible for
    1. Input validation and sanitization.
    2. Get view related data from the model.
    3. Return the appropriate view or redirect to another appropriate action method.
  9. Use PRG pattern for data modification
    PRG stands for Post-Redirect-Get to avoid the classic browser warning when refreshing a page after post.  Whenever you make a POST request, once the request completes do a redirect so that a GET request is fired.  In this way when the user refresh the page, the last GET request will be executed rather than the POST thereby avoiding unnecessary usability issue. It can also prevent the initial request being executed twice, thus avoiding possible duplication issues.

  10. Routing
    Design your routes carefully.  The classic route debugger comes to rescue http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
  11. There should be no domain logic in the views. Views must be, only, responsible for showing the data.
  12. Views should not contain presentation logic
    Views should not contain any presentation logic.  For e.g. If a "Delete" button is to be displayed only for "Admin" role this should be abstracted away in an Html Helper.  This is just an example and there will be many scenarios which will require this abstraction for easy maintenance of views.

  13. Use POST for "Delete" links instead of GET
    Using Delete links (GET) is more vulnerable than using POST.  Here is a detailed post on this along with a couple of alternatives.
    http://stephenwalther.com/blog/archive/2009/01/21/asp.net-mvc-tip-46-ndash-donrsquot-use-delete-links-because.aspx

How to find the last interactive logons in Windows using PowerShell

Use the following powershell script to find the last users to login to a box since a given date, in this case the 21st April 2022 at 12pm un...