Exemplo n.º 1
0
        private async Task <List <(string, string)> > GetEvents(SqlConnection conn)
        {
            var result = new List <(string, string)>();

            using (var command = new SqlCommand(TemplateQueries.EventsQuery(_sourceTenant), conn))
            {
                try
                {
                    command.CommandTimeout = 360;

                    using (var reader = await command.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            result.Add((
                                           reader.GetString(reader.GetOrdinal("TypeCode")),
                                           reader.GetString(reader.GetOrdinal("EventTypeCode"))
                                           ));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.GetType().ToString());
                    Console.WriteLine(ex.Message);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        private async Task GetEntities(Dictionary <string, EntityMapDefinition> definitions, SqlConnection conn)
        {
            using (var command = new SqlCommand(TemplateQueries.EntityQuery(_sourceTenant), conn))
            {
                try
                {
                    command.CommandTimeout = 360;

                    using (var reader = await command.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            var typeCode = reader.GetString(reader.GetOrdinal("TypeCode"));
                            var typeKind = reader.GetString(reader.GetOrdinal("Kind"));

                            definitions.Add(typeCode, new EntityMapDefinition(
                                                typeKind,
                                                typeCode,
                                                _kindMapper[typeKind],
                                                typeCode,
                                                new List <AttributeMap>()
                                                ));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.GetType().ToString());
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 3
0
        private async Task GetEntityAttributes(Dictionary <string, EntityMapDefinition> definitions, SqlConnection conn)
        {
            using (var command = new SqlCommand(TemplateQueries.AttributesQuery(_sourceTenant), conn))
            {
                try
                {
                    command.CommandTimeout = 360;

                    using (var reader = await command.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            var code = reader.GetString(reader.GetOrdinal("Name"));

                            if (_ignoreList.Contains(code))
                            {
                                continue;
                            }

                            var typeCode         = reader.GetString(reader.GetOrdinal("TypeCode"));
                            var dataType         = reader.GetString(reader.GetOrdinal("DataType")).Substring(0, 2);
                            var isSourceBaseType = reader.GetBoolean(reader.GetOrdinal("Base"));
                            var cardinalityPos   = reader.GetOrdinal("Cardinality");

                            if (definitions.ContainsKey(typeCode))
                            {
                                var attribute = new AttributeMap(
                                    code,
                                    _codeMapper.GetValueOrDefault(code, code),
                                    MapSourceType(),
                                    _targetTypeMapper[dataType],
                                    sourceCardinality: reader.IsDBNull(cardinalityPos) ? null : reader.GetString(cardinalityPos)
                                    );

                                if (code == "ApprovalStatus")
                                {
                                    attribute.ValueMapping.Add(new AttributeMap.AttributeValueMap("100", "Pending"));
                                    attribute.ValueMapping.Add(new AttributeMap.AttributeValueMap("200", "WaitingForApproval"));
                                    attribute.ValueMapping.Add(new AttributeMap.AttributeValueMap("400", "Rejected"));
                                    attribute.ValueMapping.Add(new AttributeMap.AttributeValueMap("500", "Approved"));
                                }

                                definitions[typeCode].Attributes.Add(attribute);
                            }

                            AttributeMap.AttributeType MapSourceType()
                            {
                                if (code == "ApprovalStatus")
                                {
                                    return(AttributeMap.AttributeType.Int);
                                }

                                return(isSourceBaseType ? _sourceTypeMapper[dataType] : AttributeMap.AttributeType.Text);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.GetType().ToString());
                    Console.WriteLine(ex.Message);
                }
            }
        }