Print Page | Close Window

DevForce and Caliburn micro

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3188
Printed Date: 13-Apr-2026 at 3:28pm


Topic: DevForce and Caliburn micro
Posted By: pponzano
Subject: DevForce and Caliburn micro
Date Posted: 30-Dec-2011 at 8:33am
Hello,
refactoring my code I've seen that in some point I use MessageBoxes to show exceptions...

Here's an example

public void LoadData()

      {

          IsBusy = true;

          _repository.LoadData(idUser, Date,

                                     results =>

                                     {

                                         DataItems = new BindableCollection<myObj>(results.Cast<MarginCCSnapShotResult>());

 

                                         CanPrintExport = true;

                                         IsBusy = false;

                                     },

                                    e =>

                                    {

                                        CanPrintExport = false;

                                        IsBusy = false;

 

                                        MessageBox.Show(e.Message);

                                    });

      }

 I've decided to use the Kevin Mees implementation of Dialogs handling... but I don't knwo how to return the type since the Coorutine Error returns a IEnumerable<IResult>.

I tried yield return for error.AsResult() but it says “The yield statement cannot be used inside an anonymous method or lambda expression”


the other problem would be what type should I return instead of the void?

Thanks


Paolo






Replies:
Posted By: mgood
Date Posted: 30-Dec-2011 at 6:02pm
Paolo,
I'm not entirely sure about your question, but I think I know what you are asking. Are you familiar with the DevForce Application Framework? It's an open source framework that we make available to our customers. It integrates Caliburn Mirco with DevForce and provides the glue in between. I'm the primary author of the framework. I think you'll find your answers there. In particular check out the write-up on the recommended approach for repositories, I believe it answers your question about what to return.
http://devforcecaliburn.codeplex.com/wikipage?title=The%20Data%20Repository&referringTitle=Documentation - http://devforcecaliburn.codeplex.com/wikipage?title=The%20Data%20Repository&referringTitle=Documentation
If you download the framework, you'll also find a sample called SimplePopup in the Samples folder, which demonstrates how to do dialogs. I'm not familiar with Kevin Mees' implementation, but it migth be very similar.
Marcel


Posted By: mgood
Date Posted: 30-Dec-2011 at 9:37pm
Never mind. I read your question again and it looks like you are already using DAF. Based on the SimplePopup I put together a sample that I think demostrates what you are asking:
        public IEnumerable<IResult> LoadData()
        {
            Exception error = null;
 
            // IsBusy = true;
 
            yield return CoroutineFns.AsResult(
                () => _repository.LoadData(result =>
                                               {
                                                   /* do something useful with the result */
                                               },
                                           e => error = e));
 
            // IsBusy = false;
 
            if (error != null)
                yield return new ShowMessageResult("Error", error.Message);
        }
You can download the entire sample from my SkyDrive. Just copy it into the DAF Samples folder if you want to build it.
https://skydrive.live.com/redir.aspx?cid=b37183c914f0fbe8&resid=B37183C914F0FBE8!198&parid=B37183C914F0FBE8!192&authkey=!AGZXml8oH_Rhs4s - https://skydrive.live.com/redir.aspx?cid=b37183c914f0fbe8&resid=B37183C914F0FBE8!198&parid=B37183C914F0FBE8!192&authkey=!AGZXml8oH_Rhs4s


Posted By: pponzano
Date Posted: 23-Jan-2012 at 11:39am
Hello Marcel,
I've got a small iussue with the code you provided me...
In a ViewModel that calls the LoadData as it's loaded the IsBusy remains in true status and no call to result=> {} is made...why this happen?
Thanks

I can provide code tomorrow here it's 21PM and I'm out of office..
Thanks


Posted By: mgood
Date Posted: 23-Jan-2012 at 1:15pm
Hard to tell with the information I have. One reason that could happen is if the query got cancelled for some reason. Are you saying the e => error = e isn't called, either? result => {} would only be called if the query was actually succesfull.



Print Page | Close Window