Пример #1
0
        public override bool CheckResponse(TestContext ctx, Response response)
        {
            if (ReturnContent == null)
            {
                return(ctx.Expect(response.Content, Is.Null, "response.Content"));
            }

            if (!ctx.Expect(response.Content, Is.Not.Null, "response.Content"))
            {
                return(false);
            }
            if (response.Content.HasLength && ReturnContent.HasLength)
            {
                if (!ctx.Expect(response.Content.Length, Is.EqualTo(ReturnContent.Length), "response.Content.Length"))
                {
                    return(false);
                }
                if (!ctx.Expect(response.Content.AsString(), Is.EqualTo(ReturnContent.AsString()), "response.Content.AsString()"))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        public HttpResponseMessage GetCesoredPatent([FromUri] string id)
        {
            string role = HttpContext.Current.Request.Cookies["account"]["role"];

            if (role != "censor")
            {
                Dictionary <string, string> res = new Dictionary <string, string>();
                res.Add("Message", "forbidden");
                return(ConvertToJson(res));
            }
            else
            {
                ReturnData <ReturnContent> res = new ReturnData <ReturnContent>();
                ReturnContent returnContent    = new ReturnContent();
                returnContent.Content = new List <Dictionary <string, string> >();
                try
                {
                    Patent find = db.Patent.FirstOrDefault(Patent => Patent.PatentID.ToString() == id);
                    Dictionary <string, string> mid = new Dictionary <string, string>();
                    mid.Add("PatentID", find.PatentID.ToString());
                    mid.Add("Title", find.Title);
                    mid.Add("IPC", find.IPC.ToString());
                    mid.Add("Abstract", find.Abstract);
                    mid.Add("ApplyDate", find.ApplyDate.ToString());
                    mid.Add("Applicant", find.Applicant);
                    mid.Add("ApplicantAddress", find.ApplicantAddress.ToString());
                    mid.Add("SIPC", find.SIPC.ToString());
                    mid.Add("State", find.State);
                    mid.Add("Agencies", find.Agencies);
                    mid.Add("PublicNum", find.PublicNum);
                    mid.Add("IsPass", find.IsPass.ToString());
                    returnContent.Content.Add(mid);
                }
                catch
                {
                    res.Message = "failed";
                    return(ConvertToJson(res));
                }
                res.Message = "success";
                res.Data    = returnContent;
                return(ConvertToJson(res));
            }
        }
Пример #3
0
        public HttpResponseMessage GetCesoredPaper([FromUri] string id)
        {
            string role = HttpContext.Current.Request.Cookies["account"]["role"];

            if (role != "censor")
            {
                Dictionary <string, string> res = new Dictionary <string, string>();
                res.Add("Message", "forbidden");
                return(ConvertToJson(res));
            }
            else
            {
                ReturnData <ReturnContent> res = new ReturnData <ReturnContent>();
                ReturnContent returnContent    = new ReturnContent();
                returnContent.Content = new List <Dictionary <string, string> >();
                try
                {
                    Paper find = db.Paper.FirstOrDefault(Paper => Paper.PaperID.ToString() == id);
                    Dictionary <string, string> mid = new Dictionary <string, string>();
                    mid.Add("PaperID", find.PaperID.ToString());
                    mid.Add("Title", find.Title);
                    mid.Add("Abstract", find.Abstract);
                    mid.Add("ReferencedNum", find.ReferencedNum.ToString());
                    mid.Add("KeyWord", find.KeyWord);
                    mid.Add("IsFree", find.IsFree.ToString());
                    mid.Add("IsPass", find.IsPass.ToString());
                    mid.Add("Authors", find.Authors);
                    mid.Add("BaiduID", find.BaiduID);
                    mid.Add("PublishYear", find.PublishYear.ToString());
                    returnContent.Content.Add(mid);
                }
                catch
                {
                    res.Message = "failed";
                    return(ConvertToJson(res));
                }
                res.Message = "success";
                res.Data    = returnContent;
                return(ConvertToJson(res));
            }
        }
Пример #4
0
        private async Task<ReturnContent> GetContent(string _requestUri, string language, string package, string pageId)
        {
            WebRequest wrGETURL;
            wrGETURL = WebRequest.Create(_requestUri);

            try
            {
                WebResponse response = await wrGETURL.GetResponseAsync();

                using (StreamReader streamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8, true))
                {
                    ReturnContent _content = new ReturnContent();
                    _content.language = language;
                    _content.package = package;
                    _content.pageId = pageId;
                    _content.content = streamReader.ReadToEnd();
                    return _content;
                }
            }
            catch (Exception)
            {
                System.Diagnostics.Debug.WriteLine("Page Translation Proglem: " + requestUri);

                return new ReturnContent();
            }
        }
Пример #5
0
        /// <summary>
        ///The method hands the return content from a request, the response.
        /// The method allows the calling method to choose a return type.
        /// </summary>
        /// <param name="redcapApi"></param>
        /// <param name="returnContent"></param>
        /// <returns>string</returns>
        public static async Task <string> HandleReturnContent(this RedcapApi redcapApi, ReturnContent returnContent = ReturnContent.count)
        {
            try
            {
                var _returnContent = returnContent.ToString();
                switch (returnContent)
                {
                case ReturnContent.ids:
                    _returnContent = ReturnContent.ids.ToString();
                    break;

                case ReturnContent.count:
                    _returnContent = ReturnContent.count.ToString();
                    break;

                default:
                    _returnContent = ReturnContent.count.ToString();
                    break;
                }
                return(await Task.FromResult(_returnContent));
            }
            catch (Exception Ex)
            {
                Log.Error(Ex.Message);
                return(await Task.FromResult(String.Empty));
            }
        }
Пример #6
0
        public HttpResponseMessage GetCesoredCotent()
        {
            string role = HttpContext.Current.Request.Cookies["account"]["role"];

            if (role != "censor")
            {
                Dictionary <string, string> res = new Dictionary <string, string>();
                res.Add("Message", "forbidden");
                return(ConvertToJson(res));
            }
            else
            {
                ReturnData <ReturnContent> res = new ReturnData <ReturnContent>();
                ReturnContent returnContent    = new ReturnContent();
                returnContent.Content = new List <Dictionary <string, string> >();
                var results =
                    from Review in db.Review
                    select Review;
                //try
                //{
                foreach (var result in results.Take(10))
                {
                    string type   = "暂缺";
                    string detail = "暂缺";
                    Dictionary <string, string> mid = new Dictionary <string, string>();

                    //if (result.UserID != null)
                    //{
                    //    type = "user";
                    //    Users find = db.Users.FirstOrDefault(Users => Users.UserID == result.UserID);
                    //    detail = find.Nickname;
                    //}
                    if (result.PaperID != null)
                    {
                        mid.Add("id", result.PaperID.ToString());
                        type = "paper";
                        Paper find = db.Paper.FirstOrDefault(Paper => Paper.PaperID == result.PaperID);
                        detail = find.Title;
                    }
                    else if (result.PatentID != null)
                    {
                        mid.Add("id", result.PatentID.ToString());
                        type = "patent";
                        Patent find = db.Patent.FirstOrDefault(Patent => Patent.PatentID == result.PatentID);
                        detail = find.Title;
                    }
                    else if (result.CommentID != null)
                    {
                        type = "comment";
                        Comment find = db.Comment.FirstOrDefault(Comment => Comment.CommentID == result.CommentID);
                        detail = find.Content;
                    }
                    mid.Add("type", type);
                    mid.Add("detail", detail);
                    returnContent.Content.Add(mid);
                }
                //}
                //catch
                //{
                //    res.Message = "failed";
                //    return ConvertToJson(res);
                //}
                res.Message = "success";
                res.Data    = returnContent;
                return(ConvertToJson(res));
            }
        }