Example #1
0
 public ColorService(
     IColorRepository colorRepository,
     IUnitOfWork unitOfWork)
 {
     _colorRepository = colorRepository;
     _unitOfWork      = unitOfWork;
 }
Example #2
0
        public ColorQuery(IColorRepository colorRepository, ITranslationRepository translationRepository)
        {
            Field <TranslationType>(
                "translation",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id", Description = "Category id"
            }
                    ),
                resolve: context => translationRepository.GetTranslationAsync(context.GetArgument <int>("id")).Result
                );

            Field <ColorType>(
                "color",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id", Description = "Product id"
            }
                    ),
                resolve: context => colorRepository.GetColorAsync(context.GetArgument <int>("id")).Result
                );
            Field <ListGraphType <ColorType> >(
                "colors",
                resolve: context => colorRepository.ColorsAsync()
                );
        }
Example #3
0
        /// <inheritdoc />
        async Task <IDictionaryRange <int, ColorPalette> > IRepository <int, ColorPalette> .FindAllAsync(CancellationToken cancellationToken)
        {
            IColorRepository self = this;
            var request           = new ColorRequest
            {
                Culture = self.Culture
            };
            var response = await this.serviceClient.SendAsync <ColorCollectionDTO>(request, cancellationToken).ConfigureAwait(false);

            if (response.Content == null || response.Content.Colors == null)
            {
                return(new DictionaryRange <int, ColorPalette>(0));
            }

            var values        = this.colorPaletteCollectionConverter.Convert(response.Content, null);
            var colorPalettes = new DictionaryRange <int, ColorPalette>(values.Count)
            {
                SubtotalCount = values.Count,
                TotalCount    = values.Count
            };

            foreach (var colorPalette in values)
            {
                colorPalette.Culture = request.Culture;
                colorPalettes.Add(colorPalette.ColorId, colorPalette);
            }

            return(colorPalettes);
        }
Example #4
0
        /// <inheritdoc />
        Task <IDictionaryRange <int, ColorPalette> > IRepository <int, ColorPalette> .FindAllAsync(CancellationToken cancellationToken)
        {
            IColorRepository self = this;
            var request           = new ColorRequest
            {
                Culture = self.Culture
            };

            return(this.serviceClient.SendAsync <ColorCollectionDataContract>(request, cancellationToken).ContinueWith <IDictionaryRange <int, ColorPalette> >(
                       task =>
            {
                var response = task.Result;
                if (response.Content == null || response.Content.Colors == null)
                {
                    return new DictionaryRange <int, ColorPalette>(0);
                }

                var values = this.converterForColorPaletteCollection.Convert(response.Content, null);
                var colorPalettes = new DictionaryRange <int, ColorPalette>(values.Count)
                {
                    SubtotalCount = values.Count,
                    TotalCount = values.Count
                };

                foreach (var colorPalette in values)
                {
                    colorPalette.Culture = request.Culture;
                    colorPalettes.Add(colorPalette.ColorId, colorPalette);
                }

                return colorPalettes;
            },
                       cancellationToken));
        }
Example #5
0
        public ListColorQueryHandlerTest()
        {
            var repository = new Mock <IColorRepository>();

            repository.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Domain.Entities.Color, bool> > >(),
                                              It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync((Expression <Func <Domain.Entities.Color, bool> > filter,
                           string orderBy, int page, int qtyPerPage) =>
            {
                var func  = filter.Compile();
                var value = func.Invoke(Domain.Entities.Color.New("test", StatusEnum.Disable, TenantId.New()));

                if (value)
                {
                    return(Pagination <Domain.Entities.Color> .Empty);
                }
                else
                {
                    return(Pagination <Domain.Entities.Color> .New(new Domain.Entities.Color[]
                    {
                        Domain.Entities.Color.New("test 1", StatusEnum.Disable, TenantId.New())
                    }, 1, 1, 1));
                }
            });

            _colorRepository = repository.Object;
        }
 public ProductQuantityService(IProductQuantityRepository productQuantityRepository, IColorRepository colorRepository, ISizeRepository sizeRepository, IUnitOfWork unitOfWork)
 {
     _productQuantityRepository = productQuantityRepository;
     _sizeRepository            = sizeRepository;
     _colorRepository           = colorRepository;
     _unitOfWork = unitOfWork;
 }
