Ejemplo n.º 1
0
 protected static string GetEntityOutputName(TflEntity entity, string processName) {
     var tflEntity = new Entity {
         Alias = entity.Alias,
         Name = entity.Name,
         PrependProcessNameToOutputName = entity.PrependProcessNameToOutputName
     };
     return Common.EntityOutputName(tflEntity, processName);
 }
        public Entity Read(TflEntity element, short entityIndex) {

            var entity = new Entity() {
                ProcessName = _process.Name,
                Schema = element.Schema,
                PipelineThreading = DetermineThreading(element),
                Name = element.Name,
                Prefix = element.Prefix,
                Group = element.Group,
                Delete = element.Delete,
                PrependProcessNameToOutputName = element.PrependProcessNameToOutputName,
                Sample = element.Sample,
                DetectChanges = element.DetectChanges,
                TrimAll = element.TrimAll,
                NoLock = element.NoLock,
                Unicode = element.Unicode,
                VariableLength = element.VariableLength,
                SqlOverride = element.Query,
                SqlScriptOverride = element.Script,
                SqlKeysOverride = element.QueryKeys,
                Alias = string.IsNullOrEmpty(element.Alias) ? element.Name : element.Alias,
                InputOperation = element.InputOperation,
                Index = entityIndex
            };

            // wire up connections
            if (_process.Connections.Contains(element.Connection)) {
                entity.Input.Add(_process.Connections.GetConnectionByName(element.Connection).NamedConnection());
            } else {
                _process.Logger.EntityWarn(element.Name, "Could not find connection '{0}'.", element.Connection);
            }

            //needs an input connection
            GuardAgainstMissingFields(element, entity, entityIndex);

            //fields
            short autoIndex = 0;

            foreach (TflField f in element.Fields) {
                var fieldType = GetFieldType(f, entityIndex == 0);

                var field = new FieldReader(_process, entity).Read(f, fieldType);
                if (field.Index.Equals(short.MaxValue)) {
                    field.Index = autoIndex;
                }

                entity.Fields.Add(field);

                if (f.PrimaryKey) {
                    entity.PrimaryKey.Add(field);
                }

                autoIndex++;
            }

            foreach (var cf in element.CalculatedFields) {
                var fieldReader = new FieldReader(_process, entity, usePrefix: false);
                var fieldType = GetFieldType(cf, entityIndex == 0);
                var field = fieldReader.Read(cf, fieldType);

                if (field.Index.Equals(short.MaxValue)) {
                    field.Index = autoIndex;
                }

                field.IsCalculated = true;
                field.Input = false;
                entity.CalculatedFields.Add(field);
                if (cf.PrimaryKey) {
                    entity.PrimaryKey.Add(field);
                }
                autoIndex++;
            }

            //depend on fields
            LoadVersion(element, entity);
            LoadFilter(element.Filter, entity, _process.Logger);

            entity.Input.AddRange(PrepareIo(element.Input, entity.Fields));
            entity.Output = PrepareIo(element.Output, entity.Fields);

            return entity;
        }
        private void LoadVersion(TflEntity element, Entity entity) {
            if (String.IsNullOrEmpty(element.Version))
                return;

            if (entity.Fields.HaveField(entity.Alias, element.Version)) {
                entity.Version = entity.Fields.Find(entity.Alias, element.Version).First();
            } else {
                if (entity.CalculatedFields.HaveField(entity.Alias, element.Version)) {
                    entity.Version = entity.CalculatedFields.Find(entity.Alias, element.Version).First();
                } else {
                    throw new TransformalizeException(_process.Logger, "version field reference '{0}' is undefined in {1}.", element.Version, element.Name);
                }
            }
            entity.Version.Output = true;
        }
        private void GuardAgainstMissingFields(TflEntity element, Entity entity, short entityIndex) {

            if (_process.Mode != "metadata" && element.Fields.Count == 0) {
                try {

                    _process.Logger.EntityInfo(entity.Name, "Detecting fields.");
                    var connection = entity.Input.First().Connection;
                    var fields = connection.GetEntitySchema(_process, entity, entityIndex == 0);
                    if (!fields.Any())
                        return;

                    foreach (var field in fields) {
                        if (String.IsNullOrEmpty(field.Label) || field.Label.Equals(field.Alias)) {
                            field.Label = MetaDataWriter.AddSpacesToSentence(field.Alias, true).Replace("_", " ");
                        }
                        var name = field.Name;
                        var f = element.GetDefaultOf<TflField>(x => x.Name = name);
                        f.Type = field.Type;
                        f.Length = field.Length;
                        f.PrimaryKey = field.FieldType.Equals(FieldType.PrimaryKey) || field.FieldType.Equals(FieldType.MasterKey);
                        f.Output = true;
                        f.Default = string.Empty;
                        f.Input = true;
                        f.Precision = field.Precision;
                        f.Scale = field.Scale;
                        f.Label = field.Label;
                        element.Fields.Add(f);
                    }
                    _process.Logger.EntityInfo(entity.Name, "Detected {0} fields.", fields.Count);
                } catch (Exception ex) {
                    throw new TransformalizeException(_process.Logger, "No fields defined.  Unable to detect them for {0}. {1}", entity.Name, ex.Message);
                } finally {
                    if (element.Fields.Count == 0) {
                        throw new TransformalizeException(_process.Logger, entity.Name, "No fields defined.  Unable to detect them for {0}.", entity.Name);
                    }
                }
            }
        }
        private PipelineThreading DetermineThreading(TflEntity element) {
            var threading = PipelineThreading.Default;
            if (_process.PipelineThreading != PipelineThreading.Default) {
                threading = _process.PipelineThreading;
            }

            if (!element.PipelineThreading.Equals("Default")) {
                PipelineThreading entityThreading;
                if (Enum.TryParse(element.PipelineThreading, true, out entityThreading)) {
                    threading = entityThreading;
                }
            }
            return threading;
        }
Ejemplo n.º 6
0
 public static string EntityOutputName(TflEntity entity, string processName) {
     return entity.PrependProcessNameToOutputName ? String.Concat(processName.Replace("-", String.Empty), entity.Alias).Replace(" ", String.Empty) : entity.Alias;
 }