/// <summary> /// 保存配置 /// </summary> /// <param name="config"></param> public static void SaveConfig(OAuthWeiboConfig config) { string sDirectory = Himall.Core.Helper.IOHelper.urlToVirtual(WorkDirectory) + "/Weibo.config"; XmlSerializer xml = new XmlSerializer(typeof(OAuthWeiboConfig)); MemoryStream Stream = new MemoryStream(); xml.Serialize(Stream, config); byte[] b = Stream.ToArray(); MemoryStream stream2 = new MemoryStream(b); Himall.Core.HimallIO.CreateFile(sDirectory, stream2, Core.FileCreateType.Create); }
public static void SaveConfig(OAuthWeiboConfig config) { FileStream fileStream = new FileStream(string.Concat(WeiboCore.WorkDirectory, "\\Weibo.config"), FileMode.Create); try { (new XmlSerializer(typeof(OAuthWeiboConfig))).Serialize(fileStream, config); } finally { if (fileStream != null) { ((IDisposable)fileStream).Dispose(); } } }
/// <summary> /// 获取配置 /// </summary> /// <returns></returns> public static OAuthWeiboConfig GetConfig() { OAuthWeiboConfig config = new OAuthWeiboConfig(); string sDirectory = Himall.Core.Helper.IOHelper.urlToVirtual(WorkDirectory) + "/Weibo.config"; if (HimallIO.ExistFile(sDirectory)) { XmlSerializer xs = new XmlSerializer(typeof(OAuthWeiboConfig)); byte[] b = Himall.Core.HimallIO.GetFileContent(sDirectory); string str = System.Text.Encoding.Default.GetString(b); MemoryStream fs = new MemoryStream(b); config = (OAuthWeiboConfig)xs.Deserialize(fs); } else { SaveConfig(config); } return(config); }