Apricot.Balloon.Balloon C# (CSharp) Method

Balloon() public method

public Balloon ( ) : System
return System
        public Balloon()
        {
            InitializeComponent();

            this.frameRateList = new List<double>();
            this.messageCollection = new Collection<Message>();
            this.messageBuffer = new StringBuilder();
            this.inlineList = new System.Collections.ArrayList();
            this.embedColorStepDictionary = new Dictionary<int, double>();
            this.embedScrollStepDictionary = new Dictionary<int, double>();
            this.embedIsScrollableHashSet = new HashSet<int>();
            this.tagScrollStepDictionary = new Dictionary<int, double>();
            this.tagIsScrollableHashSet = new HashSet<int>();
            this.attachmentFadeStepDictionary = new Dictionary<int, double>();
            this.attachmentImageLoadingStepDictionary = new Dictionary<int, double>();
            this.attachmentImageSlideStepDictionary = new Dictionary<int, double>();
            this.attachmentImagePopupStepDictionary = new Dictionary<int, double>();
            this.attachmentHighlightStepDictionary = new Dictionary<int, double>();
            this.attachmentEnableStepDictionary = new Dictionary<int, double>();
            this.attachmentFilterStepDictionary = new Dictionary<int, double>();
            this.attachmentScrollStepDictionary = new Dictionary<int, double>();
            this.attachmentIsScrollableHashSet = new HashSet<int>();
            this.attachmentImageDictionary = new Dictionary<int, BitmapImage>();
            this.cachedInlineImageDictionary = new Dictionary<int, Image>();
            this.cachedAttachmentThumbnailImageDictionary = new Dictionary<int, Image>();
            this.cachedAttachmentTextImageDictionary = new Dictionary<int, Image>();
            this.cachedTitleImageDictionary = new Dictionary<int, Image>();
            this.cachedSubtitleImageDictionary = new Dictionary<int, Image>();
            this.cachedAuthorImageDictionary = new Dictionary<int, Image>();
            this.cachedTagImageDictionary = new Dictionary<int, Image>();
            this.thresholdQueue = new Queue<double>();
            this.scrollQueue = new Queue<double>();
            this.selectedPositionQueue = new Queue<double>();
            this.circulationQueue = new Queue<int>();
            this.imageUriQueue = new Queue<Uri>();
            this.imageDictionary = new Dictionary<Uri, BitmapImage>();
            this.imageUriHashSet = new HashSet<Uri>();
            this.messageTypeTimer = new DispatcherTimer(DispatcherPriority.Normal);
            this.messageTypeTimer.Tick += new EventHandler(this.OnTick);
            this.waitTimer = new DispatcherTimer(DispatcherPriority.Normal);
            this.waitTimer.Tick += new EventHandler(this.OnTick);
            this.switchTimer = new DispatcherTimer(DispatcherPriority.Normal);
            this.switchTimer.Tick += new EventHandler(this.OnTick);
            this.switchTimer.Interval = TimeSpan.FromSeconds(3);

            System.Configuration.Configuration config = null;
            string directory = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);

            if (Directory.Exists(directory))
            {
                string fileName = System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                foreach (string s in from s in Directory.EnumerateFiles(directory, "*.config") where fileName.Equals(System.IO.Path.GetFileNameWithoutExtension(s)) select s)
                {
                    System.Configuration.ExeConfigurationFileMap exeConfigurationFileMap = new System.Configuration.ExeConfigurationFileMap();

                    exeConfigurationFileMap.ExeConfigFilename = s;
                    config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(exeConfigurationFileMap, System.Configuration.ConfigurationUserLevel.None);
                }
            }

            if (config == null)
            {
                config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
                directory = null;
            }

            if (config.AppSettings.Settings["FrameRate"] != null)
            {
                if (config.AppSettings.Settings["FrameRate"].Value.Length > 0)
                {
                    this.frameRate = Double.Parse(config.AppSettings.Settings["FrameRate"].Value, System.Globalization.CultureInfo.InvariantCulture);
                }
            }

            if (config.AppSettings.Settings["FontFamily"] != null)
            {
                if (config.AppSettings.Settings["FontFamily"].Value.Length > 0)
                {
                    this.FontFamily = new FontFamily(config.AppSettings.Settings["FontFamily"].Value);
                }
            }

            if (config.AppSettings.Settings["FontSize"] != null)
            {
                if (config.AppSettings.Settings["FontSize"].Value.Length > 0)
                {
                    this.FontSize = (double)new FontSizeConverter().ConvertFromString(config.AppSettings.Settings["FontSize"].Value);
                }
            }

            if (config.AppSettings.Settings["FontStretch"] != null)
            {
                if (config.AppSettings.Settings["FontStretch"].Value.Length > 0)
                {
                    this.FontStretch = (FontStretch)new FontStretchConverter().ConvertFromString(config.AppSettings.Settings["FontStretch"].Value);
                }
            }

            if (config.AppSettings.Settings["FontStyle"] != null)
            {
                if (config.AppSettings.Settings["FontStyle"].Value.Length > 0)
                {
                    this.FontStyle = (FontStyle)new FontStyleConverter().ConvertFromString(config.AppSettings.Settings["FontStyle"].Value);
                }
            }

            if (config.AppSettings.Settings["FontWeight"] != null)
            {
                if (config.AppSettings.Settings["FontWeight"].Value.Length > 0)
                {
                    this.FontWeight = (FontWeight)new FontWeightConverter().ConvertFromString(config.AppSettings.Settings["FontWeight"].Value);
                }
            }

            if (config.AppSettings.Settings["LineLength"] != null)
            {
                if (config.AppSettings.Settings["LineLength"].Value.Length > 0)
                {
                    this.baseWidth = Double.Parse(config.AppSettings.Settings["LineLength"].Value, System.Globalization.CultureInfo.InvariantCulture) + 30;
                }
            }

            if (config.AppSettings.Settings["LineHeight"] != null)
            {
                if (config.AppSettings.Settings["LineHeight"].Value.Length > 0)
                {
                    this.lineHeight = Double.Parse(config.AppSettings.Settings["LineHeight"].Value, System.Globalization.CultureInfo.InvariantCulture);
                }
            }

            if (config.AppSettings.Settings["BackgroundColor"] != null)
            {
                if (config.AppSettings.Settings["BackgroundColor"].Value.Length > 0)
                {
                    this.backgroundColor = (Color)ColorConverter.ConvertFromString(config.AppSettings.Settings["BackgroundColor"].Value);
                }
            }

            SolidColorBrush brush1 = new SolidColorBrush(Color.FromArgb((byte)(this.backgroundColor.A * 75 / 100), this.backgroundColor.R, this.backgroundColor.G, this.backgroundColor.B));

            if (brush1.CanFreeze)
            {
                brush1.Freeze();
            }

            this.OuterPath.Fill = brush1;

            if (config.AppSettings.Settings["BackgroundImage"] == null)
            {
                SolidColorBrush brush2 = new SolidColorBrush(this.backgroundColor);

                if (brush2.CanFreeze)
                {
                    brush2.Freeze();
                }

                this.InnerPath.Fill = brush2;
            }
            else
            {
                BitmapImage bi = new BitmapImage();

                using (FileStream fs = new FileStream(directory == null ? config.AppSettings.Settings["BackgroundImage"].Value : System.IO.Path.Combine(directory, config.AppSettings.Settings["BackgroundImage"].Value), FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    bi.BeginInit();
                    bi.StreamSource = fs;
                    bi.CacheOption = BitmapCacheOption.OnLoad;
                    bi.CreateOptions = BitmapCreateOptions.None;
                    bi.EndInit();
                }

                ImageBrush imageBrush = new ImageBrush(bi);

                imageBrush.TileMode = TileMode.Tile;
                imageBrush.ViewportUnits = BrushMappingMode.Absolute;
                imageBrush.Viewport = new Rect(0, 0, bi.Width, bi.Height);
                imageBrush.Stretch = Stretch.None;

                if (imageBrush.CanFreeze)
                {
                    imageBrush.Freeze();
                }

                this.InnerPath.Fill = imageBrush;
            }

            if (config.AppSettings.Settings["TextColor"] != null)
            {
                if (config.AppSettings.Settings["TextColor"].Value.Length > 0)
                {
                    this.textColor = (Color)ColorConverter.ConvertFromString(config.AppSettings.Settings["TextColor"].Value);
                    this.textBrush = new SolidColorBrush(this.textColor);
                }
            }

            if (this.textBrush == null)
            {
                this.textBrush = new SolidColorBrush(this.textColor);
            }

            if (this.textBrush.CanFreeze)
            {
                this.textBrush.Freeze();
            }

            if (config.AppSettings.Settings["LinkColor"] != null)
            {
                if (config.AppSettings.Settings["LinkColor"].Value.Length > 0)
                {
                    this.linkColor = (Color)ColorConverter.ConvertFromString(config.AppSettings.Settings["LinkColor"].Value);
                    this.linkBrush = new SolidColorBrush(this.linkColor);
                }
            }

            if (this.linkBrush == null)
            {
                this.linkBrush = new SolidColorBrush(this.linkColor);
            }

            if (this.linkBrush.CanFreeze)
            {
                this.linkBrush.Freeze();
            }

            this.maxMessageSize = new Size(this.baseWidth - 30, this.lineHeight * this.numberOfLines);

            Canvas.SetTop(this.FilterImage, this.baseHeaderHeight + 2);
            Canvas.SetLeft(this.ScrollCanvas, 10);
            Canvas.SetTop(this.ScrollCanvas, this.baseHeaderHeight);
            Canvas.SetTop(this.CloseImage, 8);
            Canvas.SetTop(this.BackImage, 7);

            CompositionTarget.Rendering += new EventHandler(this.OnRendering);
        }