/// <summary>
        /// Method for extracting the address information.
        /// </summary>
        /// <param name="infoHandler">The staticmapdatahandler.</param>
        /// <param name="urlIndex">The index of the page.</param>
        /// <param name="pageNumber">The number of the page.</param>
        /// <param name="dataId">The id of the data.</param>
        private void HandleUserInformation(StaticMapDataHandler infoHandler, int urlIndex, int pageNumber, int dataId)
        {
            double       x, y;
            NumberStyles style   = NumberStyles.AllowDecimalPoint;
            CultureInfo  culture = CultureInfo.InvariantCulture;

            if (infoHandler.SetDataId(dataId))
            {
                Dispatcher.Invoke(() =>
                {
                    idBufferProgressBar.Value--;
                    lblAddressData.Content = infoHandler.Url;
                });

                StaticMapData staticMapData = infoHandler.GetSerializedData(STATIC_MAP_REGEX);
                staticMapData.Birthday = infoHandler.GetStringData(BIRTHDAY_REGEX);
                staticMapData.Phone    = infoHandler.GetStringData(TELEPHONE_REGEX).Replace(LINEFEED_REGEX, String.Empty);
                staticMapData.CoordX   = staticMapData.CoordX.Replace(',', '.');
                staticMapData.CoordY   = staticMapData.CoordY.Replace(',', '.');

                if (Double.TryParse(staticMapData.CoordX, style, culture, out x) &&
                    Double.TryParse(staticMapData.CoordY, style, culture, out y))
                {
                    populationenRendering.AddCoordinate(new Point(x, y));
                }

                staticMapData.UrlIndex   = urlIndex;
                staticMapData.PageNumber = pageNumber;
                PrintListBox(staticMapData);
                UpdateDatabase(staticMapData);
            }
        }
 /// <summary>
 /// Method for rendering a cross on the map when select a address.
 /// The cross shows the coordinate of the address.
 /// </summary>
 /// <param name="sender">The caller or the sender object which is the object to fire the event.</param>
 /// <param name="e">Arguments sent from the caller.</param>
 private void searchListbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (searchListbox.Items.Count > 0)
     {
         populationenRendering_Copy.SetCrossHairVisibility(true);
         StaticMapData s = (StaticMapData)searchListbox.SelectedItem;
         if (s != null)
         {
             double x = double.Parse(s.CoordX);
             double y = double.Parse(s.CoordY);
             populationenRendering_Copy.SetCrossHairPosition(x, y);
         }
     }
 }
        /// <summary>
        /// Method for displaying the staticmapdata on the listbox.
        /// </summary>
        /// <param name="staticMapData">The staicmapdata object.</param>
        private void PrintListBox(StaticMapData staticMapData)
        {
            Dispatcher.Invoke(() =>
            {
                staticMapDataQueue.Enqueue(staticMapData);

                if (staticMapDataQueue.Count > 26)
                {
                    staticMapDataQueue.Dequeue();
                }

                staticMapListbox.Items.Refresh();
            });
        }
        /// <summary>
        /// Method for populating the database with address data.
        /// </summary>
        /// <param name="staticMapData">The staticdata object.</param>
        private void UpdateDatabase(StaticMapData staticMapData)
        {
            using (var context = new InformationContext())
            {
                Dispatcher.Invoke(() => { lblNumberOfRecords.Content = context.Persons.Count().ToString(); });

                Postal postal = context.Postals.Where(x =>
                                                      x.PostalCode == staticMapData.PostalCode &&
                                                      x.City == staticMapData.City).FirstOrDefault();

                if (postal == null)
                {
                    context.Postals.Add(staticMapData.GetPostal());
                    context.SaveChanges();
                    return;
                }

                Address address = context.Addresses.Where(x =>
                                                          x.Street == staticMapData.Addr1 &&
                                                          x.PostalCode == staticMapData.PostalCode).FirstOrDefault();

                if (address == null)
                {
                    postal.Addresses.Add(staticMapData.GetAddress(postal));
                    context.SaveChanges();
                    return;
                }

                Person person = context.Persons.Where(x =>
                                                      x.DataId.ToString() == staticMapData.Id).FirstOrDefault();

                if (person == null)
                {
                    address.Persons.Add(staticMapData.GetPerson(address));
                    context.SaveChanges();
                }
            }
        }
        /// <summary>
        /// Method for hadeling the search function.
        /// </summary>
        /// <remarks>http://blogs.msdn.com/b/adonet/archive/2011/01/31/using-dbcontext-in-ef-feature-ctp5-part-6-loading-related-entities.aspx</remarks>
        private void SearchHandler()
        {
            populationenRendering_Copy.StartRendering();

            Action <bool> SearchEnable = enable =>
            {
                Dispatcher.Invoke(() =>
                {
                    searchButton.IsEnabled = enable;
                });
            };

            Action <Action> dispatcherAction = action =>
            {
                Dispatcher.Invoke(() =>
                {
                    action();
                    searchListbox.Items.Refresh();
                });
            };

            StaticMapData staticMapData = new StaticMapData()
            {
                Name       = txbSearchName.Text.ToLower(),
                Phone      = txbSearchPhone.Text.ToLower(),
                Addr1      = txbSearchAddress.Text.ToLower(),
                PostalCode = txbSearchPostalCode.Text.ToLower(),
                City       = txbSearchCity.Text.ToLower()
            };

            Task.Run(() =>
            {
                List <Person> persons = new List <Person>();
                SearchEnable(false);

                using (var context = new InformationContext())
                {
                    persons = context.Persons.Where(p =>
                                                    p.Name.ToLower().Contains(staticMapData.Name) && p.Phone.Contains(staticMapData.Phone) &&
                                                    p.Address.Street.Contains(staticMapData.Addr1) &&
                                                    p.Address.Postal.PostalCode.Contains(staticMapData.PostalCode) &&
                                                    p.Address.Postal.City.Contains(staticMapData.City))
                              .Take(100)
                              .DefaultIfEmpty()
                              .Include(p => p.Address)
                              .Include(p => p.Address.Postal)
                              .ToList();
                }
                //PopulationenRendering
                //persons.ForEach(p => populationenRendering_Copy.AddCoordinate(new Point(p.Address.XCoord, p.Address.YCoord)));
                dispatcherAction(delegate() { persons.ForEach(p => populationenRendering_Copy.AddCoordinate(new Point(p.Address.XCoord, p.Address.YCoord))); });

                if (persons != null)
                {
                    dispatcherAction(delegate() { searchLQueue.Clear(); });

                    persons.ForEach(p =>
                    {
                        Thread.Sleep(100);
                        dispatcherAction(delegate() { searchLQueue.Enqueue(new StaticMapData(p)); });
                        populationenRendering.AddCoordinate(new Point(p.Address.XCoord, p.Address.YCoord));
                    });
                }

                SearchEnable(true);
            });
            //The ObjectContext instance has been disposed and can no longer be used for operations that require a connection System.InvalidOperationException {System.ObjectDisposedException}
            //http://blogs.msdn.com/b/adonet/archive/2011/01/31/using-dbcontext-in-ef-feature-ctp5-part-6-loading-related-entities.aspx
            // Debug.WriteLine("addresses.FirstOrDefault().Street");
        }