Thursday, September 27, 2012

Here's how I setup a fork....

Here's how I setup a fork:

I'm still mainly using http://gitextensions.googlecode.com/. A 2 minute guide to how I work is:

      • choose fork on here to create your own copy of mvx
      • assuming you're on windows, then install http://gitextensions.googlecode.com/ selecting default options along the way
      • once installed, then choose Remotes>Putty>Generate Key to create a new SSH2 Key - save the private key somewhere and copy the public key to https://github.com/settings/ssh
  • after that... with perhaps just a little bit more fiddling through "Load Key" dialogs, then you should be able to:
    • clone your fork to a local git repository on your own hard drive
    • edit the code
    • commit changes in your fork back to you local git repository
    • push changes in your fork up to your github git repository

Tuesday, September 25, 2012

Downloading dynamic Excel files from ASP.Net MVC

Have been using the wonderful EPPlus library today - http://epplus.codeplex.com/

With it, is was really quick and easy to generate an ASP.Net MVC Controller action that allowed me to generate an excel spreadsheet with embedded data and with a chart! And with no Office or COM automation nastiness on the server :)

WooHoo :)


using System;
using System.Web.Mvc;
using Newtonsoft.Json;
using OfficeOpenXml;
using OfficeOpenXml.Drawing.Chart;
using OfficeOpenXml.Style;

namespace MyApp.Controllers
{
    public class ExportController : Controller
    {
        [Authorize]
        public ActionResult SafeDownload()
        {
            using (var package = new ExcelPackage())
            {
                package.Workbook.Worksheets.Add("Test");
                ExcelWorksheet ws = package.Workbook.Worksheets[1];
                ws.Name = "Test"; //Setting Sheet's name
                ws.Cells.Style.Font.Size = 11; //Default font size for whole sheet
                ws.Cells.Style.Font.Name = "Calibri"; //Default Font name for whole sheet

                //Merging cells and create a center heading for out table
                ws.Cells[1, 1].Value = "Sample DataTable Export"; // Heading Name
                ws.Cells[1, 1, 1, 10].Merge = true; //Merge columns start and end range
                ws.Cells[1, 1, 1, 10].Style.Font.Bold = true; //Font should be bold
                ws.Cells[1, 1, 1, 10].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // Aligmnet is center

                for (var i = 1; i < 11; i++)
                {
                    for (var j = 2; j < 45; j++)
                    {
                        var cell = ws.Cells[j, i];

                        //Setting Value in cell
                        cell.Value = i * (j - 1);
                    }
                }

                var chart = ws.Drawings.AddChart("chart1", eChartType.AreaStacked);
                //Set position and size
                chart.SetPosition(0, 630);
                chart.SetSize(800, 600);

                // Add the data series.
                var series = chart.Series.Add(ws.Cells["A2:A46"], ws.Cells["B2:B46"]);

                var memoryStream = package.GetAsByteArray();
                var fileName = string.Format("MyData-{0:yyyy-MM-dd-HH-mm-ss}.xlsx", DateTime.UtcNow);
                // mimetype from http://stackoverflow.com/questions/4212861/what-is-a-correct-mime-type-for-docx-pptx-etc
                return base.File(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName);
            }
        }
    }
}

The type or namespace name 'TargetFrameworkAttribute' does not exist...

Since installing VS2012, I've seen a few of these errors in my VS2010 VSMonoTouch (Visual Studio MonoTouch) builds:

The type or namespace name 'TargetFrameworkAttribute' does not exist in the namespace 'System.Runtime.Versioning' (are you missing an assembly reference?)   

To workaround these, I've had to resort to adding a hacky line to my project files to prevent the attribute being generated and to keep them compiling:

<!-- somewhere after the Import of Microsoft.somelanguage.targets -->
<Target Name="GenerateTargetFrameworkMonikerAttribute" />

This hack from an answer in http://stackoverflow.com/questions/3104356/in-visual-studio-2010-why-is-the-netframework-version-v4-0-assemblyattributes-c

Cross platform tasks/intents?

I got asked a question on StackOverflow... http://stackoverflow.com/questions/12564272/making-mono-cross-platform-support-for-task-intent/12564548#12564548

-

I have a application for WP7 and Android, and this application must have supporthas support for "any" connection type (WiFi, NFC, Bluetooth etc)

I have then created a layered model with MVVMCross https://github.com/slodge/MvvmCross

I have an interface for example Android Bluetooth must implement

interface IConnectionService
{
    List<TargetDevice> FindDevices();
    void Connect(TargetDevice targetDevice);
    void Disconnect();
    byte[] Read();
    void Write(byte[] command);
}

