BlipFace.View.Controls.StatusBindableTextBlock.OnBoundStatusChanged C# (CSharp) Method

OnBoundStatusChanged() private static method

private static OnBoundStatusChanged ( DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e ) : void
d System.Windows.DependencyObject
e System.Windows.DependencyPropertyChangedEventArgs
return void
        private static void OnBoundStatusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d == null)
                return;
            //TextBlock mainTextBlock = (TextBlock)d;

            StatusBindableTextBlock mainTextBlock = (StatusBindableTextBlock) d;

            StatusViewModel s = (StatusViewModel) e.NewValue;
            if (s == null || s.Content == null)
                return;

            //czyścimy główny text box z pozostałości
            mainTextBlock.Inlines.Clear();

            //jeśli UserLogin == null to nie pokazujemy loginu
            if (!string.IsNullOrEmpty(s.UserLogin))
            {
                CreateUsersBegining(mainTextBlock, s);
            }

            string blipStatus = s.Content;
            var linkMatches = BlipRegExp.Link.Matches(blipStatus);

            //jeśli nie ma linka,  to od razu dodajmy całą treść
            if (linkMatches.Count < 1)
            {
                //jeśli nie ma dopasowań linków
                FormatStatusFragment(s.Content, mainTextBlock);
            }
            else
            {
                int start = 0;

                //dla wszystkich dopasowań
                for (int k = 0; k < linkMatches.Count; k++)
                {
                    int startLink = linkMatches[k].Index;

                    //sprawdzamy odkąd zaczyna się link
                    if (startLink > 0)
                    {
                        //wycinamy częśc zwykłego tekstu, przed linkiem
                        string temp = blipStatus.Substring(start, startLink - start);
                        FormatStatusFragment(temp, mainTextBlock);
                    }
                    //zrób coś z samym linkiem

                    string rlink, tooltip;
                    Hyperlink h;

                    string linkUrl = linkMatches[k].Value;
                    if (linkUrl.Contains("blip.pl"))
                    {
                        //link do cytowania blipa
                        rlink = "[blip]";
                        tooltip = linkMatches[k].Value;

                        if (s.Cites != null && s.Cites.ContainsKey(tooltip))
                        {
                            tooltip = s.Cites[linkMatches[k].Value];
                        }

                        h = CreateLinkHyperLink(rlink, linkMatches[k].Value, tooltip, mainTextBlock);
                    }else if (linkUrl.Contains("youtube."))
                    {
                        rlink = "[video]";
                        tooltip = linkMatches[k].Value;

                        if (s.Links != null && s.Links.ContainsKey(tooltip))
                        {
                            tooltip = s.Links[linkMatches[k].Value];
                        }

                        h = CreateVideoHyperLink(rlink, linkMatches[k].Value, tooltip, mainTextBlock);
                    }
                    else
                    {
                        rlink = "[link]";

                        //zwykły link

                        tooltip = linkMatches[k].Value;

                        if (s.Links != null && s.Links.ContainsKey(tooltip))
                        {
                            tooltip = s.Links[linkMatches[k].Value];
                        }

                        h = CreateLinkHyperLink(rlink, linkMatches[k].Value, tooltip, mainTextBlock);
                    }

                    // Hyperlink h = CreateLinkHyperLink(rlink, linkMatches[k].Value, linkMatches[k].Value);

                    //dołączam linka do wyświetlenia
                    mainTextBlock.Inlines.Add(h);

                    //ustaw się za linkiem w łańcuchu
                    start = startLink + linkMatches[k].Length;
                }

                //jeśli został jakiś tekst na końcu
                if (start < s.Content.Length)
                {
                    FormatStatusFragment(s.Content.Substring(start), mainTextBlock);
                }

                //dodaj na końcu linki do video

                //foreach (var url in videoUrls)
                //{
                //    var m = youtubeWatchKey.Match(url);
                //    string videoKey = m.Groups[1].Value;

                //    WebBrowser wb = new WebBrowser();
                //    wb.MinWidth = 200;
                //    wb.MinHeight = 200;
                //     string content = string.Format(embededFormat, videoKey);
                //    wb.NavigateToString(content);

                //    mainTextBlock.Inlines.Add(wb);
                //        //Inlines.Add(wb);

                //}
            }
        }