Example #7
0
 public DogService(IDogRepository repository, IColorRepository colorRepository, IMapper mapper, IImageService imgService)
 {
     _repository = repository;
     _colorRepository = colorRepository;
     _mapper = mapper;
     _imgService = imgService;
 }
Example #8
0
 public BoardController()
 {
     _boardRepository  = new BoardRepository();
     _columnRepository = new ColumnRepository();
     _colorRepository  = new ColorRepository();
     _taskRepository   = new TaskRepository();
 }
 public InventoryService(IMapper mapper,
                         ICarMakeRepository carMakeRepository,
                         ICarModelRepository carModelRepository,
                         ITrimRepository trimRepository,
                         IBodyTypeRepository bodyTypeRepository,
                         IDriveTypeRepository driveTypeRepository,
                         IFuelTypeRepository fuelTypeRepository,
                         IPurchaseTypeRepository purchaseTypeRepository,
                         IColorRepository colorRepository,
                         ICarRepository carRepository,
                         IInventoryRepository inventoryRepository,
                         IInventoryStatusRepository inventoryStatusRepository,
                         IRepairRepository repairRepository,
                         IMediaRepository mediaRepository,
                         IWebHostEnvironment appEnvironment)
 {
     _mapper                    = mapper;
     _carMakeRepository         = carMakeRepository;
     _carModelRepository        = carModelRepository;
     _trimRepository            = trimRepository;
     _bodyTypeRepository        = bodyTypeRepository;
     _driveTypeRepository       = driveTypeRepository;
     _fuelTypeRepository        = fuelTypeRepository;
     _purchaseTypeRepository    = purchaseTypeRepository;
     _colorRepository           = colorRepository;
     _carRepository             = carRepository;
     _inventoryRepository       = inventoryRepository;
     _inventoryStatusRepository = inventoryStatusRepository;
     _repairRepository          = repairRepository;
     _mediaRepository           = mediaRepository;
     _appEnvironment            = appEnvironment;
 }
 public BoardController()
 {
     _boardRepository = new BoardRepository();
     _columnRepository = new ColumnRepository();
     _colorRepository = new ColorRepository();
     _taskRepository = new TaskRepository();
 }
Example #11
0
        /// <inheritdoc />
        IDictionaryRange <int, ColorPalette> IRepository <int, ColorPalette> .FindAll()
        {
            IColorRepository self = this;
            var request           = new ColorRequest
            {
                Culture = self.Culture
            };
            var response = this.serviceClient.Send <ColorCollectionDataContract>(request);

            if (response.Content == null || response.Content.Colors == null)
            {
                return(new DictionaryRange <int, ColorPalette>(0));
            }

            var values        = this.converterForColorPaletteCollection.Convert(response.Content, null);
            var colorPalettes = new DictionaryRange <int, ColorPalette>(values.Count)
            {
                SubtotalCount = values.Count,
                TotalCount    = values.Count
            };

            foreach (var colorPalette in values)
            {
                colorPalette.Culture = request.Culture;
                colorPalettes.Add(colorPalette.ColorId, colorPalette);
            }

            return(colorPalettes);
        }
Example #12
0
 public InitStaticData(IPetRepository petRepository, IOwnerRepository ownerRepository, IPetTypeRepository petTypeRepository, IColorRepository colorRepository, IUserService userService)
 {
     this.PetRepository     = petRepository;
     this.OwnerRepository   = ownerRepository;
     this.PetTypeRepository = petTypeRepository;
     this.ColorRepository   = colorRepository;
     this.UserService       = userService;
 }
Example #13
0
 public ArticuloService(IArticuloRepository articuloRepository, IColorRepository colorRepository, IModeloRepository modeloRepository, ICategoriaRepository categoriaRepository, IMarcaRepository marcaRepository)
 {
     this._articuloRepository  = articuloRepository;
     this._modeloRepository    = modeloRepository;
     this._colorRepository     = colorRepository;
     this._marcaRepository     = marcaRepository;
     this._categoriaRepository = categoriaRepository;
 }
