/// <summary>
            /// Reporter une progression, qui ne sera pas dans les logs
            /// </summary>
            public void Report(ReporterProgress iProgress)
            {
                lock (_notifierStateListLocker)
                {
                    var notifierProgress = new NotifierProgress();

                    NotifierState theState = GetNotifierState();

                    if (theState.ProgressCounter > iProgress.ProgressCounter)
                    {
                        notifierProgress.IncoherentCounter = true;
                    }

                    theState.ProgressCounter = iProgress.ProgressCounter;

                    notifierProgress.Message = iProgress.Message;
                    notifierProgress.LevelProgressCounter = iProgress.ProgressCounter;
                    notifierProgress.Timer = iProgress.Timer;

                    notifierProgress.LevelProgressCount = theState.ProgressCount;
                    notifierProgress.ThreadCount        = theState.ThreadCount;
                    notifierProgress.Level           = theState.Level;
                    notifierProgress.TotalPercentage = ComputePercentage(_notifier);
                    _notifier.Report(notifierProgress);
                    MyDebug.PrintInformation(notifierProgress);
                }
            }
示例#2
0
        /// <summary>
        /// Classe à utiliser dans les tâches, pour retourner une progression et permettre l'annulation. Ajouter dans les boucles une vérification de IsCancellationRequested. Action de progression est par défaut une ligne en débug.
        /// </summary>
        public ProgressCancelNotifier(string iName = null)
        {
            CancellationTokenSource = new System.Threading.CancellationTokenSource();
            Name = iName;
            //Action<NotifierProgress> theAction = (NotifierProgress iProgress) => { };

            Action <NotifierProgress> theAction = (value) => { MyDebug.PrintInformation(value); };

            SetProgressAction(theAction);
            Guid = System.Guid.NewGuid().ToString();
        }
        /// <summary>
        /// Retourne si deux objets sont identiques en comparant leurs propriétés. iOnlyPrimitiveProperties permet d'ignorer les propriétés objet, list etc...
        /// </summary>
        public bool AreEqual(object iObject1, object iObject2, bool iOnlyPrimitiveProperties, bool iPrintDifference = false)
        {
            var compareLogic = new CompareLogic();

            compareLogic.Config.CompareFields            = false;
            compareLogic.Config.ComparePrivateFields     = false;
            compareLogic.Config.ComparePrivateProperties = false;
            compareLogic.Config.CompareProperties        = true;

            if (iOnlyPrimitiveProperties)
            {
                compareLogic.Config.CompareChildren = false;
            }

            if (iPrintDifference)
            {
                MyDebug.PrintInformation(compareLogic.Compare(iObject1, iObject2).DifferencesString);
            }

            return(compareLogic.Compare(iObject1, iObject2).AreEqual);
        }
        /// <summary>
        /// Retourne une liste chargée en mémoire.
        /// </summary>
        public IEnumerable <T> GetListBatchLoading <T, TKey>(
            Expression <Func <T, TKey> > iOrderByProperty, ListSortDirection iSortDirection,
            List <Expression <Func <T, object> > > iNavigationProperties = null,
            Expression <Func <T, bool> > iWhere = null,
            int?iSkip = null, int?iTake = null) where T : class, IEntity
        {
            Func <IEnumerable <T> > theTask = () =>
            {
                if (iOrderByProperty == null)
                {
                    throw new ArgumentNullException();
                }
                if (iTake != null && iOrderByProperty == null)
                {
                    throw new ArgumentNullException();
                }
                if (iSkip != null && iOrderByProperty == null)
                {
                    throw new ArgumentNullException();
                }

                //batch loading
                Int64 entitiesCount = GetQuery <T, TKey>(iWhere, iNavigationProperties, iOrderByProperty, iSortDirection, iSkip, iTake).Count();
                int   totalPage     = (int)Math.Ceiling(decimal.Divide(entitiesCount, TAKECOUNT));

                //query
                var result = new List <T>();

                for (int a = 0; a < totalPage; a++)
                {
                    Notifier.ThrowIfCancellationRequested();
                    result.AddRange(GetQuery <T, TKey>(iWhere, iNavigationProperties, iOrderByProperty, iSortDirection, iSkip, iTake).Skip(TAKECOUNT * (a)).Take(TAKECOUNT).ToList());
                    MyDebug.PrintInformation("Chargement des données page par page", a + 1, totalPage);
                }

                return(result);
            };

            return(RetryExecution(theTask));
        }
