protected virtual void MergeData(BulkLoadContext loadContext, BulkLoadSqlContext sqlContext,
                                         BulkItemsAndFieldsReader itemAndFieldReader)
        {
            var sql = sqlContext.GetEmbeddedSql(loadContext, "Sql.08.MergeTempData.sql");

            var stopwatch = Stopwatch.StartNew();

            // Execute merge and collect imported items.
            // Using sql parameters resets temp tables.
            sql = sqlContext.ReplaceOneLineSqlBitParameter(sql, "@ProcessDependingFields",
                                                           itemAndFieldReader.HasFieldDependencies);
            sql = sqlContext.ReplaceOneLineSqlBitParameter(sql, "@CleanupBlobs",
                                                           itemAndFieldReader.HasBlobFields);
            sql = sqlContext.ReplaceOneLineSqlBitParameter(sql, "@AllowTemplateChanges",
                                                           loadContext.AllowTemplateChanges);
            sql = sqlContext.ReplaceOneLineSqlStringParameter(sql, "@DefaultLanguage",
                                                              LanguageManager.DefaultLanguage.Name);

            using (var cmd = sqlContext.NewSqlCommand(sql))
            {
                cmd.CommandTimeout = int.MaxValue;
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        loadContext.ItemChanges.AddLast(new ItemChange(reader));
                    }
                }
            }
            loadContext.Log.Info($"Merged loaded data: {(int)stopwatch.Elapsed.TotalSeconds}s");
        }
        private bool CheckTempData(BulkLoadContext loadContext, BulkLoadSqlContext sqlContext)
        {
            var check     = sqlContext.GetEmbeddedSql(loadContext, "Sql.07.CheckTempData.sql");
            var hasErrors = false;

            using (var cmd = sqlContext.NewSqlCommand(check))
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (!reader.GetBoolean(reader.GetOrdinal("HasParent")))
                        {
                            loadContext.Log.Error(
                                $"Unable to find parent '{reader["ParentId"]}' for item with id '{reader["Id"]}', " +
                                $"item path '{reader["ItemPath"]}' and source info '{reader["SourceInfo"]}'.");
                        }
                        if (!reader.GetBoolean(reader.GetOrdinal("HasTemplate")))
                        {
                            loadContext.Log.Error(
                                $"Unable to find template '{reader["TemplateName"]}' with id '{reader["TemplateId"]}' " +
                                $"for item with id '{reader["Id"]}', item path '{reader["ItemPath"]}' and source info '{reader["SourceInfo"]}'.");
                        }
                        hasErrors = true;
                    }
                    reader.NextResult();
                    while (reader.Read())
                    {
                        if (!reader.GetBoolean(reader.GetOrdinal("HasItem")))
                        {
                            loadContext.Log.Error(
                                $"Unable to find item with id '{reader["ItemId"]}', item path '{reader["ItemPath"]}' " +
                                $"and source info '{reader["SourceInfo"]}' for field '{reader["FieldName"]}' with id '{reader["FieldId"]}'.");
                        }
                        if (!reader.GetBoolean(reader.GetOrdinal("HasField")))
                        {
                            loadContext.Log.Error(
                                $"Unable to find field '{reader["FieldName"]}' with id '{reader["FieldId"]}' " +
                                $"for item with id '{reader["ItemId"]}', item path '{reader["ItemPath"]}' and source info '{reader["SourceInfo"]}'.");
                        }
                        hasErrors = true;
                    }
                }

            return(!hasErrors);
        }
Пример #3
0
        private bool CheckDuplicates(BulkLoadContext context, BulkLoadSqlContext sqlContext)
        {
            var check     = sqlContext.GetEmbeddedSql(context, "Sql.05.CheckDuplicates.sql");
            var hasErrors = false;

            using (var cmd = sqlContext.NewSqlCommand(check))
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        context.Log.Error(
                            $"Duplicate item found with id '{reader["Id"]}', item path '{reader["ItemPath"]}' " +
                            $"and source info '{reader["SourceInfo"]}'.");
                        hasErrors = true;
                    }
                }
            return(!hasErrors);
        }