本文整理汇总了C#中Serializer.Put方法的典型用法代码示例。如果您正苦于以下问题:C# Serializer.Put方法的具体用法?C# Serializer.Put怎么用?C# Serializer.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serializer
的用法示例。
在下文中一共展示了Serializer.Put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CookiesToArray
public byte[] CookiesToArray()
{
Serializer serializer = new Serializer();
serializer.Put(_cookies.Count);
foreach (Cookie cookie in _cookies.GetCookies(_uri))
{
serializer.Put(cookie.Name);
serializer.Put(cookie.Value);
serializer.Put(cookie.Path);
serializer.Put(cookie.Domain);
}
return serializer.ToArray();
}
示例2: NamespacesToArray
public byte[] NamespacesToArray()
{
Serializer serializer = new Serializer();
serializer.Put(_namespaces.Count);
foreach (var pair in _namespaces)
{
serializer.Put(pair.Key);
serializer.Put(pair.Value);
}
return serializer.ToArray();
}
示例3: SwitchToLanguage
private void SwitchToLanguage(string language)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
path += @"\WikiLive\" + language;
Directory.CreateDirectory(path);
_baseName = path + @"\WikiLive.db";
if (!File.Exists(_baseName))
{
SQLiteConnection.CreateFile(_baseName);
}
if (_connection != null && _connection.State != ConnectionState.Closed)
{
_connection.Close();
}
SQLiteFactory factory = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
_connection = (SQLiteConnection)factory.CreateConnection();
_connection.ConnectionString = "Data Source = " + _baseName;
_connection.Open();
using (SQLiteCommand command = new SQLiteCommand(_connection))
{
command.CommandText = @"CREATE TABLE IF NOT EXISTS [edits] (
[id] integer PRIMARY KEY NOT NULL,
[timestamp] TEXT NOT NULL,
[user] TEXT NOT NULL,
[page] TEXT NOT NULL,
[namespace] INTEGER NOT NULL,
[flags] INTEGER NOT NULL,
[oldid] INTEGER NOT NULL,
[size] INTEGER NOT NULL,
[summary] TEXT NOT NULL
);";
command.CommandType = CommandType.Text;
command.ExecuteNonQuery();
}
using (SQLiteCommand command = new SQLiteCommand(_connection))
{
command.CommandText = @"CREATE TABLE IF NOT EXISTS [watched_pages] (
[id] integer PRIMARY KEY AUTOINCREMENT NOT NULL,
[page] TEXT NOT NULL,
[namespace] INTEGER NOT NULL
);";
command.CommandType = CommandType.Text;
command.ExecuteNonQuery();
}
if (!File.Exists(path + @"\namespaces.dat"))
{
Wiki wiki = new Wiki("http://" + language + ".wikipedia.org");
ParameterCollection parameters = new ParameterCollection();
parameters.Add("meta", "siteinfo");
parameters.Add("siprop", "namespaces");
XmlDocument xml = wiki.Enumerate(parameters, true);
XmlNodeList nodes = xml.SelectNodes("//ns[@id > 0]");
Serializer serializer = new Serializer();
serializer.Put(nodes.Count);
foreach (XmlNode node in nodes)
{
serializer.Put(node.Attributes["id"].Value);
serializer.Put(node.FirstChild.Value);
}
using (FileStream fs = new FileStream(path + @"\namespaces.dat", FileMode.CreateNew))
using (BinaryWriter streamWriter = new BinaryWriter(fs))
{
streamWriter.Write(serializer.ToArray());
}
}
}