Exemplo n.º 1
0
        public JFileFieldType MoveToNext()
        {
            switch (state)
            {
            case JReaderState.New:
                state = JReaderState.InProgress;
                break;

            case JReaderState.InProgress:
                break;

            case JReaderState.Finished:
                throw new Exception("The reader already finished reading the json object.");

            default:
                throw new Exception("Invalid reader state.");
            }

            try
            {
                bool success = MoveToNextProperty();

                CurrentPropertyType = success
                    ? JsonTextReader.Value switch
                {
                    "n" => JFileFieldType.FileName,
                    "s" => JFileFieldType.FileSize,
                    "m" => JFileFieldType.LastModifiedTime,
                    "h" => JFileFieldType.Hash,
                    _ => throw new Exception("Invalid field in file object.")
                }
                    : JFileFieldType.None;

                return(CurrentPropertyType);
            }
Exemplo n.º 2
0
        protected bool MoveToNextProperty()
        {
            while (true)
            {
                bool success = JsonTextReader.Read();

                if (!success)
                {
                    return(false);
                }

                switch (JsonTextReader.TokenType)
                {
                case JsonToken.None:
                case JsonToken.StartObject:
                case JsonToken.StartArray:
                case JsonToken.StartConstructor:
                case JsonToken.Raw:
                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.String:
                case JsonToken.Boolean:
                case JsonToken.Null:
                case JsonToken.Undefined:
                case JsonToken.EndArray:
                case JsonToken.EndConstructor:
                case JsonToken.Date:
                case JsonToken.Bytes:
                    throw new Exception("Invalid json token in directory object.");

                case JsonToken.Comment:
                    break;

                case JsonToken.PropertyName:
                    return(true);

                case JsonToken.EndObject:
                    State = JReaderState.Finished;
                    return(false);

                default:
                    throw new Exception("Invalid json token in directory object.");
                }
            }
        }
Exemplo n.º 3
0
        protected void MoveToNextState()
        {
            switch (State)
            {
            case JReaderState.New:
                State = JReaderState.InProgress;
                break;

            case JReaderState.InProgress:
                break;

            case JReaderState.Finished:
                throw new Exception("The reader already finished reading the json object.");

            default:
                throw new Exception("Invalid reader state.");
            }
        }