Example #14
0
 public ColorService(IColorRepository brandRepository,
                     IUnitOfWork unitOfWork,
                     IProductQuantityRepository productQuantityRepository)
 {
     _brandRepository           = brandRepository;
     _unitOfWork                = unitOfWork;
     _productQuantityRepository = productQuantityRepository;
 }
 public ProductRepository(AppDbContext context) : base(context)
 {
     //TODO: INIT additional repositories for other entities
     _imageRepository    = new ImageRepository(context);
     _categoryRepository = new CategoryRepository(context);
     _brandRepository    = new BrandRepository(context);
     _colorRepository    = new ColorRepository(context);
     _retailerRepository = new RetailerRepository(context);
 }
Example #16
0
 public StyleService(
     IColorRepository colorRepository,
     ISizeRepository sizeRepository,
     IStyleRepository styleRepository)
 {
     _colorRepository = colorRepository;
     _sizeRepository  = sizeRepository;
     _styleRepository = styleRepository;
 }
Example #17
0
 public ColorController(
     IMetaColorProvider metaColorProvider,
     IColorRepository colorRepository,
     IColorConvertor colorConvertor)
 {
     this.colorRepository   = colorRepository;
     this.colorConvertor    = colorConvertor;
     this.metaColorProvider = metaColorProvider;
 }
Example #18
0
 public ProductDetailService(IProductDetailRepository repo, IProductRepository productRepo,
                             IColorRepository colorRepo, ISizeRepository sizeRepo, IMapper mapper)
 {
     _repo        = repo;
     _colorRepo   = colorRepo;
     _sizeRepo    = sizeRepo;
     _productRepo = productRepo;
     _mapper      = mapper;
 }
Example #19
0
 public ColorController(IColorService colorService,
                        IColorRepository colorRepository,
                        IClaseService claseService,
                        ISubrubroService subrubroService)
 {
     this.colorService    = colorService;
     this.colorRepository = colorRepository;
     this.claseService    = claseService;
     this.subrubroService = subrubroService;
 }
Example #20
0
 public ColorService(
     IColorRepository colorRepository,
     IUnitOfWork unitOfWork,
     IMapper mapper
     )
 {
     _colorRepository = colorRepository;
     _unitOfWork      = unitOfWork;
     _mapper          = mapper;
 }
Example #21
0
        public UnitOfWork(TaskItDbContext taskItDbContext, IUserRepository userRepository, IGroupRepository groupRepository, ISubscriptionRepository subscriptionRepository, IColorRepository colorRepository, IIconRepository iconRepository)
        {
            _taskItDbContext = taskItDbContext;

            UserRepository         = userRepository;
            GroupRepository        = groupRepository;
            SubscriptionRepository = subscriptionRepository;
            ColorRepository        = colorRepository;
            IconRepository         = iconRepository;
        }
 public DataInitializer(IPetRepository petRepository, IPetTypeRepository petTypeRepository, IOwnerRepository ownerRepository, IColorRepository colorRepository, IPetColorRepository petColorRepository, IUserRepository userRepository, IAuthenticationHelper authHelper)
 {
     _petRepository       = petRepository;
     _petTypeRepository   = petTypeRepository;
     _ownerRepository     = ownerRepository;
     _colorRepository     = colorRepository;
     _petColorRepository  = petColorRepository;
     _userRepository      = userRepository;
     authenticationHelper = authHelper;
 }
Example #23
0
        /// <inheritdoc />
        async Task <IDictionaryRange <int, ColorPalette> > IRepository <int, ColorPalette> .FindAllAsync(CancellationToken cancellationToken)
        {
            IColorRepository self = this;
            var request           = new ColorPaletteBulkRequest {
                Culture = self.Culture
            };
            var response = await this.serviceClient.SendAsync <ICollection <ColorPaletteDTO> >(request, cancellationToken).ConfigureAwait(false);

            return(this.bulkResponseConverter.Convert(response, null));
        }
