Ejemplo 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"]);
 }
Ejemplo n.º 2
0
        /// <inheritdoc />
        protected override async Task ProcessRecordAsync(CancellationToken cancellationToken)
        {
            Entity entity;
            var    changes = new List <EntityEditEntry>();

            if (Item)
            {
                entity = new Entity(WikiSite, EntityType.Item);
            }
            else if (Property)
            {
                entity = new Entity(WikiSite, EntityType.Property);
                var type = BuiltInDataTypes.Get(DataType);
                if (type == null)
                {
                    throw new ArgumentException("Invalid data type name.", nameof(DataType));
                }
                changes.Add(new EntityEditEntry(nameof(entity.DataType), type));
            }
            else
            {
                throw new InvalidOperationException();
            }
            if (Labels != null)
            {
                var labeledLang = new HashSet <string>();
                foreach (var l in Labels)
                {
                    var lang = l.Language.ToLowerInvariant();
                    if (labeledLang.Contains(lang))
                    {
                        changes.Add(new EntityEditEntry(nameof(entity.Aliases), l));
                    }
                    else
                    {
                        changes.Add(new EntityEditEntry(nameof(entity.Labels), l));
                    }
                }
            }
            if (Descriptions != null)
            {
                foreach (var d in Descriptions)
                {
                    changes.Add(new EntityEditEntry(nameof(entity.Descriptions), d));
                }
            }
            await entity.EditAsync(changes, Summary,
                                   WikibaseUtility.MakeEntityEditOptions(bulk: true, bot: Bot), cancellationToken);

            WriteObject(entity);
        }
Ejemplo n.º 3
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);
        }