Exemplo n.º 1
0
        public static void GenerateFile(string sqlStatement, string outputFilePath, string tableName, List <CsvDataSource> csvDataSource)
        {
            var yamlFileMetadata = new YamlFileMetadata();

            yamlFileMetadata.TableDefinition = "";
            yamlFileMetadata.TableName       = tableName;
            List <CsvDataSource> tableRecords = null;

            yamlFileMetadata.ColumnsWithNotNullTest = new List <string>();
            var nullOptionsPresent = false;

            try
            {
                if (csvDataSource != null)
                {
                    tableRecords = csvDataSource.Where(e => e.TableName.Equals(tableName, StringComparison.OrdinalIgnoreCase)).ToList();
                    foreach (var record in tableRecords)
                    {
                        if (record.NullOption != null)
                        {
                            nullOptionsPresent = true;
                            break;
                        }
                    }
                    if (nullOptionsPresent)
                    {
                        var NotNullRecords = tableRecords.Where(e => e.NullOption.Equals("Not Null", StringComparison.OrdinalIgnoreCase)).ToList();
                        yamlFileMetadata.ColumnsWithNotNullTest = NotNullRecords.Select(e => e.ColumnName).Distinct().ToList();
                    }
                }

                var columns = DDLParser.GetDdlStatementColumns(sqlStatement);
                if (tableRecords == null || !tableRecords.Any())
                {
                    List <LabelValuePair> columnsDetails = new List <LabelValuePair>();
                    foreach (var column in columns)
                    {
                        LabelValuePair columnDetails = new LabelValuePair();
                        columnDetails.Label = column.Name;
                        columnDetails.Value = "";
                        columnsDetails.Add(columnDetails);
                    }
                    yamlFileMetadata.ColumnDefinition = columnsDetails;
                }
                else
                {
                    yamlFileMetadata.TableDefinition  = GetTableDefinition(tableRecords);
                    yamlFileMetadata.ColumnDefinition = GetColumnDefinition(tableRecords, columns);
                }
                yamlFileMetadata.TableDefinition = Regex.Replace(yamlFileMetadata.TableDefinition, @"\s+", " ");
                tableName = tableName.ToLowerInvariant();
                Logger.LogInfo("Generating yml file for " + tableName);
                if (tableName.Contains(Constants.HubFileName, StringComparison.OrdinalIgnoreCase))
                {
                    outputFilePath += "hubs";
                }
                if (tableName.Contains(Constants.LnkFileName, StringComparison.OrdinalIgnoreCase))
                {
                    outputFilePath += "links";
                }
                if (tableName.Contains(Constants.SatFileName, StringComparison.OrdinalIgnoreCase) || tableName.Contains(Constants.MasFileName, StringComparison.OrdinalIgnoreCase))
                {
                    if (tableName.Contains(Constants.SatBrFileName, StringComparison.OrdinalIgnoreCase))
                    {
                        outputFilePath += "satellitebusinessrules";
                    }
                    else
                    {
                        outputFilePath += "satellites";
                    }
                }

                Utility.CreateDirectoryIfDoesNotExists(outputFilePath);

                var yamlFileTemplate = new YamlFileTemplate(yamlFileMetadata);
                var content          = yamlFileTemplate.TransformText();

                var pathStr = $"{outputFilePath}\\{tableName}.yml";
                File.WriteAllText(pathStr, content);
                Logger.LogInfo("Generated yml file for " + tableName);
            }
            catch (Exception e)
            {
                Logger.LogError(e, Utility.ErrorGeneratingFileForTable("yml", tableName, e.Message));
            }
        }
Exemplo n.º 2
0
 public YamlFileTemplate(YamlFileMetadata yamlFileMetadata)
 {
     YamlFileMetadata = yamlFileMetadata;
 }