Example #24
0
 public LotsController(ILotRepository lotRepository, INounRepository nounRepository, IGenderRepository genderRepository, ISizeRepository sizeRepository, IStateRepository stateRepository, IColorRepository colorRepository, IStructureRepository structureRepository)
 {
     _lotRepo       = lotRepository;
     _nounRepo      = nounRepository;
     _genderRepo    = genderRepository;
     _sizeRepo      = sizeRepository;
     _stateRepo     = stateRepository;
     _colorRepo     = colorRepository;
     _structureRepo = structureRepository;
 }
Example #25
0
 public BillService(IBillRepository billRepository, IBillDetailRepository billDetailRepository,
                    IColorRepository colorRepository, ISizeRepository sizeRepository, IUnitOfWork unitOfWork,
                    IProductRepository productRepository)
 {
     this._unitOfWork           = unitOfWork;
     this._billRepository       = billRepository;
     this._billDetailRepository = billDetailRepository;
     this._colorRepository      = colorRepository;
     this._sizeRepository       = sizeRepository;
     this._productRepository    = productRepository;
 }
Example #26
0
 public HomeController()
 {
     _carsRepo                  = CarRepositoryFactory.GetRepository();
     _specialsRepo              = SpecialsRepositoryFactory.GetRepository();
     _makeRepo                  = MakeRepositoryFactory.GetRepository();
     _modelRepo                 = ModelRepositoryFactory.GetRepository();
     _colorRepo                 = ColorRepositoryFactory.GetRepository();
     _bodyStyleRepository       = BodyStyleRepositoryFactory.GetRepository();
     _transmissionRepository    = TransmissionRepositoryFactory.GetRepository();
     _customerContactRepository = CustomerContactRepositoryFactory.GetRepository();
 }
Example #27
0
        public TranslationType(IColorRepository repo)
        {
            Field(x => x.Id).Description("Translation id.");
            Field(x => x.Language).Description("Language");
            Field(x => x.Name, nullable: true).Description("Translation text.");

            Field <ColorType>(
                "color",
                resolve: context => repo.GetColorAsync(context.Source.ColorId).Result
                );
        }
Example #28
0
        /// <inheritdoc />
        Task <IDictionaryRange <int, ColorPalette> > IRepository <int, ColorPalette> .FindAllAsync(CancellationToken cancellationToken)
        {
            IColorRepository self = this;
            var request           = new ColorPaletteBulkRequest {
                Culture = self.Culture
            };

            var responseTask = this.serviceClient.SendAsync <ICollection <ColorPaletteDataContract> >(request, cancellationToken);

            return(responseTask.ContinueWith <IDictionaryRange <int, ColorPalette> >(this.ConvertAsyncResponse, cancellationToken));
        }
Example #29
0
        /// <inheritdoc />
        IDictionaryRange <int, ColorPalette> IRepository <int, ColorPalette> .FindAll()
        {
            IColorRepository self = this;
            var request           = new ColorPaletteBulkRequest {
                Culture = self.Culture
            };

            var response = this.serviceClient.Send <ICollection <ColorPaletteDataContract> >(request);

            return(this.converterForBulkResponse.Convert(response, null));
        }
Example #30
0
 public BillService(IBillRepository orderRepository, IBillDetailRepository orderDetailRepository,
                    IColorRepository colorRepository, ISizeRepository sizeRepository,
                    IProductRepository productRepository, IUnitOfWork unitOfWork)
 {
     _orderRepository       = orderRepository;
     _orderDetailRepository = orderDetailRepository;
     _colorRepository       = colorRepository;
     _sizeRepository        = sizeRepository;
     _productRepository     = productRepository;
     _unitOfWork            = unitOfWork;
 }
 public StyleService(
     IColorRepository colorRepository,
     ISizeRepository sizeRepository,
     IStyleRepository styleRepository,
     IMapper mapper)
 {
     _colorRepository = colorRepository;
     _sizeRepository  = sizeRepository;
     _styleRepository = styleRepository;
     _mapper          = mapper;
 }
Example #32
0
 public ColorService(IColorRepository colorRepository)
 {
     _colorRepository = colorRepository;
 }
