Ejemplo n.º 1
0
    public void ToFile()
    {
        var area = FocusOnSegmentName.EnsureFirstCharacterToUpper();
        var file = DirectoryInfoHelper.GetCsFileNameForContract(ApiProjectOptions.PathForEndpoints, area, NameConstants.EndpointInterfaces, InterfaceTypeName);

        ToFile(new FileInfo(file));
    }
Ejemplo n.º 2
0
        /// <summary>
        ///     Analyze a project, determine which project tasks have
        ///     to be exectued and return all these project tasks. All
        ///     tasks are then enqueued.
        /// </summary>
        /// <remarks>
        ///     This does not sync any project tasks with the data store.
        /// </remarks>
        /// <param name="projectId">The project to analyze.</param>
        /// <param name="token">The cancellation token.</param>
        public async Task AnalyzeProjectEnqueueTasksAsync(Guid projectId, CancellationToken token)
        {
            projectId.ThrowIfNullOrEmpty();
            var project = await _projectRepository.GetAsync(projectId, token);

            // TODO This should not have directory info
            var directoryInfo = DirectoryInfoHelper.GetFromProject(_options.RootDirectoryPath, project);

            var trackingFile = _fileTrackingService.GetTrackingFile(directoryInfo);

            var result = new List <ProjectTask>();

            if (DoesDirectoryContainAudioFiles(directoryInfo))
            {
                // FUTURE Check for changes in audio file. https://github.com/tabeckers/AbleSync/issues/27
                result.Add(new ProjectTask
                {
                    Id              = Guid.NewGuid(), // TODO Like this?
                    ProjectId       = trackingFile.ProjectId,
                    ProjectTaskType = ProjectTaskType.UploadAudio,
                });
            }

            // FUTURE Other task types as well

            EnqueueAll(result);

            _logger.LogTrace($"Analyzed and enqueued {result.Count} tasks for project {projectId}");
        }
Ejemplo n.º 3
0
    public void ToFile()
    {
        var controllerName = FocusOnSegmentName.EnsureFirstCharacterToUpper() + "Controller";
        var file           = DirectoryInfoHelper.GetCsFileNameForEndpoints(ApiProjectOptions.PathForEndpoints, controllerName);

        ToFile(new FileInfo(file));
    }
Ejemplo n.º 4
0
    public void ToFile()
    {
        var area       = FocusOnSegmentName.EnsureFirstCharacterToUpper();
        var resultName = ApiOperation.GetOperationName() + NameConstants.ContractResult;
        var file       = DirectoryInfoHelper.GetCsFileNameForContract(ApiProjectOptions.PathForContracts, area, NameConstants.ContractResults, resultName);

        ToFile(new FileInfo(file));
    }
    public void ToFile()
    {
        var area          = FocusOnSegmentName.EnsureFirstCharacterToUpper();
        var interfaceName = "I" + ApiOperation.GetOperationName() + NameConstants.ContractHandler;
        var file          = DirectoryInfoHelper.GetCsFileNameForContract(ApiProjectOptions.PathForContracts, area, NameConstants.ContractInterfaces, interfaceName);

        ToFile(new FileInfo(file));
    }
