Archive

Author Archive

MonoMobile.MVVM, Round 2

June 18th, 2011 3 comments

So, from part 1 with MonoMobile.MVVM we can add some controls to a screen. That has limited usefulness since rarely do you need just one page a few entry controls for any apps, even data driven apps.

Now let’s make something that’s almost useful. We won’t persist data right now, but that can be tacked on later.

We’ll have to start with a new View.

public class NotesView : View
{
	public NotesView ()
	{
		var dataModel = new NotesDataModel ();
		Notes = new ObservableCollection<NoteViewModel> ();
		foreach (var item in dataModel.Load ())
			Notes.Add (item);
	}
	[List(ViewType = typeof(NoteView))]
	public ObservableCollection<NoteViewModel> Notes { get; set; }
}

We apply the [List] attribute so that this property is the basis for this view.The constructor loads up a DataModel to generate some generic data. I wouldn’t worry about that part right now, it will change when we build in persistance later.

Just for completeness, here’s my DataModel


public class NotesDataModel
{
	public IEnumerable<NoteViewModel> Load ()
	{
		return new List<NoteViewModel> {
				new NoteViewModel { Name = "One" },
				new NoteViewModel { Name = "Two" },
				new NoteViewModel { Name = "Three" },
				new NoteViewModel { Name = "Four" },
				new NoteViewModel { Name = "Five" },
				new NoteViewModel { Name = "Six" },
				new NoteViewModel { Name = "Seven" },
				new NoteViewModel { Name = "Eight" },
				new NoteViewModel { Name = "Nine" },
				new NoteViewModel { Name = "Ten" },
				new NoteViewModel { Name = "Eleven" },
				new NoteViewModel { Name = "Dozen" }
			};
	}
}

So we need the NoteViewModel since that’s what we’re binding to the front end…

public class NoteViewModel : ViewModel
{
	public string Name {
		get { return Get (() => Name); }
		set { Set (() => Name, value); }
	}
	public string Text {
		get { return Get (() => Text); }
		set { Set (() => Text, value); }
	}

	public override string ToString ()
	{
		return Name;
	}
}

Note: See Robert’s comment below, but the Get(() => ...) and Set(() => ...) blocks are helpers for INotifyPropertyChanged implementations.

The ToString() override is important. This is what is used to define what appears in the list view for each item. Play around with the ToString() if you want to have some fun! The Get and Set overrides supports notifications between data bindings.

Last thing we need to add is the view referenced to display the actual note details

public class NoteView : View
{
	[Section]
	[Entry]
	public string Name { get; set; }

	[Section("Note")]
	[Entry]
	[Multiline]
	[Caption("")]
	public string Text { get; set; }
}

Then from our last example, you’ll need to change the starting view.

public class Application : MonoMobileApplication
{
	public static new void Main (string[] args)
	{
		Run ("Sample", typeof(NotesView), args);
	}
}

This should get you to a working example. Nothing amazing. Next time we can consider persistance!

Categories: .NET, Mobile Tags: , , ,

Parsing Balsamiq Files

June 15th, 2011 Comments off

I had the joy of building out some stuff from Balsamiq. This was the first prototype I developed, around making sure a control hierarchy could be generated even though Balsamiq just considers everything as layers. It’s not amazing, but it’s a start if someone wants to understand the data from one of those files.

You get a collection of PageObjectHierarchys back from the parser in which you can do whatever you want. The collection should have all child objects as children and not part of the base collection. Have fun with it!

Categories: .NET Tags: , ,

MonoMobile.MVVM, Round 1

June 11th, 2011 2 comments

Robert Kozak has started MonoMobile.MVVM, a MVVM framework for Mono on iOS. What this provides, is a great and easy way to work with data-driven applications on the iOS platform. I’ll walk through setting up a simple application with a few elements on it.

We’ll start with MonoDevelop, on the Mac.

When the project loads, you’ll see a couple .xib files in the project. These you can safely ignore for now. Select the project, right click, and goto options. Here you’ll see an option to set the starter .xib file for the application. Go ahead and remove that.

