Esempio n. 1
0
        public void TwiceInsertNotInSameOrderWithUnicityConstraint_RelationShouldBeUpdated()
        {
            var entityDesktopA = new EntitySync {
                UniqueIdentifier = "A"
            };
            var entityDesktopB = new EntitySync {
                UniqueIdentifier = "B"
            };

            Desktop.Repository <EntitySync, IEntitySync>().Save(entityDesktopA);
            Desktop.Repository <EntitySync, IEntitySync>().Save(entityDesktopB);

            var entityRemoteA = new EntitySync {
                UniqueIdentifier = "A"
            };
            var entityRemoteB = new EntitySync {
                UniqueIdentifier = "B"
            };

            FirstRemote.Repository <EntitySync, IEntitySync>().Save(entityRemoteB);
            FirstRemote.Repository <EntitySync, IEntitySync>().Save(entityRemoteA);

            var entityRelatedOnA = new EntityRelated {
                RelatedId = entityRemoteA.Id
            };

            FirstRemote.Repository <EntityRelated, IEntityRelated>().Save(entityRelatedOnA);

            SyncRemote();

            AssertSyncRepository(Desktop.Repository <EntitySync, IEntitySync>(), FirstRemote.Repository <EntitySync, IEntitySync>());
        }
Esempio n. 2
0
        public void DeleteEntityOnCLientAndInsertRelatedOnRemote_DeleteRelatedOnRemote()
        {
            var entity = new EntitySync {
                UniqueIdentifier = "AA"
            };

            Desktop.Repository <EntitySync, IEntitySync>().Save(entity);

            SyncRemote();

            //INsert related on remote
            var related = new EntityRelated {
                RelatedId = entity.Id
            };

            FirstRemote.Repository <EntityRelated, IEntityRelated>().Save(related);

            //Delete foreign key reference on desktop
            Desktop.Repository <EntitySync, IEntitySync>().Delete(entity);

            SyncRemote();

            AssertSyncRepository(Desktop.Repository <EntityRelated, IEntityRelated>(), FirstRemote.Repository <EntityRelated, IEntityRelated>());
            AssertSyncRepository(Desktop.Repository <EntitySync, IEntitySync>(), FirstRemote.Repository <EntitySync, IEntitySync>());
        }
Esempio n. 3
0
        public void ConflictOnUpdatedEntityLinkedToAnInsertedEntity()
        {
            var entity = new EntitySync {
                UniqueIdentifier = "AA"
            };

            Desktop.Repository <EntitySync, IEntitySync>().Save(entity);
            var related = new EntityRelated {
                RelatedId = entity.Id
            };

            Desktop.Repository <EntityRelated, IEntityRelated>().Save(related);

            SyncRemote();

            FirstRemote.Repository <EntityRelated, IEntityRelated>().Save(related);

            entity = new EntitySync {
                UniqueIdentifier = "BB"
            };
            Desktop.Repository <EntitySync, IEntitySync>().Save(entity);
            related.RelatedId = entity.Id;
            Desktop.Repository <EntityRelated, IEntityRelated>().Save(related);

            SyncRemote();

            AssertSyncRepository(Desktop.Repository <EntitySync, IEntitySync>(), FirstRemote.Repository <EntitySync, IEntitySync>());
        }
Esempio n. 4
0
 /// <summary>
 /// Determina si la propiedad es de tipo entidad
 /// </summary>
 /// <param name="index">Índice que representa la propiedad</param>
 /// <param name="local">Si es local, significa que no tiene su propio key value en la base de dato de persistencia.</param>
 /// <param name="visible">Determina si la propiedad es visible en el cliente.</param>
 public ReferenceSearchAttribute(EntityRelated index, bool local = false, bool visible = true)
 {
     KindIndex = (int)(local ? KindEntityProperty.LOCAL_REFERENCE : KindEntityProperty.REFERENCE);
     Index     = (int)index;
     Visible   = visible;
     IsEntity  = true;
 }
