Пример #1
0
        private static void SetNodeRow(DataRow row, NodeHeadData node, MsSqlDataProvider dataProvider)
        {
            row["NodeId"]             = node.NodeId;
            row["NodeTypeId"]         = node.NodeTypeId;
            row["CreatingInProgress"] = node.CreatingInProgress ? Yes : No;
            row["IsDeleted"]          = node.IsDeleted ? Yes : No;
            row["IsInherited"]        = (byte)0;
            row["ParentNodeId"]       = node.ParentNodeId;

            row["Name"]   = node.Name;
            row["Path"]   = node.Path;
            row["Index"]  = node.Index;
            row["Locked"] = node.Locked ? Yes : No;

            row["ETag"]           = node.ETag ?? string.Empty;
            row["LockType"]       = node.LockType;
            row["LockTimeout"]    = node.LockTimeout;
            row["LockDate"]       = AlignDateTime(node.LockDate, dataProvider);
            row["LockToken"]      = node.LockToken ?? string.Empty;
            row["LastLockUpdate"] = AlignDateTime(node.LastLockUpdate, dataProvider);

            row["LastMinorVersionId"] = node.LastMinorVersionId;
            row["LastMajorVersionId"] = node.LastMajorVersionId;

            row["CreationDate"]     = AlignDateTime(node.CreationDate, dataProvider);
            row["CreatedById"]      = node.CreatedById;
            row["ModificationDate"] = AlignDateTime(node.ModificationDate, dataProvider);
            row["ModifiedById"]     = node.ModifiedById;

            row["IsSystem"]    = node.IsSystem ? Yes : No;
            row["OwnerId"]     = node.OwnerId;
            row["SavingState"] = node.SavingState;
        }
Пример #2
0
 private static DateTime AlignDateTime(DateTime dateTime, MsSqlDataProvider dataProvider)
 {
     if (dateTime > dataProvider.DateTimeMaxValue)
     {
         dateTime = dataProvider.DateTimeMaxValue;
     }
     if (dateTime < dataProvider.DateTimeMinValue)
     {
         dateTime = dataProvider.DateTimeMinValue;
     }
     return(dateTime);
 }
Пример #3
0
        public static async Task InstallInitialDataAsync(InitialData data, MsSqlDataProvider dataProvider, string connectionString,
                                                         CancellationToken cancellationToken)
        {
            var dataSet = new DataSet();

            CreateTableStructure(dataSet);

            _columnNames = dataSet.Tables.Cast <DataTable>().ToDictionary(
                table => table.TableName,
                table => table.Columns.Cast <DataColumn>().Select(x => x.ColumnName).ToArray());

            CreateData(dataSet, data, dataProvider);

            await WriteToDatabaseAsync(dataSet, connectionString, cancellationToken).ConfigureAwait(false);
        }
Пример #4
0
 private static void SetVersionRow(DataRow row, VersionData version, IDictionary <PropertyType, object> dynamicProperties, MsSqlDataProvider dataProvider)
 {
     row["VersionId"]         = version.VersionId;
     row["NodeId"]            = version.NodeId;
     row["MajorNumber"]       = version.Version.Major;
     row["MinorNumber"]       = version.Version.Minor;
     row["Status"]            = (byte)version.Version.Status;
     row["CreationDate"]      = AlignDateTime(version.CreationDate, dataProvider);
     row["CreatedById"]       = version.CreatedById;
     row["ModificationDate"]  = AlignDateTime(version.CreationDate, dataProvider);
     row["ModifiedById"]      = version.ModifiedById;
     row["IndexDocument"]     = null;
     row["ChangedData"]       = null;
     row["DynamicProperties"] = dynamicProperties == null ? null : dataProvider.SerializeDynamicProperties(dynamicProperties);
 }
Пример #5
0
 private static void SetNodeTypeRow(DataRow row, NodeTypeData nodeType, List <NodeTypeData> allNodeTypes, MsSqlDataProvider dataProvider)
 {
     row["NodeTypeId"] = nodeType.Id;
     row["Name"]       = nodeType.Name;
     row["ParentId"]   = (object)allNodeTypes.FirstOrDefault(x => x.Name == nodeType.ParentName)?.Id ?? DBNull.Value;
     row["ClassName"]  = nodeType.ClassName;
     row["Properties"] = string.Join(" ", nodeType.Properties);
 }
