Esempio n. 1
0
        static async Task CreateDialog(ContentDialog Dialog, bool awaitPreviousDialog)
        {
            if (ActiveDialog != null)
            {
                if (awaitPreviousDialog)
                {
                    ActiveDialog.Hide();
                }
                else
                {
                    switch (Info.Status)
                    {
                    case AsyncStatus.Started:
                        Info.Cancel();
                        break;

                    case AsyncStatus.Completed:
                        Info.Close();
                        break;

                    case AsyncStatus.Error:
                        break;

                    case AsyncStatus.Canceled:
                        break;
                    }
                }
            }
            ActiveDialog          = Dialog;
            ActiveDialog.Closing += ActiveDialog_Closing;
            Info = ActiveDialog.ShowAsync();
        }
 internal void CloseStreamOperation()
 {
     try
     {
         if (_asyncStreamOperation != null)
         {
             _asyncStreamOperation.Close();
         }
     }
     catch { }
     _asyncStreamOperation = null;
 }
Esempio n. 3
0
        private void Done(IAsyncInfo info, AsyncStatus status, bool initial)
        {
            var error  = default(Exception);
            var result = default(TResult);

            //
            // Initial interactions with the IAsyncInfo object. Those could fail, which indicates
            // a rogue implementation. Failure is just propagated out.
            //
            switch (status)
            {
            case AsyncStatus.Error:
                error = info.ErrorCode;
                if (error == null)
                {
                    throw new InvalidOperationException("The asynchronous operation failed with a null error code.");
                }

                break;

            case AsyncStatus.Canceled:
                error = new OperationCanceledException();
                break;

            case AsyncStatus.Completed:
                if (_getResult != null)
                {
                    result = _getResult(info);
                }

                break;

            default:
                if (!initial)
                {
                    throw new InvalidOperationException("The asynchronous operation completed unexpectedly.");
                }

                _onCompleted(info, (iai, s) => Done(iai, s, false));
                return;
            }

            //
            // Close as early as possible, before running continuations which could fail. In case of
            // failure above, we don't close out the object in order to allow for debugging of the
            // rogue implementation without losing state prematurely. Notice _getResults is merely
            // an indirect call to the appropriate GetResults method, which is not supposed to throw.
            // Instead, an Error status should be returned.
            //
            info.Close();

            //
            // Now we run the continuations, which could take a long time. Failure here is catastrophic
            // and under control of the upstream subscriber.
            //
            if (error != null)
            {
                _subject.OnError(error);
            }
            else
            {
                if (_getResult != null)
                {
                    _subject.OnNext(result);
                }

                _subject.OnCompleted();
            }
        }