Esempio n. 5
0
        public void DeleteEntityOnClientAndInsertNotRelatedRemote_InsertOnRemote()
        {
            var entity = new EntitySync {
                UniqueIdentifier = "AA"
            };
            var entityToDelete = new EntitySync {
                UniqueIdentifier = "AB"
            };

            Desktop.Repository <EntitySync, IEntitySync>().Save(entity);
            Desktop.Repository <EntitySync, IEntitySync>().Save(entityToDelete);

            SyncRemote();

            //INsert related on remote
            var related = new EntityRelated {
                RelatedId = entity.Id
            };

            FirstRemote.Repository <EntityRelated, IEntityRelated>().Save(related);

            //Delete foreign key reference on desktop
            Desktop.Repository <EntitySync, IEntitySync>().Delete(entityToDelete);

            SyncRemote();

            Assert.AreEqual(Desktop.Repository <EntitySync, IEntitySync>().Count(), 1);
            Assert.AreEqual(Desktop.Repository <EntityRelated, IEntityRelated>().Count(), 1);
            AssertSyncRepository(Desktop.Repository <EntityRelated, IEntityRelated>(), FirstRemote.Repository <EntityRelated, IEntityRelated>());
            AssertSyncRepository(Desktop.Repository <EntitySync, IEntitySync>(), FirstRemote.Repository <EntitySync, IEntitySync>());
        }
        public static Type GetEntityType(EntityRelated index, Type typeOfAssembly, string Namespace)
        {
            var assembly   = Assembly.GetAssembly(typeOfAssembly);
            var modelTypes = assembly.GetLoadableTypes().Where(type => type.FullName.StartsWith(Namespace) && Attribute.IsDefined(type, typeof(ReferenceSearchAttribute)));
            var entityType = modelTypes.Where(type => type.GetTypeInfo().GetCustomAttributes <ReferenceSearchAttribute>().Any(s => s.Index == (int)index)).FirstOrDefault();

            return(entityType);
        }
Esempio n. 7
0
 public ReferenceSearchAttribute(EntityRelated index, EntityRelated bypass, bool visible = true)
 {
     KindIndex = (int)KindEntityProperty.REFERENCE;
     Index     = (int)index;
     Visible   = visible;
     RealIndex = (int)bypass;
     IsEntity  = true;
 }
Esempio n. 8
0
 /// <summary>
 /// Incluye la entidad en la metadata.
 /// </summary>
 /// <param name="index">Índice de una entidad</param>
 /// <param name="local">Si es local, significa que no tiene su propio key value en la base de dato de persistencia.</param>
 /// <param name="visible">Determina si la clase es visible en el cliente.</param>
 /// <param name="pathname">Ruta usada para la API o el router del cliente</param>
 /// <param name="entityKind">Determina si es una entidad, un proceso u otro.</param>
 public ReferenceSearchHeaderAttribute(EntityRelated index, bool local = false, bool visible = true, string pathname = "", EntityKind entityKind = EntityKind.ENTITY)
 {
     KindIndex = (int)(local ? KindEntityProperty.LOCAL_REFERENCE : KindEntityProperty.REFERENCE);
     Index     = (int)index;
     Visible   = visible;
     PathName  = pathname;
     Kind      = entityKind;
 }
        public EntitySearch[] GetElementsWithRelatedElement(EntityRelated elementToGet, EntityRelated relatedElement, string idRelatedElement)
        {
            var indexClient = _search.Indexes.GetClient(_entityIndex);
            var entities    = indexClient.Documents.Search <EntitySearch>(null, new SearchParameters {
                Filter = string.Format(Queries(SearchQuery.ENTITIES_WITH_ENTITYID), (int)elementToGet, (int)relatedElement, idRelatedElement)
            }).Results.Select(s => s.Document);

            return(entities.ToArray());
        }
        public EntitySearch GetEntity(EntityRelated entityRelated, string id)
        {
            var indexClient = _search.Indexes.GetClient(_entityIndex);
            var entity      = indexClient.Documents.Search <EntitySearch>(null, new SearchParameters {
                Filter = string.Format(Queries(SearchQuery.GET_ELEMENT), (int)entityRelated, id)
            }).Results.FirstOrDefault()?.Document;

            return(entity);
        }
