예제 #1
0
 public ApiRequest(StacManClient client, ApiUrlBuilder ub, HttpMethod httpMethod, string backoffKey)
 {
     Client     = client;
     UrlBuilder = ub;
     HttpMethod = httpMethod;
     BackoffKey = backoffKey;
 }
예제 #2
0
        public void LoadQuestions()
        {
            var client = new StacManClient();
            var response = client.Questions.GetAll(StackoverflowSite, page: 1, pagesize: 100, sort: AllSort.Creation, order: Order.Desc, tagged: _config.SelectedCategory).Result;

            questions = response.Data.Items.Select(x => new Question {Title = x.Title, Url = x.Link}).ToList();
        }
예제 #3
0
 public ApiRequest(StacManClient client, ApiUrlBuilder ub, string backoffKey)
 {
     Client     = client;
     UrlBuilder = ub;
     BackoffKey = backoffKey;
 }
        static void Main(string[] args)
        {
            StackExchange.StacMan.StacManClient stackAppClient = new StackExchange.StacMan.StacManClient("IWxKGhjr9yw)JT7GHEQGaA((", "2.1");

            DateTime startDate = DateTime.Now.AddDays(-1);
            DateTime endDate   = DateTime.Now;

            //DateTime startDate = DateTime.Parse("2017-01-01 00:00:00");
            //DateTime endDate = DateTime.Parse("2020-09-27 23:59:59");

            Task <StackExchange.StacMan.StacManResponse <Question> > mainQueryQuestiontask = stackAppClient.Search.GetMatchesAdvanced("stackoverflow.com", "withbody", null, null, startDate, endDate, null, null, null, null, null, null, null, true, 2);

            StacManResponse <Question> listOfQuestions = mainQueryQuestiontask.Result;

            List <int> listOfQuestionIds = new List <int>();

            foreach (Question q in listOfQuestions.Data.Items)
            {
                listOfQuestionIds.Add(q.QuestionId);
            }

            // now we have a list of questions with an accepted answer and more than one answer.
            // for each question
            // get the question title and question body  .. this will be one row.

            // get the question title and bodies and accepted answer id associated with list of question ids.
            Task <StackExchange.StacMan.StacManResponse <Question> > questionstask = stackAppClient.Questions.GetByIds("stackoverflow.com", listOfQuestionIds, "withbody");

            StackExchange.StacMan.StacManResponse <Question> listOfQuestionInfo = questionstask.Result;



            Task <StackExchange.StacMan.StacManResponse <Answer> > answerstask = stackAppClient.Questions.GetAnswers("stackoverflow.com", listOfQuestionIds, "withbody");

            StackExchange.StacMan.StacManResponse <Answer> listOfAnswerInfo = answerstask.Result;



            List <int> answers = new List <int>();
            List <int> questionsWithAcceptedanswer = new List <int>();

            Dictionary <int, List <int> > allAnswersWithQuestions          = new Dictionary <int, List <int> >();
            Dictionary <int, List <int> > allAnswersWithQuestionsFinalList = new Dictionary <int, List <int> >();

            //foreach (var answer in listOfAnswers.Data.Items)
            //{
            //    Console.WriteLine(" Quesiton Is " + answer.QuestionId.ToString() + " answer is " + answer.AnswerId.ToString());

            //    if (allAnswersWithQuestions.ContainsKey(answer.QuestionId) == false)
            //    {
            //        allAnswersWithQuestions.Add(answer.QuestionId, new List<int>());
            //    }

            //    allAnswersWithQuestions[answer.QuestionId].Add(answer.AnswerId);

            //    if (answer.IsAccepted == true)
            //    {
            //        if (questionsWithAcceptedanswer.Contains(answer.QuestionId) == false)
            //        {
            //            questionsWithAcceptedanswer.Add(answer.QuestionId);
            //            Console.WriteLine(" Quesiton With accepted answer : Question is " + answer.QuestionId.ToString() + " accepted answer is " + answer.AnswerId.ToString());
            //        }
            //    }

            //    //Console.WriteLine(answer.Title);
            //    //Console.WriteLine(answer.Comments);
            //    //Console.WriteLine(answer.QuestionId);
            //}

            //if (questionsWithAcceptedanswer.Count > 0)
            //{
            //Console.WriteLine("There are questions with an accepted answer");

            // loop throught questions with accepted answer;
            //  find that question in the first list and copy it to the final list;

            //foreach (int question in allAnswersWithQuestions.Keys)
            //{
            //    allAnswersWithQuestionsFinalList.Add(question, allAnswersWithQuestions[question]);
            //    Console.WriteLine("Question with accepted answer to final list is " + question.ToString());


            //    List<int> tempQuestion = new List<int>();
            //    tempQuestion.Add(question);

            //    Task<StackExchange.StacMan.StacManResponse<Question>> questiontask = stackAppClient.Questions.GetByIds("stackoverflow.com", tempQuestion, "withbody");
            //    StackExchange.StacMan.StacManResponse<Question> returnedQuestion = questiontask.Result;


            //    //int theanswers = returnedQuestion.Data.Items.Length;

            //    Question q2 = (Question)returnedQuestion.Data.Items[0];

            //    string questiontitle = q2.Title;

            //    //int? acceptedAnswerID = q2.AcceptedAnswerId;
            //    //int? numberAnswers = q2.AnswerCount;

            //    List<int> answerList = new List<int>();


            //    //for (int index = 1; index <= numberAnswers; index++)
            //    //{
            //      //  int? answer = q2.Answers[index - 1].AnswerId;
            //    answerList.Add(allAnswersWithQuestions[question][0]);
            //    //                  }

            //    // from this build the IEnumberable<int> and then then
            //    Task<StackExchange.StacMan.StacManResponse<Answer>> answertask = stackAppClient.Answers.GetByIds("stackoverflow.com", answerList, "withbody");

            //    StackExchange.StacMan.StacManResponse<Answer> returnedAnswer = answertask.Result;

            //    string answerBody = returnedAnswer.Data.Items[0].Body;


            //}

            //IEnumerable<int> queryQuestionsWithAcceptedAnswer =
            //from answer in allAnswersWithQuestions.Keys
            //from question in questionsWithAcceptedanswer where questionsWithAcceptedanswer.Contains(answer) select answer;

            //IEnumerator<int> iter = queryQuestionsWithAcceptedAnswer.GetEnumerator();

            //while (true)
            //{
            //  if (iter.MoveNext() == true)
            //Console.WriteLine("Question with accepted answer from main collection  is " + iter.Current);
            //}
            //}
            //var questions = stackAppClient.Questions.GetByIds("stackoverflow", answers).Result;
            //StringBuilder str = new StringBuilder();

            //foreach (var question in questions.Data.Items)
            //{
            //    str.Append(question.Title);
            //    str.Append("  ");
            //    str.AppendLine(question.Body);
            //    string line = str.ToString();

            //    Console.WriteLine(line);
            //}
        }
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (isValidUser)
            {
                try
                {
                    var client = new StacManClient(FilterBehavior.Strict, key: "QSWiEZktKmMv8QlQObPl8Q((");
                    var request = client.Users.GetByIds("stackoverflow", new int[] { userId });
                    int rep = request.Result.Data.Items[0].Reputation;

                    string sign = "";
                    string diffString = "";
                    System.Windows.Visibility visibility = System.Windows.Visibility.Hidden;

                    int diff = rep - lastRep;
                    if (diff != 0)
                    {
                        if (diff > 0) sign = "+";
                        diffString = sign + DisplayTruncated(diff.ToString("#,###"));
                        visibility = System.Windows.Visibility.Visible;
                    }
                    currentRep = rep;

                    var time = DateTime.Now;
                    UpdateUI(
                        (Action)(() =>
                        {
                            DiffLabel.Content = diffString;
                            DiffLabel.Visibility = visibility;
                            ValLabel.Content = rep.ToString("#,###");
                            LastUpdLabel.Content = time.ToShortTimeString();
                            DiscImg.Visibility = System.Windows.Visibility.Hidden;
                        }));
                }
                catch
                {
                    UpdateUI(
                        (Action)(() =>
                        {
                            DiscImg.ToolTip = "Connection failed";
                            DiscImg.Visibility = System.Windows.Visibility.Visible;
                        }));
                }
            }
        }