Example #1
0
        public string GetFindAllSql(DtoSearch <T> inSearch, string whereSql = "")
        {
            if (inSearch.OrderType == null)
            {
                string key = GetKeyField().Value;
                inSearch.OrderType = string.Format("{0} DESC", key);
            }

            if (!string.IsNullOrEmpty(whereSql))
            {
                whereSql = " where " + whereSql;
            }

            if (inSearch.PageIndex < 1)
            {
                inSearch.PageIndex = 1;
            }
            if (inSearch.PageSize < 1)
            {
                inSearch.PageSize = 10;
            }
            string sql = string.Format(@"
                select {0} from {1} {2} ORDER  BY  {5} limit {3},{4};
                ",
                                       string.Join(",", GetTableFields(null, inSearch.IgnoreFieldList).Select(x => x.Value + " " + x.Key)),
                                       GetTableName(),
                                       whereSql,
                                       (inSearch.PageIndex - 1) * inSearch.PageSize,
                                       inSearch.PageSize,
                                       inSearch.OrderType
                                       );

            return(sql);
        }
Example #2
0
        public void TestDummyRequest()
        {
            HttpRequest req = new HttpRequest();

            req.BaseUrl("http://ws.audioscrobbler.com/2.0");
            req.AddParameter("format", "json");
            req.AddParameter("api_key", LastFmAPI.API_KEY);

            /*
             * Search for band Muse
             */
            DtoSearch dto = (DtoSearch)req.Get(
                "?method=artist.search&artist=muse",
                typeof(DtoSearch));

            Assert.AreEqual("Muse", dto.Results.ArtistMatches.Artist[0].Name);
            Assert.AreEqual("Mouse on Mars", dto.Results.ArtistMatches.Artist[3].Name);

            /*
             * Get top tracks from Australia
             */
            DtoGeoTopTracks aus = (DtoGeoTopTracks)req.Get(
                "?method=geo.gettoptracks&country=australia",
                typeof(DtoGeoTopTracks));
            List <Track> tracks = aus.Tracks.Track;

            Assert.AreEqual("The Less I Know the Better", tracks[0].Name);
            Assert.AreEqual("Mr. Brightside", tracks[1].Name);
            Assert.AreEqual("The Killers", tracks[1].Artist.Name);
        }
        public JsonResult GetLessonLog(int courseid, DtoSearch search)
        {
            LessonBll bll  = new LessonBll();
            var       list = bll.GetLessonLogByPage(courseid, search);

            return(Json(AbhsTableFactory.Create(list, search.Pagination.TotalCount)));
        }
Example #4
0
        public void TestUploadAndSearchAngelinaJolie()
        {
            HttpClient client = new HttpClient();
            MultipartFormDataContent content = new MultipartFormDataContent(Guid.NewGuid().ToString());

            StringContent api_key = new StringContent("oxzC5V_7DvpM7uNQITr2ICdBKs1S1f2V");

            content.Add(api_key, "api_key");

            StringContent api_secret = new StringContent("IElJ3_FXpUrOxeFMYzcUziNLQq-WLX3W");

            content.Add(api_secret, "api_secret");

            byte[]           file = File.ReadAllBytes(@"C:\Users\bfillon\documents\visual studio 2015\Projects\FaceOne\FaceOneWebAPI.Tests\AngelinaJolie2.jpg");
            ByteArrayContent f    = new ByteArrayContent(file);

            f.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg");

            content.Add(f, "image_file", "image.jpg");

            HttpResponseMessage response = Task.Run <HttpResponseMessage>(() => client.PostAsync("https://api.megvii.com/facepp/v3/detect", content)).Result;

            Assert.IsTrue(response.IsSuccessStatusCode);

            DtoDetect result = JsonConvert.DeserializeObject <DtoDetect>(response.Content.ReadAsStringAsync().Result);

            Assert.AreEqual(1, result.faces.Length); // une seule personne sur la photo
            Assert.IsNotNull(result.faces[0].face_token);


            string angelinaToken = result.faces[0].face_token;

            // Get face_token into Faceset
            StringContent sContent = new StringContent("api_key=oxzC5V_7DvpM7uNQITr2ICdBKs1S1f2V&api_secret=IElJ3_FXpUrOxeFMYzcUziNLQq-WLX3W", System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");

            response = Task.Run <HttpResponseMessage>(() => client.PostAsync("https://api.megvii.com/facepp/v3/faceset/getfacesets", sContent)).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);

            DtoGetFaceSets fsresult      = JsonConvert.DeserializeObject <DtoGetFaceSets>(response.Content.ReadAsStringAsync().Result);
            string         faceset_token = fsresult.facesets[0].faceset_token;

            // Search for Angelina
            sContent = new StringContent("api_key=oxzC5V_7DvpM7uNQITr2ICdBKs1S1f2V&api_secret=IElJ3_FXpUrOxeFMYzcUziNLQq-WLX3W&face_token=" + angelinaToken + "&faceset_token=" + faceset_token, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");

            response = Task.Run <HttpResponseMessage>(() => client.PostAsync("https://api.megvii.com/facepp/v3/search", sContent)).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);

            DtoSearch searchresult = JsonConvert.DeserializeObject <DtoSearch>(response.Content.ReadAsStringAsync().Result);

            Assert.AreEqual(1, searchresult.results.Length);
            Assert.IsNotNull(searchresult.results[0].face_token);
            Assert.AreEqual("Angelina Jolie", searchresult.results[0].user_id);

            Console.WriteLine(searchresult.results[0].confidence);
        }
        public async Task <ResultObj <SysQueryEntity> > FindAllPage(DtoSearch inSearch)
        {
            var reObj  = new ResultObj <SysQueryEntity>();
            var reList = await dal.FindAllS <SysQueryEntity, KV>(inSearch);

            reObj.dataList = reList.Item1.ToList();
            if (reList.Item2 != null && reList.Item2.Count() > 0)
            {
                reObj.msg = reList.Item2.ToList()[0].v;
            }
            return(reObj);
        }