Next we need to add a reference to MonoMobile.MVVM. If you already have downloaded a built the project, add a reference to the project, to the location of the built MonoMoble.MVVM.dll.

Now, in Main.cs, you’ll find a small block of code.

public class Application
{
	static void Main (string[] args)
	{
		UIApplication.Main (args);
	}
}

Now replace it with the following below. Make sure you add a using MonoMobile.MVVM; so the references work.

public class Application : MonoMobileApplication
{
	public static new void Main (string[] args)
	{
		Run ("Sample", typeof(BasicView), args);
	}
}

public class BasicView : View
{
	public bool TestOnOff { get; set; }

	[Button]
	public void PressDown()
	{
	}
}

Make sure it builds, then we have a working iPhone application.

Now how is the UI built you might ask? Why from BasicView class that we pasted in. It has two elements, a boolean value and a method we applied the button attribute to. So those are the elements that appeared in the UI when we ran it. The UI is generated based upon the data elements in this View Model.

Well, that’s interesting and all, but there’s not a lot going on there. What else can we do? Lots! (Check out the ReadMe in the project for some more ideas)…

public class BasicView : View
{
	public bool TestOnOff { get; set; }

	[Caption("Why?")]
	[Entry]
	public string Why { get; set; }

	[Section("Actions")]
	[Button]
	public void PressDown()
	{
	}

	[NavbarButton]
	public void Done()
	{
	}
}

Categories: .NET, Mobile Tags: , , ,

Cashbox for Mobile

May 24th, 2011 Comments off

Cashbox now has a version that runs in WP7. This uses Isolated Storage instead of a file stream for storage and a slightly different JSON serializer that can run without codegen. This approach should work with other mobile platforms using mono once Xamarin has new .NET for platform ready. Setting up your app to use a DocumentSession is really easy.

The API should be the same as the regular build of Cashbox.

Download for fun today! Post any issues on github.

Categories: .NET Tags: , , , , ,

Cashbox v1.0

March 18th, 2011 Comments off

Cashbox 1.0 is ready! For all your document store needs. I think most of the important things are covered nicely in the comments of the code sample below. Know that every 100 writes (store/delete) a temp file is created to compact space. Currently this isn’t configurable but will likely be in the future. Get Cashbox from the “Downloads” button!

Categories: .NET Tags: , , ,

Announcing Topshelf 2.2

February 28th, 2011 3 comments

We have a new version of Topshelf ready for your consumption. So let’s see what’s new!

Get it, from codebetter’s teamcity or from github.

Issues? Let us know or reach out to us on the mailing list.

Web based dashboard
You can access a web-based dashboard showing the services that are running inside the host. This feature is still in the experimental stage and might be subject to change as we finish flushing it out.

Post Install/Uninstall custom actions
Thanks to Eric Lee for this implementation, you can configuration actions for things such as installing performance counters.

Service interactions
myservice start and myservice stop now work, as well as myservice install start

Backend upgrade
The backend and configuration code got an upgrade. We will have a new configuration DSL with 3.0, it should appear to work as is now but much of the new configuration API is accessible.

Windows service recovery options
We now show configuration for service recovery options but the calls to the win32 APIs aren’t working for us. If someone has some experience in this area and wants to fix it, please feel welcomed to do so.

Bug fixes, etc

  • Installation without descriptions no longer fail
  • username/password accepted on command line
  • support for non-standard services folder in shelving
  • normal service hosting no longer spins up WCF pipes
  • unnamed WCF behaviors no longer break Topshelf
  • --sudo option to show UAC if no admin when running
Categories: .NET Tags: , ,

Announcing a Simple NoSQL/Document Store: Cashbox

January 16th, 2011 Comments off

I have been unable to find a completely managed, zero config document store. So I wrote one…

The use case for this is…

  • data only needed in a single process
  • want zero configuration
  • limited amount of data, millions of records will likely become slow
  • want all managed code