Ejemplo n.º 6
0
        // FUTURE Also support other audio formats.
        // TODO This is windows coupled. See https://github.com/tabeckers/AbleSync/issues/19 and https://github.com/tabeckers/AbleSync/issues/28
        // TODO Pick correct audio file, there may be multiple mp3 files.
        /// <summary>
        ///     Execute the upload for an audio file.
        /// </summary>
        /// <remarks>
        ///     This only handles mp3.
        /// </remarks>
        /// <param name="task">The task.</param>
        /// <param name="token">The cancellation token.</param>
        public async Task ExecuteUploadAudioAsync(ProjectTask task, CancellationToken token)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }
            if (task.ProjectTaskType != ProjectTaskType.UploadAudio)
            {
                throw new InvalidOperationException(nameof(task.ProjectTaskType));
            }

            _logger.LogTrace($"Starting mp3 audio upload for project {task.ProjectId}");

            var project = await _projectRepository.GetAsync(task.ProjectId, token);

            var directoryInfo = DirectoryInfoHelper.GetFromProject(_options.RootDirectoryPath, project);
            var audioFiles    = directoryInfo.GetFiles().Where(x => Constants.ExportedAudioFileExtensions.Contains(x.Extension));

            // TODO Do elegantly.
            if (!audioFiles.Where(x => x.Extension == Constants.AudioMp3FileExtension).Any())
            {
                // TODO Custom exception.
                throw new InvalidOperationException("Could not get mp3 file in project folder");
            }

            // Get the actual physical file because we need its name.
            var audioFilePhysical = audioFiles.Where(x => x.Extension == Constants.AudioMp3FileExtension).First();

            // Get or create the audio file.
            var audioFileEntity = await _audioFileRepository.ExistsForProjectAsync(task.ProjectId, AudioFormat.Mp3, token)
                ? await _audioFileRepository.GetFromProjectAsync(task.ProjectId, AudioFormat.Mp3, token)
                : await _audioFileRepository.CreateGetAsync(new AudioFile
            {
                AudioFormat = AudioFormat.Mp3,
                Name        = audioFilePhysical.Name,
                ProjectId   = project.Id
            }, token);

            var fileNamePhysical   = audioFilePhysical.Name;
            var folderNamePhysical = $"{DirectoryInfoHelper.ParsePathFromProject(_options.RootDirectoryPath, project)}";

            using var fileStream = new FileStream($"{folderNamePhysical}/{fileNamePhysical}", FileMode.Open, FileAccess.Read);

            var fileNameStorage   = FileStorageHelper.AudioFileName(audioFileEntity.Id);
            var folderNameStorage = FileStorageHelper.AudioFileFolder(project.Id);
            await _blobStorageService.StoreFileAsync(folderNameStorage, fileNameStorage, Constants.ContentTypeMp3, fileStream, token);

            // Mark our synchronization
            await _audioFileRepository.MarkSyncedAsync(audioFileEntity.Id, token);

            _logger.LogTrace($"Finished mp3 audio upload for project {task.ProjectId} - uploaded {fileNamePhysical} as {fileNameStorage}");
        }
Ejemplo n.º 7
0
    public void ToFile()
    {
        var area          = FocusOnSegmentName.EnsureFirstCharacterToUpper();
        var parameterName = ApiOperation.GetOperationName() + NameConstants.ContractParameters;

        var file = IsForClient
            ? DirectoryInfoHelper.GetCsFileNameForContract(ApiProjectOptions.PathForContracts, area, NameConstants.ClientRequestParameters, parameterName)
            : UseOwnFolder
                ? DirectoryInfoHelper.GetCsFileNameForContract(ApiProjectOptions.PathForContracts, area, NameConstants.ContractParameters, parameterName)
                : DirectoryInfoHelper.GetCsFileNameForContract(ApiProjectOptions.PathForContracts, area, parameterName);

        ToFile(new FileInfo(file));
    }
Ejemplo n.º 8
0
        public void ParseProjectPath()
        {
            // Arrange.
            var rootDirectory = new Uri("C:/root/my folder/my-subfolder");
            var project       = new Project
            {
                RelativePath = "projects/myproject"
            };

            // Act.
            var result = DirectoryInfoHelper.ParsePathFromProject(rootDirectory, project);

            // Assert.
            Assert.Equal("C:/root/my folder/my-subfolder/projects/myproject", result);
        }
Ejemplo n.º 9
0
    public void ToFile()
    {
        var area      = FocusOnSegmentName.EnsureFirstCharacterToUpper();
        var modelName = ApiSchemaKey.EnsureFirstCharacterToUpper();

        if (IsForClient &&
            modelName.EndsWith(NameConstants.Request, StringComparison.Ordinal))
        {
            var clientFile = DirectoryInfoHelper.GetCsFileNameForContract(ApiProjectOptions.PathForContracts, area, NameConstants.ClientRequestParameters, modelName);
            ToFile(new FileInfo(clientFile));
            return;
        }

        var file = IsEnum
            ? DirectoryInfoHelper.GetCsFileNameForContractEnumTypes(ApiProjectOptions.PathForContracts, modelName)
            : IsSharedContract
                ? DirectoryInfoHelper.GetCsFileNameForContractShared(ApiProjectOptions.PathForContractsShared, modelName)
                : UseOwnFolder
                    ? DirectoryInfoHelper.GetCsFileNameForContract(ApiProjectOptions.PathForContracts, area, NameConstants.ContractModels, modelName)
                    : DirectoryInfoHelper.GetCsFileNameForContract(ApiProjectOptions.PathForContracts, area, modelName);

        ToFile(new FileInfo(file));
    }