Example #6
0
        /// <summary>
        /// 根据课程id及分页信息获取日志数据
        /// </summary>
        /// <param name="courseid"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public List <DtoLessonLog> GetLessonLogByPage(int courseid, DtoSearch search)
        {
            var list = LessonProcessServer.SelectProcessByCourseByPage(courseid, search);
            var emp  = EmployeeServer.GetEmployeeNameByIds(list.Select(l => l.Ylp_Operator).Distinct().ToList());

            return(list.Select(s => new DtoLessonLog
            {
                ID = s.Ylp_Id,
                Operator = s.Ylp_Operator,
                OperatorName = emp.ContainsKey(s.Ylp_Operator) ? emp[s.Ylp_Operator] : "",
                Remark = s.Ylp_Remark,
                Status = s.Ylp_Status,
                CreateTime = s.Ylp_CreateTime
            }).ToList());
        }
Example #7
0
        /// <summary>
        /// 查看满足条件的数量
        /// </summary>
        /// <param name="inSearch"></param>
        /// <returns></returns>
        public string GetFindNumSql(DtoSearch inSearch)
        {
            string sql = "SELECT Count(1) num FROM {0} WHERE {1}";

            if (inSearch.FilterList == null)
            {
                sql = "SELECT  Count(1) num FROM {0}";
                sql = string.Format(sql, GetTableName());
            }
            else
            {
                sql = string.Format(sql,
                                    GetTableName(),
                                    string.Join(" AND ", inSearch.FilterList.Select(x => string.Format("convert(nvarchar(max),{0})=@{0}", x.Key)))
                                    );
            }
            return(sql);
        }
Example #8
0
        public static DtoSearch ToDTO(this Repository.Model.Products.Search model)
        {
            if (model == null)
            {
                return(null);
            }
            var dto = new DtoSearch();

            dto.Categories = model.Categories;
            dto.Principles = model.Principles;
            dto.Producer   = model.Producer;
            dto.Product    = model.Product;
            dto.ProductId  = model.ProductId;
            dto.Serving    = model.Serving;
            dto.SkuName    = model.SkuName;
            dto.SkuId      = model.SkuId;
            dto.Image      = model.Image;

            return(dto);
        }
Example #9
0
        private static DtoSearch DtoSearchInit()
        {
            var dtoSearch = new DtoSearch
            {
                Results = new DtoResults {
                    ArtistMatches = new DtoArtistMatches {
                        Artist = new List <Artist>()
                    }
                }
            };
            var artist1 = new Artist {
                Name = "Black Sabbath"
            };
            var artist2 = new Artist {
                Name = "Black Eyed Peas"
            };

            dtoSearch.Results.ArtistMatches.Artist.Add(new Artist());
            dtoSearch.Results.ArtistMatches.Artist.Add(artist1);
            dtoSearch.Results.ArtistMatches.Artist.Add(artist2);
            return(dtoSearch);
        }
