public async Task <IActionResult> Delete(string projectId, string branchName)
        {
            var authorization = await _authorizationService.AuthorizeAsync(User, new ProjectDto { Id = projectId }, Operations.Update);

            if (!authorization.Succeeded)
            {
                return(Forbid());
            }

            await _branchesService.DeleteBranchAsync(projectId, branchName);

            await _searchService.DeleteDocumentsAsync(projectId, branchName);

            return(Ok());
        }
        public async Task UploadBranchAsync(string projectId, string branchName, string filePath)
        {
            var logs    = new StringBuilder();
            var logsDto = new LogsDto();

            try
            {
                LogInformation(logs, $"Starting uploading project ({projectId}/{branchName}). Temporary file name: {filePath}.");
                if (!File.Exists(filePath))
                {
                    LogInformation(logs, $"Uploading project stopped ({projectId}/{branchName}). File '{filePath}' not exists.");

                    logsDto.Message = logs.ToString();
                    await _logsService.AppendLogsAsync(projectId, logsDto);

                    return;
                }

                _httpContextHeaders.Headers = new Dictionary <string, StringValues>();
                _httpContextHeaders.Headers.Add("Authorization", $"SecureToken {_applicationParameters.SecureToken}");

                LogInformation(logs, $"Getting branches information ({projectId}/{branchName}).");
                var branches = await _branchService.GetBranchesAsync(projectId);

                LogInformation(logs, $"Branches information retrieved ({projectId}/{branchName}).");

                if (branchName != null && branches.Any(x => x.Name == branchName))
                {
                    LogInformation(logs, $"Deleting branch from storage ({projectId}/{branchName}).");
                    await _branchService.DeleteBranchAsync(projectId, branchName);

                    LogInformation(logs, $"Branch was deleted ({projectId}/{branchName}).");
                }

                LogInformation(logs, $"Uploading branch to storage ({projectId}/{branchName}).");
                LogInformation(logs, $"Reading temporary file ({projectId}/{branchName}) from path: '{filePath}'.");
                using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    LogInformation(logs, $"File '{filePath}' exists and was readed.");
                    await _documentsService.UploadBranchAsync(projectId, branchName, fileStream, logs);
                }
                LogInformation(logs, $"Branch uploaded ({projectId}/{branchName}).");

                LogInformation(logs, $"Getting project information ({projectId}/{branchName}).");
                var project = await _projectsService.GetProjectAsync(projectId);

                if (!project.IsAccessLimited)
                {
                    LogInformation(logs, $"Ordering index refresh ({projectId}/{branchName}).");
                    await _searchService.RefreshIndexAsync(projectId, branchName);

                    LogInformation(logs, $"Index refresh ordered ({projectId}/{branchName}).");
                }

                LogInformation(logs, $"Uploading project ({projectId}/{branchName}) finished successfully.");
            }
            catch (Exception exception)
            {
                LogError(logs, $"During uploadind exception occurs ({projectId}/{branchName}).");
                LogError(logs, $"Exception: {exception.ToString()}.");
                LogError(logs, $"Message: {exception.Message}.");
                LogError(logs, $"Stack trace: {exception.StackTrace}.");

                if (exception.InnerException != null)
                {
                    LogError(logs, $"Inner exception: {exception.InnerException.ToString()}.");
                    LogError(logs, $"Inner exception message: {exception.InnerException.Message}.");
                    LogError(logs, $"Inner exception stack trace: {exception.InnerException.StackTrace}.");
                }

                LogError(logs, $"Uploading project ({projectId}/{branchName}) failed.");
            }
            finally
            {
                LogInformation(logs, $"Deleting temporary file: '{filePath}'.");
                File.Delete(filePath);
                LogInformation(logs, $"Temporary file '{filePath}' was deleted.");
            }

            logsDto.Message = logs.ToString();
            await _logsService.AppendLogsAsync(projectId, logsDto);
        }
예제 #3
0
        public async Task <IActionResult> Delete(string projectId, string branchName)
        {
            await _branchesService.DeleteBranchAsync(projectId, branchName);

            return(Ok());
        }