Example #1
0
        public string DownloadNzb(Stream nzb, string title, string category, int priority, NzbgetSettings settings)
        {
            var parameters = new object[] { title, category, priority, false, Convert.ToBase64String(nzb.ToBytes()) };
            var request = BuildRequest(new JsonRequest("append", parameters));

            var response = Json.Deserialize<NzbgetResponse<Boolean>>(ProcessRequest(request, settings));
            _logger.Trace("Response: [{0}]", response.Result);

            if (!response.Result)
            {
                return null;
            }

            var queue = GetQueue(settings);
            var item = queue.FirstOrDefault(q => q.NzbName == title.Substring(0, title.Length - 4));

            if (item == null)
            {
                return null;
            }

            var droneId = Guid.NewGuid().ToString().Replace("-", "");
            var editResult = EditQueue("GroupSetParameter", 0, "drone=" + droneId, item.LastId, settings);

            if (editResult)
            {
                _logger.Debug("Nzbget download drone parameter set to: {0}", droneId);
            }

            return droneId;
        }
 public void AddDeferredMessage(TransportMessage processingTransportMessage, Stream deferredTransportMessageStream)
 {
     using (_databaseConnectionFactory.Create(IdempotenceDataSource))
     {
         _databaseGateway.ExecuteUsing(
             IdempotenceDataSource,
             RawQuery.Create(_scriptProvider.GetScript(Script.IdempotenceSendDeferredMessage))
                     .AddParameterValue(IdempotenceColumns.MessageId, processingTransportMessage.MessageId)
                     .AddParameterValue(IdempotenceColumns.MessageBody, deferredTransportMessageStream.ToBytes()));
     }
 }
Example #3
0
        public SabnzbdAddResponse DownloadNzb(Stream nzb, string title, string category, int priority, SabnzbdSettings settings)
        {
            var request = new RestRequest(Method.POST);
            var action = String.Format("mode=addfile&cat={0}&priority={1}", category, priority);

            request.AddFile("name", nzb.ToBytes(), title, "application/x-nzb");

            SabnzbdAddResponse response;

            if (!Json.TryDeserialize<SabnzbdAddResponse>(ProcessRequest(request, action, settings), out response))
            {
                response = new SabnzbdAddResponse();
                response.Status = true;
            }

            return response;
        }
Example #4
0
        public void Enqueue(Guid messageId, Stream stream)
        {
            try
            {
                using (databaseConnectionFactory.Create(dataSource))
                {
                    databaseGateway.ExecuteUsing(
                        dataSource,
                        RawQuery.CreateFrom(enqueueQueryStatement)
                                .AddParameterValue(QueueColumns.MessageId, messageId)
                                .AddParameterValue(QueueColumns.MessageBody, stream.ToBytes()));
                }
            }
            catch (Exception ex)
            {
                log.Debug(
                    string.Format(
                        "Could not enqueue message id '{0}' on queue '{1}'.  Exception: {2}", messageId, Uri, ex.Message));

                throw;
            }
        }
        private WebHeaderCollection ProcessHeaderStream(HttpRequest request, CookieContainer cookies, Stream headerStream)
        {
            headerStream.Position = 0;
            var headerData = headerStream.ToBytes();
            var headerString = Encoding.ASCII.GetString(headerData);

            var webHeaderCollection = new WebHeaderCollection();

            // following a redirect we could have two sets of headers, so only process the last one
            foreach (var header in headerString.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Reverse())
            {
                if (!header.Contains(":")) break;
                webHeaderCollection.Add(header);
            }

            var setCookie = webHeaderCollection.Get("Set-Cookie");
            if (setCookie != null && setCookie.Length > 0 && cookies != null)
            {
                try
                {
                    cookies.SetCookies((Uri)request.Url, FixSetCookieHeader(setCookie));
                }
                catch (CookieException ex)
                {
                    _logger.Debug("Rejected cookie {0}: {1}", ex.InnerException.Message, setCookie);
                }
            }

            return webHeaderCollection;
        }
Example #6
0
        public void Enqueue(Guid messageId, Stream stream)
        {
            try
            {
                using (_databaseConnectionFactory.Create(_dataSource))
                {
                    _databaseGateway.ExecuteUsing(
                        _dataSource,
                        RawQuery.Create(_enqueueQueryStatement)
                                .AddParameterValue(QueueColumns.MessageId, messageId)
                                .AddParameterValue(QueueColumns.MessageBody, stream.ToBytes()));
                }
            }
            catch (Exception ex)
            {
                _log.Error(
                    string.Format(SqlResources.EnqueueError, messageId, Uri, ex.Message));

                throw;
            }
        }
