Caliburn.Micro IEventAggregator Publish method missing an overload - caliburn.micro

I'm working through some tutorials online learning Caliburn.Micro for the first time. Some of the tutorials are using the older 1.3.0 version, I'm using the newer 2.0.0.6 version which was the latest Nuget package which is likely the source of this discrepancy:
When trying to publish the following message:
public void Red()
{
_events.Publish(new ColorEvent(new SolidColorBrush(Colors.Red)));
}
The compiler throws an error saying that the overload wasn't found. The only overload for Publish that is available has the following signature:
void Publish(object message, Action marshal)
I got this to work by using the background worker thread method shown below but in my case it seems like overkill. Was the single parameter overload really removed from Caliburn.Micro?
Also, the documentation is here:
https://caliburnmicro.codeplex.com/wikipage?title=The%20Event%20Aggregator
still show examples using the more basic, single parameter example where you simply pass a message. Is the documentation at this link the latest that correctly describes 2.0.0.6?
public void Red()
{
_events.Publish(new ColorEvent(new SolidColorBrush(Colors.Red)),
action => Task.Factory.StartNew(action));
}
Finally, for bonus points:
What is this 2nd parameter good for other than publishing the message on a background thread? Can someone give some other example(s) of what this overload can be used for?

In Caliburn Micro version 2.0, the EventAggregator.Publish method also takes an action to marshal the event. To maintain the pre-2.0 behavior, you should switch to the EventAggregator.PublishOnUIThread method instead. See the migration instructions here for information on incompatibilities between 1.5 and 2.0.
In general, I believe that the Codeplex documentation is a little bit outdated. Please refer to the new dedicated web site for most up-to-date documentation.

Related

WPF Caliburn.Micro uses wrong platform provider

In my ShellViewModel PlatformProvider.Current results in a XamlPlatformProvider as expected. In another ViewModel navigated to in a Frame PlatformProvider.Current results in a DefaultPlatformProvider.
Furthermore if I trigger a function in the ShellViewModel I can see that PlatformProvider.Current still results in a XamlPlatformProvider, so that ViewModel isn't affected.
This results in errors on Caliburn.Micro.Execute.OnUIThread and other platform specific calls such as using a BindableCollection.
It started happening after updating a large project to Caliburn.Micro version 4.0.173 from version 3.2.0.
I've been unable to reproduce the error in a smaller test project, so I can not show meaningful code.
I've tried replacing the whole bootstrapper with a minimal one and still see the error.
EDIT:
Creating a UI component from code within Caliburn.Micro.Execute.BeginOnUIThread gives the error:
"The calling thread must be STA, because many UI components require this".
Altering a BindableCollection gives the error:
"This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread."
The above scenarios work if I wrap them in a Application.Current.Dispatcher.Invoke which indicates that Caliburn.Micro fails to use the Dispatcher/UI thread.
I'm using C# on .NET Framework 4.8.
The second ViewModel, which was throwing errors was in a second project that included the NuGet package Caliburn.Micro.Core instead of Caliburn.Micro. Updating both to the same version solved the issue.
I had used NuGets Consolidate function to update Caliburn.Micro in the whole solution and had missed Caliburn.Micro.Core.

How to implement a splashscreen in a Poco application

I find a way to catch an event/message which notify the "application loaded" event, to be able to close a splashscreen. Maybe Poco implements it directly but i haven't found any clue in the Application class documentation or code.
Have you tried to use the application member function bool initialized()?
I'm using the Mitk framework, and i will have to modify some code there ; the used CommonTk framework can manage a callback dedicated for splashscreen closing. Thus, there is no event published by Poco to allow this feature.
i using POCO Thread for splash screen (where i can catch / handle status of thread). My application is programmed in WinAPI (Win32, VS C++ 2008 EE), so i using WinAPI timmers; the main message pump is also in separated thread...
Here is my WinApi32 example full code & VS90 project: WLEZLEY_SPLASH_POCO_EXAMPLE.ZIP
PS: It works since version 1.4.5 of POCO, but also works with POCO v1.7.2 (actual version is included). You can try study my code and you try it yourself.

MvvmCross MvxApplication class overriding for different platforms. (Plus, encryption)