示例#5
0
        /// <summary>
        /// Recupère les données d'un fichier excel, sans excel, utilisable sur serveur
        /// </summary>
        /// <param name="iFilePath"></param>
        /// <param name="iColumnIndexList">Liste des numéros de colonne, commence à 1</param>
        /// <param name="iSheetIndex">Index de la page à récupérer, commence à 1</param>
        /// <param name="iAllowIncompleteRow">Autorise une ligne avec des colonnes obligatoires vides</param>
        /// <param name="iMasterColumn">Numéro de la colonne qui ne peut pas être vide, sinon c'est que nous sommes la fin du fichier</param>
        /// <returns></returns>
        public List <List <string> > GetListFromExcelFile(string iFilePath, List <int> iColumnIndexList, int iSheetIndex, bool iAllowIncompleteRow, int iFirstRow)
        {
            if (iFilePath == null)
            {
                throw new ArgumentNullException("Chemin non renseigné");
            }
            if (System.IO.File.Exists(iFilePath) == false)
            {
                throw new ArgumentNullException("Le chemin {0] n'existe pas".FormatString(iFilePath));
            }

            if (iColumnIndexList.IsNotNullAndNotEmpty() &&
                iSheetIndex != 0)
            {
                var rowList = new List <List <string> >();

                IWorkbook workbook;
                using (FileStream file = new FileStream(iFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    workbook = WorkbookFactory.Create(file);

                var evaluator = workbook.GetCreationHelper().CreateFormulaEvaluator();

                var sheet       = workbook.GetSheetAt(iSheetIndex - 1);
                int lastUsedRow = sheet.LastRowNum;

                //bouclage sur les lignes
                int rowCounter = 1;
                int rowCount   = lastUsedRow + 1 - iFirstRow + 1;
                for (int rowIndex = iFirstRow - 1; rowIndex <= lastUsedRow; rowIndex++)
                {
                    var isCompletRow = true;
                    var columnList   = new List <string>();

                    //bouclage sur les colonnes
                    foreach (var columnIndex in iColumnIndexList.Enum())
                    {
                        CancellationToken.ThrowIfCancellationRequested();

                        var cellRange = sheet.GetRow(rowIndex).GetCell(columnIndex - 1);
                        if (cellRange != null)
                        {
                            columnList.Add(GetStringVisibleValue(cellRange, evaluator).Replace("\n", Environment.NewLine));
                        }
                        else
                        {
                            isCompletRow = iAllowIncompleteRow;
                            columnList.Add(string.Empty);

                            if (isCompletRow == false)
                            {
                                break;
                            }
                        }
                    }

                    if (isCompletRow)
                    {
                        rowList.Add(columnList);
                        MyDebug.PrintInformation("Ligne {0} complète importée".FormatString(rowIndex), rowCount, rowCounter);
                    }
                    else
                    {
                        MyDebug.PrintInformation("Ligne {0} imcomplète".FormatString(rowIndex), rowCount, rowCounter);
                    }

                    rowCounter++;
                }
                MyDebug.PrintInformation("Fin de l'importation excel '{0}'".FormatString(iFilePath));
                return(rowList);
            }
            return(null);
        }
示例#6
0
        /// <summary>
        /// Permet exporter vers un nouveau fichier excel une liste d'objet ou de type primitif. Sauvegarder par default dans temp sauf si chemin spécifié;
        /// </summary>
        /// <returns>Retourne le chemin du fichier créé</returns>
        public string SendListToNewExcelFile <T>(List <ExcelSheet <T> > iSheetList, string iSaveFullPath = null)
        {
            if (iSheetList.IsNullOrEmpty())
            {
                throw new ArgumentException("Les données à exporter sont vides");
            }

            var         workbook         = new HSSFWorkbook();
            IDataFormat dataFormatCustom = workbook.CreateDataFormat();

            ICellStyle doubleCellStyle = workbook.CreateCellStyle();

            doubleCellStyle.DataFormat = dataFormatCustom.GetFormat("#,##0.00");

            ICellStyle dateTimeCellStyle = workbook.CreateCellStyle();

            dateTimeCellStyle.DataFormat = dataFormatCustom.GetFormat("dd/MM/yyyy");

            ISheet workSheet;
            int    sheetIndex = 0;

            foreach (var sheetItem in iSheetList)
            {
                sheetIndex++;
                if (sheetItem.SheetName.IsNotNullAndNotEmpty())
                {
                    workSheet = workbook.CreateSheet(sheetItem.SheetName.Reduce(30));
                }
                else
                {
                    workSheet = workbook.CreateSheet();
                }

                var rowCounter    = 0;
                var columnCounter = 0;

                //Ecriture du message
                foreach (var item in sheetItem.iMessageList.Enum())
                {
                    var cell = workSheet.CreateRow(rowCounter).CreateCell(1);
                    cell.SetCellValue(item);
                    rowCounter++;
                }

                //variable sans propriété (ex string, int etc...)
                var tType = sheetItem.DataList.First().GetType();
                if (tType.IsPrimitive || tType.IsValueType || (tType == typeof(string)))
                {
                    //Bouclage sur les item de la liste (ligne excel)
                    var itemCounter = 1;
                    foreach (var item in sheetItem.DataList)
                    {
                        CancellationToken.ThrowIfCancellationRequested();
                        if (item != null)
                        {
                            var cell = workSheet.CreateRow(rowCounter).CreateCell(0);
                            cell.SetCellValue(item.ToString());
                        }
                        MyDebug.PrintInformation("Ligne exportée", itemCounter, sheetItem.DataList.Enum().Count());
                        rowCounter += 1;
                        itemCounter++;
                    }
                }

                //Object avec des propriétés (pour une classe)
                else
                {
                    var properties   = tType.GetProperties();
                    var theHeaderRow = workSheet.CreateRow(rowCounter);
                    foreach (var property in properties)
                    {
                        var theCellHeader = theHeaderRow.CreateCell(columnCounter);
                        if (sheetItem.Lang.IsNotNullAndNotEmpty())
                        {
                            var name = tType.GetName(property.Name, sheetItem.Lang);
                            if (name != null)
                            {
                                theCellHeader.SetCellValue(name);
                            }
                            else
                            {
                                theCellHeader.SetCellValue(property.Name);
                            }
                        }
                        else
                        {
                            theCellHeader.SetCellValue(property.Name);
                        }
                        columnCounter++;
                    }
                    rowCounter++;
                    columnCounter = 0;

                    //Bouclage sur les item de la liste (ligne excel)
                    var itemCounter = 1;
                    foreach (var item in sheetItem.DataList)
                    {
                        var theDataRow = workSheet.CreateRow(rowCounter);
                        //Bouclage sur les propriétés de l'item (colonne excel)
                        foreach (var propertyItem in properties)
                        {
                            CancellationToken.ThrowIfCancellationRequested();

                            var theCell         = theDataRow.CreateCell(columnCounter);
                            var thePropertyItem = propertyItem.GetValue(item);

                            if (thePropertyItem != null)
                            {
                                if (propertyItem.PropertyType == typeof(DateTime) || propertyItem.PropertyType == typeof(DateTime?))
                                {
                                    theCell.SetCellValue(((DateTime)thePropertyItem));
                                    theCell.CellStyle = dateTimeCellStyle;
                                }
                                else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal?) ||
                                         propertyItem.PropertyType == typeof(double) || propertyItem.PropertyType == typeof(double?) ||
                                         propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?) ||
                                         propertyItem.PropertyType == typeof(Int16) || propertyItem.PropertyType == typeof(Int16?) ||
                                         propertyItem.PropertyType == typeof(Int64) || propertyItem.PropertyType == typeof(Int64?))
                                {
                                    theCell.SetCellValue(Convert.ToDouble(thePropertyItem));
                                    theCell.CellStyle = doubleCellStyle;
                                }
                                else
                                {
                                    theCell.SetCellValue(thePropertyItem.ToString());
                                }
                            }
                            columnCounter++;
                        }

                        MyDebug.PrintInformation("Ligne exportée", itemCounter, sheetItem.DataList.Enum().Count());
                        rowCounter++;
                        columnCounter = 0;
                        itemCounter++;
                    }
                }
            }

            var        filePath = (iSaveFullPath.IsNotNullAndNotEmpty()) ? iSaveFullPath : Path.GetTempPath() + Guid.NewGuid().ToString() + ".xls";
            FileStream xfile    = new FileStream(filePath, FileMode.Create, System.IO.FileAccess.Write);

            workbook.Write(xfile);
            xfile.Close();
            MyDebug.PrintInformation("Exportation dans le fichier '{0}'".FormatString(filePath));
            return(filePath);
        }
示例#7
0
 public void PrintInformation()
 {
     MyDebug.PrintInformation("test");
 }