Esempio n. 11
0
        /// <summary>
        /// Elimina elementos que tengan una entidad asociada, por ejemplo, borraría todos los alumnos de ingeniería informática, pero no los de arquitectura.
        /// a diferencia de DeleteElementsWithRelatedElement
        /// púede existir un elemento que no se borrará indicandolo con el campo elementExceptId.
        /// borraría todos los alumnos de informática menos el id del alumno ingresado
        /// </summary>
        /// <param name="elementToDelete">Entidad que será eliminada, por ejemplo alumnos</param>
        /// <param name="relatedElement">Entidad que contiene la agrupación, por ejemplo carrera</param>
        /// <param name="idRelatedElement">identificador de la entidad que contiene la colección, por ejemplo carrera = informatica</param>
        /// <param name="elementExceptId">identificador de elemento que no debe ser eliminado dentro del grupo, por ejemplo, el alumno juan garcia</param>
        public void DeleteElementsWithRelatedElementExceptId(EntityRelated elementToDelete, EntityRelated relatedElement, string idRelatedElement, string elementExceptId)
        {
            // consulta para eliminar
            var query = string.Format(Queries(SearchQuery.ENTITIES_WITH_ENTITYID_EXCEPTID), (int)elementToDelete, (int)relatedElement, idRelatedElement, elementExceptId);

            //añade al registro.
            AddToQueried(nameof(AgroSearch <GeoPointType> .DeleteElementsWithRelatedElementExceptId), query);
            // eliminación.
            baseMainSearch.DeleteElements(query);
        }
Esempio n. 12
0
        /// <summary>
        /// Elimina elementos que tengan una entidad asociada, por ejemplo, borraría todos los alumnos de ingeniería informática.
        /// </summary>
        /// <param name="elementToDelete">Entidad que será elimina</param>
        /// <param name="relatedElement">el elemento que debe estar presente para la consulta de elementos a eliminar</param>
        /// <param name="idRelatedElement">identificador de elemento relacionado que debe estar presenta para la consulta de elementos a eliminar</param>
        public void DeleteElementsWithRelatedElement(EntityRelated elementToDelete, EntityRelated relatedElement, string idRelatedElement)
        {
            // obtiene la consulta desde un diccionario y asigna los parámetros
            var query = string.Format(Queries(SearchQuery.ENTITIES_WITH_ENTITYID), (int)elementToDelete, (int)relatedElement, idRelatedElement);

            // añade al registro
            AddToQueried(nameof(AgroSearch <GeoPointType> .DeleteElementsWithRelatedElement), query);

            // elimina los elementos encontrados en la consulta.
            baseMainSearch.DeleteElements(query);
        }
Esempio n. 13
0
        /// <summary>
        /// Obtener una entidad, indicando el tipo y el identificador.
        /// </summary>
        /// <param name="entityRelated">Tipo entidad que obtendremos</param>
        /// <param name="id">identificador de la entidad</param>
        /// <returns>EntitySearch del tipo solicitado</returns>
        public IEntitySearch <GeoPointType> GetEntity(EntityRelated entityRelated, string id)
        {
            // obtiene la consulta desde un diccionario y asigna los parámetros
            var query = string.Format(Queries(SearchQuery.GET_ELEMENT), (int)entityRelated, id);

            // consulta al search
            AddToQueried(nameof(AgroSearch <GeoPointType> .GetEntity), query);

            // primer elemento de la consulta.
            return(baseMainSearch.FilterElements(query)?.FirstOrDefault());
        }
Esempio n. 14
0
        /// <summary>
        /// Obtiene entidades de un tipo, que tengas un tipo asociado con identificador.
        /// por ejemplo, buscar todos los alumnos, que esten en la carrera de ingeniería informática.
        /// el related element sería la carrera y el elementToGet sería obtener el usuario.
        /// </summary>
        /// <param name="elementToGet">Elemento a obtener, por ejemplo el alumno</param>
        /// <param name="relatedElement">elemento relacionado por el cual se debe filtrar, por ejemplo la carrera</param>
        /// <param name="idRelatedElement">identificar del elemento relacionado</param>
        /// <returns>Listado de entitySearch</returns>
        public IEntitySearch <GeoPointType>[] GetElementsWithRelatedElement(EntityRelated elementToGet, EntityRelated relatedElement, string idRelatedElement)
        {
            // format query
            var filter = string.Format(Queries(SearchQuery.ENTITIES_WITH_ENTITYID), (int)elementToGet, (int)relatedElement, idRelatedElement);

            // añade a consultas
            AddToQueried(nameof(AgroSearch <GeoPointType> .GetElementsWithRelatedElement), filter);

            // retorna elementos de acuerdo al filtro.
            return(baseMainSearch.FilterElements(filter).ToArray());
        }