Пример #6
0
 private static void SetPropertyTypeRow(DataRow row, PropertyTypeData propertyType, MsSqlDataProvider dataProvider)
 {
     row["PropertyTypeId"]        = propertyType.Id;
     row["Name"]                  = propertyType.Name;
     row["DataType"]              = propertyType.DataType.ToString();
     row["Mapping"]               = propertyType.Mapping;
     row["IsContentListProperty"] = propertyType.IsContentListProperty ? Yes : No;
 }
Пример #7
0
        /* ==================================================================================================== Fill Data */

        private static void CreateData(DataSet dataSet, InitialData data, MsSqlDataProvider dataProvider)
        {
            var now = DateTime.UtcNow;

            var propertyTypes = dataSet.Tables[TableName.PropertyTypes];

            foreach (var propertyType in data.Schema.PropertyTypes)
            {
                var row = propertyTypes.NewRow();
                SetPropertyTypeRow(row, propertyType, dataProvider);
                propertyTypes.Rows.Add(row);
            }

            var nodeTypes = dataSet.Tables[TableName.NodeTypes];

            foreach (var nodeType in data.Schema.NodeTypes)
            {
                var row = nodeTypes.NewRow();
                SetNodeTypeRow(row, nodeType, data.Schema.NodeTypes, dataProvider);
                nodeTypes.Rows.Add(row);
            }

            var nodes = dataSet.Tables[TableName.Nodes];

            foreach (var node in data.Nodes)
            {
                var row = nodes.NewRow();
                node.CreationDate     = now;
                node.ModificationDate = now;
                SetNodeRow(row, node, dataProvider);
                nodes.Rows.Add(row);
            }

            var versions         = dataSet.Tables[TableName.Versions];
            var longTexts        = dataSet.Tables[TableName.LongTextProperties];
            var refProps         = dataSet.Tables[TableName.ReferenceProperties];
            var binaryProperties = dataSet.Tables[TableName.BinaryProperties];
            var files            = dataSet.Tables[TableName.Files];
            var longTextId       = 0;
            var refPropId        = 0;

            foreach (var version in data.Versions)
            {
                var props = data.DynamicProperties.FirstOrDefault(x => x.VersionId == version.VersionId);
                if (props?.LongTextProperties != null)
                {
                    foreach (var longTextData in props.LongTextProperties)
                    {
                        var longTextRow    = longTexts.NewRow();
                        var propertyTypeId =
                            data.Schema.PropertyTypes.FirstOrDefault(x => x.Name == longTextData.Key.Name)?.Id ?? 0;
                        SetLongTextPropertyRow(longTextRow, ++longTextId, version.VersionId, propertyTypeId, longTextData.Value);
                        longTexts.Rows.Add(longTextRow);
                    }
                }
                if (props?.ReferenceProperties != null)
                {
                    foreach (var referenceData in props.ReferenceProperties)
                    {
                        var propertyTypeId =
                            data.Schema.PropertyTypes.FirstOrDefault(x => x.Name == referenceData.Key.Name)?.Id ?? 0;
                        foreach (var value in referenceData.Value)
                        {
                            var refPropRow = refProps.NewRow();
                            SetReferencePropertyRow(refPropRow, ++refPropId, version.VersionId, propertyTypeId, value);
                            refProps.Rows.Add(refPropRow);
                        }
                    }
                }
                if (props?.BinaryProperties != null)
                {
                    foreach (var binaryPropertyData in props.BinaryProperties)
                    {
                        var binaryPropertyRow = binaryProperties.NewRow();
                        var propertyTypeId    =
                            data.Schema.PropertyTypes.FirstOrDefault(x => x.Name == binaryPropertyData.Key.Name)?.Id ?? 0;
                        SetBinaryPropertyRow(binaryPropertyRow, version.VersionId, propertyTypeId, binaryPropertyData.Value);
                        binaryProperties.Rows.Add(binaryPropertyRow);

                        var fileRow = files.NewRow();
                        SetFileRow(fileRow, binaryPropertyData.Value, data, binaryPropertyData.Key.Name);
                        files.Rows.Add(fileRow);
                    }
                }

                var versionRow = versions.NewRow();
                version.CreationDate     = now;
                version.ModificationDate = now;
                SetVersionRow(versionRow, version, props?.DynamicProperties, dataProvider);
                versions.Rows.Add(versionRow);
            }
        }