void RequestKeywordsForNextTagId()
 {
     if (_stopComputingCandidates || _tagIdsToProcess.Count == 0)
     {
         _computingCandidates = false;
         _stopComputingCandidates = false;
         Invoke((Action)(() =>
         {
             StatusText.Text = "";
             StatusProgressBar.Value = 0;
         }));
         return;
     }
     int tagsLeft = _tagIdsToProcess.Count;
     int tagId = _tagIdsToProcess.Dequeue();
     GeneralQuery query = new GeneralQuery(new QGeneralParams() { ResultData = QResultData.keywordData, KeywordCount = _keywordsForTagCount, SampleSize = -1, KeywordMethod = GetKeywordMethod(_keywordsForTagMethod) },
         new QArgs(new QTagIdCond(tagId)));
     string requestId;
     string request = Defaults.BuildRequest(PublisherName, "Query", query.ToString(), out requestId);
     SendRequest(request, requestId, "keywordsForTagId");
     Invoke((Action)(() => {
         string tagName = _tagIdToTagInfo[tagId].TagName;
         StatusText.Text = String.Format("Computing concepts for tag {0} with id = {1} ({2:F2}% done) ", tagName, tagId, 100 * (_tagIdsToProcessCount - tagsLeft) / (float)_tagIdsToProcessCount);
         StatusProgressBar.Value = _tagIdsToProcessCount - tagsLeft;
     }));
 }
        private void extractCandidatesFromRecentPostsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string requestId;
            CandidatesRecent candidateSettings = new CandidatesRecent();
            if (candidateSettings.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                int count = int.Parse(candidateSettings.TextBoxCandidateCount.Text);
                string method = candidateSettings.GetConceptExtractionMethod();

                GeneralQuery query = new GeneralQuery(new QGeneralParams() { ResultData = QResultData.keywordData, KeywordMethod = GetKeywordMethod(method), KeywordCount = count }, new QArgs(new QTimelineCond(candidateSettings.DateTimeStart.Value, candidateSettings.DateTimeEnd.Value)));
                string request = Defaults.BuildRequest(PublisherName, "Query", query.ToString(), out requestId);

                StatusText.Text = "Computing new candidates...";
                SendRequest(request, requestId, "keywordsForRecentPosts");
            }
        }
 private void ButtonLearnDescription_Click(object sender, EventArgs e)
 {
     string conceptLabels = TextBoxLabels.Text;
     if (string.IsNullOrEmpty(conceptLabels))
     {
         MessageBox.Show("In order to find keywords for a concept you first have to enter a set of labels for the concept.");
         return;
     }
     GeneralQuery query = new GeneralQuery(new QGeneralParams() { ResultData = QResultData.keywordData }, new QArgs(new QKeywordCond(conceptLabels)));
     string requestId;
     string request = Defaults.BuildRequest(PublisherName, "Query", query.ToString(), out requestId);
     SendRequest(request, requestId, "keywordsForDescription");
 }
 /// <summary>
 /// return the item data for the first item that exists in the thread.
 /// typically this is used to find who is the creator of the email or forum thread
 /// </summary>
 /// <param name="thread">string data representing the thread</param>
 /// <param name="itemType">what is the itemType of the item</param>
 /// <returns></returns>
 private HtmlNode GetItemDataForFirstPost(string thread, int itemType = -1)
 {
     QArgs args = new QArgs(new QThreadStrCond(thread));
     if (itemType != -1)
         args.AddCondition(new QItemTypeCond(itemType));
     GeneralQuery query = new GeneralQuery(new QGeneralParams() { ResultData = QResultData.itemData, MaxCount = 1, IncludeAttachments = false, SortBy = QResultSorting.dateAsc }, args);
     string ret = MailData.MinerQuery(query);
     XmlDocument doc = new XmlDocument();
     doc.LoadXml(ret);
     HtmlNode node = doc.DocumentNode.SelectSingleNode("//item");
     if (node == null)
         return null;
     return node;
 }
        private HtmlNode GetItemDataForBugDescription(string issueTrackerUrl, string bugId)
        {
            int bugTagId = GetTagIdForBugId(issueTrackerUrl, bugId);
            if (bugTagId == TagInfoBase.InvalidTagId)
                return null;
            QArgs args = new QArgs(new QTagIdCond(bugTagId));
            args.AddCondition(new QItemTypeCond((int)ItemType.BugDescription));
            // sort by itemIdAsc. in this way we will get the first item in the thread
            GeneralQuery query = new GeneralQuery(new QGeneralParams() { MaxCount = 1, SortBy = QResultSorting.itemIdAsc, IncludeAttachments = false }, args);

            string ret = MailData.MinerQuery(query);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(ret);
            HtmlNode node = doc.DocumentNode.SelectSingleNode("//item");
            if (node == null)
                return null;
            return node;
        }
        public string GetItemInfo(int itemId = -1, string entryId = null)
        {
            DataRow data = null;
            if (itemId != -1)
                data = SQLGetItem(itemId);
            else if (!string.IsNullOrEmpty(entryId))
                data = SQLGetItem(entryId);
            if (data == null)
                return null;
            if (itemId == -1)
                itemId = (int)(long)data[0];

            GeneralQuery generalQuery = new GeneralQuery(new QGeneralParams() { MaxCount = 1, IncludeAttachments = false, ItemDataSnipLen = -1 }, new QArgs(new QItemIdCond(itemId)));
            string ret = MinerQuery(generalQuery);
            if (string.IsNullOrEmpty(ret))
                return null;
            HtmlAgilityPack.XmlDocument doc = new HtmlAgilityPack.XmlDocument();
            doc.LoadXml(ret);
            HtmlAgilityPack.HtmlNode itemNode = doc.DocumentNode.SelectSingleNode("//item");
            if (itemNode == null)
                return null;
            itemNode.SetAttributeValue("accountId", ((long)data[2]).ToString());
            itemNode.SetAttributeValue("itemState", ((byte)data[4]).ToString());

            return itemNode.OuterHtml;
        }