public static void UpdateProxyUrl(string proxyUrl)
        {
            Map map = (MapApplication.Current != null) ? MapApplication.Current.Map : null;

            if (map == null)
            {
                return;
            }

            bool mapRequiresRefresh = false;

            #region Check if layers can be updated in-place
            List <Layer> layersForRefresh = new List <Layer>();
            foreach (Layer layer in map.Layers)
            {
                if (ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetUsesProxy(layer))
                {
                    if (ProxyUrlHelper.CanChangeProxyUrl(layer))
                    {
                        layersForRefresh.Add(layer);
                    }
                    else
                    {
                        mapRequiresRefresh = true;
                        break;
                    }
                }
            }
            #endregion
            #region Set proxy url if layers can be updated
            if (!mapRequiresRefresh)
            {
                foreach (Layer layer in layersForRefresh)
                {
                    SecureServicesHelper.SetProxyUrl(layer, proxyUrl);
                }
            }
            #endregion
            #region Else, serialize/deserialize map, remove and re-add layers
            else
            {
                MapXamlWriter writer = new MapXamlWriter(true);
                try
                {
                    string mapXaml = writer.MapToXaml(map);

                    if (!string.IsNullOrEmpty(mapXaml))
                    {
                        Map newMap = System.Windows.Markup.XamlReader.Load(mapXaml) as Map;
                        if (newMap != null && newMap.Layers.Count == map.Layers.Count)
                        {
                            map.Layers.Clear();
                            map.Extent = newMap.Extent;
                            List <Layer> layers = new List <Layer>();
                            foreach (Layer layer in newMap.Layers)
                            {
                                if (ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetUsesProxy(layer))
                                {
                                    SecureServicesHelper.SetProxyUrl(layer, proxyUrl);
                                }
                                layers.Add(layer);
                            }
                            newMap.Layers.Clear();
                            foreach (Layer layer in layers)
                            {
                                map.Layers.Add(layer);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogError(ex);
                    MessageBoxDialog.Show(ESRI.ArcGIS.Mapping.Controls.Resources.Strings.ErrorChangingProxies);
                }
            }
            #endregion
        }
        public static string GetMapXaml(MapEventArgs e)
        {
            MapXamlWriter writer = new MapXamlWriter(true);

            return(writer.MapToXaml(e.Map));
        }