Digital Tool Factory blog - Page 8 of 34 - Backend web development in Atlanta GA Digital Tool Factory blog - Page 8 of 34 - Backend web development in Atlanta GA

The Digital Tool Factory Blog

How to fix problems with data cacheing in ASP.net MVC 4, SignalR and Entity Framework

The Problem

I was using the wonderful SignalR libraries to create a status window (I have a VERY long running process in my new Data Hammer project, it takes about 15 minutes to run) and I need to inform the user on where the process is at any given time.  My original code looked like this

public class Chat : Hub
{
public void Send(int id)
{

DataHammerContext ctx = new DataHammerContext();

while (true)
{

string strName=ctx.ProcessSteps.Find(id).Name;
Clients.All.addMessage(“Status: ” + strName);
Thread.Sleep(1000);
}
}
}

And this would always display the same status, quite maddening.

The Cause

After much investigation I realized that my model of how Signal R works was flawed.  For whatever reason (by which I mean too long to go into here) the data context does not update with the while loop.

The Solution

The fix is simple, just recreate the data context every time and everything works like it should – here is a sample of the updated code.

 

public class Chat : Hub
{
public void Send(int id)
{

 

while (true)
{

DataHammerContext ctx = new DataHammerContext();
string strName=ctx.ProcessSteps.Find(id).Name;
Clients.All.addMessage(“Status: ” + strName);
Thread.Sleep(1000);

}
}
}


16
Jan 13


Written By Steve French

 

The free version of Google Apps is going away, but have no fear

A few weeks ago Google decided to end their free version of GMail, or as they referred to it, Google Apps for domains. If you are an existing customer you were grandfathered in, but otherwise you will now have to pay to use their email service (and spam filtering) with your own domain name.

Happily all is not lost. Microsoft recently released their new, free service of Outlook.com. It is a blatant attempt compete with GMail, and quite frankly, it’s great! It is nowhere near as cluttered and ad-centric as GMail and the spam-filtering is equal to Google’s.

Check it out at Outlook.com. The signup – switchover procedure takes all of about 15 minutes.

And on another note, our new, under-promoted Facebook page is quite lonely – if you have a chance, could you take a look and like us?

This first appeared on the Digital Tool Factory newsletter on 12/31/2012


14
Jan 13


Written By Steve French

 

How to configure wildcard routing in asp.net mvc 4

The Problem