I want to be able to request the user for Bluetooth Access, but I do not want to program my UI specifically to Android Bluetooth, so the view and view-model should not know which intent is used, all this should be handled by the class implementing IConnectionService

The issue is that it should also work for Windows Phone which do not use intents, it uses tasks, so how do I make an interface that allows me to make either a Intent request or a task request without anyone knowing what type of request is needed?

----------

This is similar to the way MvvmCross allows users to make phone calls.

When using this pattern:

The ViewModel code consumes a platform independent service via an interface - e.g.:

public interface IMvxPhoneCallTask
{
    void MakePhoneCall(string name, string number);
}

consumed by

    protected void MakePhoneCall(string name, string number)
    {
        var task = this.GetService<IMvxPhoneCallTask>();
        task.MakePhoneCall(name, number);
    }

in https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.Core/ViewModels/BaseViewModel.cs

The app setup code injects the platform specific implementation for the interface - e.g:

        RegisterServiceType<IMvxPhoneCallTask, MvxPhoneCallTask>();

In WP7 - this uses the PhoneCallTask - https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/WindowsPhone/Platform/Tasks/MvxPhoneCallTask.cs

public class MvxPhoneCallTask : MvxWindowsPhoneTask, IMvxPhoneCallTask
{
    #region IMvxPhoneCallTask Members    

    public void MakePhoneCall(string name, string number)
    {
        var pct = new PhoneCallTask {DisplayName = name, PhoneNumber = number};
        DoWithInvalidOperationProtection(pct.Show);
    }

    #endregion
}

In Droid - it uses the ActionDial Intent - https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/Android/Platform/Tasks/MvxPhoneCallTask.cs

public class MvxPhoneCallTask : MvxAndroidTask, IMvxPhoneCallTask
{
    #region IMvxPhoneCallTask Members

    public void MakePhoneCall(string name, string number)
    {
        var phoneNumber = PhoneNumberUtils.FormatNumber(number);
        var newIntent = new Intent(Intent.ActionDial, Uri.Parse("tel:" + phoneNumber));
        StartActivity(newIntent);
    }


    #endregion
}

In Touch - it just uses Urls - https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/Touch/Platform/Tasks/MvxPhoneCallTask.cs

public class MvxPhoneCallTask : MvxTouchTask, IMvxPhoneCallTask
{
    #region IMvxPhoneCallTask Members

    public void MakePhoneCall(string name, string number)
    {
        var url = new NSUrl("tel:" + number);
        DoUrlOpen(url);
    }

    #endregion
}


In the vnext version of mvvmcross, this approach is further formalized using plugins - see a brief introduction to these in the 'going portable' presentation at http://slodge.blogspot.co.uk/2012/06/mvvm-mvvmcross-monodroid-monotouch-wp7.html

For example, in vNext the phone call code above is contained in the PhoneCall plugin - https://github.com/slodge/MvvmCross/tree/vnext/Cirrious/Plugins/PhoneCall


One of the challenges of your task may be the word "any" - differences in platform implementation might make it hard to define a cross-platform interface that works across all the platforms for any one of NFC, Bluetooth, etc, let alone all of them.

Wednesday, September 19, 2012

Knockout - NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7

If you're doing any konockout.js data-bind work in Chrome and you see the error:

NO_MODIFICATION_ALLOWED_ERR: DOM 
Exception 7

Then check that you haven't done:

<input data-bind='text: property' />

when you meant to do:

<input data-bind='value: property' />

Doh!

Saturday, September 15, 2012

MvvmCross vNext - portable class libraries - back on track - 4 complete samples building and running...

UPDATE - 19 Dec 2012 - LATEST INFO IS ON http://slodge.blogspot.com/2012/12/cross-platform-winrt-monodroid.html

----------

Three months on from hitting some severe stumbling blocks in the Portable Library support within MonoTouch, I'm pleased to say that the last two weeks have seen huge leaps forwards in the vNext version.

Right now, the Portable Library layer is now running well under all of WP7, MonoDroid and MonoTouch :)

There are still some tooling issues... but overall, this is now working really well - so I'd like to invite users to have a play with the new projects!

Although there is some significant tooling hackery required to get portable library mvvm working, once you've done the initial hackery, then this shouldn't affect your existing workspaces and you should then be able to build and run portable versions of:
  • BestSellers (WP7, Droid, Touch)
  • CustomerManagement (WP7, Droid, Touch)
  • SimpleBinding (Droid, Touch)
  • Tutorial (WP7, Droid, Touch)
... and you might be able to run even more... :)

---

And the benefits for doing this are....

1. Simpler project structures:

