/// <summary> /// Read page details from xml during load process. /// </summary> /// <param name="xmlReader">XmlReader to use for loading.</param> /// <param name="uniqueName">Unique name of page being loaded.</param> /// <param name="existingPages">Set of existing pages.</param> /// <returns>Reference to page to be added into the workspace cell.</returns> public override KryptonPage ReadPageElement(XmlReader xmlReader, string uniqueName, UniqueNameToPage existingPages) { // If a matching page with the unique name already exists then use it, // otherwise we need to create an entirely new page instance. KryptonPage page; if (existingPages.TryGetValue(uniqueName, out page)) { existingPages.Remove(uniqueName); } else { // Use event to try and get a newly created page for use RecreateLoadingPageEventArgs args = new RecreateLoadingPageEventArgs(uniqueName); OnRecreateLoadingPage(args); if (!args.Cancel) { page = args.Page; // Add recreated page to the looking dictionary if ((page != null) && !existingPages.ContainsKey(page.UniqueName)) { existingPages.Add(page.UniqueName, page); } } } if (page != null) { // If this is a store page then recreate as a store page type if (CommonHelper.StringToBool(CommonHelper.XmlAttributeToText(xmlReader, "S"))) { page = new KryptonStorePage(page.UniqueName, _storeName); } else { // Only some values if the actual page and not if it is a store page page.UniqueName = CommonHelper.XmlAttributeToText(xmlReader, "UN"); page.Visible = CommonHelper.StringToBool(CommonHelper.XmlAttributeToText(xmlReader, "V", "True")); } } // Read past the page start element if (!xmlReader.Read()) { throw new ArgumentException("An element was expected but could not be read in."); } return(page); }
/// <summary> /// Request this sequence load and recreate children. /// </summary> /// <param name="workspace">Reference to owning workspace instance.</param> /// <param name="xmlReader">Xml reader for loading information.</param> /// <param name="existingPages">Dictionary on existing pages before load.</param> public void LoadFromXml(KryptonWorkspace workspace, XmlReader xmlReader, UniqueNameToPage existingPages) { // Load the sequence details workspace.ReadSequenceElement(xmlReader, this); // If the sequence contains nothing then exit immediately if (!xmlReader.IsEmptyElement) { do { // Read the next Element if (!xmlReader.Read()) { throw new ArgumentException("An element was expected but could not be read in."); } // Is this the end of the sequence if (xmlReader.NodeType == XmlNodeType.EndElement) { break; } // Is it another sequence? switch (xmlReader.Name) { case "WS": KryptonWorkspaceSequence sequence = new KryptonWorkspaceSequence(); sequence.LoadFromXml(workspace, xmlReader, existingPages); Children.Add(sequence); break; case "WC": KryptonWorkspaceCell cell = new KryptonWorkspaceCell(); cell.LoadFromXml(workspace, xmlReader, existingPages); Children.Add(cell); break; default: throw new ArgumentException("Unknown element was encountered."); } }while (true); } }
/// <summary> /// Request this cell load and update state. /// </summary> /// <param name="workspace">Reference to owning workspace instance.</param> /// <param name="xmlReader">Xml reader for loading information.</param> /// <param name="existingPages">Dictionary on existing pages before load.</param> public void LoadFromXml(KryptonWorkspace workspace, XmlReader xmlReader, UniqueNameToPage existingPages) { // Load the cell details and return the unique name of the selected page for the cell string selectedPageUniqueName = workspace.ReadCellElement(xmlReader, this); KryptonPage selectedPage = null; // If the cell contains nothing then exit immediately if (!xmlReader.IsEmptyElement) { do { // Read the next Element if (!xmlReader.Read()) { throw new ArgumentException("An element was expected but could not be read in."); } // Is this the end of the cell if (xmlReader.NodeType == XmlNodeType.EndElement) { break; } if (xmlReader.Name == "KP") { // Load the page details and optionally recreate the page string uniqueName = CommonHelper.XmlAttributeToText(xmlReader, "UN"); KryptonPage page = workspace.ReadPageElement(xmlReader, uniqueName, existingPages); if (xmlReader.Name != "CPD") { throw new ArgumentException("Expected 'CPD' element was not found"); } bool finished = xmlReader.IsEmptyElement; // Generate event so custom data can be loaded and/or the page to be added can be modified PageLoadingEventArgs plea = new PageLoadingEventArgs(workspace, page, xmlReader); workspace.OnPageLoading(plea); page = plea.Page; // Read everything until we get the end of custom data marker while (!finished) { // Check it has the expected name if (xmlReader.NodeType == XmlNodeType.EndElement) { finished = (xmlReader.Name == "CPD"); } if (!finished) { if (!xmlReader.Read()) { throw new ArgumentException("An element was expected but could not be read in."); } } } // Read past the end of page element if (!xmlReader.Read()) { throw new ArgumentException("An element was expected but could not be read in."); } // Check it has the expected name if (xmlReader.NodeType != XmlNodeType.EndElement) { throw new ArgumentException("End of 'KP' element expected but missing."); } // PageLoading event might have nulled the page value to prevent it being added if (page != null) { // Remember the page that should become selected if (!string.IsNullOrEmpty(page.UniqueName) && (page.UniqueName == selectedPageUniqueName)) { // Can only selected a visible page if (page.LastVisibleSet) { selectedPage = page; } } Pages.Add(page); } } else { throw new ArgumentException("Unknown element was encountered."); } }while (true); } // Did we find a matching page that should become selected? // (and we are allowed to have selected tabs) if ((selectedPage != null) && AllowTabSelect) { SelectedPage = selectedPage; } }
/// <summary> /// Request this sequence load and recreate children. /// </summary> /// <param name="workspace">Reference to owning workspace instance.</param> /// <param name="xmlReader">Xml reader for loading information.</param> /// <param name="existingPages">Dictionary on existing pages before load.</param> public void LoadFromXml(KryptonWorkspace workspace, XmlReader xmlReader, UniqueNameToPage existingPages) { // Load the sequence details workspace.ReadSequenceElement(xmlReader, this); // If the sequence contains nothing then exit immediately if (!xmlReader.IsEmptyElement) { do { // Read the next Element if (!xmlReader.Read()) throw new ArgumentException("An element was expected but could not be read in."); // Is this the end of the sequence if (xmlReader.NodeType == XmlNodeType.EndElement) break; // Is it another sequence? if (xmlReader.Name == "WS") { KryptonWorkspaceSequence sequence = new KryptonWorkspaceSequence(); sequence.LoadFromXml(workspace, xmlReader, existingPages); Children.Add(sequence); } else if (xmlReader.Name == "WC") { KryptonWorkspaceCell cell = new KryptonWorkspaceCell(); cell.LoadFromXml(workspace, xmlReader, existingPages); Children.Add(cell); } else throw new ArgumentException("Unknown element was encountered."); } while (true); } }