Ejemplo n.º 1
0
        private static void WriteField(XmlWriter writer, CremaDataRow dataRow, CremaDataColumn dataColumn, bool ignoreDefaultValue)
        {
            var dataType = dataColumn.DataType;
            var value    = dataRow[dataColumn];

            if (value == DBNull.Value)
            {
                return;
            }

            var converter = TypeDescriptor.GetConverter(dataColumn.DataType);
            var textValue = CremaXmlConvert.ToString(value, dataType);

            if (object.Equals(value, dataColumn.DefaultValue) == true)
            {
                writer.WriteStartElement(dataColumn.ColumnName);
                writer.WriteEndElement();
            }
            else
            {
                writer.WriteStartElement(dataColumn.ColumnName);
                writer.WriteValue(textValue);
                writer.WriteEndElement();
            }
        }
Ejemplo n.º 2
0
 private void ReadValue(XmlReader reader, CremaDataRow dataRow, CremaDataColumn dataColumn)
 {
     if (reader.IsEmptyElement == false)
     {
         reader.ReadStartElement();
         reader.MoveToContent();
         if (reader.HasValue == true)
         {
             this.ReadValue(dataRow, dataColumn, reader.ReadContentAsString());
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
     else
     {
         if (dataColumn.AllowDBNull == true && object.Equals(dataColumn.DefaultValue, DBNull.Value) == false)
         {
             dataRow[dataColumn] = dataColumn.DefaultValue;
         }
         else if (object.Equals(dataColumn.DefaultValue, DBNull.Value) == true)
         {
             this.ReadValue(dataRow, dataColumn, string.Empty);
         }
         reader.Skip();
     }
     reader.MoveToContent();
 }
Ejemplo n.º 3
0
        private static void ImportRow(CremaDataRow dataRow, SerializationRow serializedRow, SerializationColumn[] serializedColumns)
        {
            for (var i = 0; i < serializedRow.Fields.Length; i++)
            {
                var serializedColumn = serializedColumns[i];
                var field            = serializedRow.Fields[i];

                if (serializedColumn.Name == CremaSchema.__RelationID__)
                {
                    dataRow.RelationID = field as string;
                }
                else if (serializedColumn.Name == CremaSchema.__ParentID__)
                {
                    dataRow.ParentID = field as string;
                }
            }

            for (var i = 0; i < serializedRow.Fields.Length; i++)
            {
                var serializedColumn = serializedColumns[i];
                var isRelationColumn = serializedColumn.Name == CremaSchema.__RelationID__ || serializedColumn.Name == CremaSchema.__ParentID__;
                var field            = serializedRow.Fields[i];

                if (field != null && isRelationColumn == false)
                {
                    dataRow[serializedColumn.Name] = field;
                }
            }
        }
Ejemplo n.º 4
0
        private IDictionary <string, object> GetDataRow(CremaDataRow dataRow)
        {
            var dataTable = dataRow.Table;
            var props     = new Dictionary <string, object>();

            foreach (var item in dataTable.Columns)
            {
                var value = dataRow[item];
                if (value == DBNull.Value)
                {
                    props.Add(item.ColumnName, null);
                }
                else
                {
                    props.Add(item.ColumnName, value);
                }
            }
            if (dataRow.ParentID != null)
            {
                props.Add(CremaSchema.__ParentID__, dataRow.ParentID);
            }
            if (dataRow.RelationID != null)
            {
                props.Add(CremaSchema.__RelationID__, dataRow.RelationID);
            }
            return(props);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public static bool FillFields(this CremaDataRow dataRow)
        {
            var changed = 0;

            foreach (var item in dataRow.Table.Columns)
            {
                if (item.AutoIncrement == true)
                {
                    continue;
                }
                if (dataRow[item.ColumnName] != DBNull.Value)
                {
                    continue;
                }
                if (FillField(dataRow, item) == false)
                {
                    return(false);
                }
                changed++;
            }
            if (RandomUtility.Within(5) == true)
            {
                dataRow.IsEnabled = RandomUtility.NextBoolean();
            }

            return(changed > 0);
        }
Ejemplo n.º 7
0
 internal DiffDataRow(DiffDataTable diffTable, int index)
 {
     this.diffTable = diffTable;
     this.index     = index;
     this.item1     = index < diffTable.SourceItem1.Rows.Count ? diffTable.SourceItem1.Rows[index] : null;
     this.item2     = index < diffTable.SourceItem2.Rows.Count ? diffTable.SourceItem2.Rows[index] : null;
 }
Ejemplo n.º 8
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);
     }
 }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        private static void CopyAttributes(CremaDataRow sourceRow, CremaDataRow destRow)
        {
            var sourceTable = sourceRow.Table;

            foreach (var item in sourceTable.Attributes)
            {
                if (item.AttributeName == CremaSchema.Index)
                {
                    continue;
                }
                var sourceValue = sourceRow.GetAttribute(item.AttributeName);
                destRow.SetAttribute(item.AttributeName, sourceValue);
            }
        }
