コード例 #1
0
		protected virtual void WriteToIsolatedStorage(string fileName, PersistenceFlags flags)
		{
			using (System.IO.IsolatedStorage.IsolatedStorageFile l_Storage = GetStorage())
			{
				System.IO.IsolatedStorage.IsolatedStorageFileStream l_File = null;
				l_File = new System.IO.IsolatedStorage.IsolatedStorageFileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, l_Storage);
				try
				{
					WriteToStream(l_File, flags);
				}
				finally
				{
					l_File.Close();
				}

				l_Storage.Close();
			}		
		}
コード例 #2
0
		protected virtual void WriteToXmlElement(System.Xml.XmlElement xmlElement, PersistenceFlags flags)
		{
			//settings
			System.Xml.XmlNode xmlsettings = xmlElement.SelectSingleNode("settings");
			if (xmlsettings == null)
			{
				xmlsettings = xmlElement.OwnerDocument.CreateElement("settings");
				xmlElement.AppendChild(xmlsettings);
			}
			//items
			System.Xml.XmlNode xmlitems = xmlsettings.SelectSingleNode("items");
			if (xmlitems == null)
			{
				xmlitems = xmlsettings.OwnerDocument.CreateElement("items");
				xmlsettings.AppendChild(xmlitems);
				xmlitems.Attributes.Append(xmlitems.OwnerDocument.CreateAttribute("schemaversion"));
				xmlitems.Attributes["schemaversion"].Value = "1";
			}

			foreach (PersistableItem item in m_Dictionary.Values)
			{
				string xPath = string.Format("item[@name='{0}' and @type='{1}' and @schemaversion='1']", item.Name, item.Type.FullName);
				System.Xml.XmlNode xmlitem = xmlitems.SelectSingleNode(xPath);

				if ( (flags & PersistenceFlags.OnlyChanges) == PersistenceFlags.OnlyChanges &&
					item.IsChanged == false)
				{ //remove item
					if (xmlitem != null)
						xmlitems.RemoveChild(xmlitem);
				}
				else //add item
				{
					if (xmlitem == null)
					{
						xmlitem = xmlitems.OwnerDocument.CreateElement("item");
						xmlitems.AppendChild(xmlitem);

						xmlitem.Attributes.Append(xmlitem.OwnerDocument.CreateAttribute("name"));
						xmlitem.Attributes.Append(xmlitem.OwnerDocument.CreateAttribute("type"));
						xmlitem.Attributes.Append(xmlitem.OwnerDocument.CreateAttribute("schemaversion"));
						
						xmlitem.Attributes["name"].Value = item.Name;
						xmlitem.Attributes["type"].Value = item.Type.FullName;
						xmlitem.Attributes["schemaversion"].Value = "1";
					}
					xmlitem.InnerText = item.Validator.ValueToString(item.Value);
				}
			}
		}
コード例 #3
0
		protected virtual void WriteToStream(System.IO.Stream stream, PersistenceFlags flags)
		{
//			System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8);
//			
//			writer.Formatting = System.Xml.Formatting.Indented;
//			writer.WriteStartDocument();
//			writer.WriteStartElement("settings");
//
//			writer.WriteStartElement("items");
//			writer.WriteAttributeString("schemaversion", "1");
//			
//			foreach (PersistableItem item in m_Dictionary.Values)
//			{
//				if ( (flags & PersistenceFlags.OnlyChanges) == PersistenceFlags.OnlyChanges &&
//					item.IsChanged == false)
//					continue;
//
//				writer.WriteStartElement("item");
//				writer.WriteAttributeString("name", item.Name);
//				writer.WriteAttributeString("type", item.Type.FullName);
//				writer.WriteAttributeString("schemaversion", "1");
//				writer.WriteString(item.Validator.ValueToString(item.Value));
//				writer.WriteEndElement();
//			}
//
//			writer.WriteEndElement();
//
//			writer.WriteEndElement();
//			writer.WriteEndDocument();
//			writer.Flush();


			System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
			doc.AppendChild(doc.CreateElement("settings"));
			WriteToXmlElement(doc.DocumentElement, flags);

			System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8);
			writer.Formatting = System.Xml.Formatting.Indented;
			doc.WriteTo(writer);
			writer.Flush();
		}