예제 #1
0
        internal PutLogsResponse PutLogs(PutLogsRequest request, LogGroup logGroup)
        {
            if (logGroup.LogsCount > LogConsts.LIMIT_LOG_COUNT)
            {
                throw new LogException("InvalidLogSize", "logItems' length exceeds maximum limitation: " + LogConsts.LIMIT_LOG_COUNT + " lines.");
            }
            else if (logGroup.SerializedSize > LogConsts.LIMIT_LOG_SIZE)
            {
                throw new LogException("InvalidLogSize", "logItems' size exceeds maximum limitation: " + LogConsts.LIMIT_LOG_SIZE + " byte.");
            }
            using (ServiceRequest sReq = new ServiceRequest())
            {
                sReq.Method   = HttpMethod.Post;
                sReq.Endpoint = BuildReqEndpoint(request);

                //use empty string to replace Logstore if not set by user explicitly
                string logstore = request.IsSetLogstore() ? request.Logstore : String.Empty;
                sReq.ResourcePath = LogConsts.RESOURCE_LOGSTORES + LogConsts.RESOURCE_SEPARATOR + logstore;

                FillCommonHeaders(sReq);
                FillCommonParameters(sReq);
                sReq.Headers.Add(LogConsts.NAME_HEADER_CONTENTTYPE, LogConsts.PBVALUE_HEADER_CONTENTTYPE);
                byte[] logBytes = logGroup.ToByteArray();
                sReq.Headers[LogConsts.NAME_HEADER_BODYRAWSIZE] = logBytes.Length.ToString();
                sReq.Headers.Add(LogConsts.NAME_HEADER_COMPRESSTYPE, LogConsts.VALUE_HEADER_COMPRESSTYPE_LZ4);
                logBytes = LogClientTools.CompressToLz4(logBytes);
                sReq.Headers.Add(LogConsts.NAME_HEADER_MD5, LogClientTools.GetMd5Value(logBytes));
                sReq.Content = new MemoryStream(logBytes);

                ExecutionContext context = new ExecutionContext();
                context.Signer      = new LogRequestSigner(sReq.ResourcePath, HttpMethod.Post);
                context.Credentials = new ServiceCredentials(this.AccessKeyId, this.AccessKey);

                using (ServiceResponse response = serviceClient.Send(sReq, context))
                {
                    LogClientTools.ResponseErrorCheck(response, context.Credentials);
                    PutLogsResponse putLogResp = new PutLogsResponse(response.Headers);
                    return(putLogResp);
                }
            }
        }