Ejemplo n.º 11
0
        public static bool SetRandomValue(this CremaDataRow dataRow, CremaDataColumn dataColumn)
        {
            if (dataRow.RowState != System.Data.DataRowState.Detached && dataColumn.ReadOnly == true)
            {
                return(true);
            }
            var value = GetRandomValue(dataRow, dataColumn);

            if (value == null)
            {
                return(false);
            }
            dataRow.SetField(dataColumn, value);
            return(true);
        }
Ejemplo n.º 12
0
        private static string GetString(CremaDataRow dataRow)
        {
            var query = from item in CollectFields()
                        select GetFieldString(item);

            return(string.Join("-", query));

            IEnumerable <object> CollectFields()
            {
                foreach (var item in dataRow.Table.Columns)
                {
                    yield return(dataRow[item]);
                }
            }
        }
Ejemplo n.º 13
0
        private void ReadValue(CremaDataRow dataRow, DataColumn dataColumn, string textValue)
        {
            var dataType = dataColumn.DataType;
            var value    = textValue as object;

            try
            {
                value = CremaXmlConvert.ToValue(textValue, dataType);
                dataRow.SetField(dataColumn.ColumnName, value);
            }
            catch (Exception e)
            {
                dataRow.SetField(dataColumn.ColumnName, textValue);
                dataRow.SetColumnError(dataColumn.ColumnName, e.Message);
            }
        }
Ejemplo n.º 14
0
        internal static FindResultInfo FromDataRow(CremaDataRow dataRow, CremaDataColumn dataColumn, int index)
        {
            CremaDataTable table = dataRow.Table;
            FindResultInfo fri   = new FindResultInfo()
            {
                Path             = table.CategoryPath + table.Name,
                Row              = index,
                ColumnName       = dataColumn.ColumnName,
                Value            = dataRow[dataColumn].ToString(),
                Tags             = dataRow.DerivedTags.ToString(),
                IsEnabled        = dataRow.IsEnabled,
                ModificationInfo = dataRow.ModificationInfo,
            };

            return(fri);
        }
Ejemplo n.º 15
0
        private static void InitializeChildRows(CremaDataRow diffRow1, CremaDataRow diffRow2, CremaDataRow dataRow1, CremaDataRow dataRow2, CremaDataTable diffChildTable1, CremaDataTable diffChildTable2, CremaDataTable childTable1, CremaDataTable childTable2)
        {
            var emptyRows     = new CremaDataRow[] { };
            var inlineBuilder = new SideBySideDiffBuilder(new Differ());

            var childRows1 = dataRow1 != null && childTable1 != null?dataRow1.GetChildRows(childTable1) : emptyRows;

            var childRows2 = dataRow2 != null && childTable2 != null?dataRow2.GetChildRows(childTable2) : emptyRows;

            var rowText1 = GetString(childRows1);
            var rowText2 = GetString(childRows2);
            var rowDiff  = inlineBuilder.BuildDiffModel(rowText1, rowText2);

            FillChildRow(diffRow1, dataRow1, diffChildTable1, childTable1, childRows1, rowDiff.OldText.Lines);
            FillChildRow(diffRow2, dataRow2, diffChildTable2, childTable2, childRows2, rowDiff.NewText.Lines);
        }