I've got two questions here. The first one is just specific and another one is more general, but is a source of the first one.
So, my specific problem: I want to use Encryption (actually, Hashing) algorithms with using System.Security.Cryptography namespace (for instance, SHA256Managed class).
I found out that (happily) Xamarin has implemented those in System.dll.
But it is not portable and obviously can not be used from Core application directly.
But I've also found another great project -- PclContrib -- which allows you to do that. But, unfortunately, they don't have the implementation for Touch and Android. (However, that still works great for Desktop (Web) and Windows Phone, plus, still can be included into Core (as it uses portable project)).
Anyway, to solve that nicely, I've decided to create some base class for the encryption methods and then override core methods which require the custom dll (for any custom system).
The way I did it (at least, trying to do) was:
Defining virtual method in Core App base class:
public virtual IEncryptionProvider CreateEncryptionProvider()
Overriding Core App class in Touch project with overriding CreateEncryptionProvider (which creates an instance of TouchEncryptionProvider class instance).
Core:
public class App : MvxApplication
Touch:
public class AppTouch : App
Launching it in Touch setup.cs:
protected override Cirrious.MvvmCross.ViewModels.IMvxApplication CreateApp (
{
return new AppTouch();
}
But, that does not work for me. On startup I've got this exception message in log:
"Exception masked KeyNotFoundException: Could not find view for Mynamespace.Etc.LoginViewModel", which works fine when I do new App() instead. I am not sure if that message shows actual problem (as before it was saying the same even that was a problem with some third-party dll, unrelated to views at all). But speaking shortly, that's just a primitive inheritance of App : MvxApplication, but placed not in Core but Touch project.
So, does it requeire some more custom initialization for such situations or do I miss something else?
And, actually, more general question is how should I build such Multiplatform approaches? Actually, now I've got similar problem with HttpUtility.UrlEncode, which I would want to use in my Core project.
What is the MvvmCross "philosophy" to handle such situations?
Thank you.
For the 'viewmodel not found' problem, this is caused because mvvmcross by default only looks for viewmodels in the Assembly containing your app.
If you want it to look in other assemblies, override ViewModelAssemblies in Setup.cs - see how this done in, for example, MvvmCross - structuring shared View Models and Views
For general multplatform approach, please read questions and answers like:
Platform-specific IoC in MVVMCross
Instantiation of ViewModels and Service classes
Please also remember you don't have to use PCLs - if you prefer to use file-linking between multiple platform-specific core projects, then you can of course use this approach.
Finally, please also try to ask one question per question - I find it makes stackoverflow work better for users and with search engines too. If you need to link questions, then you can just add a hyperlink reference - stackoverflow then marks them as related.

client event handler for sending message to groups in SignalR

I'm trying to integrate SignalR in my MVC project and everything works fine,
however ther is something I can't get right,
Using the latest version of signalR:
http://blogs.msdn.com/b/webdev/archive/2012/08/22/announcing-the-release-of-signalr-0-5-3.aspx
And writing the group functionality described in this wiki:
https://github.com/SignalR/SignalR/wiki/Hubs
Especifically in thr MANAGING GROUPS topic, there is the following code to send a message to a specific group:
public Task Send(string message)
{
return Clients.Group("foo").addMessage(message);
}
I can't figure two things: as the way the code is stated I have the following exception:
'System.Threading.Tasks.Task<object>' does not contain a definition for 'addMessage'
Besides that, what exactly is the event raised in the client to handle it properly with jquery?
Sorry for the confusion. The documentation is updated to be the latest release which is 1.0 alpha2. http://weblogs.asp.net/davidfowler/archive/2012/11/11/microsoft-asp-net-signalr.aspx.
To install it do:
Install-Package Microsoft.AspNet.SignalR -pre
We're going to be deprecating the older packages soon.

MVC2 with Ninject.Web.Mvc 2.2 and Ninject 2.2 runtime version 4.0 always asks for parameterless constructor for controllers

I have a previous project running Ninject 2.0 runtime version 2.0 and now I am using Ninject in a new project and using the new Ninject, ninject web.mvc version 2.2 for runtime version 4.0.
Every single time I get the error no parameterless constructor
Invalid Operation exception
An error occurred when trying to create a controller of type HomeController'. Make sure that the controller has a parameterless public constructor.
What am I missing. All the bindings are registered.
Do I need to now define interfaces for Controllers as well such as HomeController as IHomeController as I have seen in some examples, Or do I get back to using the older version
There is one version that does not show activation exceptions properly but show this exception instead. Most likely the problem is a duplicated binding.
In addition to what Remo Gloor said, you might want to check that MVC is set up to use Ninject correctly. I was doing some things manually on an older version of the MVC plugin and ended up needing to just bite the bullet and make Global extend the NinjectHttpApplication class, which I had previously been avoiding.
The error you're getting is the error you would get if MVC tries using its built-in controller factory to produce controllers. So you may want to create a custom method binding on your controller class and put a breakpoint inside to make sure it's even being invoked.
You may also want to switch to version 2.3. You can pick up the latest builds of Ninject and all its extensions here.
I have seen this issue mentioned couple of times on forums where there is no direct answer, here is the solution to the above problem, i.e., working with latest ninject
Download the latest Ninject from github.
The ninject I got for MVC2 is named as Ninject.Web.Mvc2-2.2.0.0-release-net-4.0 (runtime version 4)
Now during adding reference add Ninject.Web.Mvc.dll(check the version is same as above by right click properties in VS)
Now Add Ninject.dll from the lib folder in same parent folder (check the version as above)
Now Add CommonServiceLocator.NinjectAdapter.dll from the extensions folder in lib parent folder (check the version as above.)
The missing link in all these have been the commonserviceLocator.dll and the correct version should match. This should be tried if you are sure your bindings are correct as mine were and check to see if your project work with older version.
Thanks to everyone, and good luck :)

Resources