Example #1
0
        public static SynColMapping CreateMapping(Dictionary <string, string> dict)
        {
            var res = new SynColMapping();

            foreach (var item in dict)
            {
                res.Columns.Add(new SynItem
                {
                    Source = item.Value,
                    Target = item.Key,
                });
            }
            return(res);
        }
Example #2
0
        public static SynColMapping CreateMapping(ITableStructure source, ITableStructure target)
        {
            if (source.Columns.Count != target.Columns.Count)
            {
                throw new DataSynError(String.Format("DAE-00321 Table {0}: column count mitchmatch", target.FullName));
            }
            var res = new SynColMapping();

            foreach (var dstcol in target.Columns)
            {
                var srccol = source.FindColumn(dstcol.ColumnName, true);
                if (srccol == null)
                {
                    throw new DataSynError(String.Format("DAE-00322 Table {0}: cannout find source for column {1}", target.FullName, dstcol.ColumnName));
                }
                res.Columns.Add(new SynItem
                {
                    Source = srccol.ColumnName,
                    Target = dstcol.ColumnName,
                });
            }
            return(res);
        }
Example #3
0
        public void BuildInfo(IDatabaseSource srcConn, IDatabaseSource dstConn, out SynSourceInfo source, out SynSourceInfo target)
        {
            source = new SynSourceInfo();
            target = new SynSourceInfo();

            if (!(Source is DataSynQuerySource))
            {
                source.SqlCondition = Source.SqlCondition;
            }
            target.SqlCondition = Target.SqlCondition;

            source.Model = Source.GetModel(srcConn);
            target.Model = Target.GetModel(dstConn);

            if (KeyColsOverride != null)
            {
                target.KeyCols = KeyColsOverride.ToArray();
            }
            else
            {
                target.KeyCols = target.Model.GetPkColumns().GetNames();
            }
            if (target.KeyCols.Length == 0)
            {
                throw new DataSynError("DAE-00319 Table " + target.Model.FullName.ToString() + " has empty synchronize key or table has not primary key");
            }

            SynColMapping map = null;

            if (ColMode != ColumnMode.CustomMapping)
            {
                map = SynColMapping.CreateMapping(source.Model, target.Model);
            }
            else
            {
                map = SynColMapping.CreateMapping(SelectedMapping);
            }
            switch (ColMode)
            {
            case ColumnMode.All:
                AssignColsAndQuery(source, target, srcConn, dstConn, map.SourceCols, map.TargetCols);
                break;

            case ColumnMode.Selected:
                AssignColsAndQuery(source, target, srcConn, dstConn, map[SelectedColumns], SelectedColumns.ToArray());
                break;

            case ColumnMode.AllExceptSelected:
                string[] selcols = map.Complement(SelectedNoColumns);
                AssignColsAndQuery(source, target, srcConn, dstConn, map[selcols], selcols);
                break;

            case ColumnMode.CustomMapping:
                AssignColsAndQuery(source, target, srcConn, dstConn, SelectedMapping.Values.ToArray(), SelectedMapping.Keys.ToArray());
                break;
            }
            switch (CompareColMode)
            {
            case ColumnMode.All:
                AssignCompareCols(source, target, srcConn, dstConn, source.DataCols, target.DataCols);
                break;

            case ColumnMode.Selected:
                AssignCompareCols(source, target, srcConn, dstConn, map[CompareColsOverride], CompareColsOverride.ToArray());
                break;

            case ColumnMode.AllExceptSelected:
                string[] ccols = ArrayTool.Difference(target.DataCols, CompareNoColsOverride);
                AssignCompareCols(source, target, srcConn, dstConn, map[ccols], ccols.ToArray());
                break;
            }
        }