2. Automated cross-platform refactoring - e.g. using resharper

3. Simpler porting to new platforms

4. A new plugin structure which makes mvvmcross lighter (smaller executables), which provides developers with more choice and which makes contributing new IoC modules more straightforward - now anyone can provide and consume new "plugins"

---

If you are interested in all this, then here's the instructions:

----

To get the source...

- you will need to download from the vNext branch on https://github.com/slodge/MvvmCross/tree/vnext

- the only working solution in this download is the MvvmCross_All.sln file - which contains all the projects - portable and platform specific.

---

To get your Windows development environment working with this portable branch:

- assuming you start from Visual Studio 2010, Windows Phone SDK 7.5, MonoDroid on a PC

1. Install the Portable Library tools for the VS2010 - http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981

2. Install VisualStudio 2012 on the same PC... this updates the Portable Library tools to include v2 PCL support (which includes some MVVM/DataBinding helpers)


1 and 2. Install the latest PCL plugin from http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981 - thanks to @dsplaisted for the update.

3. Install VSMonoTouch - https://github.com/follesoe/VSMonoTouch
- be sure to also copy across the v1.0 MonoTouch framework assemblies in the instructions there

4. Follow instructions based on http://jpobst.blogspot.co.uk/2012/04/mono-for-android-portable-libraries-in.html
- these say to install a file called "MonoAndroid,Version=v1.6+.xml" in "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\SupportedFrameworks" with content:



BUT PLEASE NOTE - the target directory is Profile104

5. Install a similar file called "VSMonoTouch,Version=v1.0+.xml" in the same directory and for its content use:


(Note: this file is even hackier than the MonoDroid one - it points the portable tools at Full .Net v1.0 in line with what the VSMonoTouch plugin does!)

After you have done this.... then you should be able to load and run the WP7 and Droid samples within MvvmCross_All.sln 

... and you should also be able to build MonoTouch solutions too. And you should be able to refactor across all 3 platforms!

---

For the Mac:

Assuming you are starting with MonoDevelop with MonoTouch installed on a Mac

1. Follow the instructions in http://stackoverflow.com/questions/12041290/monodevelop-is-it-possible-to-switch-pcls-compiler/12062589#12062589

This is only a temporary hack - it's a workaround for: https://bugzilla.xamarin.com/show_bug.cgi?id=6649

2. Before opening the MvvmCross_All.sln solution, you need to run a search and replace in "*.csproj" files - this search and replace will:
- search for : <targetframeworkprofile>Profile104</targetframeworkprofile>
- replace with : <targetframeworkprofile>Profile1</targetframeworkprofile>

This is only a temporary hack - it's a workaround for: https://bugzilla.xamarin.com/show_bug.cgi?id=7173
3. Sometimes (if I've checked in the wrong .sln file version) then before opening the MvvmCross_All.sln solution, you may need to change the first line from

Microsoft Visual Studio Solution File, Format Version 12.00
to

Microsoft Visual Studio Solution File, Format Version 11.00
This is only a temporary hack - it's a workaround for: https://bugzilla.xamarin.com/show_bug.cgi?id=4919


After you've done these 3 steps.... then you should be able to:
- open the solution
- switch to the Debug|iPhoneSimulator branch
- run the BestSellers, CustomerManagement, SimpleDialogBinding, and Tutorial projects - other projects currently still have unresolved problems.

---

Further Notes....

- I'll be trying to get this branch fully working in the next month (that's my aim!)
- My intention is to switch all future MvvmCross development across to this portable approach 
- If this happens, then I expect the existing non-portable tree will only get bug fixes - not new features.
- The exact timing of any switchover may depend a bit on tool changes from both Microsoft and Xamarin (and it may depend on clashes in my work and leisure time too!)
- There are a number of class and namespace breaking changes in the vNext (portable libraries) branch - most notably:
-- all Cirrious.MvvmCross.Android namespaces have moved to Cirrious.MvvmCross.Droid - this is to avoid name clashing issues with the global::Android namespace.
-- FirePropertyChanged has become RaisePropertyChanged - as this seems to be the more normal method name
- There are a number of fixes on the master branch which are not yet on the vnext branch
- There are a number of changes still to make in the vnext branch - e.g. IMvxServiceConsumer might switch to a simpler IMvxServiceConsumer - following a request/suggestion from @dsplaisted
- There are several dead files and directories left in the tree at present - mainly left over after refactoring - these will get tidied away soon.
- I've not yet tried much WinRT, console or PSS development on the vnext branch - so don't be surprised if those projects don't build or work!
- If anyone wants to help - with code, documentation, tools, samples or suggestions, then you are very welcome - just get in touch.
- As ever, bugs to GitHub issues please, and questions to StackOverflow :)

