Пример #1
0
        private void SaveAsync(Stream stream, string path)
        {
            if (this.Model == null)
            {
                return;
            }

            SavingEventArgs savingEventArgs = new SavingEventArgs(path);

            this.OnSavingInternal(savingEventArgs);
            this.RaiseSavingEvent(savingEventArgs);

            SendOrPostCallback onSaved = delegate(object eventArgs)
            {
                SavedEventArgs savedEventArgs = eventArgs as SavedEventArgs;
                Debug.Assert(savedEventArgs != null);
                this.OnSavedInternal(savedEventArgs);
            };

            SendOrPostCallback raiseEvent = delegate(object eventArgs)
            {
                SavedEventArgs savedEventArgs = eventArgs as SavedEventArgs;
                Debug.Assert(savedEventArgs != null);
                this.RaiseSavedEvent(savedEventArgs);
            };

            AnonymousMethod save = delegate
            {
                SavedEventArgs savedEventArgs = null;

                try
                {
                    this.SaveInternal(stream, path);
                    savedEventArgs = new SavedEventArgs(path, null);
                }
                catch (Exception exception)
                {
                    savedEventArgs = new SavedEventArgs(path, exception);
                }

                try
                {
                    // For the OnSaved virtual method, do a synchronous send so that we
                    // can trap any exceptions and report them to the event handlers
                    this.asyncOperation.SynchronizationContext.Send(onSaved, savedEventArgs);
                }
                catch (Exception exception)
                {
                    savedEventArgs = new SavedEventArgs(path, exception);
                }

                // For the Saved event, do an asynchronous post because we don't care about
                // exceptions that are raised by event handlers
                this.asyncOperation.Post(raiseEvent, savedEventArgs);
            };

            save.BeginInvoke(null, null);
        }
Пример #2
0
        private void OpenAsync(Stream stream, string path)
        {
            if (this.Close())
            {
                OpeningEventArgs openingEventArgs = new OpeningEventArgs(path);
                this.OnOpeningInternal(openingEventArgs);
                this.RaiseOpeningEvent(openingEventArgs);

                SendOrPostCallback onOpened = delegate(object eventArgs)
                {
                    OpenedEventArgs openedEventArgs = eventArgs as OpenedEventArgs;
                    Debug.Assert(openedEventArgs != null);
                    this.OnOpenedInternal(openedEventArgs);
                };

                SendOrPostCallback raiseEvent = delegate(object eventArgs)
                {
                    OpenedEventArgs openedEventArgs = eventArgs as OpenedEventArgs;
                    Debug.Assert(openedEventArgs != null);
                    this.RaiseOpenedEvent(openedEventArgs);
                };

                AnonymousMethod open = delegate
                {
                    OpenedEventArgs openedEventArgs = null;

                    try
                    {
                        this.OpenInternal(stream, path);
                        openedEventArgs = new OpenedEventArgs(path, null);
                    }
                    catch (ConfigurationSchemaViolationException e)
                    {
                        openedEventArgs = new OpenedEventArgs(path, e);
                    }
                    catch (ConfigurationBusinessRuleViolationException e)
                    {
                        openedEventArgs = new OpenedEventArgs(path, e);
                    }
                    catch (Exception exception)
                    {
                        openedEventArgs = new OpenedEventArgs(path, exception);
                    }

                    try
                    {
                        // For the OnOpened virtual method, do a synchronous send so that we
                        // can trap any exceptions and report them to the event handlers
                        this.asyncOperation.SynchronizationContext.Send(onOpened, openedEventArgs);
                    }
                    catch (Exception exception)
                    {
                        openedEventArgs = new OpenedEventArgs(path, exception);
                    }

                    // For the Opened event, do an asynchronous post because we don't care about
                    // exceptions that are raised by event handlers
                    this.asyncOperation.Post(raiseEvent, openedEventArgs);
                };

                open.BeginInvoke(null, null);
            }
        }