Example #1
0
        private void Collect(DiffPair pair, ConcurrentDictionary <string, DataDiffTable> result)
        {
            var basis         = pair.Base ?? new XElement("stub");
            var updated       = pair.Updated ?? new XElement("stub");
            var baseTableName = pair.Updated.Attr("table");
            var mixed         = pair.Updated.Attr("mixed").ToBool();
            var dynamicname   = mixed || string.IsNullOrWhiteSpace(baseTableName);
            var hierarchy     = pair.Updated.Attr("tree").ToBool();
            var script        = pair.Updated.Attr("script");

            if (string.IsNullOrWhiteSpace(script))
            {
                script = "10_Main";
            }
            var diffconfig = new XDiffOptions {
                IsHierarchy                    = hierarchy,
                MergeAttributeChanges          = true,
                TreatNewAttributesAsChanges    = true,
                TreatDeleteAttributesAsChanges = _context.EmptyAttributesAsUpdates,
                IncludeActions                 = XDiffAction.RenameElement | XDiffAction.MainCreateOrUpdate
            };
            var sw   = Stopwatch.StartNew();
            var diff = new XDiffGenerator(diffconfig).GetDiff(basis, updated).ToArray();

            Collect(dynamicname, baseTableName, diff, result, script);
            sw.Stop();
            _context.Log.Debug("diff of " + baseTableName + " : " + sw.Elapsed);
        }
Example #2
0
        /// <summary>
        /// Компилирует исходую и целевую версию проекта, сравнивает классы и формирует пары для сравнений
        /// </summary>
        public void Generate()
        {
            Directory.CreateDirectory(_context.RootDirectory);
            IDictionary <string, XElement> sourceClasses = new Dictionary <string, XElement>();

            _context.Log.Trace("start initialize git");
            PrepareGitRepository();
            _context.Log.Info("git initialized");
            if (_context.FullUpdate)
            {
                _context.Log.Trace("full update mode");
            }
            else
            {
                _context.Log.Trace("start base proj reading");
                sourceClasses = GetBSharpClasses(_context.GitBaseRevision);
                _context.Log.Trace("end base proj reading");
            }
            _context.Log.Trace("start update proj reading");
            IDictionary <string, XElement> updatedClasses = GetBSharpClasses(_context.GitUpdateRevision);

            _context.Log.Trace("end base proj reading");
            IDictionary <string, DiffPair> result = new Dictionary <string, DiffPair>();

            foreach (var updatedClass in updatedClasses)
            {
                var name = updatedClass.Key;
                var diff = new DiffPair {
                    Updated = updatedClass.Value, Base = new XElement("stub"), FileName = name
                };
                if (sourceClasses.ContainsKey(name))
                {
                    diff.Base = sourceClasses[name];
                }
                if (diff.Base.ToString() == diff.Updated.ToString())
                {
                    continue;
                }
                result[name] = diff;
            }
            _context.DiffPairs = result.Values.ToArray();
            FixCodeUpdates();
        }
Example #3
0
        /// <summary>
        /// Формирует полный контекст сравнения обновления данных
        /// </summary>
        /// <returns></returns>
        public static TableDiffGeneratorContext GenerateContext(IDbConnection connection, XElement update, params string[] fields)
        {
            if (update.Name.LocalName == "batch")
            {
                var updateList = new List <DiffPair>();
                var i          = 0;
                foreach (var e in update.Elements())
                {
                    var name = "dynamic" + i++;
                    var s    = GetBaseXml(connection, e, fields);
                    var diff = new DiffPair {
                        FileName = name, Base = s, Updated = e
                    };
                    updateList.Add(diff);
                }
                return(GenerateContext(updateList.ToArray()));
            }
            var baseXml = GetBaseXml(connection, update, fields);

            return(GenerateContext(baseXml, update));
        }