/// <summary>
        /// Convert client filters to Select object.
        /// </summary>
        /// <param name="userConnection">A <see cref="instance"/> of the current user connection.</param>
        /// <param name="ruleId">Unique identifier of the scoring rule.</param>
        /// <param name="entitySchemaName">Rule entity schema name.</param>
        /// <returns>Select object</returns>
        public Select GetRuleSelectQuery(UserConnection userConnection, Guid ruleId, string entitySchemaName)
        {
            EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager;
            EntitySchemaQuery   formESQ             = new EntitySchemaQuery(entitySchemaManager, entitySchemaName);

            formESQ.PrimaryQueryColumn.IsAlwaysSelect = true;
            formESQ.AddColumn("SearchData");
            formESQ.Filters.Add(formESQ.CreateFilterWithParameters(
                                    FilterComparisonType.Equal,
                                    "Id",
                                    new object[] { ruleId }
                                    ));
            EntityCollection formEntityCollection = formESQ.GetEntityCollection(userConnection);
            Entity           entity = formEntityCollection.First();

            byte[] searchData        = entity.GetColumnValue("SearchData") as byte[];
            string serializedFilters = UTF8Encoding.UTF8.GetString(searchData, 0, searchData.Length);

            DataContract.Filters jsonFilters = Json.Deserialize <DataContract.Filters>(serializedFilters);
            var leadSchema = entitySchemaManager.GetInstanceByName("Lead");
            var esqFilters = jsonFilters.BuildEsqFilter(leadSchema.UId, userConnection);
            var leadEsq    = new EntitySchemaQuery(userConnection.EntitySchemaManager, leadSchema.Name);

            leadEsq.UseAdminRights = false;
            leadEsq.PrimaryQueryColumn.IsVisible = true;
            leadEsq.Filters.Add(esqFilters);
            return(leadEsq.GetSelectQuery(userConnection));
        }
Esempio n. 2
0
 public virtual void DeleteRemindingList(EntityCollection entities)
 {
     while (entities.Any())
     {
         entities.First().Delete();
     }
 }
        private static bool DeleteEntities(EntityCollection favoriteFolders)
        {
            bool deleted = false;

            while (favoriteFolders.Any())
            {
                favoriteFolders.First().Delete();
                deleted = true;
            }
            return(deleted);
        }
Esempio n. 4
0
        private Guid GetTimeZoneId(string code)
        {
            var    query        = new EntitySchemaQuery(_userConnection.EntitySchemaManager, "TimeZone");
            string idColumnName = query.AddColumn("Id").Name;

            query.Filters.Add(query.CreateFilterWithParameters(FilterComparisonType.Equal, "Code", code));
            EntityCollection collection = query.GetEntityCollection(_userConnection);
            Entity           entity     = collection.First();

            return(entity.GetTypedColumnValue <Guid>(idColumnName));
        }
 private Entity GetFirstEntity(EntityCollection entityCollection)
 {
     if (entityCollection.Count > 0)
     {
         return(entityCollection.First());
     }
     else
     {
         return(null);
     }
 }
        public void should_add_created_entity_into_the_collection()
        {
            var mockEventSystem   = Substitute.For <IEventSystem>();
            var mockEntityFactory = Substitute.For <IEntityFactory>();

            mockEntityFactory.Create(null).Returns(new Entity(Guid.NewGuid(), mockEventSystem));

            var entityCollection = new EntityCollection("", mockEntityFactory, mockEventSystem);
            var entity           = entityCollection.CreateEntity();

            Assert.Equal(1, entityCollection.Count());
            Assert.Equal(entity, entityCollection.First());
        }
Esempio n. 7
0
        public static void DeleteAll <TEntity>(
            this DbContext context,
            EntityCollection <TEntity> collection)
            where TEntity : class, IEntityWithRelationships
        {
            if (!collection.IsLoaded)
            {
                collection.Load( );
            }

            while (collection.Any( ))
            {
                var entity = collection.First( );
                context.Set <TEntity>( ).Remove(entity);
            }
        }
