private async Task <BaseObject> OnAfterDelivery(ActivityDeliveryContext ctx)
 {
     ctx.IsReading  = false;
     ctx.IsWriting  = true;
     ctx.HasWritten = true;
     return(await GetPipe().Pipe(ctx));
 }
Exemplo n.º 2
0
 public async Task <BaseObject> Pipe(ActivityDeliveryContext ctx)
 {
     if (ctx.IsReading || (ctx.IsWriting && !ctx.HasWritten))
     {
         foreach (var handler in this)
         {
             var objTask = handler.Pipe(ctx);
             var obj     = await(objTask ?? throw new Exception($"{handler.GetType().FullName}.Pipe() returned null task"));
             if (ctx.item == null)
             {
                 return(null);
             }
             else if (obj != null)
             {
                 return(obj);
             }
         }
     }
     else
     {
         for (int i = this.Count - 1; i >= 0; i--)
         {
             var obj = await this[i].Pipe(ctx);
             if (ctx.item == null)
             {
                 return(null);
             }
             else if (obj != null)
             {
                 return(obj);
             }
         }
     }
     return(null);
 }
        public override async Task <BaseObject> Set(ActivityObject item, ActivityStreamFilter filter)
        {
            var box = GetBox(filter);
            var ctx = new ActivityDeliveryContext {
                context = this, box = box, item = item, Filter = filter
            };
            var ret = await OnBeforeDelivery(ctx);

            if (ret == null)
            {
                ret = await box.Write(item);

                if (ret == null)
                {
                    throw new Exception("Box returned null");
                }
                else if (ret is Error err)
                {
                    return(ret);
                }
                else if (ret is ActivityObject activity)
                {
                    ctx.item = activity;
                    ret      = await OnAfterDelivery(ctx);
                }
                else
                {
                    throw new ArgumentException($"Box returned invalid type {ret.type ?? ret.GetType().FullName}");
                }
            }

            return(ret);
        }