/// <summary>
 /// Persists the selection state of the client, file names of all the stores
 /// loaded into the client and all the stores in the client.
 /// </summary>
 void SaveClientModelState(XmlElement userXmlElement,
                           ClientModel clientModel) {
   XmlElement clientXmlElement =
       this.xmlDocument.CreateElement(LKGStatePersistor.ClientElementName);
   userXmlElement.AppendChild(clientXmlElement);
   clientXmlElement.SetAttribute(
       LKGStatePersistor.NameAttrName,
       clientModel.Client.Name);
   clientXmlElement.SetAttribute(
       LKGStatePersistor.SelectionStateAttrName,
       clientModel.IsSelected.ToString());
   foreach (
     string storeFileName in
       clientModel.Client.LoadedStoreFileNames) {
     XmlElement loadedStoreXmlElement =
       this.xmlDocument.CreateElement(
           LKGStatePersistor.LoadedStoreElementName);
     clientXmlElement.AppendChild(loadedStoreXmlElement);
     loadedStoreXmlElement.SetAttribute(
         LKGStatePersistor.PathAttrName,
         storeFileName);
   }
   foreach (StoreModel storeModel in clientModel.Children) {
     this.SaveStoreModelState(
         clientXmlElement,
         storeModel);
   }
 }
 /// <summary>
 /// Restores the selection state of the given client model, and then
 /// walks the xml and loads all the loaded stores. Then it goes on to load
 /// the state of each store.
 /// </summary>
 void LoadClientModelState(XmlElement clientXmlElement,
                           ClientModel clientModel) {
   LKGStatePersistor.LoadSelectedState(
       clientXmlElement,
       clientModel);
   foreach (XmlNode childXmlNode in clientXmlElement.ChildNodes) {
     XmlElement childXmlElement = childXmlNode as XmlElement;
     if (childXmlElement == null) {
       continue;
     }
     if (childXmlElement.Name != LKGStatePersistor.LoadedStoreElementName) {
       continue;
     }
     string filePath =
         childXmlElement.GetAttribute(LKGStatePersistor.PathAttrName);
     if (filePath == null || filePath.Length == 0) {
       continue;
     }
     if (!File.Exists(filePath)) {
       continue;
     }
     clientModel.OpenStore(filePath);
   }
   foreach (XmlNode childXmlNode in clientXmlElement.ChildNodes) {
     XmlElement childXmlElement = childXmlNode as XmlElement;
     if (childXmlElement == null) {
       continue;
     }
     if (childXmlElement.Name != LKGStatePersistor.StoreElementName) {
       continue;
     }
     string storeDisplayName =
         childXmlElement.GetAttribute(LKGStatePersistor.DisplayNameAttrName);
     string storePersistName =
         childXmlElement.GetAttribute(LKGStatePersistor.PersistNameAttrName);
     foreach (StoreModel storeModel in clientModel.Children) {
       if (storeDisplayName != storeModel.Store.DisplayName ||
           storePersistName != storeModel.Store.PersistName) {
         continue;
       }
       this.LoadStoreModelState(
           childXmlElement,
           storeModel);
     }
   }
 }