/// <summary>Creates the ACTION part of the response object for the given operation. </summary>
        /// <param name="urlScheme">The protocol part of the URL.</param>
        /// <param name="urlAuthority">The domain part of the URL.</param>
        /// <param name="requestApplicationPath">The path part of the URL.</param>
        /// <param name="operationName">The requested operation specified in the LFS request.</param>
        /// <param name="requestObject">The LFS request.</param>
        /// <param name="repositoryName">The repository to which this request applies.</param>
        /// <param name="storageProvider">The storage provider to use for managing LFS data.</param>
        /// <returns></returns>
        public BatchApiResponse.BatchApiObjectAction CreateBatchApiObjectActions(
            string urlScheme, string urlAuthority, string requestApplicationPath,
            string operationName, BatchApiRequest.LfsObjectToTransfer requestObject, string repositoryName, ILfsDataStorageProvider storageProvider)
        {
            if (!LfsOperationNames.IsValid(operationName))
            {
                throw new NotSupportedException($"Invalid operation name ({operationName})");
            }

            var result = new BatchApiResponse.BatchApiObjectAction();

            // If this is an upload, generate an upload action.
            if (operationName.Equals(LfsOperationNames.UPLOAD))
            {
                string fileUrl = FileUrl(urlScheme, urlAuthority, ref requestApplicationPath, requestObject, repositoryName);

                var uploadAction = new BatchApiResponse.BatchApiObjectTransferAction()
                {
                    Href       = fileUrl,
                    Header     = null,
                    Expires_in = 0x07FFFFFFF
                };
                result.Upload = uploadAction;
            }

            // If this is an upload, we *may* generate a verify action here.
            if (operationName.Equals(LfsOperationNames.UPLOAD))
            {
                // Optional and not yet implemented.
            }

            // If this is a download, gnerate a download action.
            if (operationName.Equals(LfsOperationNames.DOWNLOAD))
            {
                string fileUrl = FileUrl(urlScheme, urlAuthority, ref requestApplicationPath, requestObject, repositoryName);

                var downloadAction = new BatchApiResponse.BatchApiObjectTransferAction()
                {
                    Href       = fileUrl,
                    Header     = null,
                    Expires_in = 0x07FFFFFFF
                };
                result.Download = downloadAction;
            }

            return(result);
        }
Ejemplo n.º 2
0
 public static bool IsValid(string operationName)
 {
     LfsOperation[] values = (LfsOperation[])Enum.GetValues(typeof(LfsOperation));
     return(values.Any(o => LfsOperationNames.GetName(o).Equals(operationName)));
 }