Beispiel #1
0
        /// <summary>
        /// Implements the SetObject command
        /// </summary>
        public virtual IEnumerable <IPersistenceObject> SetObjects(
            Guid version,
            IZetboxContext ctx,
            IEnumerable <IPersistenceObject> objList,
            IEnumerable <ObjectNotificationRequest> notificationRequests)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (objList == null)
            {
                throw new ArgumentNullException("objList");
            }
            if (notificationRequests == null)
            {
                throw new ArgumentNullException("notificationRequests");
            }
            ZetboxGeneratedVersionAttribute.Check(version);

            var objects       = objList.Cast <BaseServerPersistenceObject>().ToList();
            var entityObjects = new Dictionary <IPersistenceObject, IPersistenceObject>();

            ApplyObjectChanges(ctx, notificationRequests, objects, entityObjects);

            ctx.SubmitChanges();

            var requestedObjects = GetRequestedObjects(ctx, notificationRequests, entityObjects);

            return(entityObjects.Values.Concat(requestedObjects));
        }
Beispiel #2
0
 public Stream GetBlobStream(Guid version, IZetboxContext ctx, int ID)
 {
     if (ctx == null)
     {
         throw new ArgumentNullException("ctx");
     }
     ZetboxGeneratedVersionAttribute.Check(version);
     return(ctx.GetStream(ID));
 }
Beispiel #3
0
        public IEnumerable <IStreamable> GetList(Guid version, IZetboxContext ctx, int maxListCount, List <Expression> filter, List <OrderBy> orderBy)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            ZetboxGeneratedVersionAttribute.Check(version);

            if (maxListCount > Zetbox.API.Helper.MAXLISTCOUNT)
            {
                maxListCount = Zetbox.API.Helper.MAXLISTCOUNT;
            }

            var result = ctx.GetQuery <T>();

            if (filter != null)
            {
                foreach (var f in filter)
                {
                    result = (IQueryable <T>)result.AddFilter(f);
                }
            }

            if (orderBy != null)
            {
                bool first = true;
                foreach (var o in orderBy)
                {
                    if (first)
                    {
                        if (o.Type == OrderByType.ASC)
                        {
                            result = result.AddOrderBy <T>(o.Expression);
                        }
                        else
                        {
                            result = result.AddOrderByDescending <T>(o.Expression);
                        }
                    }
                    else
                    {
                        if (o.Type == OrderByType.ASC)
                        {
                            result = result.AddThenBy <T>(o.Expression);
                        }
                        else
                        {
                            result = result.AddThenByDescending <T>(o.Expression);
                        }
                    }
                    first = false;
                }
            }

            return(result.Take(maxListCount).ToList().Cast <IStreamable>());
        }
Beispiel #4
0
        public Zetbox.App.Base.Blob SetBlobStream(Guid version, IZetboxContext ctx, Stream blob, string filename, string mimetype)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }
            ZetboxGeneratedVersionAttribute.Check(version);

            var id  = ctx.CreateBlob(blob, filename, mimetype);
            var obj = ctx.Find <Zetbox.App.Base.Blob>(id);

            ctx.SubmitChanges();
            return(obj);
        }
Beispiel #5
0
        /// <summary>
        /// Since IsList properties are not automatically transferred,
        /// GetListOf can be used to get the list of values in the property
        /// <code>property</code> of the object with the <code>ID</code>
        /// </summary>
        /// <returns>the list of values in the property</returns>
        public IEnumerable <IStreamable> GetListOf(Guid version, IZetboxContext ctx, int ID, string property)
        {
            if (ID <= API.Helper.INVALIDID)
            {
                throw new ArgumentException("ID must not be invalid");
            }
            ZetboxGeneratedVersionAttribute.Check(version);

            T obj = GetObjectInstance(ctx, ID);

            if (obj == null)
            {
                throw new ArgumentOutOfRangeException("ID", "Object not found");
            }

            IEnumerable list = (IEnumerable)obj.GetPropertyValue <IEnumerable>(property);

            return(list.Cast <IStreamable>());
        }
Beispiel #6
0
        public object InvokeServerMethod(Guid version, IZetboxContext ctx, int ID, string method, IEnumerable <Type> parameterTypes, IEnumerable <object> parameter, IEnumerable <IPersistenceObject> objects, IEnumerable <ObjectNotificationRequest> notificationRequests, out IEnumerable <IPersistenceObject> changedObjects)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (objects == null)
            {
                throw new ArgumentNullException("objects");
            }
            if (notificationRequests == null)
            {
                throw new ArgumentNullException("notificationRequests");
            }
            ZetboxGeneratedVersionAttribute.Check(version);

            var objList       = objects.Cast <BaseServerPersistenceObject>().ToList();
            var entityObjects = new Dictionary <IPersistenceObject, IPersistenceObject>();

            BaseServerObjectSetHandler.ApplyObjectChanges(ctx, notificationRequests, objList, entityObjects);

            // Call Method
            var obj = GetObjectInstance(ctx, ID);
            var mi  = obj.GetType().FindMethod(method, parameterTypes.ToArray());

            if (mi == null)
            {
                throw new InvalidOperationException(string.Format("Method {0}.{1}({2}) not found", typeof(T).FullName, method, string.Join(", ", parameterTypes.Select(i => i.Name).ToArray())));
            }
            object result = mi.Invoke(obj, parameter.ToArray());

            var requestedObjects = BaseServerObjectSetHandler.GetRequestedObjects(ctx, notificationRequests, entityObjects);

            changedObjects = entityObjects.Values.Concat(requestedObjects);

            return(result);
        }
Beispiel #7
0
        public IEnumerable <IRelationEntry> GetCollectionEntries(
            Guid version,
            IZetboxContext ctx,
            Guid relId, RelationEndRole endRole,
            int parentId)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            ZetboxGeneratedVersionAttribute.Check(version);

            var rel = ctx.FindPersistenceObject <Relation>(relId);
            //var relEnd = rel.GetEndFromRole(endRole);
            //var relOtherEnd = rel.GetOtherEnd(relEnd);
            var parent = ctx.Find(ctx.GetImplementationType(typeof(TParent)).ToInterfaceType(), parentId);
            var ceType = ctx.ToImplementationType(rel.GetEntryInterfaceType()).Type;

            var method = this.GetType().GetMethod("GetCollectionEntriesInternal", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            return((IEnumerable <IRelationEntry>)method
                   .MakeGenericMethod(ceType)
                   .Invoke(this, new object[] { parent, rel, endRole }));
        }