profilemanager.cs
来自「可以收藏RSS和ATOM格式新闻频道,还可以收藏常用的html格式的网址;可以在」· CS 代码 · 共 100 行
CS
100 行
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
namespace NewsReader
{
public class ProfileManager
{
private Profile profile = new Profile();
public Profile Profile
{
get { return profile; }
set { profile = value; }
}
public ProfileManager(){}
public ProfileManager(Profile profile) { this.Profile = profile; }
public void Save()
{
try
{
FileStream fs = new FileStream("config.dat", FileMode.Create);
BinaryFormatter bw = new BinaryFormatter();
bw.Serialize(fs, profile);
}
catch (IOException ioe)
{
Console.Write(ioe.ToString());
return;
}
}
public void Save(string filename)
{
try
{
FileStream fs = new FileStream(filename, FileMode.Create);
BinaryFormatter bw = new BinaryFormatter();
bw.Serialize(fs, profile);
}
catch (IOException ioe)
{
Console.Write(ioe.ToString());
return;
}
}
private void ChannelReset()
{
Profile.Feeds.Clear();
//实例化频道
//FeedBase rssfeed;
}
public void Load()
{
try
{
if (!File.Exists("config.dat"))//如果文件不存在,则报错
{
MessageBox.Show("文件被损坏或不存在了!", "打开时出错了", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
FileStream fso = new FileStream("config.dat", FileMode.Open);
BinaryFormatter br = new BinaryFormatter();
Profile.Feeds.Clear();
profile = (Profile)br.Deserialize(fso);
}
catch (IOException ioe)
{
Console.Write(ioe.ToString());
return;
}
}
public void Load(string filename)
{
try
{
FileStream fso = new FileStream(filename, FileMode.Open);
BinaryFormatter br = new BinaryFormatter();
Profile.Feeds.Clear();
profile = (Profile)br.Deserialize(fso);
}
catch (IOException ioe)
{
Console.Write(ioe.ToString());
return;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?