Пример #1
0
        private static void RunProgram()
        {
            WebClient client = new WebClient();

            fullMagazineList = new List <Magazine>();
            subscribers      = null;


            //Step 1 - Get Token.  All other steps are dependent on this, so  no need to
            //         run asynchronously.
            TokenResponse tokenResponseObject = GetToken(client);
            //Step 2 - Get List of subscribers.  This has no dependencies so
            //         run it asynchronously
            Task subscriberTask = GetSubscribersAsync(tokenResponseObject.token);
            //Step 3 - Get list of categories.  The magazine list needs to use the category
            //         list, so no benefit to running asynchronously.
            CategoryListResponse categories = GetCategoryList(client, tokenResponseObject.token);

            //Step 4 - Get list of magazines.  This method is synchronous, but will create
            //         a task to asynchronously get results for each category.
            GetMagazineList(categories, tokenResponseObject.token);

            //Wait for the asynchronous task to complete before building the answer.
            subscriberTask.Wait();

            //Build the answer
            int    categoryCount = categories.data.Length;
            Answer answer        = BuildAnswer(categoryCount, subscribers);

            //Post the answer and write out the response.
            PostAnswer(answer, tokenResponseObject.token);

            Console.WriteLine("Job has completed. Press <Enter> to end, or <Tab> to run again.");
        }
Пример #2
0
        /// <summary>
        /// Return a list of categories.
        /// </summary>
        /// <param name="client">webclient object</param>
        /// <param name="token">the token string returned with the first call.</param>
        /// <returns>a CaegoryListResponse object with an array of categories</returns>
        private static CategoryListResponse GetCategoryList(WebClient client, string token)
        {
            string categoryListRequest      = string.Concat(C_SITE, String.Format(C_REQUEST_CATEGORIES, token));
            var    categoryListResponse     = client.DownloadString(categoryListRequest);
            CategoryListResponse categories = (CategoryListResponse)JsonConvert.DeserializeObject(categoryListResponse, typeof(CategoryListResponse));

            return(categories);
        }
Пример #3
0
        public override async Task <CategoryListResponse> GetCategories(Empty request, ServerCallContext context)
        {
            var response = new CategoryListResponse();

            await foreach (var category in _db.GetCategoryTree())
            {
                response.Categories.Add(category.ToRpc());
            }

            return(response);
        }
Пример #4
0
 public IActionResult GetList()
 {
     categoryListResponse = categoryService.GetCategories();
     if (categoryListResponse.Success)
     {
         return(Ok(categoryListResponse.categories));
     }
     else
     {
         return(BadRequest(categoryListResponse.Message));
     }
 }
Пример #5
0
        /// <summary>
        /// Makes an asynchronous call for magazines for each category in list
        /// </summary>
        /// <param name="categories">CategoryListResponse object with list of category names</param>
        /// <param name="client"></param>
        /// <param name="tokenString"></param>
        private static void GetMagazineList(CategoryListResponse categories, string tokenString)
        {
            using (var httpClient = new HttpClient())
            {
                List <Task> taskList = new List <Task>();
                foreach (string categoryName in categories.data)
                {
                    string magazineRequest = string.Concat(C_SITE, string.Format(C_REQUEST_MAGAZINES, tokenString, categoryName));
                    Task   newTask         = GetMagazineListForCategoryAsync(httpClient, magazineRequest);
                    taskList.Add(newTask);
                }

                //We created a task for each category.
                //wait for them all to complete before we exit the procedure
                foreach (Task t in taskList)
                {
                    t.Wait();
                }
            }
        }
Пример #6
0
        public IHttpActionResult GetWallpaperCategory()
        {
            List <CategoryInfo> categoryList = new List <CategoryInfo>();

            categoryList.Add(new CategoryInfo {
                Id = 1, CategoryName = "Category 1", Photo = "www.testdomain.com/photo/image1.jpg", Added = DateTime.Now
            });
            categoryList.Add(new CategoryInfo {
                Id = 2, CategoryName = "Category 2", Photo = "www.testdomain.com/photo/image2.jpg", Added = DateTime.Now
            });

            var response = new CategoryListResponse
            {
                Data = new CategoryListResponse.ResponseData
                {
                    CategoryList = categoryList,
                    SyncDateTime = DateTimeOffset.Parse(DateTime.Now.ToString()).UtcDateTime
                }
            };

            return(Ok(response));
        }
        public async Task <IActionResult> GetCategories()
        {
            CategoryListResponse categoryListResponse = await soundpadService.GetCategories();

            return(categoryListResponse == null?NotFound("No categories exist.") : Ok(categoryListResponse));
        }