Example #1
0
        private async Task <IEnumerable <IEnumerable <CriteriaValues> > > GetValueObjectsFromCriteria(IEnumerable <IEnumerable <CriteriaValues> > criteriaValues, long dataSetId)
        {
            List <Expression <Func <ValueObject, bool> > > where = new List <Expression <Func <ValueObject, bool> > >();
            Dictionary <long, DataSetDimension> dimIds = await DataSetDimensionDomain.GetDimensionColumns(dataSetId);

            HttpResponseMessageResult res = ValueObjectDomain.BuildFilterRequest(where, criteriaValues, dimIds, false);

            Dictionary <long, IEnumerable <CriteriaValues> > dico = CriteriaValuesDomain.GetCriteriaValuesByDimension(criteriaValues);

            IQueryable <ValueObject>  dbQuery        = UnitOfWork.GetDbContext().Set <ValueObject>();
            IEnumerable <ValueObject> lstValueObject = await where
                                                       .Aggregate(dbQuery, (current, predicate) => current.Where(predicate))
                                                       .AsNoTracking()
                                                       .ToAsyncEnumerable()
                                                       .ToList();

            Dictionary <string, List <CriteriaValues> > dicoProduitCartesien = new Dictionary <string, List <CriteriaValues> >();

            foreach (ValueObject vo in lstValueObject)
            {
                List <CriteriaValues> lstCV = new List <CriteriaValues>();

                if (vo.Dimension1 != null)
                {
                    lstCV.Add(GetCriteriaValuesFromDimension(Constant.DATA_DIMENSION_1, cv => cv.Value == vo.Dimension1, dimIds, dico));
                }
                if (vo.Dimension2 != null)
                {
                    lstCV.Add(GetCriteriaValuesFromDimension(Constant.DATA_DIMENSION_2, cv => cv.Value == vo.Dimension2, dimIds, dico));
                }
                if (vo.Dimension3 != null)
                {
                    lstCV.Add(GetCriteriaValuesFromDimension(Constant.DATA_DIMENSION_3, cv => cv.Value == vo.Dimension3, dimIds, dico));
                }
                if (vo.Dimension4 != null)
                {
                    lstCV.Add(GetCriteriaValuesFromDimension(Constant.DATA_DIMENSION_4, cv => cv.Value == vo.Dimension4, dimIds, dico));
                }
                if (vo.Dimension5 != null)
                {
                    lstCV.Add(GetCriteriaValuesFromDimension(Constant.DATA_DIMENSION_5, cv => cv.Value == vo.Dimension5, dimIds, dico));
                }
                if (vo.Dimension6 != null)
                {
                    lstCV.Add(GetCriteriaValuesFromDimension(Constant.DATA_DIMENSION_6, cv => cv.Value == vo.Dimension6, dimIds, dico));
                }
                if (vo.Dimension7 != null)
                {
                    lstCV.Add(GetCriteriaValuesFromDimension(Constant.DATA_DIMENSION_7, cv => cv.Value == vo.Dimension7, dimIds, dico));
                }
                if (vo.Dimension8 != null)
                {
                    lstCV.Add(GetCriteriaValuesFromDimension(Constant.DATA_DIMENSION_8, cv => cv.Value == vo.Dimension8, dimIds, dico));
                }
                if (vo.Dimension9 != null)
                {
                    lstCV.Add(GetCriteriaValuesFromDimension(Constant.DATA_DIMENSION_9, cv => cv.Value == vo.Dimension9, dimIds, dico));
                }
                if (vo.Dimension10 != null)
                {
                    lstCV.Add(GetCriteriaValuesFromDimension(Constant.DATA_DIMENSION_10, cv => cv.Value == vo.Dimension10, dimIds, dico));
                }

                lstCV = lstCV.Where(cv => cv != null).ToList();
                string keyLstCv = GetUniqueKeyFromCriteriaValues(lstCV);
                if (!dicoProduitCartesien.ContainsKey(keyLstCv))
                {
                    dicoProduitCartesien.Add(keyLstCv, lstCV);
                }
            }

            return(dicoProduitCartesien.Select(kv => kv.Value));
        }
