private void InitCat_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e) { if (e.Error != null) { _SignAc.HideWaiting(); Main.ShowAlert(e.Error.Message); return; } string xml = e.Result; using (XmlReader reader = XmlReader.Create(new StringReader(xml))) { if (xml.IndexOf("<Error>") > 0) { _SignAc.HideWaiting(); reader.ReadToFollowing("Error"); Main.ShowAlert(reader.ReadElementContentAsString()); return; } Cat cat; while (reader.Name == "Cat" || reader.ReadToFollowing("Cat")) { cat = new Cat(); if (!cat.FromXml(reader)) { continue; } _DataModel.SaveVcs(cat); } } WebClient client = new WebClient(); client.Headers["Content-type"] = "application/x-www-form-urlencoded"; client.Encoding = Encoding.UTF8; client.UploadStringCompleted += new UploadStringCompletedEventHandler(InitLib_UploadStringCompleted); client.UploadStringAsync(new Uri(CApp.SERVER_PATH), "POST", "&o=lib&c=" + _UserModel.Code); }
/// <summary> /// 类别 /// </summary> /// <param name="userModel"></param> /// <param name="setting"></param> private void ImportWPwdCat(AUserModel userModel, XmlReaderSettings setting) { string file = Path.Combine(userModel.DatHome, "WPwd-Cat.xml"); if (!File.Exists(file)) { return; } StreamReader stream = new StreamReader(file); using (XmlReader reader = XmlReader.Create(stream, setting)) { Cat cat; while (reader.Name == "Cat" || reader.ReadToFollowing("Cat")) { cat = new Cat(); if (!cat.FromXml(reader)) { continue; } _DataModel.DeleteVcs(cat); _DataModel.SaveVcs(cat); } } stream.Close(); }
private void InitDat() { _UserModel.Load(); BeanUtil.UnZip(CApp.FILE_DAT, _UserModel.DatHome); _DataModel = new ADataModel(_UserModel); _DataModel.Init(); string file; StreamReader stream; XmlReaderSettings setting = new XmlReaderSettings { IgnoreWhitespace = true }; #region 字符 file = Path.Combine(_UserModel.DatHome, "App-Udc.xml"); if (File.Exists(file)) { stream = new StreamReader(file); using (XmlReader reader = XmlReader.Create(stream, setting)) { Udc udc; while (reader.Name == "Udc" || reader.ReadToFollowing("Udc")) { udc = new Udc(); if (!udc.FromXml(reader)) { continue; } _DataModel.SaveVcs(udc); } } stream.Close(); } #endregion #region 类别 file = Path.Combine(_UserModel.DatHome, "App-Cat.xml"); if (File.Exists(file)) { stream = new StreamReader(file); using (XmlReader reader = XmlReader.Create(stream, setting)) { Cat cat; while (reader.Name == "Cat" || reader.ReadToFollowing("Cat")) { cat = new Cat(); if (!cat.FromXml(reader)) { continue; } _DataModel.SaveVcs(cat); } } stream.Close(); } #endregion #region 模板 file = Path.Combine(_UserModel.DatHome, "WPwd-Lib.xml"); if (File.Exists(file)) { stream = new StreamReader(file); using (XmlReader reader = XmlReader.Create(stream, setting)) { Lib header; while (reader.Name == "Lib" || reader.ReadToFollowing("Lib")) { header = new Lib(); if (!header.FromXml(reader)) { continue; } _DataModel.SaveVcs(header); } } stream.Close(); } #endregion #region 目录 file = Path.Combine(_UserModel.DatHome, "WPwd-Dir.xml"); if (File.Exists(file)) { stream = new StreamReader(file); using (XmlReader reader = XmlReader.Create(stream, setting)) { Dir dir; while (reader.Name == "Dir" || reader.ReadToFollowing("Dir")) { dir = new Dir(); if (!dir.FromXml(reader)) { continue; } _DataModel.SaveVcs(dir); } } stream.Close(); } #endregion _DataModel.Dispose(); _SignAc.CallBack(CApp.IAPP_WPWD); }