当前位置: 首页>>代码示例>>C#>>正文


C# DeserializeContext.Close方法代码示例

本文整理汇总了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();
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:21,代码来源:AuthorityEntity.cs

示例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;
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:46,代码来源:Prime.cs

示例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;
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:36,代码来源:BackupFile.cs

示例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;
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:23,代码来源:PiException.cs


注:本文中的DeserializeContext.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。