Exemplo n.º 1
0
        private async Task ProcessCollectionsToClient(HttpContext context, ModelFromClient fromClient, ModelToClient model)
        {
            if (fromClient.root.children != null && fromClient.root.children.Count > 0)
            {
                if (model.refreshAll)
                {
                    model.collections = null;
                }
                if (model.collections == null)
                {
                    await ProcessCollectionsFromClient(context, fromClient, model);
                }
                foreach (ModelFromClientCollection clientCol in fromClient.root.children)
                {
                    BusinessCollectionBase col = await Collection(clientCol.path);

                    List <ModelToClient> elements     = model.collections[clientCol.path];
                    ModelToClient        currentModel = null;

                    foreach (BusinessBase obj in col)
                    {
                        currentModel = elements.Find(element => element.keyObject == obj.Key);

                        await obj.ProcessResponseInternalElement(context, clientCol, currentModel);
                    }
                }
            }
        }
        public virtual async Task CopyTo(BusinessCollectionBase colTarget)
        {
            await EnsureList();

            foreach (BusinessBase objOrigen in this)
            {
                bool         isNew     = false;
                BusinessBase objTarget = colTarget.Search(objOrigen);

                if (objTarget == null)
                {
                    isNew     = true;
                    objTarget = colTarget.CreateNew();
                }

                objOrigen.CopyTo(objTarget, null);

                if (isNew)
                {
                    colTarget.AddActiveObject();
                }
            }

            colTarget.CreateNew();
        }
Exemplo n.º 3
0
        private async Task ProcessCollectionsFromClient(HttpContext context, ModelFromClient fromClient, ModelToClient model)
        {
            if (fromClient.root.children != null && fromClient.root.children.Count > 0)
            {
                model.collections = new Dictionary <string, List <ModelToClient> >(fromClient.root.children.Count);

                foreach (ModelFromClientCollection clientCol in fromClient.root.children)
                {
                    BusinessCollectionBase col = await Collection(clientCol.path);

                    List <ModelToClient> elements = new List <ModelToClient>(col.Count);
                    ModelFromClientData  clientElement;

                    foreach (BusinessBase obj in col)
                    {
                        clientElement = null;

                        if (clientCol.elements != null && !model.refreshAll)
                        {
                            clientElement = clientCol.elements.Find(element => obj.Key == element.key);
                        }

                        elements.Add(await obj.ProcessRequestInternalElement(context, clientCol, clientElement, fromClient.action));
                    }

                    model.collections.Add(clientCol.path, elements);
                }
            }
        }
        public virtual async Task <BusinessCollectionBase> Collection(string collectionName)
        {
            BusinessCollectionBase col = NotEnsuredCollection(collectionName);

            await col.EnsureList();

            return(col);
        }
        public BusinessCollectionFiltered(BusinessCollectionBase col, string filterName)
        {
            filtered = new BusinessCollectionFilteredEnumerator(col, filterName);

            while (filtered.MoveNext())
            {
                Count++;
            }
            filtered.Reset();
        }
        public virtual BusinessCollectionBase NotEnsuredCollection(string collectionName)
        {
            BusinessCollectionBase col = null;

            try
            {
                col = relatedCollections[collectionName];
                if (col == null)
                {
                    throw new Exception("Not possible.");
                }
            }
            catch
            {
                throw new ArgumentException("Collection " + collectionName + " not defined in " + this.ObjectName + ".");
            }

            return(col);
        }
 public BusinessCollectionFilteredEnumerator(BusinessCollectionBase col, string filterName)
 {
     _col        = col;
     _filterName = filterName;
     Reset();
 }