Saturday, January 25, 2014

Type-safe ViewModel to ViewModel navigation in MvvmCross


In MvvmCross you can navigate between view-model's as described in the Wiki:
https://github.com/MvvmCross/MvvmCross/wiki/ViewModel--to-ViewModel-navigation

It's good however to use a simple type-safety mechanism.
Suppose we have a ProductViewModel which expects two arguments for initialization:

public class ProductViewModel : MvxViewModel
{
     public void Init(int productId, int clientId)
     {
          ....
     }
}

With a type-safe mechanism, instead of writing:

ShowViewModel<ProductViewModel>(new { productId = pid, clientId = cid });

we can write:

NavigationHelper.ShowProduct(pid, cid);

where NavigationHelper is a simple utility class:

using Cirrious.CrossCore;
using Cirrious.MvvmCross.ViewModels;
using Cirrious.MvvmCross.Views;
using MyApp.Core.ViewModels;
using Cirrious.MvvmCross.Platform;

namespace MyApp.Core.Common
{
    public static class NavigationHelper
    {
        public static void ShowProduct(int productId, int clientId)
        {
            ShowViewModel<ProductViewModel>(new { productId = productId, clientId = clientId });
        }

        static void ShowViewModel<T>(object parameter) where T : IMvxViewModel
        {
            var viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();
            var request = MvxViewModelRequest.GetDefaultRequest(typeof(T));
            request.ParameterValues = ((object)parameter).ToSimplePropertyDictionary();
            viewDispatcher.ShowViewModel(request);
        }
    }
}

using Cirrious.MvvmCross.Platform; namespace statement is important because it contains the ToSimplePropertyDictionary() extension method implemented by MvvmCross.

Furthermore, instead of using the NavigationHelper class, we can move the ShowViewModel method to a ViewModelBase class:

public class ViewModelBase : MvxViewModel
{
       protected static void ShowViewModel<T>(dynamic parameter) where T : IMvxViewModel        
       {            
           var viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();            
           var request = MvxViewModelRequest.GetDefaultRequest(typeof(T));            
           request.ParameterValues = ((object)parameter).ToSimplePropertyDictionary();            
           viewDispatcher.ShowViewModel(request);        
       }
}

public class ProductViewModel : ViewModelBase
{
    public static Show(int productId, int clientId)
    {
        ShowViewModel<ProductViewModel>(new { productId = productId, clientId = clientId });
    }

    public void Init(int productId, int clientId)
    {
        ...
    }
}

and we can now write:

ProductViewModel.Show(pid, cid);

Having the Show method near the Init method in the ViewModel class, makes it a bit more easier to maintain the parameters.

Saturday, January 18, 2014

ASP.NET errors

 

#1. There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined

Check .NET Framework version for app pool.

Projects developed in (2.0,3.0,3.5) should run under an Application Pool with .NET FRAMEWORK VERSION v2.0.50727 

Projects developed in 4.0 should run under an Application Pool with .NET FRAMEWORK VERSION v4.0.30319

#2. Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Make sure that "Enable 32 - Bit Applications" is set to false or true for the app pool, depending on System.Data.SQLite.dll

System.Data.SQLite.dll is a mixed assembly, i.e. it contains both managed code and native code. Therefore a particular System.Data.SQLite.dll is either x86 or x64, but never both.

#3. HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Requested URL
   http://localdev.site.com/Webservices/UserProviderService.svc

You need to run this: http://enginecore.blogspot.ro/2013/06/svc-handling-in-iis.html

Thursday, January 16, 2014

Invalid markup in XAML in Visual Studio 2013


If you get this error in designer when there’s clearly no error in your XAML:
- close all files open in Visual Studio
- close Visual Studio
- delete the .suo file near the .sln
- delete bin and obj folders

if still doesn't work you can try to delete all directories from:
%LocalAppData%\Microsoft\VisualStudio\12.0\Designer\ShadowCache

More info:
http://stackoverflow.com/questions/12871358/visual-studio-2012-xaml-designer-invalid-markup
http://forums.xamarin.com/discussion/10284/xamarin-new-pcls-w8-wp8-net45-xamarin-ios-xamarin-droid-plus-new-microsoft-bcl-terribly-broken

Monday, January 13, 2014

Installing Windows 8 and customization

1. Use Windows 7 USB/DVD download tool to create a Windows bootable USB drive

2. If you want to create a Windows x64 bootable image, you need to run the Windows 7 USB/DVD download tool from a x64 Windows computer.

3. During the Windows 8 installation if you encounter error while installing \ copying files, and it’s at the same point (same percent), then the USB image is corrupted.

4. If doing Android dev. with Intel x86 Emulator Accelerator (HAXM), you must disable Hyper V in Windows.
disable: bcdedit /set hypervisorlaunchtype off
re-enable (restart): bcdedit /set hypervisorlaunchtype auto
5. For Samsung 840 Pro SSD: Install Samsung Magician
     http://www.samsung.com/global/business/semiconductor/samsungssd/downloads.html
It will start on each Windows start but it’s annoying it shows UAC. One solution is to remove it from startup

C:\users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
6. There are a number of SSD optimizations to be done
http://www.thessdreview.com/ssd-guides/optimization-guides/the-ssd-optimization-guide-ultimate-windows-8-edition/

7. Disable Windows Narrator. it’s annoying it starts anytime Windows Key + Enter are pressed.
http://enginecore.blogspot.ro/2013/09/disable-windows-narator.html
8. Make Word to minimize to tray: right click on tray icon and choose “Hide when minimized
9. Automatically user login
1. run netplwiz 
2. uncheck the “Users must enter a user name and password to use this computer”, click Apply
3. enter username and password
http://www.howtogeek.com/112919/how-to-make-your-windows-8-computer-logon-automatically/
10. Force Visual Studio always run as admin
http://stackoverflow.com/questions/12257110/can-you-force-visual-studio-to-always-run-as-an-administrator-in-windows-8

In Windows 8, you have to right-click devenv.exe and select "Troubleshoot compatibility".
  1. select "Troubleshoot program"
  2. check "The program requires additional permissions"
  3. click "Next", click "Test the program..."
  4. wait for the program to launch
  5. click "Next"
  6. select "Yes, save these settings for this program"
  7. click "Close"
11. On Windows 8, make sure you get the latest Intel x86 Emulator Accelerator (HAXM), At this moment, the one from Android SDK manager is buggy on Windows 8. 
http://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager/