Пример #1
0
        public override void ProcessGet()
        {
            bool IsSuccess = false;

            if (RequestUrl.Contains("print.pdf"))
            {
                string pid = string.Empty;
                if (ServiceRequest.QueryString.Get("pid") != null)
                {
                    pid = ServiceRequest.QueryString.Get("pid").ToString();
                }
                if (!string.IsNullOrEmpty(pid))
                {
                    // Read html content from template
                    string       template = string.Empty;
                    StreamReader sr;
                    try
                    {
                        sr       = File.OpenText(ServiceContext.Server.MapPath("/Assets/cors/Agreement.html"));
                        template = sr.ReadToEnd();
                        sr.Close();
                    }
                    catch
                    {
                    }
                    if (!string.IsNullOrEmpty(template))
                    {
                        // Replace texts
                        //template = template.Replace("<%Name%>", "jithesh");

                        Document pdfDoc      = new Document(PageSize.A4, 10, 10, 10, 10);
                        string   destination = ServiceContext.Server.MapPath("/Assets/Media/Property/");
                        try
                        {
                            PdfWriter.GetInstance(pdfDoc, new FileStream(destination + pid + "/" + pid + "_" + DateTime.UtcNow.ToString("yyyyMMdd") + ".pdf", FileMode.Create));
                            pdfDoc.Open();
                            var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(template), null);
                            foreach (var htmlElement in parsedHtmlElements)
                            {
                                pdfDoc.Add(htmlElement as IElement);
                            }
                            pdfDoc.Close();
                            IsSuccess = true;
                        }
                        catch
                        {
                        }
                    }
                }
            }
            if (IsSuccess)
            {
                PostResponse("Created");
            }
            else
            {
                PostResponse("Failed");
            }
        }
        private void UrlButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (_currentToken.IsNullOrEmpty())
            {
                MessageBox.Show(this, "请获取token后查询");
                return;
            }
            var realurl = string.Format(RequestUrl.Contains("?") ? @"{0}&access_token={1}" : @"{0}?access_token={1}",
                                        RequestUrl, CurrentToken);

            if (RequestType.ToUpper() == "POST")
            {
                var responsejson = HttpHelper.HttpRequestPost(realurl, RequestBody);
                ResponseBody = responsejson;
            }
            if (RequestType.ToUpper() == "GET")
            {
                var responsejson = HttpHelper.HttpRequestGet(realurl);
                ResponseBody = responsejson;
            }

            UrlList.Add(RequestUrl);
        }
Пример #3
0
        public override async Task <IEnumerable <LuoVol> > GetVolsAsync()
        {
            //网络请求获得原料
            // 暂用新的API
            // check if it's tag request
            if (!RequestUrl.Contains("tag"))
            {
                //var result = await _cloudService.GetVolsAsync_w(Offset, Count, GetCancellationToken(), RequestUrl);
                var result = await _cloudService.GetNumVolsAsync_w(Offset, Count, GetCancellationToken(), RequestUrl);

                if (result != null)
                {
                    //工厂加工,获得成品
                    var volList = _VolFactory.GetVols(result);
                    // to realize 20 each time
                    if ((volList.Count - (Page - LastPage) * Count) > Count)
                    {
                        //the rest is more than 20
                        var list = volList.ToList().GetRange((Page - LastPage) * Count, Count);
                        return(list);
                    }
                    else
                    {
                        //the rest is less than 20
                        var list = volList.Skip((Page - LastPage) * Count);
                        Offset   = Offset + 1;
                        LastPage = Page + 1;
                        return(list);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                var result = await _cloudService.GetTagVolsAsync_w(TagOffset, Count, GetCancellationToken(), RequestUrl);

                if (result != null)
                {
                    //工厂加工,获得成品
                    var volList = _VolFactory.GetVols(result);
                    // to realize 20 each time
                    if ((volList.Count - (Page - TagLastPage) * Count) > Count)
                    {
                        //the rest is more than 20
                        var list = volList.ToList().GetRange((Page - TagLastPage) * Count, Count);
                        return(list);
                    }
                    else
                    {
                        //the rest is less than 20
                        var list = volList.Skip((Page - TagLastPage) * Count);
                        TagOffset   = TagOffset + 1;
                        TagLastPage = Page + 1;
                        return(list);
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Token认证
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        public async Task Invoke(HttpContext httpContext)
        {
            PreProceed(httpContext);

            if (!RequestUrl.Contains(httpContext.Request.Path.Value.ToLower()))
            {
                //是否包含Authorization请求头
                if (!httpContext.Request.Headers.ContainsKey("Authorization"))
                {
                    PostProceed(httpContext);
                    ResponseModel responseModel = new ResponseModel()
                    {
                        Code    = ResponseCode.Error,
                        Message = MessageModel.InvalidToken
                    };
                    await ResponseUnAuth(httpContext, responseModel);
                }
                else
                {
                    var tokenHeader = httpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", "");

                    if (tokenHeader.Length >= 128)
                    {
                        JwtTokenModel tm = JwtHelper.SerializeJwt(tokenHeader);

                        // 是否过期
                        if (DateTime.Now.CompareTo(tm.Expiration) <= 0)
                        {
                            var claims = new List <Claim> {
                                new Claim(ClaimTypes.Sid, tm.Uid.ToString()),
                                new Claim(ClaimTypes.Name, tm.Name)
                            };
                            claims.AddRange(tm.Role.Split('|').Select(s => new Claim(ClaimTypes.Role, s)));
                            var identity  = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                            var principal = new ClaimsPrincipal(identity);
                            httpContext.User = principal;

                            PostProceed(httpContext);
                            await _next(httpContext);
                        }
                        else
                        {
                            ResponseModel responseModel = new ResponseModel()
                            {
                                Code    = ResponseCode.Error,
                                Message = MessageModel.ExpirationToken
                            };
                            await ResponseUnAuth(httpContext, responseModel);
                        }
                    }
                    else
                    {
                        ResponseModel responseModel = new ResponseModel()
                        {
                            Code    = ResponseCode.Error,
                            Message = MessageModel.InvalidToken
                        };
                        await ResponseUnAuth(httpContext, responseModel);
                    }
                }
            }
            else
            {
                PostProceed(httpContext);
                await _next(httpContext);
            }
        }