Example #2
0
        /// <summary>
        /// This function permits to do a INIT action.
        /// </summary>
        /// <param name="selectorInstance">SelectorInstance</param>
        /// <param name="wfInstance">Workflow instance</param>
        /// <returns>Message</returns>
        public async Task <HttpResponseMessageResult> Init(SelectorInstance selectorInstance, WorkflowInstance wfInstance)
        {
            if ((selectorInstance == null) || (wfInstance == null))
            {
                throw new WrongParameterException("Process.SelectorInstance.Init: SelectorInstance or WorkflowInstance are null!");
            }

            HttpResponseMessageResult res = new HttpResponseMessageResult()
            {
                IsSuccess = true
            };

            // Sélection des données et enregistrement des liaisons (subset)
            ICollection <CriteriaValues>        lstCv  = selectorInstance.CriteriaValues;
            Dictionary <long, DataSetDimension> dimIds = await DataSetDimensionDomain.GetDimensionColumns(wfInstance.DataSetId);

            List <Expression <Func <ValueObject, bool> > > where = new List <Expression <Func <ValueObject, bool> > >();

            res.Append(ValueObjectDomain.BuildFilterRequest(where, new List <IEnumerable <CriteriaValues> >()
            {
                lstCv
            }, dimIds, true));

            IQueryable <ValueObject> dbQuery = UnitOfWork.GetDbContext().Set <ValueObject>();
            // Vérification que le SelectorInstance n'utilise pas les données d'un autre SelectorInstance.
            int nbrLinkVoSi = await where
                              .Aggregate(dbQuery, (current, predicate) => current.Where(predicate))
                              .Include(vo => vo.SelectorInstanceValueObject)
                              .Where(vo => vo.SelectorInstanceValueObject.Count > 0)
                              .AsNoTracking()
                              .CountAsync();

            if (nbrLinkVoSi > 0)
            {
                throw new SequenceException($"SelecotrEngine.Init: Can't allocate data for SelectorInstance (from {selectorInstance?.SelectorConfig?.Name}) because there are already SelectorInstance for data.");
            }

            IEnumerable <ValueObject> lstValueObject = await where
                                                       .Aggregate(dbQuery, (current, predicate) => current.Where(predicate))
                                                       .Include(vo => vo.DataSet)
                                                       .Where(vo => vo.DataSet.Id == wfInstance.DataSetId)
                                                       //.AsNoTracking()
                                                       .ToAsyncEnumerable()
                                                       .ToList();

            selectorInstance.SelectorInstanceValueObject = new List <SelectorInstanceValueObject>();
            foreach (ValueObject vo in lstValueObject)
            {
                vo.FutureValue = null;
                SelectorInstanceValueObject sivo = new SelectorInstanceValueObject()
                {
                    SelectorInstance = selectorInstance,
                    ValueObject      = vo
                };
                sivo.InitDatesAndUser("");

                selectorInstance.SelectorInstanceValueObject.Add(sivo);
                vo.SelectorInstanceValueObject.Add(sivo);
                vo.Status = ValueObjectStatusEnum.Modify;
            }
            int nbr = await UnitOfWork.GetDbContext().SaveChangesAsync();

            // Création de la table temporaire de données...
            res.Append(await GridConfigurationDomain.CreateDataTableDB(selectorInstance, wfInstance));

            // Recherche des modificateurs
            res.Append(await SelectorInstanceDomain.FindModificator(selectorInstance, wfInstance));

            // Recherche des validateurs
            res.Append(await SelectorInstanceDomain.FindValidators(selectorInstance, wfInstance));

            // On régle les données modifiables
            res.Append(await SelectorInstanceDomain.SetModifyData(selectorInstance, wfInstance, dimIds));

            return(res);
        }