protected override void HandleRequest() { XmlDocument xDoc = new XmlDocument(); Site site = null; try { xDoc.Load(Request.InputStream); XmlElement rootElem = xDoc.DocumentElement; string siteName = rootElem.GetAttribute("Name"); string siteTitle = rootElem.GetAttribute("Title"); string description = rootElem.GetAttribute("Description"); string templateId = rootElem.GetAttribute("TemplateId"); SitePublishInfo info = Utils.GetSitePublishInfoFromXml(rootElem); site = CreateSite(siteName, siteTitle, description, templateId, info); } catch (Exception ex) { base.WriteError(ex.Message); return; } if (site == null) { base.WriteError("Unable to create site"); return; } XmlSerializer serializer = new XmlSerializer(typeof(Site)); serializer.Serialize(Response.OutputStream, site); Response.OutputStream.Flush(); }
private void serializeSitePublishInfo(SitePublishInfo info, XElement rootElem) { if (!string.IsNullOrWhiteSpace(info.ApplicationXml)) { rootElem.Add(new XElement("ApplicationXml", info.ApplicationXml)); } if (!string.IsNullOrWhiteSpace(info.MapXaml)) { rootElem.Add(new XElement("MapXaml", info.MapXaml)); } if (!string.IsNullOrWhiteSpace(info.BehaviorsXml)) { rootElem.Add(new XElement("BehaviorsXml", info.BehaviorsXml)); } if (!string.IsNullOrWhiteSpace(info.ColorsXaml)) { rootElem.Add(new XElement("ColorsXaml", info.ColorsXaml)); } if (!string.IsNullOrWhiteSpace(info.ControlsXml)) { rootElem.Add(new XElement("ControlsXml", info.ControlsXml)); } if (!string.IsNullOrWhiteSpace(info.ToolsXml)) { rootElem.Add(new XElement("ToolsXml", info.ToolsXml)); } if (info.PreviewImageBytes != null) { rootElem.Add(new XElement("PreviewImageBytes", info.PreviewImageBytes)); } if (info.ExtensionsXapsInUse != null) { rootElem.Add(new XElement("ExtensionsXapsInUse", string.Join(",", info.ExtensionsXapsInUse))); } }
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); } } }
public void SaveConfigurationForSiteAsync(string siteId, SitePublishInfo info, string siteTitle, object userState = null) { XDocument xDoc = new XDocument(); XElement rootElem = new XElement("SaveApplication"); xDoc.Add(rootElem); rootElem.SetAttributeValue("Title", siteTitle); serializeSitePublishInfo(info, rootElem); Uri uri = CreateRestRequest("Sites/Save", "siteId=" + siteId); WebClient webClient = new WebClient(); webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(onSaveConfigurationCompleted); webClient.UploadStringAsync(uri, "POST", xDoc.ToString(SaveOptions.OmitDuplicateNamespaces), userState); }
public static SitePublishInfo GetSitePublishInfoFromXml(XmlElement rootElem) { SitePublishInfo info = new SitePublishInfo(); XmlElement elem = rootElem.SelectSingleNode("ApplicationXml") as XmlElement; if (elem != null) { info.ApplicationXml = elem.InnerText; } elem = rootElem.SelectSingleNode("MapXaml") as XmlElement; if (elem != null) { info.MapXaml = elem.InnerText; } elem = rootElem.SelectSingleNode("BehaviorsXml") as XmlElement; if (elem != null) { info.BehaviorsXml = elem.InnerText; } elem = rootElem.SelectSingleNode("ColorsXaml") as XmlElement; if (elem != null) { info.ColorsXaml = elem.InnerText; } elem = rootElem.SelectSingleNode("ControlsXml") as XmlElement; if (elem != null) { info.ControlsXml = elem.InnerText; } elem = rootElem.SelectSingleNode("ToolsXml") as XmlElement; if (elem != null) { info.ToolsXml = elem.InnerText; } elem = rootElem.SelectSingleNode("PreviewImageBytes") as XmlElement; if (elem != null && elem.InnerText != null) { info.PreviewImageBytes = Encoding.UTF8.GetBytes(elem.InnerText); } elem = rootElem.SelectSingleNode("ExtensionsXapsInUse") as XmlElement; if (elem != null && elem.InnerText != null) { info.ExtensionsXapsInUse = elem.InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } return(info); }
protected override void HandleRequest() { string siteId = Request["siteId"]; XmlDocument xDoc = new XmlDocument(); xDoc.Load(Request.InputStream); XmlElement rootElem = xDoc.DocumentElement; string siteTitle = rootElem.GetAttribute("Title"); SitePublishInfo info = Utils.GetSitePublishInfoFromXml(rootElem); try { SaveSite(siteId, siteTitle, info); } catch (Exception ex) { base.WriteError(ex.Message); } }
protected override void SaveSite(string siteId, string newTitle, SitePublishInfo info) { Site site = SiteConfiguration.FindExistingSiteByID(siteId); if (site == null) { throw new Exception("Unable to find site with siteId = " + siteId); } FaultContract Fault = null; if (!(new ApplicationBuilderHelper()).SaveConfigurationForSite(site, info, out Fault, newTitle)) { throw new Exception(Fault != null ? Fault.Message : "Unable to save site"); } if (!string.IsNullOrEmpty(newTitle) && site.Title != newTitle) // Update site's title in site configuration list { site.Title = newTitle; SiteConfiguration.SaveSite(site); } }
public void CreateViewerApplicationFromTemplateAsync(string siteName, string siteTitle, string description, string templateId, SitePublishInfo info, object userState = null) { XDocument xDoc = new XDocument(); XElement rootElem = new XElement("CreateApplication"); xDoc.Add(rootElem); rootElem.SetAttributeValue("Name", siteName); rootElem.SetAttributeValue("Description", description); rootElem.SetAttributeValue("TemplateId", templateId); rootElem.SetAttributeValue("Title", siteTitle); serializeSitePublishInfo(info, rootElem); Uri uri = CreateRestRequest("Sites/Create"); WebClient webClient = new WebClient(); webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(onCreateApplicationCompleted); webClient.UploadStringAsync(uri, "POST", xDoc.ToString(SaveOptions.OmitDuplicateNamespaces), userState); }
protected abstract Site CreateSite(string siteName, string siteTitle, string description, string templateId, SitePublishInfo sitePublishInfo);
protected abstract void SaveSite(string siteId, string newTitle, SitePublishInfo info);
protected override Site CreateSite(string targetSiteName, string targetTitle, string targetSiteDescription, string targetSiteTemplateId, SitePublishInfo targetSitePublishInfo) { // Make sure target site directory does not already exist string physicalPath = string.Format("{0}\\{1}", AppSettings.AppsPhysicalDir, targetSiteName); if (System.IO.Directory.Exists(physicalPath)) { throw new Exception("Site with name '" + targetSiteName + "' is in use already. Please try an alternate name."); } // Create a new site Site targetSite = new Site() { ID = Guid.NewGuid().ToString("N"), IsHostedOnIIS = true, Name = targetSiteName, Title = targetTitle, Description = targetSiteDescription, PhysicalPath = physicalPath, Url = string.Format("{0}/{1}", AppSettings.AppsBaseUrl.TrimEnd('/'), targetSiteName.TrimStart('/')) }; Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; targetSite.ProductVersion = string.Format("{0}.{1}.{2}.0", currentVersion.Major, currentVersion.Minor, currentVersion.Build); // Create the viewer application ApplicationBuilderHelper appBuilderHelper = new ApplicationBuilderHelper(); FaultContract Fault = null; if (!appBuilderHelper.CreateSiteFromTemplate(targetSiteTemplateId, targetSite, true, out Fault)) { throw new Exception(Fault != null ? Fault.Message : "Unable to create site"); } // Save the configuration files if (!appBuilderHelper.SaveConfigurationForSite(targetSite, targetSitePublishInfo, out Fault)) { return(null); } // Add entry to Sites.xml SiteConfiguration.AddSite(targetSite); // Return target site object return(targetSite); }