Jquery user interface
Organising MVC Projects: NO code at all in UI
Monday, 23 November 2009
Friday, 20 November 2009
Wednesday, 18 November 2009
ASP.net Problems
- Starting IIS on Vista for the first time Skype was found to be using port 8080 so stopped Skype and restarted iis without a problem.
- Error message CS0016: Could not write to output file 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\etc etc .dll' -- 'Access is denied. Add full permissions for 'Network Service' & 'YourComputerName\IIS_IUSERS to:
- C:\Windows\Temp
- C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
- ASP.net local iis problem when trying to run locally
Error message not very helpfull, eventually fixed by removing directives in the Web.Config for
ScriptModule
WebExtensions
Not 100% sure why though they are probably in the Machine.config file and therefore created a duplicate which was only detected when running outside debug environment
Tuesday, 17 November 2009
Friday, 13 November 2009
C# Constructors
For some reason I always forget how to call one constructor from another. Of course now I've written it down I'll probably never need to refer to it again but anyway:
public Car(string model, int noWheels){}
Car(string model) : this(model,4){}
public Car(string model, int noWheels){}
Car(string model) : this(model,4){}
Thursday, 5 November 2009
WPF: NUnit Testing when using the WPF Dispatcher
I have encoutered problems when using NUnit to test a ViewModel which has ThreadSafeObservableCollection. The thread safety comes about through using the Dispatcher and when you call Dispatcher.BeginInvoke, you are instructing the dispatcher to run the delegates on its thread when the thread is idle.
When running unit tests, the main thread will never be idle. It will run all of the tests then terminate.
To overcome this I have written a trap which looks for the NUnit Thread Name. A true result and the ThreadSafeCollection proceeds without using the Dispatcher.
private bool CheckDispatcherAccess()
{
if (_dispatcher.Thread.Name == "TestRunnerThread")
{
return true;
}
return _dispatcher.CheckAccess();
}
...
Other references to the Dispatcher issue when using NUnit
Using the WPF Dispatcher in NUnit Tests
When running unit tests, the main thread will never be idle. It will run all of the tests then terminate.
To overcome this I have written a trap which looks for the NUnit Thread Name. A true result and the ThreadSafeCollection proceeds without using the Dispatcher.
private bool CheckDispatcherAccess()
{
if (_dispatcher.Thread.Name == "TestRunnerThread")
{
return true;
}
return _dispatcher.CheckAccess();
}
...
Other references to the Dispatcher issue when using NUnit
Using the WPF Dispatcher in NUnit Tests
Monday, 2 November 2009
LINQ: Update Data
var product = (from p in dataContext.Products
where p.ProductID == 1
select p).Single();
product.Name = "New Product Name";
dataContext.SubmitChanges();
Using LINQ with MVC
The following code using the Attach method on the Linq entity will throw an exception as per Stephen Walther's excellent article Stephen Walther blog archive. This is a concurrency issue and can be remedied in 2 ways as per Stephen's article.
public ActionResult Edit(DxDataBook editedPart)
{
try
{
var originalPart = (from p in dc.DxDataBooks
where p.P_D_Num == editedPart.P_D_Num
select p).First();
if (!ModelState.IsValid)
{
return View(originalPart);
}
dc.DxDataBooks.Attach(editedPart,true);
dc.SubmitChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
where p.ProductID == 1
select p).Single();
product.Name = "New Product Name";
dataContext.SubmitChanges();
Using LINQ with MVC
The following code using the Attach method on the Linq entity will throw an exception as per Stephen Walther's excellent article Stephen Walther blog archive. This is a concurrency issue and can be remedied in 2 ways as per Stephen's article.
public ActionResult Edit(DxDataBook editedPart)
{
try
{
var originalPart = (from p in dc.DxDataBooks
where p.P_D_Num == editedPart.P_D_Num
select p).First();
if (!ModelState.IsValid)
{
return View(originalPart);
}
dc.DxDataBooks.Attach(editedPart,true);
dc.SubmitChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
Subscribe to:
Posts (Atom)