本文整理汇总了C#中DeserializeContext.Close方法的典型用法代码示例。如果您正苦于以下问题:C# DeserializeContext.Close方法的具体用法?C# DeserializeContext.Close怎么用?C# DeserializeContext.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeserializeContext
的用法示例。
在下文中一共展示了DeserializeContext.Close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
/// <summary>
/// Load data of authority from file.
/// </summary>
/// <param name="fileName">Name of file to load.</param>
private void Load(string fileName)
{
FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
DeserializeContext context = new DeserializeContext(fileStream);
this.parameters = context.ReadObject<VotingParameters>();
this.signedParameters = context.ReadObject<Signed<VotingParameters>>();
this.authorities = new Dictionary<int,Certificate>();
int count = context.ReadInt32();
count.Times(() => this.authorities.Add(context.ReadInt32(), context.ReadObject<Certificate>()));
this.authority = new Authority(context, this.parameters);
context.Close();
fileStream.Close();
}
示例2: TryLoadPregeneratedSafePrime
/// <summary>
/// Tries to load a pregenerated safe prime.
/// </summary>
/// <param name="dataPath">Path where application data is stored.</param>
/// <param name="bitLength">Length of the prime.</param>
/// <param name="prime">Prime loaded.</param>
/// <param name="safePrime">Safe prime loaded.</param>
/// <returns>Was a prime and safe prime found?</returns>
public static bool TryLoadPregeneratedSafePrime(string dataPath, int bitLength, out BigInt prime, out BigInt safePrime)
{
var dataDirectory = new DirectoryInfo(dataPath);
var files = dataDirectory.GetFiles(Files.SafePrimePattern);
foreach (var file in files)
{
try
{
FileStream fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read);
DeserializeContext context = new DeserializeContext(fileStream);
prime = context.ReadBigInt();
safePrime = context.ReadBigInt();
context.Close();
fileStream.Close();
file.Delete();
if (Prime.HasSufficientLength(prime, bitLength) &&
Prime.HasSufficientLength(safePrime, bitLength) &&
Prime.IsPrime(prime) &&
Prime.IsSafePrime(safePrime))
{
return true;
}
}
catch
{
file.Delete();
}
}
prime = null;
safePrime = null;
return false;
}
示例3: RunExtract
private void RunExtract()
{
try
{
Progress = 0;
FileStream fileStream = new FileStream(this.backupFile, FileMode.Open, FileAccess.Read);
GZipStream gzipStream = new GZipStream(fileStream, CompressionMode.Decompress);
DeserializeContext context = new DeserializeContext(gzipStream);
int fileCount = context.ReadInt32();
long totalSize = context.ReadInt64();
long doneSize = 0;
for (int index = 0; index < fileCount; index++)
{
string fileName = context.ReadString();
FileName = fileName;
byte[] data = context.ReadBytes();
File.WriteAllBytes(Path.Combine(this.dataPath, fileName), data);
doneSize += data.Length;
Progress = 1d / (double)totalSize * (double)doneSize;
}
context.Close();
gzipStream.Close();
fileStream.Close();
}
catch (Exception exception)
{
Exception = exception;
}
Complete = true;
}
示例4: FromBinary
/// <summary>
/// Deserializes an exception from binary data.
/// </summary>
/// <param name="data">Binary data of exception.</param>
/// <returns>An exception.</returns>
public static PiException FromBinary(byte[] data)
{
MemoryStream stream = new MemoryStream(data);
DeserializeContext context = new DeserializeContext(stream);
string typeName = context.ReadString();
ExceptionCode code = (ExceptionCode)context.ReadInt32();
string message = context.ReadString();
Type type = Type.GetType(typeName);
PiException exception = (PiException)Activator.CreateInstance(type, new object[] { code, code.Text() });
exception.ServerMessage = message;
context.Close();
stream.Close();
return exception;
}