If you need something with higher performance, multiple clients, or shared across many processes I would stick with other document stores out there. However, if you needs are simple, here you go. I am releasing this as a v0.9, “works on my box”/RC version. If someone has a need for it, please try it and provide feedback on the Cashbox Github page. Just drop in an issue.

using (Cashbox.DocumentSession session =
               Cashbox.DocumentSessionFactory.Create(storeFilename))
{
	for (int i = 0; i <100; i++)
	{
		string key = i.ToString();
		session.Store<TestDocument>(key, new TestDocument(i));
	} // inserted some records, with a simple numeric key

	session.Delete<TestDocument>(55.ToString()); // delete a record

	session.Retrieve<TestDocument>(55.ToString()); // should be null

	session.Retrieve<TestDocument>(10).IntValue; // should be 10
}
Categories: .NET Tags: , , ,

Topshelf 2.1

November 11th, 2010 Comments off

Topshelf 2.1 has been released. See the github page and hit the downloads button to get a release. This is mostly a bug fix release and I would suggest all users upgrade.

General

  • better state handling
  • better logging an exception handling [including issue #15]
  • corrected bug in message handling
  • fixed handling of instance command line argument [issue #13, thanks Ramon]

Shelving

  • host, by default, will not crash when a unhandled exception happens
  • host has an icon
  • log4net should unload when the app domain does

Some things I think should be addressed shortly…

  • ignore folders starting with underscore in shelving
  • auto discovery of bootstrapper in shelving

Please, submit any bugs on the github issues page or hit us up on the mailing list.

Categories: .NET Tags: , ,

MassTransit Distributor (Load Balancing)

August 25th, 2010 Comments off

MassTransit has a distributor built in now (actually for some time…). I’ll try to explain what it does and how to use it.

What is the distributor? It provides the ability to load balancing across multiple endpoints for a given message.

Distributor Setup

For setting up the distributor, when doing the service bus configuration, call UseDisttributorFor(IEndpointFactory endpointFactory) on IServiceBusConfigurator. An instance of the endpoint factory is required.

For setting up the worker(s), when doing the service bus configuration, call ImplementDistributorWorker(Action consumeAction) on IServiceBusConfigurator.

Default IWorkerSelectionStrategy Implementation

The default worker selection strategy simple looks at the current message count in queue vs. the message count limits. It selects the worker with the smallest number of messages pending or in progress.

The data used to identify which worker is busy might be out of date. There is additional message traffic to keep this data in sync and it can fall behind when the system is under load.

Custom IWorkerSelectionStrategy

For setting up the distributor, when doing the service bus configuration, call UseDisttributorFor(IEndpointFactory endpointFactory, IWorkerSelectionStrategy workerSelectionStrategy) on IServiceBusConfigurator.

This requires a custom implementation of the IWorkerSelectionStrategy interface. There are two methods to implement.

  • HasAvaiableWorker - Using the list of candidate workers, indicates if one is available
  • SelectWorker - Using the list of candidate workers, find the best candidate available

Sample

Okay, so I know you’re now asking if I’ll get to any real code. There’s a sample in the MT solution Grid.Distributor that shows the basics of using the Distributor.

There are two parts, the activator (who sends commands) and the workers (who completes the commands). You can spin up multiple workers to work on the commands.

Topshelf 2.0 Released!

August 19th, 2010 Comments off

Topshelf 2.0 was released today! You can get it at Topshelf’s github.

2.0.1 was also released today! A bugfix release…

  • Shelving: renamed events no longer cause exceptions
  • Shelving: less likely for a service to start up then re-start again right away

There are a couple known issues though…

  • Some log4net log events seem to be squelched. This might be related to ilmerging we started doing for releases. When it’s run from source I don’t see this behavior but I am looking into it.
  • When shutting down you might see an exception about a pipe not being open. There are a lot of threads ‘doing’ stuff to keep everything going right. When shutting down it seems possible for them to not shut down in the right order. I have spent some time trying to pin it down exactly and I haven’t gotten it yet. I haven’t seen any negative side effects from it yet though.

Thanks to everyone who’s tried it out so far!

Categories: .NET Tags: , ,