public void Execute(ResultItem command, Func<string,string> additionalFunc=null) { string target = String.Empty; if (command.Type.Equals("url")) { var uri = new Uri(command.URL); command.Domain =uri.Host; target = command.URL; //get "a" if exist string aParam = HttpUtility.ParseQueryString(uri.Query).Get("a"); string cParam = HttpUtility.ParseQueryString(uri.Query).Get("c"); if (aParam != null) command.ID = aParam; if (cParam != null) command.CampaignID = cParam; } if (target.Equals(String.Empty)) { target = "https://"+command.Domain; if (currentTokens.ContainsKey("page")) { switch (currentTokens["page"].Value) { case "Setup": target += "/ct/c_admin_options.bix"; break; case "WSA": target += "/w/s.bix"; break; case "SBA": target += "/s/b.bix"; break; case "dev.bix": target += "/ct/dev.bix"; break; } target += "?a=" + command.ID + "&c=" + command.CampaignID; } else { if(command.CampaignID==null) target += "/ct/c_es.bix?a=" + command.ID; else target += "/ct/s.bix?c=" + command.CampaignID; } } string email = Config.Email; if (currentTokens.ContainsKey("email")) { email = currentTokens["email"].Value; } string apiSessionLogin = "******"; string apiURL = "https://" + command.Domain + apiSessionLogin + "?email=" + email + "&a=" + command.ID + "&campaign_id=" + command.CampaignID + "&target=" + System.Web.HttpUtility.UrlEncode(target); if (additionalFunc != null) apiURL = additionalFunc(apiURL); loadingCircle.Active = true; loadingCircle.Visible = true; using (BackgroundWorker bw = new BackgroundWorker()) { bw.DoWork += new DoWorkEventHandler(bw_DoExecute); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_DoneExecute); string[] args = new string[2]; args[0] = command.Domain; args[1] = apiURL; bw.RunWorkerAsync(args); } }
private void searchByTokens() { var searchResult = from JObject af in data["affiliates"] select af; searchResult = applyCurrentFilter(searchResult); listBox.Items.Clear(); foreach (JObject result in searchResult) { ResultItem resultItem = new ResultItem(); resultItem.Type = "title"; resultItem.Value = (string)result["title"]; resultItem.Text = result["title"]+" ("+result["id"]+"->"+result["db"]+")"; resultItem.ID = (string)result["id"]; resultItem.Domain = servers[(string)result["db"]]; resultItem.TopID = (string)result["top_id"]; listBox.Items.Add(resultItem); } //if affiliate is found, don't show auto complete window automatically if (selectedAffiliate != null && (currentTokens.ContainsKey("title") || currentTokens.ContainsKey("url"))) { hideResults(); if (currentTokens.ContainsKey("title")) { loadingCircle.Active = true; loadingCircle.Visible = true; using (BackgroundWorker bw = new BackgroundWorker()) { bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_DoneWork); bw.RunWorkerAsync(selectedAffiliate.TopID); } } } else { showResults(); } }
private void hitResult(object sender) { ResultItem selected = (ResultItem)((ListBox)sender).SelectedItem; SearchToken token = currentToken(); if (selected.Type == "title") { selectedAffiliate = selected; } if (selected.Type == "WS") { selectedAffiliate.CampaignID = selected.CampaignID; } insertTokenToBox(selected.Type, selected.Value, token); hideResults(); this.Focus(); searchByTokens(); }
private void processTokens(bool altFeature=false) { SearchToken token = currentToken(); if (!token.Closed) { if (String.IsNullOrEmpty(token.Text) && selectedAffiliate != null && (currentTokens.ContainsKey("title") || currentTokens.ContainsKey("url"))) { if (altFeature) { Execute(selectedAffiliate, i => i + "&admin=1"); } else { Execute(selectedAffiliate); } } else if (Regex.IsMatch(token.Text.Trim(), @"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$", RegexOptions.IgnoreCase)) { insertTokenToBox("email", token.Text, token); searchByTokens(); } else if (Regex.IsMatch(token.Text.Trim(), @"(https?|ftp)://(-\.)?([^\s/?\.#]+\.?)+(/[^\s]*)?$", RegexOptions.IgnoreCase)) { insertTokenToBox("url", token.Text, token); selectedAffiliate = new ResultItem(); selectedAffiliate.Type = "url"; selectedAffiliate.URL = token.Text; reloadTokens(); } else { if (listBox.Items.Count > 0) { resultForm.Focus(); resultForm.Activate(); ((ListBox)resultForm.control).SetSelected(0, true); } } } else { skipTypeahead = true; searchByTokens(); } }
private void box_TextChangedDelayed(object sender, TextChangedEventArgs e) { int limit = 20; if (!skipTypeahead) { try { listBox.Items.Clear(); SearchToken token = currentToken(); if (token.Text.Length < 1) return; MatchCollection matches = Regex.Matches(box.Text, "<[^>]+>"); Dictionary<string, string> currentCriteria = new Dictionary<string, string>(); foreach (Match match in matches) { String[] matchToken = match.Value.Split(new char[] { ':' }, 2); string key = matchToken[0].TrimStart('<'); string value = matchToken[1].TrimEnd('>'); currentCriteria.Add(key, value); } //if affiliate is already selected, choose campaign and pages if (selectedAffiliate != null && currentCriteria.ContainsKey("title")) { var pageSearch = from string page in Config.quickLogin where (page.IndexOf(token.Text, 0, StringComparison.CurrentCultureIgnoreCase) != -1) select page; foreach (string page in pageSearch) { ResultItem resultItem = new ResultItem(); resultItem.Type = "page"; resultItem.Value = page; listBox.Items.Add(resultItem); } if (selectedAffiliate.TopID.Equals(affiliateCache.TopID)) { var campaignSearch = from JObject c in affiliateCache.campaigns["campaign_list"] where (((string)c["name"]).IndexOf(token.Text, 0, StringComparison.CurrentCultureIgnoreCase) != -1) select c; foreach (JObject result in campaignSearch) { ResultItem resultItem = new ResultItem(); resultItem.Type = "WS"; resultItem.Value = (string)result["name"]; resultItem.Text = "WS: " + result["name"]; resultItem.CampaignID = (string)result["id"]; listBox.Items.Add(resultItem); } //var domainSearch = from JObject c in affiliateCache.domains["domain"] // where (((string)c["host_name"]).IndexOf(token.Text, 0, StringComparison.CurrentCultureIgnoreCase) != -1) // select c; //foreach (JObject result in domainSearch) //{ // ResultItem resultItem = new ResultItem(); // resultItem.Type = "Domain"; // resultItem.Value = (string)result["host_name"]; // resultItem.Text = "Domain: " + result["host_name"]; // resultItem.Domain = (string)result["host_name"]; // listBox.Items.Add(resultItem); //} } } else { IEnumerable<JObject> searchQuery; IEnumerable<string> searchResult; if (listBox.Items.Count < limit) { searchQuery = from JObject af in data["affiliates"] where ((string)af["db"]).StartsWith(token.Text, StringComparison.CurrentCultureIgnoreCase) select af; searchQuery = applyCurrentFilter(searchQuery); searchResult = searchQuery.Select(af => (string)af["db"]).Distinct(); foreach (string result in searchResult) { ResultItem resultItem = new ResultItem(); resultItem.Type = "db"; resultItem.Value = result; listBox.Items.Add(resultItem); } } if (listBox.Items.Count < limit) { searchQuery = from JObject af in data["affiliates"] where (((string)af["id"]).IndexOf(token.Text, 0, StringComparison.CurrentCultureIgnoreCase) != -1) select af; searchQuery = applyCurrentFilter(searchQuery); searchResult = searchQuery.Select(af => (string)af["id"]).Distinct(); foreach (string result in searchResult) { ResultItem resultItem = new ResultItem(); resultItem.Type = "id"; resultItem.Value = result; listBox.Items.Add(resultItem); } } if (listBox.Items.Count < limit) { searchQuery = from JObject af in data["affiliates"] where (((string)af["title"]).IndexOf(token.Text, 0, StringComparison.CurrentCultureIgnoreCase) != -1) select af; searchQuery = applyCurrentFilter(searchQuery); foreach (JObject result in searchQuery) { ResultItem resultItem = new ResultItem(); resultItem.Type = "title"; resultItem.Value = (string)result["title"]; resultItem.Text = result["title"] + " (" + result["id"] + "->" + result["db"] + ")"; resultItem.ID = (string)result["id"]; resultItem.Domain = servers[(string)result["db"]]; resultItem.TopID = (string)result["top_id"]; listBox.Items.Add(resultItem); } } } } catch (Exception ex) { //ignore any exception during auto complete } if (box.Text.Length == 0) { hideResults(); return; } if (listBox.Items.Count > 0) { showResults(); } else { hideResults(); } } else { skipTypeahead = false; } //clear old styles of chars e.ChangedRange.ClearStyle(getStyle()); //append style for word 'Babylon' e.ChangedRange.SetStyle(getStyle(), @"<[^>]+>", RegexOptions.IgnoreCase); }