Example #33
0
        /// <summary>
        /// Applies required transformations to input GIS datasets for web publishing of study sources.
        /// </summary>
        /// <param name="args">Ag</param>
        /// <param name="srcDir"></param>
        /// <param name="resultDirectory"></param>
        /// <param name="colorRepo"></param>
        /// <param name="legendRepo"></param>
        /// <param name="fileSearchPattern">Locates files to process in a directory by matching * + this against filenames.</param>
        /// <param name="processedDatasets"></param>
        /// <returns></returns>
        private static Tuple<List<string>, List<string>> ProcessDatasets(string[] args, string srcDir, string resultDirectory, 
			IColorRepository colorRepo, LegendRepository legendRepo, string fileSearchPattern, List<string> processedDatasets)
        {
            if (!fileSearchPattern.Equals(".tif") && !fileSearchPattern.Equals(".shp") && !fileSearchPattern.Contains(".adf"))
            {
                throw new NotSupportedException("Only '.tif', '.shp' and 'hdr.adf' files are supported.");
            }
            DirectoryInfo di = new DirectoryInfo(srcDir);
            List<string> skipped = new List<string>();
            int filesToProcess = di.GetFiles("*" + fileSearchPattern).Count();
            Tuple<List<string>, List<string>> results;
            if (filesToProcess > 0)
            {
                DirectoryInfo resultDir = new DirectoryInfo(resultDirectory);
                if (!resultDir.Exists)
                {
                    resultDir.Create();
                }

                if (fileSearchPattern == ".tif")
                {
                    results = ProcessRasterFiles(args, colorRepo, legendRepo, fileSearchPattern, di, resultDir, processedDatasets);
                    processedDatasets = results.Item1;
                    skipped.AddRange(results.Item2);
                }
                else if (fileSearchPattern == ".shp")
                {
                    results = ProcessVectorFiles(args, colorRepo, legendRepo, fileSearchPattern, di, resultDir, processedDatasets);
                    processedDatasets = results.Item1;
                    skipped.AddRange(results.Item2);
                }
                else
                {
                    results = ProcessGridFiles(args, colorRepo, legendRepo, fileSearchPattern, di, resultDir, processedDatasets);
                    processedDatasets = results.Item1;
                    skipped.AddRange(results.Item2);
                }
            }

            //recurse through subdirectories
            foreach (DirectoryInfo subDi in di.GetDirectories())
            {
                results = ProcessDatasets(args, subDi.FullName, resultDirectory, colorRepo, legendRepo, fileSearchPattern, processedDatasets);
                processedDatasets = results.Item1;
                skipped.AddRange(results.Item2);
            }
            return new Tuple<List<string>,List<string>>(processedDatasets, skipped);
        }
Example #34
0
        /// <summary>
        /// Applies color map to input 1-band 32-bit float raster files and persists results as new .tif files with equivalent spatial 
        /// metadata as respective source files as 3-band 8-bit int raster files suitable for web tiling.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="colorRepo"></param>
        /// <param name="extension"></param>
        /// <param name="di"></param>
        /// <param name="resultDir"></param>
        private static Tuple<List<string>, List<string>> ProcessRasterFiles(string[] args, IColorRepository colorRepo, LegendRepository legend, string extension, DirectoryInfo di, DirectoryInfo resultDir, List<string> processedDatasets)
        {
            OSGeo.GDAL.Driver srcDrv = Gdal.GetDriverByName("GTiff");
            List<string> skipped = new List<string>();
            foreach (FileInfo fi in FilesInDirectoryWithExtension(extension, di))
            {
                if (colorRepo.HasColorMappingOfFile(fi.Name))
                {
                    foreach (string resultName in colorRepo.ResultFileName(fi.Name))
                    {
                        if (!processedDatasets.Contains(resultName))
                        {
                            if (colorRepo.FileLegend(fi.Name, resultName).Any(a => string.IsNullOrEmpty(a.LegendFile)))
                            {
                                ProcessRasterFile(args, colorRepo, resultDir, srcDrv, fi, resultName);
                            }

                            string plainName = resultName.Replace(".tif", "").Replace(".json", "");
                            DirectoryInfo dirOut = new DirectoryInfo(resultDir + plainName);
                            if (!dirOut.Exists)
                            {
                                dirOut.Create();
                            }
                            legend.Add(plainName, colorRepo.FileLegend(fi.Name, resultName));
                            processedDatasets.Add(resultName);
                        }
                    }
                }
                else
                {
                    skipped.Add(fi.Name);
                }
            }
            return new Tuple<List<string>, List<string>>(processedDatasets, skipped);
        }