Esempio n. 8
0
        private string GetDimensionEntitySchemaName(Guid forecastId)
        {
            var dimensionEsq = new EntitySchemaQuery(_userConnection.EntitySchemaManager, "Dimension");
            EntitySchemaQueryColumn columnName = dimensionEsq.AddColumn("[SysSchema:UId:EntitySchemaUId].Name");

            dimensionEsq.Filters.Add(dimensionEsq.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                                             "[ForecastDimension:Dimension:Id].Forecast", forecastId));
            EntityCollection dimensions = dimensionEsq.GetEntityCollection(_userConnection);

            if (dimensions.Count == 0)
            {
                return(string.Empty);
            }
            Entity dimension        = dimensions.First();
            string entitySchemaName = (string)dimension.GetColumnValue(columnName.Name);

            return(entitySchemaName);
        }
Esempio n. 9
0
        /// <summary>
        /// Returns SearchData of the folder.
        /// </summary>
        /// <param name="userConnection">Instance of the <see cref="Terrasoft.Core.UserConnection"/>.</param>
        /// <param name="recordId">Unique identifier of the folder.</param>
        /// <param name="folderSchemaUId">Unique identifier of the folder schema.</param>
        /// <returns>Search data.</returns>
        public static byte[] GetFolderSearchData(UserConnection userConnection, Guid recordId, Guid folderSchemaUId)
        {
            EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager;
            EntitySchema        schema = entitySchemaManager.GetInstanceByUId(folderSchemaUId);
            var    esq = new EntitySchemaQuery(schema);
            string searchDataColumnName = esq.AddColumn("SearchData").Name;

            esq.Filters.Add(
                esq.CreateFilterWithParameters(FilterComparisonType.Equal, false, "Id", recordId));
            EntityCollection entities = esq.GetEntityCollection(userConnection);

            if (!entities.Any())
            {
                return(null);
            }
            Entity folderEntity = entities.First();

            return(folderEntity.GetBytesValue(searchDataColumnName));
        }
Esempio n. 10
0
        public MarketingMaterial GetCustomContent(long campaignId, string tag)
        {
            IRelationPredicateBucket bucket = new RelationPredicateBucket(CustomCampaignContentFields.CampaignId == campaignId);

            bucket.PredicateExpression.Add(CustomCampaignContentFields.Tag == tag);

            var campaignContentEntities = new EntityCollection <CustomCampaignContentEntity>();

            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                adapter.FetchEntityCollection(campaignContentEntities, bucket);
            }

            if (campaignContentEntities.Any())
            {
                return(_marketingMaterialRepository.GetMarketingMaterialById(campaignContentEntities.First().MarketingMaterialId));
            }

            return(null);
        }