Wednesday, September 05, 2012

Bootstrap + ASP.Net MVC - [Bootstrap] "object has no method on" error

Just a quickie

If you add Bootstrap to an ASP.Net MVC project and then see a few "object [Object] has no method on" errors which cause $.ready to fail, then.... check your jquery version 

Shifting to:
    <script src="http://code.jquery.com/jquery-latest.js"></script>  
solved it for me :)
  

A helper on getting MonoTouch building Portable Library code

I've not had a lot of time to play with this yet, but in the last 24 hours I've managed to get a lot more of the Mvx vNext portable code building using the hint:

You may be able to fix this by editing the file /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild/Microsoft/Portable/v4.0/Microsoft.Portable.CSharp.targets, finding the PropertyGroup that sets
MonoTouchAnd to it, adding the lines:
smcs/Developer/MonoTouch/usr/bin

Found this hint via http://stackoverflow.com/questions/12041290/monodevelop-is-it-possible-to-switch-pcls-compiler/12062589#12062589 and https://bugzilla.xamarin.com/show_bug.cgi?id=5329 - wish I'd found it months ago (note to self - don't give up so easy next time!)

For Mac newbies, note that this file is in the root from the hard disk (not from the user) and that you will need to edit file (and folder?) permissions in order to edit it - you can do this from finder using 'more info'.


Tuesday, September 04, 2012

A cross platform dropbox client written in mvvmcross

Rune Grimstad (@runegri) has published this sample.

https://github.com/runegri/CrossBox

More to follow when I've played with it :)

Sunday, September 02, 2012

Monocross now moved to github

Just discovered that monocross - the cross platform library that I started mvvmcross from - is now on GitHub

If you prefer mvc to mvvm, or if you need webkit support, then follow it at: https://github.com/ToeJam/MonoCross

Thursday, August 30, 2012

Some useful mvvmcross links

A great 3 part tutorial - in French - really good walk through:

http://www.e-naxos.com/Blog/post/2012/08/26/Strategie-de-developpement-Cross-Platform–Partie-3.aspx-3.aspx

Mono for Android data binding for spinner controls

http://blog.ostebaronen.dk/2012/08/mvvmcross-binding-spinner.html

An enterprise app using MVX:

http://www.aviva.co.uk/ratemydrive/

Featured in: http://www.bbc.co.uk/iplayer/episode/b01m9396/Click_18_08_201/ - ffwd to 9 minutes in

A picker based element for monotouch.dialog:

https://gist.github.com/3552565


Monday, June 25, 2012

I wonder... where did the "2 days of developer stuff" disappear from the Windows Phone summit?

Early May:


Early June:


June 20th arrives:
"Welcome to the Windows Phone 8 Platform Preview" - a press conference lasting 2 hours and sharing very limited developer info.

Saturday, June 23, 2012

Thursday, June 14, 2012

MvvmCross on Channel9

My friend Daniel Plaisted at Microsoft has just posted this video on Channel 9 - it includes TwitterSearch from MvvmCross vNext.



In particular he shows the code sharing in MvvmCross across Metro, WP7, MonoTouch and MonoDroid:




Portable libraries are the future - love em!

Changing Navigation Bar Button colour (color) in MonoTouch and MvvmCross



This was my answer:

At the end of this, I was able to add some bar button changes like:
        var leftButton = new UIBarButtonItem("FooBar", UIBarButtonItemStyle.Bordered, null);
        leftButton.TintColor = UIColor.Green;
        NavigationItem.SetLeftBarButtonItem(leftButton, false);
        NavigationItem.RightBarButtonItem.TintColor = UIColor.Red;
Which resulted in:
four
Alternatively, by placing code in the WelcomeView:
        var leftButton = new UIBarButtonItem("FooBar", UIBarButtonItemStyle.Bordered, null);
        leftButton.TintColor = UIColor.Green;
        NavigationItem.BackBarButton = leftButton;
Then I succeed in achieving:
three
Alternatively, by using code like:
        UIBarButtonItem.AppearanceWhenContainedIn(typeof(UINavigationBar)).TintColor = UIColor.Blue;
Then this enabled me to customise all the navigation bar buttons like:
two

At one point, I also managed to achieve:
one
... but sadly I've genuinely no idea which code combo gave me that! If your problem is with back buttons in particular, then I think you will need to dig around other questions and/or post some code and hope someone can help - there's lots of posts about how to do this, but I can't quite figure out what they all mean for MonoTouch - e.g. Separate title in NavigationBar and navigation buttons

