public static Report BuildMatchQuery(Report report)
        {

         

            var bsonArray = new BsonArray();
            DateTime outDate = DateTime.MinValue;
            int filterCount = 0;

            foreach (var query in report.LambdaQuery)
            {

                if (report.FilterDataValue[query.Values] == null ||
                        string.IsNullOrEmpty(report.FilterDataValue[query.Values].ToString()))
                {
                    if ( query.AllowNull)
                    {
                        continue;
                    }
                    else
                    {

                        throw new Exception("champs obligatoire non renségné ");
                    }
                }

                BsonDocument element = null;
                if (query.Operator == LambdaOperator.Eq)
                {
                    if (DateTime.TryParse(report.FilterDataValue[query.Values].ToString(), out outDate))
                    {
                        element = new BsonDocument(query.Field, BsonDateTime.Create(outDate));
                        
                    }

                    else
                    {
                        element = new BsonDocument(query.Field, BsonString.Create(report.FilterDataValue[query.Values]));
                    }
                    filterCount++;
                    bsonArray.Add(element);
                }

                if (query.Operator == LambdaOperator.Gt)
                {
                 

                    if (DateTime.TryParse(report.FilterDataValue[query.Values].ToString(), out outDate))
                    {

                        element = new BsonDocument("$gt", BsonDateTime.Create(outDate));
                    }

                    else
                    {
                        element = new BsonDocument("$gt", BsonString.Create(report.FilterDataValue[query.Values]));
                    }

                    var surElement = new BsonDocument(query.Field, element);
                    bsonArray.Add(surElement);
                    filterCount++;
                }

              
                if (query.Operator == LambdaOperator.Lt)
                {
                    if ( DateTime.TryParse( report.FilterDataValue[query.Values].ToString(),out  outDate))
                    {
                        element = new BsonDocument("$lt", BsonDateTime.Create(outDate));
                    }

                    else
                    {
                        element = new BsonDocument("$lt", BsonString.Create(report.FilterDataValue[query.Values]));
                    }
                    var surElement = new BsonDocument(query.Field, element);
                    bsonArray.Add(surElement);
                    filterCount++;

                }

            }
            
            if(filterCount == 0)
            {
                throw new Exception("Au moins un filtre doit être renségné");
            }

            var bsonAnd = new BsonDocument("$and", bsonArray);
            var bsonMatch = new BsonDocument("$match", bsonAnd);
          

            for(int i=0;i< report.Query.Count; i++)
            {
                if(report.Query[i].Contains("$$lambdaFilter$$"))
                {
                    report.Query[i] = bsonMatch.ToString();
                }
            }

            var aggregationFrameWork  = new AggregationFrameWorkPipline(report.ServerUri,
                                                                            report.ServerPort,
                                                                            report.DataBase,
                                                                            report.CollectionName);


            var result =  aggregationFrameWork.Execute(report.Query,report.Grid.MaxInPage,
                                                                report.CurrentPage,
                                                                report.ResultCount
                                                                );

            report.ResultCount = result.Item2;
            report.Log = result.Item3;

            long rem = 0;

            report.PageCount = Math.DivRem(report.ResultCount, report.Grid.MaxInPage, out rem);

            if(rem >0)
            {
                report.PageCount = report.PageCount + 1;
            }

           BuildGridResult(report, result.Item1);

            return report;
        }
        public static Report ExcelExport(Report report)
        {

            var aggregationFrameWork = new AggregationFrameWorkPipline(report.ServerUri,
                                                                            report.ServerPort,
                                                                            report.DataBase,
                                                                            report.CollectionName);

            var result = aggregationFrameWork.Execute(report.Query,-1,-1,-1);

            BuildExcelResult(report, result.Item1);
            report.Log = result.Item3;

            return report;
        }