public void Execute(object parameter)
        {
            if (ParentDropDownButton != null)
            {
                ParentDropDownButton.IsContentPopupOpen = false;
            }

            if (ViewerApplicationControl.Instance == null || BuilderApplication.Instance == null ||
                BuilderApplication.Instance.CurrentSite == null)
            {
                return;
            }

            ViewerApplicationControl va = ViewerApplicationControl.Instance;

            if (va != null)
            {
                IncrementVersionNumber(va.ViewerApplication);
                va.View.SaveExtensionsConfigData();

                // Get add-in configuration (tools, controls, and behaviors) before map configuration so add-ins have a chance
                // to perform map-related cleanup (e.g. removing temp layers) before the map is saved
                string toolsXml = va.ToolPanels != null?va.ToolPanels.GetToolPanelsXml() : string.Empty;

                string controlsXml = va.View.GetConfigurationOfControls();

                // Publish only Xaps in use
                string behaviorsXml = null;
                ObservableCollection <string> usedXaps = BuilderApplication.Instance.GetXapsInUse(out behaviorsXml);
                BuilderApplication.Instance.SyncExtensionsInUse(usedXaps);

                string mapXaml = va.View.GetMapConfiguration(null);

                // Now that the extensions list has been updated - serialize the applicationXml
                string appXml            = va.ViewerApplication.ToXml();
                string colorsXaml        = va.GetColorXaml();
                byte[] previewImageBytes = BuilderApplication.Instance.GetPreviewImage();

                SitePublishInfo info = new SitePublishInfo()
                {
                    ApplicationXml      = appXml,
                    BehaviorsXml        = behaviorsXml,
                    ColorsXaml          = colorsXaml,
                    ControlsXml         = controlsXml,
                    ExtensionsXapsInUse = usedXaps.ToArray(),
                    MapXaml             = mapXaml,
                    PreviewImageBytes   = previewImageBytes,
                    ToolsXml            = toolsXml,
                };
                var title = "";
                if (ViewerApplicationControl.Instance != null && ViewerApplicationControl.Instance.ViewerApplication != null)
                {
                    title = ViewerApplicationControl.Instance.ViewerApplication.TitleText;
                }
                ApplicationBuilderClient client = WCFProxyFactory.CreateApplicationBuilderProxy();
                client.SaveConfigurationForSiteCompleted += new EventHandler <SaveConfigurationForSiteCompletedEventArgs>(client_SaveConfigurationForSiteCompleted);
                client.SaveConfigurationForSiteAsync(BuilderApplication.Instance.CurrentSite.ID, info, title);
            }
        }
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (validateInput())
            {
                enableDisableUI(true);
                showHideProgressIndicator(Visibility.Visible);
                ViewerApplicationControl va = ViewerApplicationControl.Instance;
                if (va != null)
                {
                    va.View.SaveExtensionsConfigData();

                    // Get add-in configuration (tools, controls, and behaviors) before map configuration so add-ins have a chance
                    // to perform map-related cleanup (e.g. removing temp layers) before the map is saved
                    string toolsXml = va.ToolPanels != null?va.ToolPanels.GetToolPanelsXml() : string.Empty;

                    string controlsXml = va.View.GetConfigurationOfControls();

                    // Publish only Xaps in use
                    string behaviorsXml = null;
                    ObservableCollection <string> usedXaps = BuilderApplication.Instance.GetXapsInUse(out behaviorsXml);
                    BuilderApplication.Instance.SyncExtensionsInUse(usedXaps);

                    string mapXaml = va.View.GetMapConfiguration(null);

                    // Now that the extensions list has been updated - serialize the applicationXml
                    string   appXml            = va.ViewerApplication.ToXml();
                    string   colorsXaml        = va.GetColorXaml();
                    byte[]   previewImageBytes = BuilderApplication.Instance.GetPreviewImage();
                    Template template          = BuilderApplication.Instance.Templates.FirstOrDefault <Template>(t => t.IsDefault);
                    string   templateId        = template != null ? template.ID : "Default";

                    SitePublishInfo info = new SitePublishInfo()
                    {
                        ApplicationXml      = appXml,
                        BehaviorsXml        = behaviorsXml,
                        ColorsXaml          = colorsXaml,
                        ControlsXml         = controlsXml,
                        ExtensionsXapsInUse = usedXaps.ToArray(),
                        MapXaml             = mapXaml,
                        PreviewImageBytes   = previewImageBytes,
                        ToolsXml            = toolsXml
                    };

                    var title = "";
                    if (ViewerApplicationControl.Instance != null && ViewerApplicationControl.Instance.ViewerApplication != null)
                    {
                        title = ViewerApplicationControl.Instance.ViewerApplication.TitleText;
                    }
                    ApplicationBuilderClient client = WCFProxyFactory.CreateApplicationBuilderProxy();
                    client.CreateViewerApplicationFromTemplateCompleted += new EventHandler <CreateViewerApplicationFromTemplateCompletedEventArgs>(client_CreateViewerApplicationFromTemplateCompleted);
                    client.CreateViewerApplicationFromTemplateAsync(NameTextBox.Text.Trim(), title,
                                                                    DescriptionTextBox.Text.Trim(), templateId, info);
                }
            }
        }