Esempio n. 11
0
        public static LocalizableString GetLocalizableValue(UserConnection userConnection, string schemaName,
                                                            string columnName, Guid recordId)
        {
            EntitySchemaQuery       esq;
            EntitySchemaQueryColumn column;
            var result = new LocalizableString();
            EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager;
            SysUserInfo         currentUser         = userConnection.CurrentUser;
            CultureInfo         currentUserCulture  = currentUser.Culture;
            EntitySchema        schema = entitySchemaManager.GetInstanceByName(schemaName);

            if (UseMultilanguageData)
            {
                esq    = new EntitySchemaQuery(entitySchemaManager, schemaName);
                column = esq.AddColumn(columnName);
                esq.Filters.Add(esq.CreateFilterWithParameters(
                                    FilterComparisonType.Equal, schema.GetPrimaryColumnName(), recordId));
            }
            else
            {
                Guid   columnUId     = schema.Columns.GetByName(columnName).UId;
                string lczSchemaName = schema.GetLocalizableStringsSchemaName();
                esq    = new EntitySchemaQuery(entitySchemaManager, lczSchemaName);
                column = esq.AddColumn("Value");
                esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "ColumnUId", columnUId));
                esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Record", recordId));
                esq.Filters.Add(
                    esq.CreateFilterWithParameters(FilterComparisonType.Equal, "SysCulture", currentUser.SysCultureId));
            }
            EntityCollection entities = esq.GetEntityCollection(userConnection);

            if (entities.Count > 0)
            {
                Entity entity   = entities.First();
                string lczValue = entity.GetTypedColumnValue <string>(column.Name);
                result.SetCultureValue(currentUserCulture, lczValue);
            }
            return(result);
        }
        public void TestFirstOperator()
        {
            EntityCollection<TestAccountEntity> entities = new EntityCollection<TestAccountEntity>();
            entities.Add(new TestAccountEntity(100, 5));
            entities.Add(new TestAccountEntity(102, 8));
            entities.Add(new TestAccountEntity(103, 15));
            entities.Add(new TestAccountEntity(104, 2));

            IEnumerable<TestAccountEntity> result =
                    entities.First(
                            delegate(TestAccountEntity entity)
                            {
                                return (entity.Amount > 8) ? true : false;
                            });

            Assert.IsNotNull(result);
            foreach (TestAccountEntity entity in result)
            {
                Assert.IsNotNull(entity);
                Console.WriteLine(entity);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Mets à jour la map ainsi que les entités qu'elle contient.
        /// </summary>
        /// <param name="time"></param>
        public void Update(GameTime time)
        {
            // Mise à jour de la vision.
            Vision.Update(time, Entities);

            // Mets à jour les signaux.
            UpdateSignals();

            // Mise à jour des entités
            List <int>       entitiesToDelete   = new List <int>();
            List <Spellcast> spellcastsToDelete = new List <Spellcast>();

            // Ajoute les entités en attente.
            while (m_entitiesAddList.Count != 0)
            {
                var first = m_entitiesAddList.First();
                m_entities.Add(first.Key, first.Value);
                m_entitiesAddList.Remove(first.Key);
            }

            // Refresh les events
            // Certains events sont dépendant d'entités, il faut donc attendre qu'elles soient ajoutées au jeu.
            // C'est pourquoi ce code est ici.
            if (m_refreshEvents)
            {
                foreach (var kvp in m_events)
                {
                    kvp.Value.Initialize();
                }
                m_refreshEvents = false;
            }

            // Mets à jour tous les spells lancés.
            foreach (Spellcast cast in m_spellcasts)
            {
                cast.Update(time);
                if (cast.IsDisposing)
                {
                    spellcastsToDelete.Add(cast);
                }
            }



            // Mets à jour tous les évènements.
            foreach (var kvp in m_events)
            {
                kvp.Value.Update(time);
            }

            // Mets à jour les entités.
            foreach (var kvp in m_entities)
            {
                if (kvp.Value.IsDisposing)
                {
                    entitiesToDelete.Add(kvp.Key);
                }
                else
                {
                    // Vérifie les collisions spells / entités.
                    foreach (Spellcast cast in m_spellcasts)
                    {
                        if (cast.GetShape().Intersects(kvp.Value.Shape))
                        {
                            cast.OnCollide(kvp.Value);
                        }
                    }
                }
                kvp.Value.Update(time);
            }



            // Suppression des entités marquées Disposed
            foreach (int key in entitiesToDelete)
            {
                m_entities[key].Dispose();
                m_entities.Remove(key);
            }
            foreach (Spellcast cast in spellcastsToDelete)
            {
                cast.Dispose();
                m_spellcasts.Remove(cast);
            }


            // Lance l'évènement indiquant que la map a été modifiée.
            if (__fireMapModifiedEvent)
            {
                if (OnMapModified != null)
                {
                    OnMapModified();
                }
                __fireMapModifiedEvent = false;
            }
        }