Exemplo n.º 1
0
        private async Task <APEntity> _flatten(IEntityStore store, ASObject @object, bool generateId, IDictionary <string, APEntity> entities, string parentId = null)
        {
            var entity = new APEntity();

            if (@object["href"].Any()) // Link
            {
                return(null);
            }

            if (@object.Id == null)
            {
                if (!generateId)
                {
                    return(null);
                }
                @object.Id = await _urlService.FindUnusedID(store, @object, null, parentId);

                entity.IsOwner = true;
            }

            entity.Id = @object.Id;
            var t = @object.Type.FirstOrDefault();

            if (t?.StartsWith("_") != false && t?.StartsWith("_:") != true)
            {
                t = "Unknown";
            }
            entity.Type = t;

            foreach (var kv in @object)
            {
                foreach (var value in kv.Value)
                {
                    if (value.SubObject == null)
                    {
                        continue;
                    }

                    var subObject = await _flatten(store, value.SubObject, generateId, entities, entity.Id);

                    if (subObject == null)
                    {
                        continue;
                    }

                    value.Id        = subObject.Id;
                    value.Primitive = null;
                    value.SubObject = null;
                }
            }

            entity.Data         = @object;
            entities[entity.Id] = entity;

            return(entity);
        }
Exemplo n.º 2
0
        public async Task <APEntity> NewCollection(IEntityStore store, ASObject mold = null, string type = null, string superItem = null)
        {
            if (mold == null)
            {
                mold = new ASObject();
            }
            mold.Type.Add("https://www.w3.org/ns/activitystreams#OrderedCollection");
            var owner = mold.Id == null;

            if (mold.Id == null)
            {
                mold.Id = await _urlService.FindUnusedID(store, mold, type?.Replace("_", "").ToLower(), superItem);
            }

            var entity = new APEntity
            {
                Id      = mold.Id,
                Data    = mold,
                Type    = type ?? "https://www.w3.org/ns/activitystreams#OrderedCollection",
                IsOwner = owner
            };

            return(entity);
        }