Esempio n. 15
0
        /// <summary>
        /// Elimina entidades que tengan un tipo y un id.
        /// </summary>
        /// <param name="entityRelated">Tipo de elemento a eliminar</param>
        /// <param name="id">identificador de la entidad</param>
        public void DeleteEntity(EntityRelated entityRelated, string id)
        {
            // consulta desde diccionario
            var query = string.Format(Queries(SearchQuery.GET_ELEMENT), (int)entityRelated, id);

            // registro de consulta
            AddToQueried(nameof(AgroSearch <GeoPointType> .DeleteEntity), query);

            // elimina elementos de la consulta.
            baseMainSearch.DeleteElements(query);
        }
Esempio n. 16
0
        public void EntityCreatedBeforeUsingSyncFrameworkHasNoCreatedAtValue()
        {
            var entity = new EntityRelated();

            Desktop.DataStore.Insert(entity);
            FirstRemote.DataStore.Insert(entity);
            AssertSyncRepository(Desktop.Repository <EntityRelated, IEntityRelated>(), FirstRemote.Repository <EntityRelated, IEntityRelated>());

            entity.IntField = 2;
            Desktop.Save <EntityRelated, IEntityRelated>(entity);

            SyncRemote();

            AssertSyncRepository(Desktop.Repository <EntityRelated, IEntityRelated>(), FirstRemote.Repository <EntityRelated, IEntityRelated>());
        }
Esempio n. 17
0
        public void EntityRelatedCanHaveCustomEntityTombstone()
        {
            var entity = new EntityRelated();
            var repo   = Desktop.Repository <EntityRelated, IEntityRelated>();

            repo.Save(entity);

            repo.Delete(entity);

            var columnExist = Desktop.DataStore.ExecuteScalar("SELECT COUNT(*) FROM information_schema.columns WHERE [TABLE_NAME] = 'entity_related_tombstone' AND [COLUMN_NAME] = 'CustomProp'");

            Assert.AreEqual(1, columnExist);

            SyncRemote();

            columnExist = FirstRemote.DataStore.ExecuteScalar("SELECT COUNT(*) FROM information_schema.columns WHERE [TABLE_NAME] = 'entity_related_tombstone' AND [COLUMN_NAME] = 'CustomProp'");
            Assert.AreEqual(1, columnExist);

            var rometeRows = FirstRemote.DataStore.ExecuteScalar("SELECT Count(*) FROM entity_related_tombstone");

            Assert.AreEqual(1, rometeRows);
        }
Esempio n. 18
0
        public void Sync_EntityReferencesInFKDeletedInLocal_IsDeleteOnRemote()
        {
            var entity = new EntitySync {
                UniqueIdentifier = "AA"
            };

            Desktop.Repository <EntitySync, IEntitySync>().Save(entity);
            var related = new EntityRelated {
                RelatedId = entity.Id
            };

            Desktop.Repository <EntityRelated, IEntityRelated>().Save(related);

            SyncRemote();

            related.RelatedId = null;
            Desktop.Repository <EntityRelated, IEntityRelated>().Save(related);
            Desktop.Repository <EntitySync, IEntitySync>().Delete(entity);

            SyncRemote();

            Assert.AreEqual(Desktop.Repository <EntitySync, IEntitySync>().Count(), 0);
            AssertSyncRepository(Desktop.Repository <EntitySync, IEntitySync>(), FirstRemote.Repository <EntitySync, IEntitySync>());
        }