Example #7
0
        private WebHeaderCollection ProcessHeaderStream(HttpWebRequest webRequest, Stream headerStream)
        {
            headerStream.Position = 0;
            var headerData = headerStream.ToBytes();
            var headerString = Encoding.ASCII.GetString(headerData);

            var webHeaderCollection = new WebHeaderCollection();

            foreach (var header in headerString.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Skip(1))
            {
                webHeaderCollection.Add(header);
            }

            var setCookie = webHeaderCollection.Get("Set-Cookie");
            if (setCookie != null && setCookie.Length > 0 && webRequest.CookieContainer != null)
            {
                webRequest.CookieContainer.SetCookies(webRequest.RequestUri, setCookie);
            }

            return webHeaderCollection;
        }
Example #8
0
 public static Stream Decompress(Stream input) {
     return new MemoryStream(Decompress(input.ToBytes()));
 }
Example #9
0
        /// <summary>
        /// 원본 스트림을 압축하여, 대상 스트림에 씁니다.
        /// </summary>
        /// <param name="sourceStream"></param>
        /// <param name="destinationStream"></param>
        public virtual void CompressAsync(Stream sourceStream, Stream destinationStream) {
            sourceStream.ShouldNotBeNull("sourceStream");
            destinationStream.ShouldNotBeNull("destinationStream");

            var compressedBytes = Compress(sourceStream.ToBytes());
            destinationStream.WriteAsync(compressedBytes, 0, compressedBytes.Length);
        }
Example #10
0
 /// <summary>
 /// 지정된 스트림을 압축합니다.
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public virtual byte[] Compress(Stream input) {
     input.ShouldNotBeNull("input");
     return Compress(input.ToBytes());
 }
Example #11
0
        /// <summary>
        /// 원본 스트림을 압축 해제하여, 대상 스트림에 씁니다.
        /// </summary>
        /// <param name="sourceStream"></param>
        /// <param name="targetStream"></param>
        public virtual void DecompressAsync(Stream sourceStream, Stream targetStream) {
            sourceStream.ShouldNotBeNull("sourceStream");
            targetStream.ShouldNotBeNull("destinationStream");

            var decompresedBytes = Decompress(sourceStream.ToBytes());
            targetStream.WriteAsync(decompresedBytes, 0, decompresedBytes.Length);
            targetStream.SetStreamPosition();
        }
 public override void Store(Stream stream, FileSystemObject fso)
 {
     SaveToMap(stream.ToBytes(), fso);
 }
Example #13
0
        /// <summary>
        /// POST 방식으로 서버에 접속하여 응답 Stream을 반환 받는다.
        /// </summary>
        /// <param name="stream">서버에 전달할 내용</param>
        /// <returns></returns>
        protected virtual Stream PostStream(Stream stream) {
            stream.ShouldNotBeNull("stream");

            if(IsDebugEnabled)
                log.Debug("지정된 스트림을 전송합니다.");

            Request.Credentials = GetCredentials();
            Request.Method = WebRequestMethods.Http.Post;
            Request.ContentType = POST_CONTENT_TYPE;

            if(stream == null) {
                Request.ContentLength = 0;
            }
            if(stream != null) {
                byte[] payload = stream.ToBytes();

                using(var requestStream = Request.GetRequestStream())
                using(var bw = new BinaryWriter(requestStream, XmlTool.XmlEncoding)) {
                    bw.Write(payload);
                }
            }

            return IsAsync
                       ? With.TryFunctionAsync(() => Request.GetResponseStreamAsync().Result)
                       : Request.GetResponse().GetResponseStream();
        }
Example #14
0
 public Task SaveBlobAsync(string container, string key, Stream bloblStream)
 {
     return PostHttpReqest(container, key, bloblStream.ToBytes());
 }
Example #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="requestStream"></param>
        /// <param name="productName"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public static Stream ExecuteStreamInternal(Stream requestStream, string productName, ISerializer serializer) {
            XdsResponseDocument xdsResponse = null;
            MemoryStream result = null;
            try {
                Guard.Assert(requestStream != null && requestStream.Length > 0, "요청 정보가 없습니다.");
                CheckProductExists(productName);

                var xdsRequest = (XdsRequestDocument)serializer.Deserialize(requestStream.ToBytes());
                xdsResponse = XmlDataServiceFacade.Execute(xdsRequest, productName);
            }
            catch(Exception ex) {
                if(log.IsErrorEnabled)
                    log.ErrorException("예외가 발생했습니다.", ex);

                if(xdsResponse == null)
                    xdsResponse = new XdsResponseDocument();
                xdsResponse.ReportError(ex);
            }
            finally {
                result = new MemoryStream(serializer.Serialize(xdsResponse));
            }
            return result;
        }