System.Configuration.Internal.WriteFileContext.Complete C# (CSharp) Méthode

Complete() private méthode

private Complete ( string filename, bool success ) : void
filename string
success bool
Résultat void
        internal void Complete(string filename, bool success) {
            try {
                if (success) {
                    if ( File.Exists( filename ) ) {
                        // Test that we can write to the file
                        ValidateWriteAccess( filename );

                        // Copy Attributes from original
                        DuplicateFileAttributes( filename, _tempNewFilename );
                    } 
                    else {
                        if ( _templateFilename != null ) {
                            // Copy Acl from template file
                            DuplicateTemplateAttributes( _templateFilename, _tempNewFilename );
                        }
                    }

                    ReplaceFile(_tempNewFilename, filename);

                    // Don't delete, since we just moved it.
                    _tempFiles.KeepFiles = true;
                }
            }
            finally {
                ((IDisposable)_tempFiles).Dispose();
                _tempFiles = null;
            }
        }

Usage Example

        // Parameters:
        //  assertPermissions - If true, then we'll assert all required permissions.  Used by ClientSettingsConfigurationHost.
        //                      to allow low-trust apps to use ClientSettingsStore.
        static internal void StaticWriteCompleted(string streamName, bool success, object writeContext, bool assertPermissions)
        {
            WriteFileContext writeFileContext = (WriteFileContext)writeContext;
            bool             revertAssert     = false;

            if (assertPermissions)
            {
                // If asked to assert permissions, we will assert allAccess on the streamName, the temporary file
                // created by WriteContext, and also the directory itself.  The last one is needed because
                // WriteFileContext will call TempFileCollection.Dispose, which will remove a .tmp file it created.
                string           dir        = Path.GetDirectoryName(streamName);
                string[]         filePaths  = new string[] { streamName, writeFileContext.TempNewFilename, dir };
                FileIOPermission fileIOPerm = new FileIOPermission(FileIOPermissionAccess.AllAccess, AccessControlActions.View | AccessControlActions.Change, filePaths);
                fileIOPerm.Assert();
                revertAssert = true;
            }

            try {
                writeFileContext.Complete(streamName, success);
            }
            finally {
                if (revertAssert)
                {
                    CodeAccessPermission.RevertAssert();
                }
            }
        }
All Usage Examples Of System.Configuration.Internal.WriteFileContext::Complete