Esempio n. 19
0
        private static IEntitySearch <GeoPointTs>[] ReturnSearchElement(string id, EntityRelated index)
        {
            switch (index)
            {
            case EntityRelated.WAITINGHARVEST:
                return(AgroData.WaitingHarvestSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.BARRACK:
                return(AgroData.BarracksSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.BUSINESSNAME:
                return(AgroData.BusinessNamesSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.CATEGORY_INGREDIENT:
                return(AgroData.IngredientCategoriesSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.CERTIFIED_ENTITY:
                return(AgroData.CertifiedEntitiesSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.COSTCENTER:
                return(AgroData.CostCentersSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.DOSES:
                return(AgroData.DosesSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.INGREDIENT:
                return(AgroData.IngredientsSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.JOB:
                return(AgroData.JobsSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.NEBULIZER:
                return(AgroData.NebulizersSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.PHENOLOGICAL_EVENT:
                return(AgroData.PhenologicalEventsSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.PLOTLAND:
                return(AgroData.PlotLandsSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.PRODUCT:
                return(AgroData.ProductSearchs.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.ROLE:
                return(AgroData.RolesSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.ROOTSTOCK:
                return(AgroData.RootstocksSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.SEASON:
                return(AgroData.SeasonsSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.SECTOR:
                return(AgroData.SectorsSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.PREORDER:
                return(AgroData.PreOrdersSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.TARGET:
                return(AgroData.ApplicationTargetsSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.TRACTOR:
                return(AgroData.TractorsSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.USER:
                break;

            case EntityRelated.VARIETY:
                return(AgroData.VarietiesSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.NOTIFICATION_EVENT:
                break;

            case EntityRelated.POLLINATOR:
                break;

            case EntityRelated.ORDER_FOLDER:
                break;

            case EntityRelated.EXECUTION_ORDER:
                break;

            case EntityRelated.ORDER:
                break;

            case EntityRelated.BARRACK_EVENT:
                break;

            case EntityRelated.DOSES_ORDER:
                break;

            case EntityRelated.EXECUTION_ORDER_STATUS:
                break;

            case EntityRelated.SPECIE:
                return(AgroData.SpeciesSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            case EntityRelated.GEOPOINT:
                break;

            case EntityRelated.BRAND:
                return(AgroData.BrandsSearch.Where(s => Mdm.Reflection.Collections.GetId(s).Equals(id)).ToArray());

            default:
                break;
            }

            throw new Exception("not good");
        }
Esempio n. 20
0
        private static void RemoveSearchElement(string id, EntityRelated index)
        {
            switch (index)
            {
            case EntityRelated.WAITINGHARVEST:
                AgroData.WaitingHarvestSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.WaitingHarvestSearch);
                break;

            case EntityRelated.BARRACK:
                AgroData.BarracksSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.BarracksSearch);
                break;

            case EntityRelated.BUSINESSNAME:
                AgroData.BusinessNamesSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.BusinessNamesSearch);
                break;

            case EntityRelated.CATEGORY_INGREDIENT:
                AgroData.IngredientCategoriesSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.IngredientCategoriesSearch);
                break;

            case EntityRelated.CERTIFIED_ENTITY:
                AgroData.CertifiedEntitiesSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.CertifiedEntitiesSearch);
                break;

            case EntityRelated.COSTCENTER:
                AgroData.CostCentersSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.CostCentersSearch);
                break;

            case EntityRelated.DOSES:
                AgroData.DosesSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.DosesSearch);
                break;

            case EntityRelated.INGREDIENT:
                AgroData.IngredientsSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.IngredientsSearch);
                break;

            case EntityRelated.JOB:
                break;

            case EntityRelated.NEBULIZER:
                break;

            case EntityRelated.PHENOLOGICAL_EVENT:
                break;

            case EntityRelated.PLOTLAND:
                AgroData.PlotLandsSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.PlotLandsSearch);
                break;

            case EntityRelated.PRODUCT:
                AgroData.ProductSearchs = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.ProductSearchs);
                break;

            case EntityRelated.ROLE:
                break;

            case EntityRelated.ROOTSTOCK:
                AgroData.RootstocksSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.RootstocksSearch);
                break;

            case EntityRelated.SEASON:
                AgroData.SeasonsSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.SeasonsSearch);
                break;

            case EntityRelated.SECTOR:
                AgroData.SectorsSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.SectorsSearch);
                break;

            case EntityRelated.PREORDER:
                break;

            case EntityRelated.TARGET:
                break;

            case EntityRelated.TRACTOR:
                break;

            case EntityRelated.USER:
                break;

            case EntityRelated.VARIETY:
                AgroData.VarietiesSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.VarietiesSearch);
                break;

            case EntityRelated.NOTIFICATION_EVENT:
                break;

            case EntityRelated.POLLINATOR:
                break;

            case EntityRelated.ORDER_FOLDER:
                break;

            case EntityRelated.EXECUTION_ORDER:
                break;

            case EntityRelated.ORDER:
                break;

            case EntityRelated.BARRACK_EVENT:
                break;

            case EntityRelated.DOSES_ORDER:
                break;

            case EntityRelated.EXECUTION_ORDER_STATUS:
                break;

            case EntityRelated.SPECIE:
                AgroData.SpeciesSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.SpeciesSearch);
                break;

            case EntityRelated.GEOPOINT:
                break;

            case EntityRelated.BRAND:
                AgroData.BrandsSearch = Mdm.Reflection.Collections.DeleteElementInCollection(id, AgroData.BrandsSearch);
                break;

            default:
                break;
            }
        }
 /// <summary>
 /// Si un autonumérico depende de otra entidad se podrá indicar en el constructor,
 /// dependerán de otra entidad cuando la generación de la secuencia depende de otra entidad,
 /// por ejemplo un listado de producto que tiene un autonumérico que depende de una factura, todas las facturas empezarían desde cero.
 /// </summary>
 /// <param name="index">Índice de la propiedad numérica que será autonumérica</param>
 /// <param name="dependant">Índice de la entidad de la que depende</param>
 public AutoNumericSearchAttribute(StringRelated index, EntityRelated dependant) : this(index)
 {
     Dependant = (int?)dependant;
 }
Esempio n. 22
0
 public DisplaySearchEntity(EntityRelated index) : base(ResourcesExtension.GetResourceCollection(ResourceRelated.REF), ResourceRelated.REF)
 {
     Index = index;
 }
Esempio n. 23
0
        public void Intercept(IInvocation invocation)
        {
            Entity entity = invocation.InvocationTarget.CastToType <Entity>();

            Debug.Assert(entity.IsNotNull(), "EntityInterceptor error");
            if (!entity.Disposing)
            {
                string propertyName = invocation.Method.Name;
                if (propertyName.StartsWith("get_"))
                {
                    propertyName = propertyName.Substring(4, propertyName.Length - 4);
                }
                EntityProperty property = entity.EntityCtx.Properties.FirstOrDefault(p => p.Name == propertyName);
                if (property.IsNotNull() && property.ReletedEntity.IsNotNull() &&
                    property.ReletedEntity.Related == Releted.Entity && property.ReletedEntity.Relation.IsNotNull())
                {
                    EntitiesRelation relation      = property.ReletedEntity.Relation;
                    EntityRelated    relatedEntity = relation.Parent;
                    EntityRelated    currentEntity = relation.Child;
                    Debug.Assert(relatedEntity.IsNotNull() || currentEntity.IsNotNull(), "EntityInterceptor error");
                    if (!relatedEntity.Entity.Uid.Equals(entity.GetUid(propertyName)))
                    {
                        List <T> list = relatedEntity.Entity.Entities.WhereEntity(p => relatedEntity.Value(p).
                                                                                  Equals(currentEntity.Value(entity)) &&
                                                                                  property.ReletedEntity.Discriminators.TrueForAll(new Predicate <Discriminator>((d) => { return(d.Discriminate(p)); }))).Cast <T>().ToList();

                        if (list.Count() == 1)
                        {
                            invocation.ReturnValue = list[0].CastToType <T>();
                            if (property.Setter.IsNotNull())
                            {
                                entity[propertyName] = invocation.ReturnValue;
                            }
                            entity.SetUid(propertyName, relatedEntity.Entity.Uid);
                        }
                        else if (list.Count() > 1)
                        {
                            throw new ModelException();
                        }
                        else
                        {
                            invocation.ReturnValue = default(T);
                            if (property.Setter.IsNotNull())
                            {
                                entity[propertyName] = invocation.ReturnValue;
                            }
                            entity.SetUid(propertyName, relatedEntity.Entity.Uid);
                        }
                    }
                    else
                    {
                        invocation.Proceed();
                    }
                }
                else
                {
                    Debug.Assert(false, "EntityInterceptor error");
                }
            }
            else
            {
                invocation.Proceed();
            }
        }
 public ReferenceSearchHeaderAttribute(EntityRelated index, bool local = false) : base(index, local)
 {
 }
 public AutoNumericSearchAttribute(NumRelated index, EntityRelated dependant) : this(index)
 {
     Dependant = dependant;
 }
 public ReferenceSearchAttribute(EntityRelated index, bool local = false)
 {
     _index = index;
     Local  = local;
 }
        public void DeleteElementsWithRelatedElementExceptId(EntityRelated elementToDelete, EntityRelated relatedElement, string idRelatedElement, string elementExceptId)
        {
            var query = string.Format(Queries(SearchQuery.ENTITIES_WITH_ENTITYID_EXCEPTID), (int)elementToDelete, (int)relatedElement, idRelatedElement, elementExceptId);

            DeleteElements <EntitySearch>(query);
        }
        public static ModelDictionary GetModel(IEnumerable <PropertySearchInfo> propertySearchInfos, EntityRelated index)
        {
            var propByRelatedAndIndex = propertySearchInfos.GroupBy(s => new { s.Related, s.IndexClass, s.Index }).Select(s => s.FirstOrDefault());
            var enumEmun        = GetDescription(typeof(EnumRelated));
            var modelInfo       = ResourceExtension.ResourceModel(Related.REFERENCE, propByRelatedAndIndex.FirstOrDefault().IndexClass);
            var modelDictionary = new ModelDictionary()
            {
                Index       = index,
                Description = modelInfo.Description,
                ShortName   = modelInfo.ShortName,
                Title       = modelInfo.Title,
                BoolData    = GetDictionaryFromRelated(propByRelatedAndIndex, Related.BOOL),
                StringData  = GetDictionaryFromRelated(propByRelatedAndIndex, Related.STR),
                DateData    = GetDictionaryFromRelated(propByRelatedAndIndex, Related.DATE),
                DoubleData  = GetDictionaryFromRelated(propByRelatedAndIndex, Related.DBL),
                EnumData    = GetEnumDictionaryFromRelated(propByRelatedAndIndex, enumEmun),
                GeoData     = GetDictionaryFromRelated(propByRelatedAndIndex, Related.GEO),
                NumData     = GetDictionaryFromRelated(propByRelatedAndIndex, Related.NUM32),
                relData     = GetDictionaryFromRelated(propByRelatedAndIndex, Related.REFERENCE),
            };
            var suggestions           = GetDictionaryFromRelated(propByRelatedAndIndex, Related.SUGGESTION);
            var num64                 = GetDictionaryFromRelated(propByRelatedAndIndex, Related.NUM64);
            var suggestionNotInString = suggestions.Where(sg => !modelDictionary.StringData.Any(s => s.Key == sg.Key));
            var num64NotInNum         = num64.Where(sg => !modelDictionary.NumData.Any(s => s.Key == sg.Key));
            var relLocal              = GetDictionaryFromRelated(propByRelatedAndIndex, Related.LOCAL_REFERENCE);

            if (suggestionNotInString.Any())
            {
                foreach (var item in suggestionNotInString)
                {
                    modelDictionary.StringData.Add(item.Key, item.Value);
                }
            }
            if (num64NotInNum.Any())
            {
                foreach (var item in num64NotInNum)
                {
                    modelDictionary.NumData.Add(item.Key, item.Value);
                }
            }
            if (relLocal.Any())
            {
                foreach (var item in relLocal)
                {
                    modelDictionary.relData.Add(item.Key, item.Value);
                }
            }


            return(modelDictionary);
        }
        public void DeleteEntity(EntityRelated entityRelated, string id)
        {
            var query = string.Format(Queries(SearchQuery.GET_ELEMENT), (int)entityRelated, id);

            DeleteElements <EntitySearch>(query);
        }