New Posts New Posts RSS Feed: Questions about Migration and Async
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Questions about Migration and Async

 Post Reply Post Reply
Author
iDave View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Jun-2011
Location: Belgiƫ
Posts: 11
Post Options Post Options   Quote iDave Quote  Post ReplyReply Direct Link To This Post Topic: Questions about Migration and Async
    Posted: 14-Jan-2013 at 6:15pm
Good day,

I've migrated from 2010 to 2012 and some code doesn't work. All of them related to async.
So, I wonder if someone could be so kind to give me a hint here.

For example:

Here's what I was doing back in 2010:


        public void GetCustomers(Action<IEnumerable<Customer>> onSuccess, Action<Exception> onFail)
        {
            Manager.Customers
              .Include(c => c.Address)
              .OrderBy(c => c.Id)
              .ExecuteAsync(
                  op =>
                  {
                      if (op.CompletedSuccessfully)
                      {
                          if (onSuccess != null)
                              onSuccess(op.Results);
                      }
                      else
                      {
                          if (onFail != null)
                          {
                              op.MarkErrorAsHandled();
                              onFail(op.Error);
                          }
                      }
                  }
               );
        }


How should I convert it to 2012 in order to have this code working again?

Thanks in advance!
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 14-Jan-2013 at 6:32pm
Hi,

I would suggest you read up on Tasks, it replaces coroutines. Essentially the code would look like this:


public Task<IEnumerable<Customer>> GetCustomers()
{
    return await Manager.Customers
        .Include(c => c.Address)
        .OrderBy(c => c.Id)
        .ExecuteAsync();
}

I just typed that up in notepad, so I may be slightly off. As you can see it is a lot less code.

In your VM you can then write code like this:

var customers = await Repository.GetCustomers();

you can also wrap try statements around them now, unlike coroutines. ie:

try
{
  await MyRoutine();
}
catch (MyException ex)
{
}

etc

I would strongly advise looking at the TempHire and other examples that have been updated to DF 2012




Edited by smi-mark - 14-Jan-2013 at 6:34pm
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 14-Jan-2013 at 6:35pm
If you can't upgrade all your code right now, you can use the compatibility pack.

This link will explain it:

http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-backward-compatibility
Back to Top
iDave View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Jun-2011
Location: Belgiƫ
Posts: 11
Post Options Post Options   Quote iDave Quote  Post ReplyReply Direct Link To This Post Posted: 14-Jan-2013 at 6:38pm
Thank you for your lighting-fast reply!

Indeed, the code is more shorter and clean.. I'm now taking a look at TempHire sample and will look forward to the Compatibility Pack if the there's a lot of code and no time to upgrade all.

Thanks again!

Regards,
Dave
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down