Beispiel #1
0
        private void findElementsInText(string fullText)
        {
            if (parsingOfTextItemsInProgress)
            {
                return;
            }
            if (string.IsNullOrEmpty(fullText))
            {
                return;
            }
            parsingOfTextItemsInProgress = true;
            try
            {
                string twitlongerLink      = "";
                string twitlongerShortLink = "";
                List <TextSubTypes.ISubType> foundElements = new List <TextSubTypes.ISubType>();
                string[] words = Regex.Split(fullText, @"([\r\n \(\)\{\}\[\];])");
                foreach (string word in words)
                {
                    twitlongerLink = "";
                    if (word.ToLower().StartsWith("http://") || word.ToLower().StartsWith("https://"))
                    {
                        string url          = word;
                        string expandedLink = word;

                        if (AppController.Current.AllShortenedLinksInItems.ContainsKey(word))
                        {
                            //AppController.Current.Logger.writeToLogfile("Cached shortened link found for " + word);
                            expandedLink = AppController.Current.AllShortenedLinksInItems[word];
                        }
                        else
                        {
                            //AppController.Current.Logger.writeToLogfile("No cached shortened link found for " + word);
                            // tl.gd wird sonst zu www.twitlonger.com/show expandiert :(
                            if (!word.StartsWith("http://tl.gd/") && 1 == 2)
                            {
                                foreach (API.UrlShortener.ILinkShortener shortener in AppController.Current.AlllinkShortenerServices)
                                {
                                    if (shortener.IsLinkOfThisShortener(word))
                                    {
                                        string unshortedLink = shortener.ExpandLink(word);
                                        if (!string.IsNullOrEmpty(unshortedLink) && unshortedLink != word)
                                        {
                                            expandedLink = unshortedLink;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (expandedLink.StartsWith("http://tl.gd/") || expandedLink.StartsWith("http://www.twitlonger.com/show/"))
                        {
                            twitlongerLink      = expandedLink;
                            twitlongerShortLink = word;
                        }

                        if (AppController.Current.AllImagesInItems.ContainsKey(expandedLink))
                        {
                            TextSubTypes.ImageLink imageLink = new TextSubTypes.ImageLink(expandedLink, word, AppController.Current.AllImagesInItems[expandedLink]);
                            foundElements.Add(imageLink);
                        }
                        else
                        {
                            TextSubTypes.Link currentLink = new TextSubTypes.Link(expandedLink, word);
                            foundElements.Add(currentLink);
                        }
                    }
                    else if (word.StartsWith("#") && word.Length > 1)
                    {
                        TextSubTypes.HashTag hashTag = new TextSubTypes.HashTag(word);
                        foundElements.Add(hashTag);
                    }
                    else if (word.StartsWith("@") && word.Length > 1)
                    {
                        TextSubTypes.User user = new TextSubTypes.User(word);
                        foundElements.Add(user);
                    }
                    else
                    {
                        TextSubTypes.Text currentText = new TextSubTypes.Text(word);
                        foundElements.Add(currentText);
                    }
                }
                if (twitlongerLink != "")
                {
                    fullText = fullText.Replace(twitlongerShortLink, twitlongerLink);
                    ExternalServices.Twitlonger.TwitLongerResponse response = ExternalServices.Twitlonger.GetLongText(fullText);
                    if (response != null)
                    {
                        if (!string.IsNullOrEmpty(response.MessageText))
                        {
                            IsTwitLongerItem = true;
                            fullText         = response.MessageText;
                            findElementsInText(fullText);
                            return;
                        }
                    }
                }
                ElementsInText.Clear();
                foreach (TextSubTypes.ISubType element in foundElements)
                {
                    ElementsInText.Add(element);
                }
                _text = fullText;
                parsingOfTextItemsInProgress = false;
            }
            catch (Exception exp)
            {
                AppController.Current.Logger.writeToLogfile(exp, true);
                parsingOfTextItemsInProgress = false;
            }
        }
Beispiel #2
0
        private void findElementsInText(string fullText)
        {
            if (string.IsNullOrEmpty(fullText))
            {
                return;
            }

            List <TextSubTypes.ISubType> foundElements = new List <TextSubTypes.ISubType>();

            string[] words = Regex.Split(fullText, @"([\r\n \(\)\{\}\[\];])");
            foreach (string word in words)
            {
                if (word.ToLower().StartsWith("http://") || word.ToLower().StartsWith("https://"))
                {
                    string url          = word;
                    string expandedLink = word;

                    if (AppController.Current.AllShortenedLinksInItems.ContainsKey(word))
                    {
                        //AppController.Current.Logger.writeToLogfile("Cached shortened link found for " + word);
                        expandedLink = AppController.Current.AllShortenedLinksInItems[word];
                    }
                    else
                    {
                        foreach (API.UrlShortener.ILinkShortener shortener in AppController.Current.AlllinkShortenerServices)
                        {
                            if (shortener.IsLinkOfThisShortener(word))
                            {
                                string unshortedLink = shortener.ExpandLink(word);
                                if (!string.IsNullOrEmpty(unshortedLink) && unshortedLink != word)
                                {
                                    expandedLink = unshortedLink;
                                    break;
                                }
                            }
                        }
                    }


                    if (AppController.Current.AllImagesInItems.ContainsKey(expandedLink))
                    {
                        TextSubTypes.ImageLink imageLink = new TextSubTypes.ImageLink(expandedLink, word, AppController.Current.AllImagesInItems[expandedLink]);
                        foundElements.Add(imageLink);
                    }
                    else
                    {
                        TextSubTypes.Link currentLink = new TextSubTypes.Link(expandedLink, word);
                        foundElements.Add(currentLink);
                    }
                }
                else
                {
                    TextSubTypes.Text currentText = new TextSubTypes.Text(word);
                    foundElements.Add(currentText);
                }
                if (ElementsInText == null)
                {
                    ElementsInText = new List <TextSubTypes.ISubType>();
                }
                else
                {
                    ElementsInText.Clear();
                }
                foreach (TextSubTypes.ISubType element in foundElements)
                {
                    ElementsInText.Add(element);
                }
            }
        }