Beispiel #1
0
 public static void Write(Stream stream, NupkgMetadataFile hashFile)
 {
     using (var textWriter = new StreamWriter(stream))
     {
         Write(textWriter, hashFile);
     }
 }
Beispiel #2
0
        public static void Write(TextWriter textWriter, NupkgMetadataFile hashFile)
        {
            using (var jsonWriter = new JsonTextWriter(textWriter))
            {
                jsonWriter.Formatting = Formatting.Indented;

                JsonSerializer.Serialize(jsonWriter, hashFile);
            }
        }
        private static NupkgMetadataFile ReadHashFile(JObject cursor)
        {
            var hashFile = new NupkgMetadataFile()
            {
                Version     = ReadInt(cursor, VersionProperty, defaultValue: int.MinValue),
                ContentHash = ReadProperty <string>(cursor, HashProperty),
            };

            return(hashFile);
        }
        private static JObject WriteHashFile(NupkgMetadataFile hashFile)
        {
            var json = new JObject
            {
                [VersionProperty] = new JValue(hashFile.Version),
                [HashProperty]    = hashFile.ContentHash
            };

            return(json);
        }
        public static void Write(TextWriter textWriter, NupkgMetadataFile hashFile)
        {
            using (var jsonWriter = new JsonTextWriter(textWriter))
            {
                jsonWriter.Formatting = Formatting.Indented;

                var json = WriteHashFile(hashFile);
                json.WriteTo(jsonWriter);
            }
        }
Beispiel #6
0
        public static void Write(string filePath, NupkgMetadataFile hashFile)
        {
            // Create the directory if it does not exist
            var fileInfo = new FileInfo(filePath);

            fileInfo.Directory.Create();

            using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                Write(stream, hashFile);
            }
        }
Beispiel #7
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                NupkgMetadataFile nupkgMetadataFile = existingValue as NupkgMetadataFile;

                if (nupkgMetadataFile == null)
                {
                    nupkgMetadataFile = new NupkgMetadataFile();
                }

                if (reader.TokenType != JsonToken.StartObject)
                {
                    throw new InvalidDataException();
                }

                while (reader.Read())
                {
                    switch (reader.TokenType)
                    {
                    case JsonToken.EndObject:
                        return(nupkgMetadataFile);

                    case JsonToken.PropertyName:
                        switch ((string)reader.Value)
                        {
                        case VersionProperty:
                            var intValue = reader.ReadAsInt32();
                            if (intValue.HasValue)
                            {
                                nupkgMetadataFile.Version = intValue.Value;
                            }
                            break;

                        case HashProperty:
                            nupkgMetadataFile.ContentHash = reader.ReadAsString();
                            break;

                        case SourceProperty:
                            nupkgMetadataFile.Source = reader.ReadAsString();
                            break;
                        }
                        break;

                    default:
                        reader.Skip();
                        break;
                    }
                }

                throw new JsonReaderException();
            }