private void MapButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         base.IsEnabled = false;
         base.Hide();
         Mouse.OverrideCursor = Cursors.Wait;
         OnlineSearchItem onlineSearchItem = (OnlineSearchItem)this.lbMaps.SelectedItem;
         string           item             = onlineSearchItem.Item;
         string           uRL = item;
         if (item.ToLower().Contains("/rest/"))
         {
             int startIndex = item.ToLower().IndexOf("/rest/");
             uRL = item.Remove(startIndex, 5);
         }
         AGSMapService aGSMapService = AGSMapService.BuildMapServiceFromURL(onlineSearchItem.Name, uRL);
         string        wKT           = AfaDocData.ActiveDocData.DocPRJ.WKT;
         if (aGSMapService != null)
         {
             if (string.IsNullOrEmpty(wKT))
             {
                 try
                 {
                     wKT = aGSMapService.GetWKT();
                     MSCPrj.AssignWKT(AfaDocData.ActiveDocData.Document, wKT);
                 }
                 catch
                 {
                     AfaDocData.ActiveDocData.Document.Editor.WriteMessage(AfaStrings.UnableToAssignCoordinateSystem);
                 }
             }
             aGSMapService.ExportOptions.OutputWKT = wKT;
             if (!aGSMapService.AddService())
             {
                 string text = AfaStrings.ErrorAddingService;
                 if (!string.IsNullOrEmpty(aGSMapService.ErrorMessage))
                 {
                     text = text + "  " + aGSMapService.ErrorMessage;
                 }
                 ErrorReport.ShowErrorMessage(text);
             }
         }
         else
         {
             ErrorReport.ShowErrorMessage(AfaStrings.ErrorAddingService);
         }
         Mouse.OverrideCursor = null;
         base.IsEnabled       = true;
         base.Close();
     }
     catch
     {
         Mouse.OverrideCursor = null;
         base.IsEnabled       = true;
         base.Close();
     }
 }
 private static void FinishedGeneratingImages(AGS_ESRIMaps.ImageAndIndex si)
 {
     try
     {
         OnlineSearchItem onlineSearchItem = AGS_ESRIMaps.m_searchResult.Results[si.index];
         BitmapImage      bitmapImage      = new BitmapImage();
         bitmapImage.BeginInit();
         bitmapImage.StreamSource   = si.image;
         bitmapImage.CacheOption    = BitmapCacheOption.OnLoad;
         bitmapImage.CreateOptions  = BitmapCreateOptions.None;
         bitmapImage.UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheIfAvailable);
         bitmapImage.EndInit();
         if (!bitmapImage.IsDownloading)
         {
             bitmapImage.Freeze();
         }
         onlineSearchItem.TheThumbnail = bitmapImage;
     }
     catch (SystemException ex)
     {
         AGS_ESRIMaps.ConnectionFailed = true;
         Trace.WriteLine(ex.Message);
     }
 }