Ejemplo n.º 1
0
        private static JFileFields ReadAllFieldsFrom(string json)
        {
            using StringReader stringReader     = new StringReader(json);
            using JsonTextReader jsonTextReader = new JsonTextReader(stringReader);
            jsonTextReader.Read();

            JFileFields fields = new JFileFields();

            JFileReader jFileReader = new JFileReader(jsonTextReader);

            while (true)
            {
                JFileFieldType fieldType = jFileReader.MoveToNext();

                if (fieldType == JFileFieldType.None)
                {
                    break;
                }

                switch (fieldType)
                {
                case JFileFieldType.None:
                    break;

                case JFileFieldType.FileName:
                    fields.FileName = jFileReader.ReadName();
                    break;

                case JFileFieldType.FileSize:
                    fields.FileSize = jFileReader.ReadSize();
                    break;

                case JFileFieldType.LastModifiedTime:
                    fields.LastModifiedTime = jFileReader.ReadLastModifiedTime();
                    break;

                case JFileFieldType.Hash:
                    fields.FileHash = jFileReader.ReadHash();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(fields);
        }
        private HFile ReadFile(JFileReader jFileReader)
        {
            HFile hFile = new HFile();

            bool isFinished = false;

            while (!isFinished)
            {
                switch (jFileReader.CurrentPropertyType)
                {
                case JFileFieldType.None:
                    isFinished = true;
                    break;

                case JFileFieldType.FileName:
                    hFile.Name = jFileReader.ReadName();
                    break;

                case JFileFieldType.FileSize:
                    hFile.Size = jFileReader.ReadSize();
                    break;

                case JFileFieldType.LastModifiedTime:
                    hFile.LastModifiedTime = jFileReader.ReadLastModifiedTime();
                    break;

                case JFileFieldType.Hash:
                    hFile.Hash = jFileReader.ReadHash();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                jSnapshotReader.MoveNext();
            }

            return(hFile);
        }