Example #35
0
        /// <summary>
        /// Processes a raster file stored as an ESRI Grid into an 8-bit RGB .tif file based on a value-color map. Pass the function the hdr.adf file.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="colorRepo"></param>
        /// <param name="resultDir"></param>
        /// <param name="srcDrv"></param>
        /// <param name="fi">FileInfo of the hdr.adf file of the grid.</param>
        /// <param name="resultName"></param>
        private static void ProcessRasterGrid(string[] args, IColorRepository colorRepo, DirectoryInfo resultDir, OSGeo.GDAL.Driver srcDrv, FileInfo fi, string resultName)
        {
            Console.WriteLine(string.Format("Processing {0}.adf into {1}...", fi.Directory.Name, resultName));
            StringBuilder bldr = new StringBuilder();

            //read data from source raster
            Dataset src = Gdal.Open(fi.FullName, Access.GA_ReadOnly);
            Band band = src.GetRasterBand(1);
            double[] r = new double[band.XSize * band.YSize];
            byte[] red = new byte[band.XSize * band.YSize];
            byte[] green = new byte[band.XSize * band.YSize];
            byte[] blue = new byte[band.XSize * band.YSize];
            band.ReadRaster(0, 0, band.XSize, band.YSize, r, band.XSize, band.YSize, 0, 0);

            //assign values to rgb rasters to produce new raster with rgb bands matching color pattern
            for (int cell = 0; cell < r.Length; cell++)
            {
                RGBColors colors = colorRepo.ColorsOfValueInFile(fi.Directory.Name, resultName, r[cell]);
                red[cell] = (byte)colors.Red;
                green[cell] = (byte)colors.Green;
                blue[cell] = (byte)colors.Blue;
            }

            //write new output
            using (Dataset output = srcDrv.Create(resultDir + resultName, band.XSize, band.YSize, 3, DataType.GDT_Byte, null))
            {
                if (output == null)
                {
                    Console.WriteLine("Can't create " + args[0]);
                    System.Environment.Exit(-1);
                }
                //set metadata
                output.SetProjection(src.GetProjection());
                double[] geotransform = new double[0];
                src.GetGeoTransform(geotransform);
                output.SetGeoTransform(geotransform);

                //prepare data for write
                int[] colorData = new int[red.Length * 3];
                red.CopyTo(colorData, 0);
                green.CopyTo(colorData, red.Length);
                blue.CopyTo(colorData, red.Length + green.Length);

                //write data to disk
                output.WriteRaster(0, 0, band.XSize, band.YSize, colorData, band.XSize, band.YSize, 3, null, 0, 0, 0);
                output.FlushCache();
            }
        }