Thursday, June 07, 2012

How to bind to a UIViewController instance Property in Monotouch MvvmCross

From http://stackoverflow.com/questions/10929779/monotouch-mvvmcross-binding-to-instance-variables




From reading your question, I think what you are saying is that the View itself has a field of type string...
Your code:
this.AddBindings(
     new Dictionary()
     {
          { StringTemp, "{'Text':{'Path':'AboutText'}}" },
     });
is trying to bind the property Text on the object referred to by StringTemp to whatever is inAboutText on the ViewModel.

To set the StringTemp string itself you should be able to bind to it using something like:
 this.AddBindings(
      new Dictionary()
      {
           { this, "{'StringTemp':{'Path':'AboutText'}}" },
      });

Just to explain the parts in: { this, "{'StringTemp':{'Path':'AboutText'}}" }, these can be thought of as { TargetObject, "{'TargetPropertyName':{'Path':'SourcePropertyName'}}" } where:
  • TargetObject (this) is the object you are aiming to set property values on
  • TargetPropertyName (StringTemp) is the name property that you are aiming to set
  • SourcePropertyName (AboutText) is the name of the property that will be the source of the value
Note that Mvx uses Properties - not fields - so private string StringTemp {get;set;} is bindable, but private string StringTemp; is not.

You could also do two-way binding for this string reference if you wanted to... but you would need to setup some custom binding information to do so - there would need to be some event fired and captured in order to update the ViewModel (I'll leave that for another day!)

For situations where direct binding isn't what you are looking for, then you can always subscribe to PropertyChanged and handle the notifications in more verbose code... e.g.:
ViewModel.PropertyChanged += (s,e) => 
{
    if (e.PropertyName == "AboutText")
    {
         // do something complicated here with the new ViewModel.AboutText value
    }
};
...but I personally tend to avoid this type of code where I can...

Saturday, June 02, 2012

Mvvm - MvvmCross - MonoDroid, MonoTouch, Wp7 and WinRT - going portable

A presentation in progress about the changes for using Portable Class Libraries (and Portable Library Projects) within MvvmCross for MonoDroid, MonoTouch and WP7

On SpeakerDeck:

https://speakerdeck.com/u/cirrious/p/mvvmcross-going-portable

On SlideShare:

Tuesday, May 29, 2012

Please put some time and love into the WP7 marketplace submission process

I love my Windows Phone

Seriously

I love it

And I love building apps for it too.

But in recent months, I've been finding the Microsoft AppHub slower and slower to use

  • certification which used to take 2-3 days now takes 7+ days
  • post-certification app publishing which used to take an hour, now takes a day
  • beta app publishing which used to take 2-3 hours now takes 2+ days
  • the support on my recent "stuck" app submission has been horrible - the app is currently on day 15 of waiting for testing and the support responses from Microsoft have basically just told me to wait, even though I told them the need for the app was urgent - it was for a conference last weekend :(

The few emails I've received from AppHub support seem to indicate that either Microsoft doesn't care, or that the team simply can't work in an agile way - their automated process has control and when it breaks, then their users don't seem to know how to detect it's broken or how to fix it.

Perhaps also, the Marketplace team are now too busy preparing for Win8 to remember WP7?

From the looks of a straw poll on Twitter today (see some of the comments below), it looks like I'm not alone in noticing the growing and slowing pains.

But I hold out hope that Microsoft care... In fact, I hope and believe that they care a lot...

Dear Microsoft. Please put some time and love into the marketplace. Please stop aiming to match Apple's experience - that's not an experience developers and app publishers love.

Thanks

Stuart


seems the general opinon about marketplace and the certification process is not good. 1 person even said "worse than Apple" :(
 Two weeks ago one of our apps was submitted, but got stuck before being signed, thereby stopping the process.
 Yes, In Firefox, trying to submit an app kicks me into a loop. Forcing me in to *ugh!* Internet explorer.
  I've launched one app and apart from not being able to delete a beta app, the process was find. I also release updates
 yes. update for current app submitted 7 days ago, still waiting for certification
 Haven't tried recently but, in the past, I couldn't submit using any non-IE browsers.
  Yes - beta apps now take 2 days, full app publishing 9 days and my current app is on day 14 "certified" + support no help
 yep, I've even emailed support but no feedback on what's up. My new app taken more than 1.5 weeks to certify, still waiting
 Not recently, but I've certainly seen tweets about it. Maybe I've been lucky and submitted off-peak times.
RT  quick straw poll: have you had issues with the marketplace and/or apphub submission? 
quick straw poll: have you had issues with the  marketplace and/or apphub submission?