예제 #1
0
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        public override object ReadJson( Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer )
        {
            var catalog = new Catalog();
            if( reader.TokenType == Newtonsoft.Json.JsonToken.StartObject )
            {
                while( reader.Read() && reader.TokenType != Newtonsoft.Json.JsonToken.EndObject )
                {
                    switch( reader.Value.ToString() )
                    {
                        case "name": catalog.Name = reader.ReadAsString(); break;
                        case "uuid": catalog.Uuid = new Guid( reader.ReadAsString() ); break;
                        case "validAttributes":
                            if( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.StartArray )
                            {
                                var atts = new List<ushort>();
                                while( reader.Read() && reader.TokenType != Newtonsoft.Json.JsonToken.EndArray )
                                {
                                    atts.Add( Convert.ToUInt16( reader.Value ) );
                                }
                                catalog.ValidAttributes = atts.ToArray();
                            }
                            break;
                        case "catalogEntries":
                            if( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.StartArray )
                            {
                                if( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.StartObject )
                                {
                                    var entries = new List< CatalogEntry >();
                                    while( reader.TokenType != Newtonsoft.Json.JsonToken.EndArray )
                                    {
                                        entries.Add(serializer.Deserialize<CatalogEntry>( reader ));
                                        reader.Read();
                                    }
                                    catalog.CatalogEntries = entries.ToArray();
                                }
                            }
                            break;

                    }
                }
            }
            return catalog;
        }
예제 #2
0
		/// <summary> 
		/// Updates the specified catalogs. If the catalog contains entries, the entries will be updated too.
		/// </summary>
		/// <param name="catalogs">The catalogs to update.</param>
		/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
		public Task UpdateCatalogs( Catalog[] catalogs, CancellationToken cancellationToken = default(CancellationToken) )
		{
			return Put( "catalogs", catalogs, cancellationToken );
		}