Пример #1
0
        public async Task <IHttpActionResult> SearchAsync(String queryStr)
        {
            var youtubeResponse = new YoutubeResponse
            {
                BaseUrl               = "https://www.youtube.com/embed",
                ThumbnailUrl          = "https://img.youtube.com/vi",
                ThumbnailDefaultImage = "mqdefault.jpg"
            };

            try
            {
                var youtubeDataSearchResult = await new YoutubeData().Run(queryStr);
                youtubeResponse.Videos = youtubeDataSearchResult.YoutubeVideos;

                var youtubeSearchLog = new YoutubeSearchLog
                {
                    SearchDateTime     = DateTime.Now,
                    SearchedKeyword    = queryStr,
                    SearchTotalResults = youtubeDataSearchResult.TotalResults
                };

                _youtubeSearchService.AddLog(youtubeSearchLog);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            return(Ok(youtubeResponse));
        }
Пример #2
0
        public async Task <IHttpActionResult> SearchAsyncPost(YoutubeSearchRequest searchRequest)
        {
            var youtubeResponse = new YoutubeResponse
            {
                BaseUrl               = "https://www.youtube.com/embed",
                ThumbnailUrl          = "https://img.youtube.com/vi",
                ThumbnailDefaultImage = "mqdefault.jpg"
            };

            try
            {
                var youtubeDataSearchResult = await new YoutubeData().Run(searchRequest.Keyword);
                youtubeResponse.Videos = youtubeDataSearchResult.YoutubeVideos;

                var youtubeSearchLog = new YoutubeSearchLog
                {
                    SearchDateTime     = DateTime.Now,
                    SearchedKeyword    = searchRequest.Keyword,
                    SearchTotalResults = youtubeDataSearchResult.TotalResults
                };

                var assembly = Assembly.Load(searchRequest.NamespaceName);
                var type     = assembly.GetType(searchRequest.NamespaceName + "." + searchRequest.ClassName);

                var constructor = type.GetConstructor(new Type[] { typeof(YoutubeSearchLogRepository) });
                var classObject = constructor.Invoke(new Object[] { this._youtubeSearchRepository });

                var method = type.GetMethod(searchRequest.MethodName);
                method.Invoke(classObject, new Object[] { youtubeSearchLog });
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            return(Ok(youtubeResponse));
        }
Пример #3
0
 public void AddLog(YoutubeSearchLog youtubeSearchLog)
 {
     _youtubeSearchLogRepository.InsertLog(youtubeSearchLog);
     _youtubeSearchLogRepository.Save();
 }
 public void InsertLog(YoutubeSearchLog searchLog)
 {
     this.context.YoutubeSearchLogs.Add(searchLog);
 }