Example #1
0
        public static object CreateInstanceAndMapAndValidate(ICommonMapper mapper, Type sourceType, Type destinationType, object source)
        {
            //Complete mapping
            var        result     = mapper.Map(source, sourceType, destinationType);
            MethodInfo methodInfo = destinationType.GetMethod("Validate");

            //add validation logic here.
            if (methodInfo != null)
            {
                object isValid = methodInfo.Invoke(result, null);
            }

            return(result);
        }
Example #2
0
        public static TDestination CreateInstanceAndMapAndValidate <TSource, TDestination>(ICommonMapper mapper, TSource source)
        {
            //Complete mapping
            TDestination result = mapper.Map <TSource, TDestination>(source);

            Type       destinationType = result.GetType();
            MethodInfo methodInfo      = destinationType.GetMethod("Validate");

            //add validation logic here.
            if (methodInfo != null)
            {
                object isValid = methodInfo.Invoke(result, null);
            }

            return(result);
        }
Example #3
0
 public static object CreateInstanceAndMap(ICommonMapper mapper, Type sourceType, Type destinationType, object source)
 {
     //Complete mapping
     return(mapper.Map(source, sourceType, destinationType));
 }
Example #4
0
 public static TDestination CreateInstanceAndMap <TSource, TDestination>(ICommonMapper mapper, TSource source)
 {
     //Complete mapping
     return(mapper.Map <TSource, TDestination>(source));
 }
Example #5
0
 public IActionResult Get()
 {
     return(Ok(mapper.Map <List <CountryDto> >(countryRepository.GetAll())));
 }
Example #6
0
        /// <summary>
        /// Загрузка базы данных в память
        /// </summary>
        /// <returns></returns>
        public void Load()
        {
            string      filePath = Path.Combine(_environment.ContentRootPath, _dbFileName);
            BinGeoModel binModel;

            using (FileStream stream = new FileStream(filePath, FileMode.Open))
            {
                Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();

                using (BufferedBinaryReader bufferedReader = new BufferedBinaryReader(stream, 65536))
                {
                    stopwatch.Start();

                    bufferedReader.FillBuffer();

                    int    version         = bufferedReader.ReadInt32();
                    byte[] nameBytes       = bufferedReader.Read(0, 32);
                    ulong  timestamp       = bufferedReader.ReadUInt64();
                    int    records         = bufferedReader.ReadInt32();
                    uint   offsetRanges    = bufferedReader.ReadUInt32();
                    uint   offsetCities    = bufferedReader.ReadUInt32();
                    uint   offsetLocations = bufferedReader.ReadUInt32();

                    binModel = new BinGeoModel(version, nameBytes, timestamp, records, offsetRanges, offsetCities, offsetLocations);

                    int currentIndex = 0;
                    binModel.IpRangeCollection = new BinIpRange[binModel.RecordsCount];
                    while (bufferedReader.FillBuffer() && currentIndex < binModel.RecordsCount)
                    {
                        for (; currentIndex < binModel.RecordsCount && bufferedReader.NumBytesAvailable >= IpRangeBytesCount; currentIndex++)
                        {
                            binModel.IpRangeCollection[currentIndex] = new BinIpRange()
                            {
                                IpFrom        = bufferedReader.ReadUInt32(),
                                IpTo          = bufferedReader.ReadUInt32(),
                                LocationIndex = bufferedReader.ReadUInt32()
                            };
                        }
                    }

                    currentIndex = 0;
                    binModel.LocationCollection = new BinLocation[binModel.RecordsCount];
                    while (bufferedReader.FillBuffer() && currentIndex < binModel.RecordsCount)
                    {
                        for (; currentIndex < binModel.RecordsCount && bufferedReader.NumBytesAvailable >= LocationBytesCount; currentIndex++)
                        {
                            byte[] country      = bufferedReader.Read(0, 8);
                            byte[] region       = bufferedReader.Read(0, 12);
                            byte[] postal       = bufferedReader.Read(0, 12);
                            byte[] city         = bufferedReader.Read(0, 24);
                            byte[] organization = bufferedReader.Read(0, 32);
                            float  latitude     = bufferedReader.ReadSingle();
                            float  longitude    = bufferedReader.ReadSingle();

                            binModel.LocationCollection[currentIndex] = new BinLocation(country, region, postal, city, organization, latitude, longitude);
                        }
                    }

                    currentIndex     = 0;
                    binModel.Indexes = new uint[binModel.RecordsCount];
                    while (bufferedReader.FillBuffer() && currentIndex < binModel.RecordsCount)
                    {
                        for (; currentIndex < binModel.RecordsCount && bufferedReader.NumBytesAvailable >= IndexBytesCount; currentIndex++)
                        {
                            binModel.Indexes[currentIndex] = bufferedReader.ReadUInt32();
                        }
                    }

                    stopwatch.Stop();
                    DatabaseLoadedTimeMs = stopwatch.ElapsedMilliseconds;
                    _logger.LogInformation($"Database loading time: {stopwatch.ElapsedMilliseconds} ms");
                }

                // Отображение объектов сущностей двоичной базы в объекты бизнес сущностей
                GeoModel = _mapper.Map <GeoModel>(binModel);
            }
        }