public void Start() { var groups = UriActions .GroupBy(x => x.Key); //Group By Domain var actionChains = groups .Select(g => ExecuteActionChain(g.Select(x => x.Value), new Task(() => { /* Completion Task */ }))) //Execute one at a time per domain .ToArray(); Task.WaitAll(actionChains); }
private void ExtractUriTasks(Tweet tweet) { if (tweet.Status.Entities != null && tweet.Status.Entities.UrlEntities != null) { foreach (var urlmentions in tweet.Status.Entities.UrlEntities) { var link = new UriEx(urlmentions.ExpandedUrl); UriActions.Add(new KeyValuePair <string, Action>(link.Uri.Authority, () => CreateUriAction(link, () => ProcessingComplete(tweet, link, urlmentions)))); tweet.Links.Add(link); tweet.TweetText = tweet.Status.Text.Replace(urlmentions.Url, "<a target=\"_blank\" href=\"" + urlmentions.ExpandedUrl + "\">[" + link.Title + "]</a>"); } } if (tweet.Status.Entities != null && tweet.Status.Entities.MediaEntities != null) { foreach (var media in tweet.Status.Entities.MediaEntities) { var link = new UriEx(media.ExpandedUrl); UriActions.Add(new KeyValuePair <string, Action>(link.Uri.Authority, () => CreateUriAction(link, () => ProcessingComplete(tweet, link, media)))); tweet.Links.Add(link); tweet.TweetText = tweet.Status.Text.Replace(media.Url, "<a target=\"_blank\" href=\"" + media.ExpandedUrl + "\">[" + link.Title + "]</a>"); } } /* * if (Links.Count == 0 && !string.IsNullOrEmpty(Status.Text)) * { * var regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase); * var matches = regx.Matches(Status.Text); * for (int i = 0; i < matches.Count; i++ ) * { * var m = matches[i]; * var link = new UriEx(m.Value); * CompletionTasks.Add(link.CreateProcessUriTask(l => * { * TweetText = Status.Text.Replace(m.Value, "<a target=\"_blank\" href=\"" + m.Value + "\">[" + l.Title + "]</a>"); * })); * link.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler((x, y) => { base.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Links")); }); * Links.Add(link); * TweetText = Status.Text.Replace(m.Value, "<a target=\"_blank\" href=\"" + m.Value + "\">[" + link.Title + "]</a>"); * } * } */ }
public UriAction[] UriActionsForActionPredicate(Func <Models.Action, bool> pred) { int[] actions = Actions.Where(pred).Select(x => x.ActionId).ToArray(); return(UriActions.Where(x => actions.Contains(x.Id)).ToArray()); }