コード例 #1
0
        internal JavaRequest(RestApiCredentials credentials, JavaOptions options) : base(credentials, options)
        {
            Version = options.Version;

            JarFile = new ApiFileInfo
            {
                FileName     = Path.GetFileName(options.JarFilePath),
                FileData     = File.ReadAllBytes(options.JarFilePath),
                FileMimeType = MimeMapping.MimeUtility.GetMimeMapping(options.JarFilePath)
            };
        }
コード例 #2
0
        public static void UploadApiReferences(this ICakeContext context, RestApiCredentials credentials, JavaOptions options)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var request = new JavaRequest(credentials, options);

            context.Log.Write(Verbosity.Normal, LogLevel.Information, "Uploading API Refs for {0}-{1} at {2}",
                              request.ProductKey, request.SectionKey, credentials.Uri);

            var multipartContent = new MultipartFormDataContent();
            var json             = JsonConvert.SerializeObject(request,
                                                               new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            multipartContent.Add(new StringContent(json, Encoding.UTF8, "application/json"), request.ContentName);

            var content = new ByteArrayContent(request.JarFile.FileData);

            content.Headers.ContentType = new MediaTypeHeaderValue(request.JarFile.FileMimeType);
            multipartContent.Add(content, "jarFile", request.JarFile.FileName);

            PostContent(context, credentials, multipartContent);
        }