Beispiel #1
0
        protected override void DoOperation()
        {
            SaveAsOperation sao = new SaveAsOperation(byteBuffer, tempPath, this.progressCallback, null, false);

            stageReached = SaveStage.BeforeSaveAs;

            // Check for free space for final file
            // free space for temporary file is checked in sao.DoOperation()
            if (!CheckFreeSpace(Path.GetDirectoryName(byteBuffer.Filename), byteBuffer.fileBuf.Size))
            {
                string msg = string.Format(Catalog.GetString("There is not enough free space on the device to save file '{0}'."), byteBuffer.Filename);
                throw new IOException(msg);
            }

            // Save ByteBuffer as a temp file
            sao.OperationThread();

            if (sao.Result == ThreadedAsyncOperation.OperationResult.CaughtException)
            {
                throw sao.ThreadException;
            }
            else if (sao.Result == ThreadedAsyncOperation.OperationResult.Cancelled)
            {
                cancelled = true;
            }

            // if user hasn't cancelled, move temp file to
            // its final location
            if (!cancelled)
            {
                this.ActivateProgressReport(true);
                stageReached = SaveStage.BeforeDelete;

                // Delete here to fail early (before invalidating the byteBuffer)
                // if there are any issues.
                if (System.IO.File.Exists(savePath))
                {
                    System.IO.File.Delete(savePath);
                }

                // close the file, make sure that File Operations
                // are temporarily allowed
                lock (byteBuffer.LockObj) {
                    // CloseFile invalidates the file buffer,
                    // so make sure undo/redo data stays valid
                    byteBuffer.MakePrivateCopyOfUndoRedo();
                    byteBuffer.FileOperationsAllowed = true;
                    byteBuffer.CloseFile();
                    byteBuffer.FileOperationsAllowed = false;
                }

                stageReached = SaveStage.BeforeMove;
                System.IO.File.Move(tempPath, savePath);
            }
        }
Beispiel #2
0
            private IEnumerable <IDbSaveHook> PostExecute(IEnumerable <IHookedEntity> changedHookEntries)
            {
                if (changedHookEntries == null || !changedHookEntries.Any())
                {
                    return(Enumerable.Empty <IDbSaveHook>());
                }

                // the existence of hook entries actually implies that hooking is enabled.

                _stage = SaveStage.PostSave;

                var importantHooksOnly = !_ctx.HooksEnabled && _hookHandler.HasImportantSaveHooks();

                return(_hookHandler.TriggerPostSaveHooks(changedHookEntries, importantHooksOnly));
            }
Beispiel #3
0
            private void PostExecute(HookedEntity[] changedHookEntries)
            {
                if (changedHookEntries == null || changedHookEntries.Length == 0)
                {
                    return;
                }

                // the existence of hook entries actually implies that hooking is enabled.

                _stage = SaveStage.PostSave;

                var importantHooksOnly = !_ctx.HooksEnabled && _hookHandler.HasImportantSaveHooks();

                _hookHandler.TriggerPostSaveHooks(changedHookEntries, importantHooksOnly);
            }