Beispiel #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.");
        }
Beispiel #2
0
        public static SubscriberResponse GetUserSubscriber(SubscriberRequest request)
        {
            Service            client   = new Service();
            SubscriberResponse response = client.GetUserSubscriber(request);

            return(response);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="categoryCount"></param>
        /// <param name="subscribers"></param>
        /// <returns></returns>
        private static Answer BuildAnswer(int categoryCount, SubscriberResponse subscribers)
        {
            Answer        answer          = new Answer();
            List <string> fullSubscribers = new List <string>();


            foreach (Subscriber s in subscribers.data)
            {
                //This linq statement gets the distinct list of categories
                // in this subscriber's list, then gets the count.

                var subScriberCatCount = (from cc in s.magazineIds
                                          join mag in fullMagazineList
                                          on cc equals mag.id
                                          select mag.category).Distinct().Count();

                //If the count of this subscriber's categories = the total count of
                //subscriber categories, add to the list.
                if (subScriberCatCount == categoryCount)
                {
                    fullSubscribers.Add(s.id);
                }
            }
            answer.description = "Answer Description";
            answer.subscribers = fullSubscribers.ToArray();
            return(answer);
        }
        private void GetSubscribers()
        {
            string             endpoint = String.Format("api/subscribers/{0}", this.Token);
            SubscriberResponse response = JsonConvert.DeserializeObject <SubscriberResponse>(this.ExecuteGet(endpoint));

            this.ValidateResponse(response, endpoint);
            this.Subscribers = response.data;
        }
Beispiel #5
0
        /// <summary>
        /// Asynchronous call to get a list of subscribers
        /// </summary>
        /// <param name="token">token string retrieved at beginning of run</param>
        /// <returns>Task.  Also populated the subscribers object.</returns>
        private static async Task GetSubscribersAsync(string token)
        {
            using (var httpClient = new HttpClient())
            {
                string subscriberRequest  = string.Concat(C_SITE, String.Format(C_REQUEST_SUBSCRIBERS, token));
                var    subscriberResponse = await httpClient.GetStringAsync(subscriberRequest);

                subscribers = (SubscriberResponse)JsonConvert.DeserializeObject(subscriberResponse, typeof(SubscriberResponse));
            }
        }
Beispiel #6
0
        public static SubscriberResponse GetUserSubscriber(SubscriberRequest request)
        {
            SubscriberResponse response = new SubscriberResponse();

            using (SqlConnection con = new SqlConnection(Variables.PaymentSystemDBConnection))
            {
                try
                {
                    con.Open();
                    using (SqlCommand cmd = new SqlCommand(SQLConstants.SP_GET_USER_SUBSCRIBER, con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@IDENTIFICATION_TAX_NUMBER", request.IdentificationTaxNumber);

                        SqlDataAdapter adapter = new SqlDataAdapter();
                        adapter.SelectCommand = cmd;
                        DataTable table = new DataTable();
                        adapter.Fill(table);

                        if (table.Rows.Count > 0)
                        {
                            response.SubscriberId            = Convert.ToInt32(table.Rows[0]["SUBSCRIBER_ID"]);
                            response.Name                    = table.Rows[0]["NAME"].ToString();
                            response.Surname                 = table.Rows[0]["SURNAME"].ToString();
                            response.SubscriberTypeId        = Convert.ToInt32(table.Rows[0]["SUBSCRIBER_TYPE_ID"]);
                            response.SubscriberTypeName      = table.Rows[0]["SUBSCRIBER_TYPE_NAME"].ToString();
                            response.IdentificationTaxNumber = table.Rows[0]["IDENTIFICATION_TAX_NUMBER"].ToString();
                            response.SubscriptionId          = Convert.ToInt32(table.Rows[0]["SUBSCRIPTION_ID"]);
                            response.SubscriptionType        = table.Rows[0]["SUBSCRIPTION_TYPE"].ToString();
                            response.Active                  = Convert.ToBoolean(table.Rows[0]["ACTIVE"]);
                            response.InsertUser              = table.Rows[0]["INSERT_USER"].ToString();
                            response.InsertDate              = Convert.ToDateTime(table.Rows[0]["INSERT_DATE"].ToString());
                            response.UpdateUser              = table.Rows[0]["UPDATE_USER"].ToString();
                            if (!String.IsNullOrEmpty(table.Rows[0]["UPDATE_DATE"].ToString()))
                            {
                                response.UpdateDate = Convert.ToDateTime(table.Rows[0]["UPDATE_DATE"].ToString());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }

            return(response);
        }
        public async Task <IActionResult> Subscriber()
        {
            SubscriberResponse response = new SubscriberResponse();
            var message = await _subscriberService.PeekNextMessage();

            if (message != null)
            {
                response.Message = message;
            }
            else
            {
                response.ErrorMessage = "No messages found.";
            }

            return(Ok(response));
        }
Beispiel #8
0
        protected void SearchButton_Click(object sender, EventArgs e)
        {
            if (IdentificationTaxNumberTextBox.Text.Trim().Equals(""))
            {
                LabelWarning.Text = "Abone Bulunamadı!";
                return;
            }

            Subscriber = WebServiceHelpers.GetUserSubscriber(new SubscriberRequest()
            {
                IdentificationTaxNumber = IdentificationTaxNumberTextBox.Text.Trim()
            });

            if (Subscriber.SubscriberId > 0)
            {
                FillGrid();
            }
            else
            {
                LabelWarning.Text = "Abone Bulunamadı!";
            }
        }
 public void Init()
 {
     instance = new SubscriberResponse();
 }