예제 #1
0
        public void ProcessOperations(TrackableEntities list)
        {
            if (!this.isConnected)
            {
                return;
            }

            if (list == null)
            {
                return;
            }

            // We could have entities of different type within the same collection, couldn't we?

            /*
             * if (string.IsNullOrEmpty(list.Name))
             * {
             *  return;
             * }*/

            foreach (TrackableEntity item in list.Items)
            {
                object entity = item.Entity;

                switch (item.OperationType)
                {
                case TrackableEntity.Operation.Insert:

                    // I need to make it generic!
                    Type   entityType = entity.GetType();
                    string entityName = entityType.Name;

                    this.container.AddObject(entityName, entity);
                    break;

                case TrackableEntity.Operation.Update:
                    this.container.UpdateObject(entity);
                    break;

                case TrackableEntity.Operation.Delete:
                    this.container.DeleteObject(entity);
                    break;
                }
            }
        }
예제 #2
0
 // New version
 public CustomViewModel()
 {
     this.entityList = new TrackableEntities();
 }
예제 #3
0
        public void ProcessOperations(TrackableEntities list)
        {
            bool rst;

            if (this.serviceContext == null)
            {
                return;
            }

            if (list == null)
            {
                return;
            }

            // We could have entities of different type within the same collection, couldn't we?

            /*
             * if (string.IsNullOrEmpty(list.Name))
             * {
             *  return;
             * }*/

            foreach (TrackableEntity item in list.Items)
            {
                object entity = item.Entity;

                switch (item.OperationType)
                {
                case TrackableEntity.Operation.Insert:

                    // I need to make it generic!
                    string entityName = string.Empty;

                    Type entityType = entity.GetType();
                    if (string.IsNullOrEmpty(item.EntityName))
                    {
                        entityName = entityType.Name;
                    }
                    else
                    {
                        entityName = item.EntityName;
                    }

                    this.serviceContext.AddObject(entityName, entity);
                    break;

                // if the entity's context is null
                // then, runtime exception
                // run GetEntities() first
                case TrackableEntity.Operation.Update:
                    rst = this.IsValidEntity(entity);
                    if (rst)     // should we throw an exception here?
                    {
                        this.serviceContext.UpdateObject(entity);
                    }
                    break;

                // if the entity's context is null
                // then, runtime exception
                // run GetEntities() first
                case TrackableEntity.Operation.Delete:
                    rst = this.IsValidEntity(entity);
                    if (rst)
                    {
                        this.serviceContext.DeleteObject(entity);
                    }
                    break;
                }
            }
        }