You are trying to configure Widlcard routing (i.e. something like http://domain.com/SomeUserName/) and find it problematic.

The Cause

That is largely by design – wildcard routing is resource intensive and rarely needed.

The Solution

If you want to do it anyway, use the following routes

routes.MapRoute(“Default”, “”, new { controller = “Home”, action = “Index”, id = UrlParameter.Optional });
routes.MapRoute(“CatchAll”, “{*id}”, new { controller = “Home”, action = “Handle”, id = “” });

Things to note

 

  • The Catch-All route is AFTER the home route
  • The syntax is *id – this will ensure that the value of ID is sent to the “Handle” action
  • The purpose of this route is to throw control to the “Handle” action with the appropriate value – Handle must be set up to use that value.

 

Okay, after some more digging (and some failed integration tests) here is what you have to do

Add in the following routes

routes.MapRoute(“Handle”, “Home/Handle/{id}”, new { controller = “Home”, action = “Handle”, id = “” });
routes.MapRoute(“User”, “{*id}”, new { controller = “Home”, action = “Index”, id = “” });
routes.MapRoute(“Default”, “{controller}/{action}/{id}”, new { controller = “Home”, action = “Index”, id = UrlParameter.Optional });

And then create an action called “Handler”, and change your Index action on your home controller to look like this

public ActionResult Index(string id=””)
{
if (!string.IsNullOrWhiteSpace(id))
{
return RedirectToAction(“Handle”, new {@id = id});
}
else {
return View();
}

What does this do?  It routes all wildcard traffic to your Index controller, which then hands it off to the “Handle” Action.  You would think that you could just hand everything off to the Handle action, but if you do that, then your Index action becomes inaccessible,  and in some circumstances you get a recursive loop where the handle action is called endlessly.  That does show an interesting error screen though.

One annoying side effect of this course of action is the need to map out each and every route explicitly, otherwise the wildcard route will pick it up and hand it off to the “Handle” action, which will take it somewhere where you do not want it to go.


04
Jan 13


Written By Steve French

 

How to fix problems with entity framework decimal precision

The Problem

You are attempting to change a database column of type decimal from a precision of two decimal place to one decimal place via data annotations, and there does not seem to be a good way to do it.

The Cause

There isn’t a good way to do it.

The Solution

However, there is at least one non-elegant way to do it – in your OnModelCreating code in your data context, enter in the following piece of code

protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
modelBuilder.Entity().Property(xx=>xx.Handicap).HasPrecision(12, 1);
base.OnModelCreating(modelBuilder);

}
The “HasPrecision” part is the key – the second parameter is the number of decimal places to use


12
Dec 12


Written By Steve French

 

How to order a custom WordPress Post Type by a custom numeric field

So, you need to order a custom WordPress Post Type by a custom numeric field – how?

The Problem

You have a WordPress custom post types, and you need to order by a custom numeric field – how do you do that?

The Cause

You would think that it would be relatively simple, for example the below should work

<?php $loop = new WP_Query( array( 'post_type' => 'staff-member',
'posts_per_page' => 100, 'order' => 'ASC', 'orderby'	=>
'meta_value', 'meta_key' 	=> 'OrderByField','type' => 'numeric' ) ); ?>

But ‘OrderByField’ is treated as a text field, and the number 10, comes after 1, not 2.

The Solution

Use the magic keyword meta_value_num, so your WP_Query would look like this

<?php $loop = new WP_Query( array( 'post_type' => 'staff-member',
'posts_per_page' => 100, 'order' => 'ASC', 'orderby'	=>
'meta_value_num', 'meta_key' => 'StaffOrderBy',
'type' => 'numeric' ) ); ?>
the _num makes all the difference - WordPress will treat it as a numeric field.

04
Dec 12


Written By Steve French

 

How to fix problems with asp.net mvc 4 javascript bundling

The Problem

You are using the new JavaScript bundling and minification features in asp.net mvc 4, and some of your JavaScript files are not being included

The Cause

The minification process – in it’s strange wisdom, does not include .min files when it bundles.  Therefore something like

.Include(“~/Scripts/jHtmlArea-0.7.0.min.js”)

will not be included, leading to JavaScript errors.

The Solution

Just use the non-minified version of the script file –

.Include(“~/Scripts/jHtmlArea-0.7.0.js”)

will work just fine – it seems that the asp.net mvc bundler prefers to do it’s own minification.


04
Dec 12


Written By Steve French

 

How to hire a web company – Who am I?

As part of my upcoming book, How to hire a web company.

Who am I?

I’m Steve French – I started Digital Tool Factory in 2002, and recently celebrated ten full years as an independent business.  Prior to that I worked at a .com startup that went nowhere, and then for an advertising agency.  That agency went out of business and I started Digital Tool Factory.  Actually I called it Creative Plumbing at first.   A poor choice in name but you have to start somewhere.

 

I originally started out as “technical muscle” for graphic design firms.  I had always specialized in implementing challenging graphic looks and feels.  That role eventually morphed into both the front-end and the back-end for websites and over the years the market for the front end development has become commoditized and I moved into back-end development, though with the advent of jquery I’ve gotten more onto the front side again as well.

 

I’ve always developed on the Microsoft Stack since 1999, largely for the reason that my boss at the time liked one particular feature of classic Active Server Pages.  I’ve stuck with the Microsoft Stack (defined as server and database) for many reasons largely because they solve the problems I have.

 

I’ve worked for many, many different companies for clients, in many different fields and industries and I’ve learned from all of them.  I am not naturally a good salesman or marketer.  However I am an excellent explainer and adviser on technical matters.  I’ve found that I have the same conversations with new clients, and the communication problems tend to happen over and over again.

 

That’s why I’m writing this book, to speed up the development process by getting the communication problems out of the way.

 


26
Nov 12


Written By Steve French

 

How to fix problems with WordPress taxonomy permalinks

The Problem

You are attempting to use WordPress taxonomies to create custom permalinks, and all you get are 404 errors.

To clarify, I was trying to use the taxonomies purely to maniplate custom page types and their permalinks, to create something like http://Domain.com/SummerCrops/Tomatos where SummerCrops is my custom taxonomy, and Tomatos is a page name

The Cause

WordPress is finicky about permalink syntax, specifically the difference between /%PostName%/ and /%PageName%/ – so for example a custom permalink structure of /%content%/%postname%/ would not work ,whereas  /%content%/%pagename%/ will.  Practically all online documentation refers to posts, not pages.

The Solution

Just use the custom permalink of /%content%/%pagename%/ and everything will be perfect.


20
Nov 12


Written By Steve French

 

How to hire a web company – the new book from Digital Tool Factory

'Hire Us' photo (c) 2012, Dita Margarita - license: http://creativecommons.org/licenses/by/2.0/After talking a to many potential, and actual clients lately I have decided to expand my internal checklists stock questions into an e-book called “How To  Hire A Web Company”.   After reading this book you should get from a search engine result to a successful Client-Vendor relationship much faster, and you will find the best company, and not the best salesman.  I will show you how the web company sees their clients, and show you how to move faster towards a successful website.

 

Think of the book as an operating manual for the client-vendor relationship.

 

My tentative outline

  1. Who am I – about my experience, company, and insights
  2. Who are you –   How web companies see clients.  A practical discussion of the differences between the needs of marketing and operations departments (as seen through the eyes of a web company).
  3. Personality types – and how they affect client-vendor relationships
  4. What are your needs – Broadly speaking of course – The five kinds of web sites
  5. What technology should the site use?  – The differences in what your web company cares about and what you should care about.  What you should care about, and what you should not care about
  6. Cheap and easy ways to make your web company feel loved (and get better service and a better deal) – this chapter will go into the non-intuitive things your web company will care about that probably never occurred to you.
  7. Checking references, what to look for and what to ask for
  8. Offshoring, Mobile, Apps, SEO and other hot buzzwords, what to care about, and what to watch for
  9. Checklists, checklists, checklists!
Most of the content will appear on the blog first – please stay tuned.  Any commentary will be much appreciated

20
Nov 12


Written By Steve French

 

How to fix problems with ReSharper LINQ Intellisense

The Problem

Resharper’s Intellisense, while generally awesome, does not find navigation properties in Linq statements

The Cause:

No Idea

The Solution

Switch back to Visual Studio 2012’s Intellisense, then go to Resharper > Options > Environment > General and make sure that the “Store Caches in the System Temp Folder

Close and Reopen Visual Studio 2012 and everything should be working well.


18
Oct 12


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.