Example #36
0
        /// <summary>
        /// Returns MarkerType property for legend.
        /// </summary>
        /// <param name="colorRepo"></param>
        /// <param name="resultDir"></param>
        /// <param name="fi"></param>
        /// <param name="resultName"></param>
        /// <returns></returns>
        private static void ProcessVectorFile(IColorRepository colorRepo, DirectoryInfo resultDir, FileInfo fi, string resultName)
        {
            string localFileName = fi.Name;
            string localResultName = resultName;

            Console.WriteLine(string.Format("Processing {0} into {1}...", localFileName, localResultName));
            StringBuilder bldr = new StringBuilder();

            NetTopologySuite.IO.ShapefileDataReader dataReader = new NetTopologySuite.IO.ShapefileDataReader(fi.FullName, new GeometryFactory());
            NetTopologySuite.Features.FeatureCollection featureCollection = new NetTopologySuite.Features.FeatureCollection();
            List<string> csvHdr = dataReader.DbaseHeader.Fields.Select(a => a.Name).ToList();
            csvHdr.Add(appColorNamspace);
            bldr.AppendLine(string.Join(",", csvHdr)); //write csv file header
            while (dataReader.Read())
            {
                NetTopologySuite.Features.Feature feature = new NetTopologySuite.Features.Feature();
                feature.Geometry = dataReader.Geometry;

                int numFields = dataReader.DbaseHeader.NumFields + 1;
                string[] keys = new string[numFields];
                int colorValueField = -1;
                for (int i = 0; i < numFields - 1; i++)
                {
                    keys[i] = dataReader.DbaseHeader.Fields[i].Name;
                    if (keys[i].Equals(colorRepo.ColorFieldForOutput(localFileName, localResultName)))
                    {
                        colorValueField = i;
                    }
                }

                //add attributes from source attribute table
                feature.Attributes = new AttributesTable();
                List<string> csvLine = new List<string>();
                for (int i = 0; i < numFields - 1; i++)
                {
                    object val = dataReader.GetValue(i);
                    feature.Attributes.AddAttribute(keys[i], val);
                    csvLine.Add(val.ToString());
                }

                if (colorRepo.MapColorsToThisResult(localFileName, localResultName))
                {
                    //mark outline colors in a different attribute than fill colors
                    string colorNs = colorRepo.IsOutlinedNotFilled(localFileName, localResultName) ? appOutlineNamespace : appColorNamspace;
                    keys[numFields - 1] = colorNs;

                    //add additional attribute for color binding
                    string hexClr = colorRepo.SingleColorForFile(localFileName, localResultName); //only path where colorValueField, i.e. ColorMap.clrField can be unpopulated.

                    if (string.IsNullOrEmpty(hexClr) && colorValueField > -1)
                    {
                        if (colorRepo.IsCategoricalMap(localFileName, resultName))
                        {
                            //categorical color map
                             hexClr = colorRepo.ColorsOfValueInFile(localFileName, localResultName, dataReader.GetString(colorValueField)).HexColor;
                        }
                        else
                        {
                            //numerical range color map
                            hexClr = colorRepo.ColorsOfValueInFile(localFileName, localResultName, dataReader.GetDouble(colorValueField)).HexColor;
                        }
                    }

                    if (string.IsNullOrEmpty(hexClr)) // else if (string.IsNullOrEmpty(hexClr) && colorValueField < 0)
                    {
                        throw new NotSupportedException("Cannot color a file with no attributes to bind to and no single-color given.");
                    }
                    csvLine.Add(hexClr);
                    feature.Attributes.AddAttribute(colorNs, hexClr);
                }

                bldr.AppendLine(string.Join(",", csvLine));
                featureCollection.Add(feature);
            }
            GeoJsonWriter wtr = new GeoJsonWriter();
            string layerJson = wtr.Write(featureCollection);

            File.WriteAllText(resultDir.FullName + localResultName, layerJson);
            File.WriteAllText(resultDir.FullName + localResultName.Replace(".json", ".csv"), bldr.ToString());
        }
Example #37
0
 /// <summary>
 /// Changes vector shapefiles into GeoJSON-formatted JSON objects, and csv files of the data in their attribute tables
 /// </summary>
 /// <param name="args"></param>
 /// <param name="colorRepo"></param>
 /// <param name="extension"></param>
 /// <param name="di"></param>
 /// <param name="resultDir"></param>
 /// <remarks>See http://nettopologysuite.googlecode.com/svn/branches/v2.0/NetTopologySuite.Samples.Console/SimpleTests/Attributes/AttributesTest.cs </remarks>
 private static Tuple<List<string>, List<string>> ProcessVectorFiles(string[] args, IColorRepository colorRepo, LegendRepository legend, string extension, DirectoryInfo di, DirectoryInfo resultDir, List<string> processedDatasets)
 {
     List<string> skipped = new List<string>();
     foreach (FileInfo fi in FilesInDirectoryWithExtension(extension, di))
     {
         if (colorRepo.HasColorMappingOfFile(fi.Name))
         {
             foreach (string resultName in colorRepo.ResultFileName(fi.Name))
             {
                 if (!processedDatasets.Contains(resultName))
                 {
                     ProcessVectorFile(colorRepo, resultDir, fi, resultName);
                     legend.Add(resultName, colorRepo.FileLegend(fi.Name, resultName));
                     processedDatasets.Add(resultName);
                 }
             }
         }
         else
         {
             skipped.Add(fi.Name);
         }
     }
     return new Tuple<List<string>, List<string>>(processedDatasets, skipped);
 }