示例#1
0
 public static CremaDataRow NewRandomRow(this CremaDataTable dataTable)
 {
     if (dataTable.Parent != null)
     {
         var parentRow = dataTable.Parent.Rows.Random();
         if (parentRow == null)
         {
             return(null);
         }
         return(dataTable.NewRow(parentRow));
     }
     return(dataTable.NewRow());
 }
示例#2
0
        public static bool CreateRow(this CremaDataTable dataTable)
        {
            var          parent    = dataTable.Parent;
            CremaDataRow parentRow = null;

            if (parent != null)
            {
                if (parent.Rows.Any() == true)
                {
                    parentRow = parent.Rows.Random();
                }
                else
                {
                    return(false);
                }
            }

            var dataRow = dataTable.NewRow(parentRow);

            foreach (var item in dataTable.Columns)
            {
                dataRow.SetField(item.ColumnName, GetRandomValue(item));
            }

            try
            {
                dataTable.Rows.Add(dataRow);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
示例#3
0
 public static void FillTable(CremaDataTable dataTable)
 {
     for (var i = 0; i < 10000; i++)
     {
         var row = dataTable.NewRow();
         row.FillFields();
         dataTable.Rows.Add(row);
     }
 }
示例#4
0
 private static void CreatePropertyTable(CremaDataTable propertyTable, CremaDataRow classRow, Type type)
 {
     foreach (var item in type.GetProperties())
     {
         var dataRow = propertyTable.NewRow(classRow);
         dataRow["Name"] = item.Name;
         propertyTable.Rows.Add(dataRow);
     }
 }
示例#5
0
        public static CremaDataRow AddEmptyRow(this CremaDataTable dataTable)
        {
            dataTable.InternalObject.BeginLoadData();
            var row = dataTable.NewRow();

            row.EmptyFields();
            dataTable.Rows.Add(row);
            dataTable.InternalObject.EndLoadData();
            return(row);
        }
示例#6
0
        public static void FillStandardChild(CremaDataTable table, CremaDataRow parentRow, TagInfo tags)
        {
            var row = table.NewRow(parentRow);

            row.Tags             = tags;
            row["column_key"]    = $"{parentRow.Tags}.{tags}.key".ToLower();
            row["column_all"]    = $"{parentRow.Tags}.{tags}.all".ToLower();
            row["column_server"] = $"{parentRow.Tags}.{tags}.server".ToLower();
            row["column_client"] = $"{parentRow.Tags}.{tags}.client".ToLower();
            row["column_unused"] = $"{parentRow.Tags}.{tags}.unused".ToLower();
            table.Rows.Add(row);
        }
 private static void ImportRow(CremaDataTable dataTable, SerializationTable serializedTable)
 {
     dataTable.BeginLoad();
     foreach (var item in serializedTable.Rows)
     {
         if (dataTable.Parent == null)
         {
             var dataRow = dataTable.NewRow();
             ImportRow(dataRow, item, serializedTable.Columns);
             dataTable.Rows.Add(dataRow);
         }
         else
         {
             var parentRow = dataTable.Parent.Rows.First(i => i.RelationID == item.ParentID);
             var dataRow   = dataTable.NewRow(parentRow);
             ImportRow(dataRow, item, serializedTable.Columns);
             dataTable.Rows.Add(dataRow);
         }
     }
     dataTable.EndLoad();
 }
示例#8
0
        private CremaDataRow NewRow(CremaDataTable dataTable, Dictionary <string, object> fields, IXLRow row)
        {
            if (dataTable.Parent == null)
            {
                return(dataTable.NewRow());
            }

            if (fields.ContainsKey(CremaSchema.RelationID) == false)
            {
                throw new CremaDataException(string.Format("'{0}!{1}'에 부모 행 번호가 존재하지 않습니다.", row.Worksheet.Name, row.RangeAddress));
            }

            var rowIndex    = (int)fields[CremaSchema.RelationID];
            var index       = rowIndex - 2;
            var parentTable = dataTable.Parent;

            if (index < 0 || index >= parentTable.Rows.Count)
            {
                throw new CremaDataException(string.Format("'{0}!{1}'에 부모 행 번호'{2}'은(는) 잘못된 값입니다.", row.Worksheet.Name, row.RangeAddress, rowIndex));
            }
            var parentRow = parentTable.Rows[index];

            return(dataTable.NewRow(parentRow));
        }
示例#9
0
        private void ReadRow(CremaDataTable dataTable, string[] columns, IXLRow row)
        {
            var fields = this.CollectFields(dataTable, columns, row);

            if (fields.Any() == false)
            {
                return;
            }

            var dataRow = dataTable.NewRow();

            foreach (var item in dataTable.Columns)
            {
                if (fields.ContainsKey(item.ColumnName) == true)
                {
                    dataRow[item] = fields[item.ColumnName];
                }
            }

            foreach (var item in dataTable.Attributes)
            {
                if (fields.ContainsKey(item.AttributeName) == true)
                {
                    dataRow.SetAttribute(item.AttributeName, fields[item.AttributeName]);
                }
            }

            if (fields.ContainsKey(CremaSchema.__RelationID__))
            {
                dataRow.RelationID = $"{fields[CremaSchema.__RelationID__]}";
            }

            if (fields.ContainsKey(CremaSchema.__ParentID__))
            {
                dataRow.ParentID = $"{fields[CremaSchema.__ParentID__]}";
            }

            try
            {
                dataTable.Rows.Add(dataRow);
            }
            catch (Exception e)
            {
                throw new CremaDataException(string.Format("'{0}!{1}' 행 추가중에 문제가 발생했습니다.", row.Worksheet.Name, row.RangeAddress), e);
            }
        }
示例#10
0
        private static void FillChildRow(CremaDataRow diffParentRow, CremaDataRow parentRow, CremaDataTable childDiffTable, CremaDataTable childTable, CremaDataRow[] childRows, List <DiffPiece> lines)
        {
            var index = 0;

            foreach (var item in lines)
            {
                var diffRow = childDiffTable.NewRow(diffParentRow);
                if (item.Text != null)
                {
                    var dataRow = childRows[index];
                    CopyFields(dataRow, diffRow);
                    CopyAttributes(dataRow, diffRow);
                    diffRow.RelationID = diffParentRow.RelationID;
                    childDiffTable.ExtendedProperties[diffRow] = dataRow;
                    index++;
                }
                diffRow.SetAttribute(DiffUtility.DiffEnabledKey, item.Text != null);
                childDiffTable.Rows.Add(diffRow);
            }
        }
示例#11
0
        public static CremaDataRow FillStandardTable(CremaDataTable table, TagInfo tags)
        {
            var row = table.NewRow();

            row.Tags             = tags;
            row["column_key"]    = $"{tags}.key".ToLower();
            row["column_all"]    = $"{tags}.all".ToLower();
            row["column_server"] = $"{tags}.server".ToLower();
            row["column_client"] = $"{tags}.client".ToLower();
            row["column_unused"] = $"{tags}.unused".ToLower();
            table.Rows.Add(row);

            foreach (var item in table.Childs)
            {
                FillStandardChild(item, row, TagInfoUtility.All);
                FillStandardChild(item, row, TagInfoUtility.Server);
                FillStandardChild(item, row, TagInfoUtility.Client);
                FillStandardChild(item, row, TagInfoUtility.Unused);
            }
            return(row);
        }
示例#12
0
        private static void FillRows(CremaDataTable diffTable, CremaDataTable dataTable, List <DiffPiece> lines)
        {
            var index = 0;

            diffTable.MinimumCapacity = lines.Count;
            foreach (var item in lines)
            {
                var diffRow = diffTable.NewRow();
                if (item.Text != null)
                {
                    var dataRow = dataTable.Rows[index];
                    CopyFields(dataRow, diffRow);
                    CopyAttributes(dataRow, diffRow);
                    diffRow.RelationID = null;
                    diffTable.ExtendedProperties[diffRow] = dataRow;
                    index++;
                }

                diffRow.SetAttribute(DiffUtility.DiffEnabledKey, item.Text != null);
                diffTable.Rows.Add(diffRow);
            }
        }
示例#13
0
        public static CremaDataRow AddRandomRow(this CremaDataTable dataTable, bool throwOnError)
        {
            CremaDataRow dataRow;

            if (dataTable.Parent != null)
            {
                var parentRow = dataTable.Parent.Rows.RandomOrDefault();
                if (parentRow == null)
                {
                    return(null);
                }
                try
                {
                    dataRow = dataTable.NewRow(parentRow);
                }
                catch (OverflowException)
                {
                    return(null);
                }
            }
            else
            {
                try
                {
                    dataRow = dataTable.NewRow();
                }
                catch (OverflowException)
                {
                    return(null);
                }
            }

            if (dataRow == null)
            {
                return(null);
            }

            if (dataRow.InitializeRandom() == false)
            {
                return(null);
            }

            if (RandomUtility.Within(5) == true)
            {
                dataRow.IsEnabled = RandomUtility.NextBoolean();
            }

            try
            {
                dataTable.Rows.Add(dataRow);
            }
            catch
            {
                if (throwOnError == true)
                {
                    throw;
                }
                return(null);
            }
            return(dataRow);
        }