Ejemplo n.º 1
0
        /// <inheritdoc />
        protected override async Task ProcessRecordAsync(CancellationToken cancellationToken)
        {
            var entities = GetEntities();
            var options  = EntityQueryOptions.FetchInfo
                           | EntityQueryOptions.FetchLabels
                           | EntityQueryOptions.FetchAliases;

            if (Descriptions)
            {
                options |= EntityQueryOptions.FetchDescriptions;
            }
            if (Claims)
            {
                options |= EntityQueryOptions.FetchClaims;
            }
            if (SiteLinks)
            {
                options |= EntityQueryOptions.FetchSiteLinks;
            }
            var languages = Languages ?? WikibaseUtility.GetLocalLanguages();

            if (languages.Count == 1 && languages[0] == "*")
            {
                languages = null;
            }
            await entities.RefreshAsync(options, languages, cancellationToken);

            WriteObject(entities, true);
        }
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
        /// <inheritdoc />
        protected override async Task ProcessRecordAsync(CancellationToken cancellationToken)
        {
            if (Labels == null || Labels.Length == 0)
            {
                return;
            }
            var entity = Entity ?? new Entity(WikiSite, Id);

            if (!ShouldProcess(string.Format("Setting {0} labels for {1}.", Labels.Length, entity.Id)))
            {
                return;
            }
            await entity.EditAsync(Labels.Select(l => new EntityEditEntry(nameof(entity.Labels), l)),
                                   Summary, WikibaseUtility.MakeEntityEditOptions(bot: Bot), cancellationToken);
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        protected override async Task ProcessRecordAsync(CancellationToken cancellationToken)
        {
            var entity   = Entity ?? new Entity(WikiSite, Id);
            var summary  = Summary;
            var property = new Entity(entity.Site, Property);
            await property.RefreshAsync(EntityQueryOptions.FetchInfo, null, cancellationToken);

            if (!ShouldProcess(string.Format("{0}.{1} := {2}", entity.Id, property.Id, Value)))
            {
                return;
            }
            await entity.EditAsync(new[]
            {
                new EntityEditEntry(nameof(entity.Claims), new Claim(property.Id)
                {
                    MainSnak =
                    {
                        DataType  = property.DataType,
                        DataValue = Value,
                    }
                })
            }, summary, WikibaseUtility.MakeEntityEditOptions(bot: Bot), cancellationToken);
        }