= Function() Do

1 posts, 0 answers
  1. Bob
    Bob avatar
    1 posts
    Member since:
    Mar 2012

    Posted 19 Mar 2012 Link to this post

    Here is a Snippet that seems to Fail to convert to VB correctly:
    If you can do this one I have two more from the same project that also fail.
    As you may note in the Imports statements - this conversion is taken from a Caliburn Micro learning sample project

    Bob


    namespace HelloScreensWPF.Shell {
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using Framework;
        using Caliburn.Micro;

        public class ApplicationCloseStrategy : ICloseStrategy<IWorkspace> {
            IEnumerator<IWorkspace> enumerator;
            bool finalResult;
            Action<bool, IEnumerable<IWorkspace>> callback;

            public void Execute(IEnumerable<IWorkspace> toClose, Action<bool, IEnumerable<IWorkspace>> callback) {
                enumerator = toClose.GetEnumerator();
                this.callback = callback;
                finalResult = true;

                Evaluate(finalResult);
            }

            void Evaluate(bool result)
            {
                finalResult = finalResult && result;

                if (!enumerator.MoveNext() || !result)
                    callback(finalResult, new List<IWorkspace>());
                else
                {
                    var current = enumerator.Current;
                    var conductor = current as IConductor;
                    if (conductor != null)
                    {
                        var tasks = conductor.GetChildren()
                            .OfType<IHaveShutdownTask>()
                            .Select(x => x.GetShutdownTask())
                            .Where(x => x != null);

                        var sequential = new SequentialResult(tasks.GetEnumerator());
                        sequential.Completed += (s, e) => {
                            if(!e.WasCancelled)
                            Evaluate(!e.WasCancelled);
                        };
                        sequential.Execute(new ActionExecutionContext());
                    }
                    else Evaluate(true);
                }
            }
        }
    }

Back to Top