Beispiel #1
0
        public override void Verify(WDBContext context)
        {
            WDBField field = GetField(context);
            WDBCell  cell  = GetCell(context);

            string cellContent = cell.GetContent(field);

            if (!bool.TryParse(cellContent, out _))
            {
                context.AppendError(string.Format(WDBErrorMessages.CELL_CONTENT_CONVERT_ERROR, cellContent, cell.Row, cell.Column, typeof(bool)));
            }
        }
        public void Check(WDBContext context)
        {
            WDBField field = context.Get <WDBField>(WDBContextKey.CURRENT_FIELD_NAME);

            context.Add(WDBContextKey.CURRENT_CELL_NAME, this);
            {
                var cellValidations = field.GetValidations();
                for (int i = 0; i < cellValidations.Length; i++)
                {
                    cellValidations[i].Verify(context);
                }
            }
            context.Remove(WDBContextKey.CURRENT_CELL_NAME);
        }
Beispiel #3
0
        static void OnSuccess(Options options)
        {
            if (string.IsNullOrEmpty(options.InputFilePath))
            {
                Console.WriteLine("The path of input is empty");
                return;
            }
            if (!File.Exists(options.InputFilePath))
            {
                Console.WriteLine($"The path({options.InputFilePath}) is not found");
                return;
            }

            if (!Directory.Exists(options.OutputFileDir))
            {
                var dInfo = Directory.CreateDirectory(options.OutputFileDir);
                if (dInfo == null || !dInfo.Exists)
                {
                    Console.WriteLine($"Create directory for outputFile({options.OutputFileDir}) failed");
                    return;
                }
            }

            WDBSheet[]    sheets          = null;
            StringBuilder errorStrBuilder = null;

            if (!string.IsNullOrEmpty(options.ErrorLogPath))
            {
                var logDir = Path.GetDirectoryName(options.ErrorLogPath);
                if (!Directory.Exists(logDir))
                {
                    var dInfo = Directory.CreateDirectory(logDir);
                    if (dInfo != null && dInfo.Exists)
                    {
                        errorStrBuilder = new StringBuilder();
                    }
                }
            }

            System.Action <LogType, string> printLogHandler = (logType, message) =>
            {
                PrintLog(logType, message);

                errorStrBuilder?.AppendLine($"{logType.ToString()} -> {message}");
            };

            if (options.FileType == OriginFileType.Excel)
            {
                sheets = WDBExcelReader.ReadFromFile(options.InputFilePath, printLogHandler);
            }

            if (sheets == null || sheets.Length == 0)
            {
                printLogHandler(LogType.Error, "The wdbsheet is null");
            }
            else
            {
                WDBContext context = new WDBContext();
                foreach (var sheet in sheets)
                {
                    if (sheet == null)
                    {
                        printLogHandler(LogType.Error, "The sheet is null");
                        continue;
                    }
                    sheet.Check(context);

                    string filePath = $"{options.OutputFileDir}/{sheet.Name}{options.OutputFileExtension}";
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    if (context.HasError())
                    {
                        foreach (var error in context.GetErrors())
                        {
                            printLogHandler(LogType.Error, error);
                        }
                        continue;
                    }

                    string targetContent = null;
                    if (options.FormatType == TargetFormatType.Json)
                    {
                        targetContent = WDBJsonWriter.WriteToJson(sheet, options.PlatformType);
                    }
                    else if (options.FormatType == TargetFormatType.Lua)
                    {
                        targetContent = WDBLuaWriter.WriteToLua(sheet, options.PlatformType);
                    }
                    if (!string.IsNullOrEmpty(targetContent))
                    {
                        File.WriteAllText(filePath, targetContent);
                    }
                    else
                    {
                        printLogHandler(LogType.Error, "Converter failed");
                    }
                }
            }

            if (errorStrBuilder != null)
            {
                File.WriteAllText(options.ErrorLogPath, errorStrBuilder.ToString());
            }
        }