Example #1
0
 private void ExtractDllFromZip(string zipPath, string extractPath, string toPath)
 {
     if (!_directoryService.Exists(toPath))
     {
         _directoryService.ExtractToDirectory(zipPath, extractPath);
         _directoryService.Move(extractPath, toPath);
         _directoryService.Delete(zipPath, false);
     }
 }
        public static void ForceDeleteDirectory(this IDirectoryService directoryService, IFileService fileService, string folderPath, out List <string> failedEntries)
        {
            Argument.IsNotNull(() => directoryService);
            Argument.IsNotNull(() => folderPath);

            failedEntries = new List <string>(); //list of directories which cause unavoidable errors during deletion
            var fallbackFlag = false;

            try
            {
                directoryService.Delete(folderPath, true);
            }
            catch (UnauthorizedAccessException)
            {
                // Caller doesn't have enough permissions
                fallbackFlag = true;
            }
            catch (PathTooLongException)
            {
                // Exceed the system maximum length
                failedEntries.Add(folderPath);
            }
            catch (IOException)
            {
                // Directory.Delete has multiple causes of exception
                // We try to handle read-only attributes on file in sub-directories which can cause this exceptions
                fallbackFlag = true;
            }

            // Do some preparations and try again
            if (fallbackFlag)
            {
                ForceDeleteFilesFromSubDirectories(folderPath, directoryService, fileService, failedEntries);

                try
                {
                    directoryService.Delete(folderPath, true);
                }
                catch (UnauthorizedAccessException)
                {
                    // The caller does not have the required permission
                    failedEntries.Add(folderPath);
                }
                catch (PathTooLongException)
                {
                    // Exceed the system maximum length
                    failedEntries.Add(folderPath);
                }

                catch (IOException)
                {
                    throw;
                }
            }
        }
Example #3
0
        public void Restore(string fullPath)
        {
            Log.Info("Restoring backup for {0}", fullPath);

            try
            {
                if (_fileService.Exists(fullPath))
                {
                    //restore only single file on this path
                    fullPath = Catel.IO.Path.GetDirectoryName(fullPath);
                }
                else
                {
                    //clean-up directory from files created after backup, like .deleteme etc
                    _directoryService.Delete(fullPath);
                }

                var sourceDirectory = GetBackupFolder(fullPath);
                _directoryService.Copy(sourceDirectory, fullPath);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to restore backup for {0}", fullPath);
            }
        }
Example #4
0
        public async Task <IActionResult> Delete()
        {
            _logger.LogTrace($"{nameof(Delete)}");

            bool status = await _directoryService.Delete();

            return(status ? Ok() : NotFound());
        }
Example #5
0
        public IActionResult Delete(Directory directory)
        {
            var result = _directoryService.Delete(directory);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
 /// <inheritdoc/>
 public void UninstallLibrary(LibraryListItem libraryListItem)
 {
     if (libraryListItem.Library != null)
     {
         if (TryGetLibraryWithNameAndVersion(libraryListItem.Library, out NodeLibrary library))
         {
             if (!string.IsNullOrEmpty(library.PathOnDisk))
             {
                 _directoryService.Delete(library.PathOnDisk, true);
                 InstalledLibraryItems.Remove(libraryListItem);
             }
         }
         else
         {
             if (!string.IsNullOrEmpty(libraryListItem?.Library?.PathOnDisk))
             {
                 _directoryService.Delete(libraryListItem.Library.PathOnDisk, true);
                 InstalledLibraryItems.Remove(libraryListItem);
             }
         }
     }
 }
 public IActionResult Delete([FromBody] int data)
 {
     try
     {
         var userData = jwtService.ParseData(this.User);
         int result   = dirService.Delete(data, userData.UserId);
         return(Ok(result));
     }
     catch (ServiceException e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #8
0
        [HttpDelete("{id}")] //[FromBody] Json, que vai conter um userEntity
        public async Task <ActionResult> Delete(Guid Id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                return(Ok(await _service.Delete(Id)));
            }
            catch (ArgumentException ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Example #9
0
        public async Task <IActionResult> Delete([FromQuery] Guid directoryId)
        {
            return(await ProcessAsync(async() =>
            {
                var user = await UserService.GetUserByPrincipal(User);

                if (await _directoryService.IsAuthorised(user, directoryId))
                {
                    await _directoryService.Delete(directoryId);

                    return Ok("The directory was successfully deleted.");
                }

                return Unauthorized("Access denied.");
            }));
        }
Example #10
0
        protected virtual void Dispose(bool disposing)
        {
#pragma warning disable IDISP023 // Don't use reference types in finalizer context.
            try
            {
                Log.Info("Deleting temporary files from '{0}'", _rootDirectory);

                _directoryService.Delete(_rootDirectory, true);

                Log.Info("Temporary files has been successfully deleted from '{0}'", _rootDirectory);
            }
            catch (Exception)
            {
                Log.Warning("Unable to cleanup temporary files");
            }
#pragma warning restore IDISP023 // Don't use reference types in finalizer context.
        }
        protected override void OnOperationStarting(object sender, PackageOperationEventArgs e)
        {
            var packagesConfig = Catel.IO.Path.Combine(Catel.IO.Path.GetParentDirectory(e.InstallPath), "packages.config");

            if (e.PackageOperationType == PackageOperationType.Uninstall)
            {
                _backupFileSystemService.BackupFolder(e.InstallPath);
                _backupFileSystemService.BackupFile(packagesConfig);

                _rollbackPackageOperationService.PushRollbackAction(() =>
                {
                    _backupFileSystemService.Restore(e.InstallPath);
                    _backupFileSystemService.Restore(packagesConfig);
                }, CurrentContext);
            }

            if (e.PackageOperationType == PackageOperationType.Install)
            {
                _rollbackPackageOperationService.PushRollbackAction(() =>
                {
                    bool success = true;
                    try
                    {
                        _directoryService.Delete(e.InstallPath);
                        success = !_directoryService.Exists(e.InstallPath);
                    }
                    catch (Exception)
                    {
                        success = false;
                    }
                    finally
                    {
                        if (!success)
                        {
                            _fileSystemService.CreateDeleteme(e.PackageDetails.Id, e.InstallPath);
                            Log.Error($"Failed to delete directory {e.InstallPath} during rollback actions.");
                        }
                    }
                },
                                                                    CurrentContext
                                                                    );
            }
        }
Example #12
0
        private bool DeleteDirectory(string fullName)
        {
            Argument.IsNotNullOrWhitespace(() => fullName);

            Log.Debug($"Deleting directory '{fullName}'");

            try
            {
                if (_directoryService.Exists(fullName))
                {
                    _directoryService.Delete(fullName, true);
                }
            }
            catch (Exception ex)
            {
                Log.Warning(ex, $"Failed to delete directory '{fullName}'");
            }

            return(!_directoryService.Exists(fullName));
        }
 public IActionResult Delete(int id, int returnDirId)
 {
     directoryService.Delete(id, this.User.Identity.Name);
     return(RedirectToAction(nameof(Index), new { id = returnDirId }));
 }
 public void Delete([FromQuery] int id)
 {
     _directoryService.Delete(id);
 }
Example #15
0
 public void Delete_Directory_NullArgument_Test()
 {
     directoryService.Delete(null);
 }