Beispiel #1
0
        private ObservableCollection <LogEntry> RunHashCalculation()
        {
            ICalculate            calculate            = new Calculate();
            IMultiThreadingHelper multiThreadingHelper = new MultiThreadingHelper();
            IFilePath             filePath             = new FilePath(multiThreadingHelper);
            ILogging logging = new Logging();
            IFileListCalculationProcessor fileListCalculationProcessor = new FileListCalculationProcessor(calculate, filePath, logging);

            var result = fileListCalculationProcessor.ValueFor(_configuration);

            if (_configuration.CloseHiddenInstancesOnFinish)
            {
                CurrentHiddenInstance.Close();
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 获取Sheet实体集合
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="sheetModel"></param>
        private List <TEntity> GetEntityList(ISheet sheet, ExcelSheetModel <TEntity> sheetModel)
        {
            //获取图片
            List <ColumnFile> files = FileHelper.GetFiles(sheet);

            var pairs           = new ConcurrentDictionary <int, TEntity>();
            var parallelOptions = MultiThreadingHelper.GetParallelOptions();

            Parallel.For(
                (sheetModel.StartRowIndex.Value) + 1,
                sheet.LastRowNum + 1,
                parallelOptions,
                rowNum =>
            {
                TEntity entity = GetEntity(rowNum, sheetModel, sheet, files);
                if (entity != null)
                {
                    pairs[rowNum] = entity;
                }
            }
                );
            return(pairs.OrderBy(o => o.Key).Select(s => s.Value).ToList());
        }
        /// <summary>
        /// </summary>
        public MainWindow()
        {
            _coreSettings = new CoreSettings();
            InitializeComponent();
            _style = new MetroStyle(this, Accent, ThemeSwitch, _coreSettings);
            _style.Load(true);
            var linkerTime = Assembly.GetExecutingAssembly().GetLinkerTime();
            LinkerTime.Content = linkerTime.ToString(CultureInfo.InvariantCulture);
            WindowState = WindowState.Minimized;
            _app = (App) Application.Current;
            var multiThreadingHelper = new MultiThreadingHelper();
            var filePath = new FilePath(multiThreadingHelper);
            _worker = new Worker(filePath, _app);

            using (var backgroundWorker = new BackgroundWorker())
            {
                backgroundWorker.DoWork += (sender, args) => Load();
                backgroundWorker.WorkerReportsProgress = true;
                backgroundWorker.RunWorkerCompleted += BackgroundWorkerRunWorkerCompleted;
                backgroundWorker.RunWorkerAsync();
            }
            _overrideProtection = 1;
        }
        private void CheckDates(string dateType, DateTime filterDate, bool? direction)
        {
            var outputList = new List<string>();
            var outputBuilder = new StringBuilder();

            var excludeExtensionList = new List<string>
                                       {
                                           "sln",
                                           "db"
                                       };

            var excludeFileNameList = new List<string>
                                      {
                                          "listfilesbydate_log_"
                                      };

            var excludeFilePathList = new List<string>
                                      {
                                          "deploy",
                                          ".vs",
                                          "argos-localizer",
                                          ".git"
                                      };

            var multiThreadingHelper = new MultiThreadingHelper();
            var filePath = new FilePath(multiThreadingHelper);
            var fileList = filePath.GetFileList(_initialDirectory, null, excludeExtensionList, null, excludeFileNameList, null, excludeFilePathList).Distinct();
            outputBuilder.Append($"Start: {DateTime.Now}{Environment.NewLine}{Environment.NewLine}");

            Parallel.ForEach(fileList,
                file =>
                {
                    // DateTime.Today, Time.LastWrite

                    if (_checkFileDates.IsDifferent(file, dateType, filterDate, direction))
                    {
                        var checkFiles = _checkFileDates.For(file);
                        var output =
                            $"{checkFiles.FileName}{Environment.NewLine}" +
                            $"{checkFiles.CreationTime}{Environment.NewLine}" +
                            $"{checkFiles.LastWriteTime}{Environment.NewLine}" +
                            $"{checkFiles.LastAccessTime}{Environment.NewLine}{Environment.NewLine}";

                        outputList.Add(output);
                    }
                });

            outputList.ForEach(o => outputBuilder.Append(o));
            outputBuilder.Append($"End: {DateTime.Now}{Environment.NewLine}{Environment.NewLine}");
            _result = outputBuilder.ToString();
            File.AppendAllText($@"{_loggingPath}\ListFilesByDate_Log_{DateTime.Now:yyyy-MM-dd_HHmm}.txt", _result);
        }
Beispiel #5
0
        /// <summary>
        /// 验证内容
        /// </summary>
        public virtual void ValidationValue()
        {
            //遍历Sheet实体集合
            foreach (var sheet in ExcelGlobalDTO.Sheets)
            {
                //获取Sheet头部实体集合
                var headDtoList = sheet.SheetHeadList;

                //为空判断
                if (sheet.SheetEntityList == null)
                {
                    continue;
                }

                var pairs           = new ConcurrentDictionary <int, List <ValidationResult> >();
                var parallelOptions = MultiThreadingHelper.GetParallelOptions();
                Parallel.ForEach(sheet.SheetEntityList, parallelOptions, entity =>
                {
                    pairs.TryAdd(entity.RowNumber, ValidationHelper.Exec <TEntity>(entity));
                });

                foreach (var item in sheet.SheetEntityList)
                {
                    #region  项值校验
                    //校验文本框的值是否在下拉框选项中
                    foreach (var headDto in headDtoList)
                    {
                        #region 基础判断
                        //判断是否为选项列
                        if (headDto.ColumnType != Attribute.Enum.ColumnTypeEnum.Option)
                        {
                            continue;
                        }
                        //判断选项是否存在
                        if (sheet.ColumnOptions == null)
                        {
                            continue;
                        }

                        //判断属性是否存在
                        if (string.IsNullOrEmpty(headDto.PropertyName))
                        {
                            continue;
                        }
                        #endregion

                        //其他列的键值
                        string key = null;

                        #region 获其他列的键值
                        if (sheet.ColumnOptions.Keys.Contains(headDto.HeadName))
                        {
                            key = headDto.HeadName;
                        }
                        if (sheet.ColumnOptions.Keys.Contains(headDto.PropertyName))
                        {
                            key = headDto.PropertyName;
                        }
                        //判断键是否为空
                        if (key == null)
                        {
                            continue;
                        }
                        #endregion

                        //变量设置
                        PropertyInfo propertyInfo = item.GetType().GetProperty(headDto.PropertyName);
                        string       value        = propertyInfo.GetValue(item).ToString();

                        #region 校验
                        //类型判断decimal
                        if (propertyInfo.PropertyType == typeof(decimal) || propertyInfo.PropertyType == typeof(decimal?))
                        {
                            List <decimal> options = sheet.ColumnOptions[key].Select(n => Convert.ToDecimal(n)).ToList();
                            if (options.Contains(Convert.ToDecimal(value)) == true)
                            {
                                continue;
                            }
                        }

                        //类型判断double
                        if (propertyInfo.PropertyType == typeof(double) || propertyInfo.PropertyType == typeof(double?))
                        {
                            List <double> options = sheet.ColumnOptions[key].Select(n => Convert.ToDouble(n)).ToList();
                            if (options.Contains(Convert.ToDouble(value)) == true)
                            {
                                continue;
                            }
                        }

                        //判断输入的值是否在选项值中
                        if (sheet.ColumnOptions[key].Contains(value) == true)
                        {
                            continue;
                        }

                        #endregion

                        #region  通过则提示异常
                        //异常信息
                        ColumnErrorMessage errorMsg = new ColumnErrorMessage
                        {
                            PropertyName = headDto.PropertyName,
                            ColumnName   = headDto.HeadName,
                            ErrorMessage = ExcelGlobalDTO.ExcelValidationMessage.Clgyl_Common_Import_NotExistOptions
                        };
                        item.ColumnErrorMessage.Add(errorMsg);
                        #endregion
                    }
                    #endregion

                    #region  实体特性验证
                    List <ValidationResult> result = pairs[item.RowNumber];
                    if (result == null)
                    {
                        continue;
                    }
                    foreach (var msg in result)
                    {
                        //异常信息
                        ColumnErrorMessage errorMsg = new ColumnErrorMessage
                        {
                            PropertyName = msg.PropertyName,
                            ErrorMessage = msg.ErrorMessage
                        };

                        //设置列信息
                        var headDto = headDtoList.Where(w => w.PropertyName == msg.PropertyName).FirstOrDefault();
                        if (headDto != null)
                        {
                            errorMsg.ColumnName = headDto.HeadName;
                        }

                        //添加至集合
                        item.ColumnErrorMessage.Add(errorMsg);
                    }
                    #endregion
                }
            }

            //动态列验证
            DynamicColumn <TEntity> .ValidationValue(ExcelGlobalDTO, ValidationModelEnum.DynamicColumn);

            //验证值后
            this.ValidationValueAfter();
        }
Beispiel #6
0
        /// <summary>
        /// 行颜色
        /// </summary>
        /// <param name="excelGlobalDTO"></param>
        public void SetRowColor(ExcelGlobalDTO <TEntity> excelGlobalDTO)
        {
            foreach (var item in excelGlobalDTO.Sheets)
            {
                ISheet sheet = excelGlobalDTO.Workbook.GetSheetAt(item.SheetIndex);

                //为空判断
                if (item.SheetHeadList == null || item.SheetEntityList == null)
                {
                    continue;
                }

                //多线程处理
                MultiThreadingHelper.ForEach(item.SheetEntityList, entity =>
                {
                    if (entity.RowStyleSet == null)
                    {
                        return;
                    }
                    IRow row         = sheet.GetRow(entity.RowNumber);
                    ICellStyle style = excelGlobalDTO.Workbook.CreateCellStyle();//创建单元格样

                    //创建头部
                    foreach (var head in item.SheetHeadList)
                    {
                        //列
                        var cell = row.GetCell(head.ColumnIndex);
                        if (cell == null)
                        {
                            continue;
                        }

                        //如果列有设置背景色,则使用
                        if (entity.RowStyleSet.CellBackgroundColorDic != null && entity.RowStyleSet.CellBackgroundColorDic.Keys.Contains(head.ColumnIndex))
                        {
                            style.FillForegroundColor = entity.RowStyleSet.CellBackgroundColorDic[head.ColumnIndex];
                            style.FillPattern         = FillPattern.SolidForeground;
                            cell.CellStyle            = style;
                        }
                        //如果对行设置背景色,则使用
                        else if (entity.RowStyleSet.RowBackgroundColor != null)
                        {
                            style.FillForegroundColor = entity.RowStyleSet.RowBackgroundColor.Value;
                            style.FillPattern         = FillPattern.SolidForeground;
                            cell.CellStyle            = style;
                        }

                        //如果列有设置字体颜色,则使用
                        if (entity.RowStyleSet.CellFontColorDic != null && entity.RowStyleSet.CellFontColorDic.Keys.Contains(head.ColumnIndex))
                        {
                            IFont font = excelGlobalDTO.Workbook.CreateFont();                  //创建字体样式
                            font.Color = entity.RowStyleSet.CellFontColorDic[head.ColumnIndex]; //设置字体颜色
                            style.SetFont(font);
                            cell.CellStyle = style;
                        }
                        //如果对行设置字体颜色,则使用
                        else if (entity.RowStyleSet.RowFontColor != null)
                        {
                            IFont font = excelGlobalDTO.Workbook.CreateFont();  //创建字体样式
                            font.Color = entity.RowStyleSet.RowFontColor.Value; //设置字体颜色
                            style.SetFont(font);
                            cell.CellStyle = style;
                        }
                    }
                });
            }
        }