Example #10
0
        public string[] GetFindAllAndCountSql(DtoSearch inSearch)
        {
            string key = GetKeyField().Value;

            if (string.IsNullOrEmpty(inSearch.OrderType))
            {
                inSearch.OrderType = string.Format("{0} DESC", key);
            }
            string whereSql = "";

            if (inSearch.FilterList != null && inSearch.FilterList.Count() > 0)
            {
                whereSql = " where " + string.Join(" AND ", inSearch.FilterList.Select(x => string.Format("{0}=@{0}", x)));
            }
            if (inSearch.PageIndex < 1)
            {
                inSearch.PageIndex = 1;
            }
            if (inSearch.PageSize < 1)
            {
                inSearch.PageSize = 10;
            }
            string sql = string.Format(@"
                select {0} from {1} {2} ORDER  BY  {5} limit {3},{4};
                select count(1) V from {1} {2}
                ",
                                       string.Join(",", GetTableFields(null, inSearch.IgnoreFieldList).Select(x => x.Value + " " + x.Key)),
                                       GetTableName(),
                                       whereSql,
                                       (inSearch.PageIndex - 1) * inSearch.PageSize,
                                       inSearch.PageSize,
                                       inSearch.OrderType
                                       );

            return(sql.Split(';'));
        }
        public async Task <List <SysQueryEntity> > FindAll(DtoSearch inSearch)
        {
            var reList = await dal.FindAll(inSearch);

            return(reList.ToList());
        }
Example #12
0
        public string Post([FromBody] JToken base64image)
        {
            string str = base64image.ToString();

            str = str.Split(',')[1];

            try
            {
                File.WriteAllBytes(Path.GetTempPath() + @"\yourfile.png", Convert.FromBase64String(str));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


            HttpClient client = new HttpClient();
            MultipartFormDataContent content = new MultipartFormDataContent(Guid.NewGuid().ToString());

            StringContent api_key = new StringContent("oxzC5V_7DvpM7uNQITr2ICdBKs1S1f2V");

            content.Add(api_key, "api_key");

            StringContent api_secret = new StringContent("IElJ3_FXpUrOxeFMYzcUziNLQq-WLX3W");

            content.Add(api_secret, "api_secret");

            byte[]           file = File.ReadAllBytes(Path.GetTempPath() + @"\yourfile.png");
            ByteArrayContent f    = new ByteArrayContent(file);

            f.Headers.ContentType = MediaTypeHeaderValue.Parse("image/png");

            content.Add(f, "image_file", "image.png");

            String s = Task.Run <String>(() => content.ReadAsStringAsync()).Result;

            Console.WriteLine(s);

            HttpResponseMessage response = Task.Run <HttpResponseMessage>(() => client.PostAsync("https://api.megvii.com/facepp/v3/detect", content)).Result;

            DtoDetect result = JsonConvert.DeserializeObject <DtoDetect>(response.Content.ReadAsStringAsync().Result);


            string token = result.faces[0].face_token;

            // Get face_token into Faceset
            StringContent sContent = new StringContent("api_key=oxzC5V_7DvpM7uNQITr2ICdBKs1S1f2V&api_secret=IElJ3_FXpUrOxeFMYzcUziNLQq-WLX3W", System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");

            response = Task.Run <HttpResponseMessage>(() => client.PostAsync("https://api.megvii.com/facepp/v3/faceset/getfacesets", sContent)).Result;

            DtoGetFaceSets fsresult      = JsonConvert.DeserializeObject <DtoGetFaceSets>(response.Content.ReadAsStringAsync().Result);
            string         faceset_token = fsresult.facesets[0].faceset_token;

            // Search for token
            sContent = new StringContent("api_key=oxzC5V_7DvpM7uNQITr2ICdBKs1S1f2V&api_secret=IElJ3_FXpUrOxeFMYzcUziNLQq-WLX3W&face_token=" + token + "&faceset_token=" + faceset_token, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");

            response = Task.Run <HttpResponseMessage>(() => client.PostAsync("https://api.megvii.com/facepp/v3/search", sContent)).Result;

            DtoSearch searchresult = JsonConvert.DeserializeObject <DtoSearch>(response.Content.ReadAsStringAsync().Result);

            Console.WriteLine(searchresult.results[0].user_id);

            string newUserIdComingFromSF = searchresult.results[0].user_id; // "0030Y000008AjMD";

            SalesforceHelper.NotifyDetection(newUserIdComingFromSF);


            return(searchresult.results[0].user_id);
        }
 /// <summary>
 /// 根据课程id查找历史数据
 /// </summary>
 /// <param name="courseId"></param>
 /// <returns></returns>
 public List <Yw_CourseLessonProcess> SelectProcessByCourseByPage(int courseId, DtoSearch search)
 {
     return(base.QueryPaging <Yw_CourseLessonProcess>("*", "Yw_CourseLessonProcess where [Ylp_CourseId] = @courseid", "Ylp_CreateTime desc", search.Pagination, new { courseid = courseId }).ToList());
 }