Ejemplo n.º 16
0
        public static void FillRow(CremaDataRow dataRow)
        {
            var table = dataRow.Table;

            foreach (var item in table.Columns)
            {
                if (item.CremaType != null)
                {
                    dataRow[item] = item.CremaType.GetRandomValue();
                }
                else
                {
                    dataRow[item] = RandomUtility.Next(item.DataType);
                }
            }
        }
Ejemplo n.º 17
0
        public SerializationRow(CremaDataRow dataRow, CremaDataColumn[] columns)
            : this()
        {
            var columnCount = columns.Length;

            if (dataRow.Table.Childs.Any())
            {
                columnCount++;
            }
            if (dataRow.Table.Parent != null)
            {
                columnCount++;
            }

            var fields = new object[columnCount];

            var i = 0;

            for (; i < columns.Length; i++)
            {
                var field = dataRow[columns[i]];
                if (field is TimeSpan timeSpan)
                {
                    fields[i] = timeSpan.Ticks;
                }
                else
                {
                    fields[i] = field;
                }
            }

            if (dataRow.Table.Childs.Any())
            {
                fields[i++] = dataRow.RelationID;
            }
            if (dataRow.Table.Parent != null)
            {
                fields[i++] = dataRow.ParentID;
            }

            this.Tags        = dataRow.Tags;
            this.DerivedTags = dataRow.DerivedTags;
            this.Fields      = fields;
            this.RelationID  = dataRow.RelationID;
            this.ParentID    = dataRow.ParentID;
        }
Ejemplo n.º 18
0
        private void WriteDataRow(XmlWriter writer, CremaDataRow dataRow)
        {
            var dataTable = dataRow.Table;

            writer.WriteStartElement(dataTable.GetXmlName(this.targetNamespace));

            foreach (var item in dataTable.Attributes)
            {
                if (item.IsVisible == false)
                {
                    continue;
                }
                this.WriteAttribute(writer, dataRow.InternalObject, item.InternalAttribute);
            }

            if (dataTable.Childs.Count > 0)
            {
                writer.WriteStartAttribute(CremaSchema.RelationID);
                writer.WriteValue(dataRow.Field <string>(dataTable.RelationColumn));
                writer.WriteEndAttribute();
            }

            foreach (var item in dataTable.Columns)
            {
                WriteField(writer, dataRow, item);
            }

            if (dataTable.Childs.Count > 0)
            {
                var relationID = dataRow.Field <string>(dataTable.RelationColumn);

                foreach (var child in dataTable.Childs)
                {
                    var rows = child.Select(string.Format("{0} = '{1}'", "__ParentID__", relationID));

                    foreach (var row in rows)
                    {
                        this.WriteDataRow(writer, row);
                    }
                }
            }

            writer.WriteEndElement();
        }
