Exemplo n.º 1
0
 private void LoadFromContract(Contracts.Snak snak)
 {
     Debug.Assert(snak != null);
     SnakType     = ParseSnakType(snak.SnakType);
     Hash         = snak.Hash;
     RawDataValue = snak.DataValue;
     DataType     = BuiltInDataTypes.Get(snak.DataType)
                    ?? MissingPropertyType.Get(snak.DataType, (string)snak.DataValue?["type"]);
 }
Exemplo n.º 2
0
        internal static SerializableEntity Load(Contracts.Entity entity)
        {
            // If caller deserializes entity from EOF-ed stream, the caller can get null.
            if (entity == null)
            {
                return(null);
            }
            var inst = new SerializableEntity(false)
            {
                Id   = entity.Id,
                Type = ParseEntityType(entity.Type)
            };

            if (entity.DataType != null)
            {
                inst.DataType = BuiltInDataTypes.Get(entity.DataType) ?? MissingPropertyType.Get(entity.DataType, entity.DataType);
            }
            inst.Labels = new WbMonolingualTextCollection(
                entity.Labels?.Values.Select(v => new WbMonolingualText(v.Language, v.Value))
                ?? Enumerable.Empty <WbMonolingualText>());
            inst.Descriptions = new WbMonolingualTextCollection(
                entity.Descriptions?.Values.Select(v => new WbMonolingualText(v.Language, v.Value))
                ?? Enumerable.Empty <WbMonolingualText>());
            inst.Aliases = new WbMonolingualTextsCollection(
                entity.Aliases?.Values.SelectMany(vs => vs).Select(v => new WbMonolingualText(v.Language, v.Value))
                ?? Enumerable.Empty <WbMonolingualText>());
            inst.SiteLinks = new EntitySiteLinkCollection(
                entity.Sitelinks?.Values.Select(v => new EntitySiteLink(v.Site, v.Title,
                                                                        new ReadOnlyCollection <string>(v.Badges)))
                ?? Enumerable.Empty <EntitySiteLink>());
            if (entity.Claims == null || entity.Claims.Count == 0)
            {
                inst.Claims = new ClaimCollection();
            }
            else
            {
                // { claims : { P47 : [ {}, {}, ... ], P105 : ... } }
                inst.Claims = new ClaimCollection(entity.Claims.Values.SelectMany(c => c).Select(Claim.FromContract));
            }
            return(inst);
        }