Пример #1
0
 /// <summary>
 /// RaiseSavedEvent should be called by a controller extending Save after the model is saved.
 /// </summary>
 /// <param name="eventArgs"></param>
 protected void RaiseSavedEvent(SavedEventArgs eventArgs)
 {
     if (this.Saved != null)
     {
         this.Saved(this, eventArgs);
     }
 }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Save the model.
        /// </summary>
        /// <returns></returns>
        public bool Save(Guid sessionGroupUniqueId, bool saveAsNew)
        {
            if (this.Model == null)
            {
                return(false);
            }

            string guid = sessionGroupUniqueId.ToString();

            SavingEventArgs savingEventArgs = new SavingEventArgs(guid);

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

            SavedEventArgs savedEventArgs = null;

            try
            {
                this.Model.Save(saveAsNew);
                savedEventArgs = new SavedEventArgs(guid, null);
            }
            catch (Exception exception)
            {
                savedEventArgs = new SavedEventArgs(guid, exception);
            }

            try
            {
                this.OnSavedInternal(savedEventArgs);
            }
            catch (Exception exception)
            {
                savedEventArgs = new SavedEventArgs(guid, exception);
            }

            this.RaiseSavedEvent(savedEventArgs);

            return(true);
        }
Пример #4
0
        private bool Save(Stream stream, string path)
        {
            if (this.Model == null)
            {
                return(false);
            }

            SavingEventArgs savingEventArgs = new SavingEventArgs(path);

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

            SavedEventArgs savedEventArgs = null;

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

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

            this.RaiseSavedEvent(savedEventArgs);

            return(true);
        }
Пример #5
0
 /// <summary>
 /// OnSavedInternal should be called by a controller extending Save after the model is saved.
 /// </summary>
 /// <param name="eventArgs"></param>
 protected void OnSavedInternal(SavedEventArgs eventArgs)
 {
     this.OnSaved(eventArgs);
 }
Пример #6
0
 /// <summary>
 /// Called before the Saved event is raised.
 /// </summary>
 /// <remarks>
 /// Notes to Inheritors: When overriding OnSaved in a derived class, calling the base class's OnSaved method is not necessary because there is no initial implementation.
 /// </remarks>
 /// <param name="eventArgs">An EventArgs that contains the event data.</param>
 protected virtual void OnSaved(SavedEventArgs eventArgs)
 {
 }