Ejemplo n.º 19
0
        public static bool FillField(this CremaDataRow dataRow, CremaDataColumn dataColumn)
        {
            for (int i = 0; i < 20; i++)
            {
                object value = GetRandomValue(dataColumn);

                if (dataColumn.AllowDBNull == false && value == DBNull.Value)
                {
                    continue;
                }

                //if (Contains(content, columnInfo.Name, value) == false)
                {
                    dataRow.SetField(dataColumn, value);
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 20
0
        public static bool SetRandomValue(this CremaDataRow dataRow, int tryCount)
        {
            var count = 0;

            for (var i = 0; i < tryCount; i++)
            {
                try
                {
                    if (SetRandomValue(dataRow) == true)
                    {
                        count++;
                    }
                }
                catch
                {
                }
            }
            return(count > 0);
        }
Ejemplo n.º 21
0
        public static bool InitializeRandom(this CremaDataRow dataRow)
        {
            if (dataRow.RowState != System.Data.DataRowState.Detached)
            {
                throw new ArgumentException();
            }

            foreach (var item in dataRow.Table.Columns)
            {
                if (dataRow[item.ColumnName] != DBNull.Value && item.Unique == false && item.IsKey == false)
                {
                    continue;
                }
                if (SetRandomValue(dataRow, item) == false)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 22
0
        private void ReadNodeAttributes(XmlReader reader, CremaDataTable dataTable, CremaDataRow dataRow)
        {
            for (var i = 0; i < reader.AttributeCount; i++)
            {
                reader.MoveToAttribute(i);

                var columnName = reader.Name == CremaSchemaObsolete.DataLocation ? CremaSchema.Tags : reader.Name;
                if (columnName == CremaSchema.RelationID)
                {
                    dataRow.RelationID = reader.Value;
                }
                else if (columnName != "xmlns")
                {
                    var dataColumn = dataTable.Attributes[columnName].InternalAttribute;
                    this.ReadValue(dataRow, dataColumn, reader.Value);
                }

                this.ReadModifiedDateTimeVersion2(dataTable, dataRow);
            }
        }
Ejemplo n.º 23
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);
            }
        }
Ejemplo n.º 24
0
 private static void CopyFields(CremaDataRow sourceRow, CremaDataRow destRow)
 {
     foreach (var item in destRow.Table.Columns)
     {
         if (item.ExtendedProperties.ContainsKey(nameof(CremaDataColumn.ColumnName)))
         {
             var columnName = item.ExtendedProperties[nameof(CremaDataColumn.ColumnName)] as string;
             if (columnName.StartsWith(DiffUtility.DiffDummyKey) == true)
             {
                 continue;
             }
             var sourceValue = sourceRow[columnName];
             destRow[item.ColumnName] = sourceValue;
         }
         else if (sourceRow.Table.Columns.Contains(item.ColumnName))
         {
             var sourceValue = sourceRow[item.ColumnName];
             destRow[item.ColumnName] = sourceValue;
         }
     }
 }
Ejemplo n.º 25
0
        private CremaDataTable GetTable(XmlReader reader, CremaDataRow parentRow)
        {
            var tableName = reader.Name;

            if (parentRow != null)
            {
                return(parentRow.Table.Childs[tableName]);
            }
            else if (reader.NamespaceURI == CremaSchema.BaseNamespace)
            {
                return(this.tables[tableName]);
            }
            else if (this.itemName == null)
            {
                return(this.tables[tableName]);
            }
            else
            {
                return(this.tables[this.itemName.Name]);
            }
        }
Ejemplo n.º 26
0
        private static object GetRandomValue(this CremaDataRow dataRow, CremaDataColumn dataColumn)
        {
            var value = dataColumn.GetRandomValue();

            if (dataColumn.Unique == true)
            {
                var tryCount = 0;
                while (tryCount < 5)
                {
                    //var textValue = CremaConvert.ChangeType(value, typeof(string));
                    //var expression = value == DBNull.Value ? $"[{dataColumn.ColumnName}] is null" : $"{dataColumn.ColumnName}='{textValue}'";
                    //var items = dataColumn.Table.Select(expression);
                    //if (items.Any() == false)
                    //    return value;
                    if (Exists() == false)
                    {
                        return(value);
                    }
                    value = dataColumn.GetRandomValue();
                    tryCount++;

                    bool Exists()
                    {
                        foreach (var item in dataColumn.Table.Rows)
                        {
                            if (object.Equals(item[dataColumn], value) == true)
                            {
                                return(true);
                            }
                        }
                        return(false);
                    }
                }
                return(null);
            }
            else
            {
                return(value);
            }
        }
Ejemplo n.º 27
0
        //[Obsolete("for 2.0")]
        private void ReadModifiedDateTimeVersion2(CremaDataTable dataTable, CremaDataRow dataRow)
        {
            if (this.version.Major >= CremaSchema.MajorVersion)
            {
                return;
            }

            var dateTimeValue = dataRow.GetAttribute(CremaSchema.ModifiedDateTime);

            if (dateTimeValue == DBNull.Value)
            {
                return;
            }

            var dateTime  = (DateTime)dateTimeValue;
            var userValue = dataRow.GetAttribute(CremaSchema.Modifier);
            var user      = userValue is DBNull ? string.Empty : userValue as string;

            if (dateTime > dataTable.ContentsInfo.DateTime)
            {
                dataTable.InternalContentsInfo = new SignatureDate(user, dateTime);
            }
        }
Ejemplo n.º 28
0
        private void ReadValue(CremaDataRow dataRow, CremaDataColumn dataColumn, string textValue)
        {
            var dataType = dataColumn.DataType;
            var value    = textValue as object;

            try
            {
                value = CremaXmlConvert.ToValue(textValue, dataType);
                if (dataColumn.CremaType != null)
                {
                    if (long.TryParse(textValue, out long v) == true)
                    {
                        value = dataColumn.CremaType.ConvertToString(v);
                    }
                }
                dataRow.SetField(dataColumn, value);
            }
            catch (Exception e)
            {
                dataRow.SetField(dataColumn, textValue);
                dataRow.SetColumnError(dataColumn, e.Message);
            }
        }
Ejemplo n.º 29
0
        static void Write(string outputPath, CremaDataRow dataRow)
        {
            var localPath   = dataRow.Field <string>("ProjectPath").Replace(PathUtility.SeparatorChar, Path.DirectorySeparatorChar);
            var projectPath = Path.Combine(outputPath, localPath);

            var projectXml  = File.ReadAllText(projectPath);
            var projectInfo = new ProjectInfo(projectXml);

            foreach (var item in projectInfo.ResxInfos)
            {
                var dataTable = FindDataTable(item);
                if (dataTable == null)
                {
                    continue;
                }

                Write(Path.GetDirectoryName(projectPath), item, dataTable);

                if (item.ResgenFileName != string.Empty)
                {
                    WriteDesigner(Path.GetDirectoryName(projectPath), projectInfo, item);
                }
            }

            CremaDataTable FindDataTable(ResxInfo resxInfo)
            {
                foreach (var item in dataRow.GetChildRows("ExportInfo"))
                {
                    if (item.Field <string>("FileName") == resxInfo.Name)
                    {
                        var tableName = item.Field <string>("TableName");
                        return(dataRow.Table.DataSet.Tables[tableName]);
                    }
                }
                return(null);
            }
        }
Ejemplo n.º 30
0
        private void WriteDataRow(XmlWriter writer, CremaDataRow dataRow)
        {
            var dataTable = dataRow.Table;

            writer.WriteStartElement(dataTable.GetXmlName(this.targetNamespace));

            foreach (var item in dataTable.Attributes)
            {
                if (item.IsVisible == false)
                {
                    continue;
                }
                this.WriteAttribute(writer, dataRow.InternalObject, item.InternalAttribute);
            }

            if (dataTable.ColumnRelation != null)
            {
                writer.WriteStartAttribute(CremaSchema.RelationID);
                writer.WriteValue(dataRow.Field <string>(dataTable.ColumnRelation));
                writer.WriteEndAttribute();
            }

            if (dataTable.ParentRelation != null)
            {
                writer.WriteStartAttribute(CremaSchema.ParentID);
                writer.WriteValue(dataRow.Field <string>(dataTable.ParentRelation));
                writer.WriteEndAttribute();
            }

            foreach (var item in dataTable.Columns)
            {
                WriteField(writer, dataRow, item);
            }

            writer.WriteEndElement();
        }