public IEnumerable <IDataObject> GetData()
        {
            Migrator.Current.Tracer.TraceLine($"DataSource ({ this }) - Get data...");

            uint rowCounter = 0;

            foreach (var valuesObject in GetDataInternal())
            {
                rowCounter++;
                var ctx = new ValueTransitContext(valuesObject, valuesObject);

                if (Filter != null && ctx.Execute(Filter) == false)
                {
                    continue;
                }

                ctx.Execute(Key);
                var strKey = ctx.TransitValue?.ToString();

                if (strKey.IsEmpty())
                {
                    continue;
                }

                valuesObject.Key       = UnifyKey(strKey);
                valuesObject.RowNumber = rowCounter;
                if (PrepareData != null)
                {
                    ctx.Execute(PrepareData);
                }
                yield return(valuesObject);
            }
        }
Exemplo n.º 2
0
        public void Run()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            Tracer.TraceLine("====== Migration start ======");

            try
            {
                foreach (string name in _mapConfig.Variables.Keys.ToList())
                {
                    if (_mapConfig.Variables[name] is CommandBase command)
                    {
                        var ctx = new ValueTransitContext(null, null);
                        ctx.Execute(command);
                        _mapConfig.Variables[name] = ctx.TransitValue;
                    }
                }

                foreach (var pipeline in _mapConfig.Pipeline.Where(i => i.Enabled))
                {
                    pipeline.Run();
                }
            }
            catch (DataMigrationException e)
            {
                Tracer.TraceMigrationException("Error occured while pipeline processing", e);
                if (ThrowExeptionOnError)
                {
                    throw;
                }
            }
            catch (Exception e)
            {
                Tracer.TraceLine(e.ToString());
                if (ThrowExeptionOnError)
                {
                    throw;
                }
            }

            stopwatch.Stop();
            Tracer.SaveLogs();
            Tracer.TraceLine($"====== END {stopwatch.Elapsed.TotalMinutes} mins ======");
        }
        public override void ExecuteInternal(ValueTransitContext ctx)
        {
            Init();
            var  value            = ctx.TransitValue;
            char decimalSeparator = DecimalSeparator == 0 ? MapConfig.Current.DefaultDecimalSeparator : DecimalSeparator;

            try
            {
                var typedValue = TypeConverter.GetTypedValue(_typeCode, value, decimalSeparator, Format);
                ctx.SetCurrentValue(typedValue);
            }
            catch (Exception e)
            {
                if (OnError == null)
                {
                    throw;
                }

                ctx.Execute(OnError);
            }
        }
        public override void ExecuteInternal(ValueTransitContext ctx)
        {
            foreach (var childTransition in Commands)
            {
                ctx.Execute(childTransition);

                if (ctx.Flow == TransitionFlow.SkipValue)
                {
                    //if ReplaceUnit returned SkipValue then need to stop ONLY replacing sequence (hack, need to refactor to do
                    //it in more convenient way
                    ctx.Flow = TransitionFlow.Continue;
                    break;
                }

                if (ctx.Flow != TransitionFlow.Continue)
                {
                    ctx.TraceLine($"Breaking {this.GetType().Name}");
                    break;
                }
            }
        }
        public override void ExecuteInternal(ValueTransitContext ctx)
        {
            object lookupObject = null;

            var valueToFind = ctx.TransitValue?.ToString();

            if (valueToFind.IsNotEmpty())
            {
                lookupObject = FindLookupObject(valueToFind, ctx);

                if (lookupObject == null)
                {
                    if (TraceNotFound)
                    {
                        string message = $"Lookup ({Source}) object not found by value '{valueToFind}'\nSource row: { ctx.Source.RowNumber}, Source key: {ctx.Source.Key}";
                        Migrator.Current.Tracer.TraceEvent(MigrationEvent.LookupFailed, ctx, message);
                    }

                    ctx.Execute(OnNotFound);
                }
            }

            ctx.SetCurrentValue(lookupObject);
        }
Exemplo n.º 6
0
 protected virtual void TransitChild(T childCommand, ValueTransitContext ctx)
 {
     ctx.Execute(childCommand);
 }
        public override void ExecuteInternal(ValueTransitContext ctx)
        {
            string result = Commands.Select(i => ctx.Execute(i)?.ToString()).Join("/");

            ctx.SetCurrentValue(result);
        }