public PersistentCacheProviderBase(string dataStoreSetId, object dataSourceReader, IEnumerable <PropertyInfo> cachedProperties)
        {
            if (dataSourceReader == null)
            {
                throw new ArgumentNullException(nameof(dataSourceReader));
            }

            _dataStoreSetId = dataStoreSetId;

            _dataSourceEnumerator = (dataSourceReader as IDataSourceEnumerator <T>)
                                    ?? throw new InvalidOperationException("DataAccessObject must implement IDataSourceEnumerator in order to use persistent cache");

            ValidateCacheProperties(cachedProperties);
            _cachedProperties = cachedProperties;

            _keyGetter = GeneralHelper.GetIdentiferGetter <T>(out var notused);

            _dataSourceReader     = dataSourceReader as IDataSourceReader <T>;
            _dataSourceBulkReader = dataSourceReader as IDataSourceBulkReader <T>;
            _dataSourceWithCache  = dataSourceReader as IDataSourceCacheProvider <T>;


            if (_dataSourceBulkReader == null && _dataSourceReader == null)
            {
                throw new InvalidOperationException($"Data Access Object for type {typeof(T)} must implement {nameof(IDataSourceReader<T>)} or {nameof(IDataSourceBulkReader<T>)}");
            }
        }
예제 #2
0
            public object FilterData(IDataSourceReader dataSrc)
            {
                if (dataSrc is GDALReader)
                {
                    // get as many bands as available and average values
                    GDALReader reader   = (GDALReader)dataSrc;
                    int[]      avrData  = new int[reader.Info.Resolution.Width * reader.Info.Resolution.Height];
                    byte[]     tempData = new byte[reader.Info.Resolution.Width * reader.Info.Resolution.Height];
                    int        numBands = reader.Info.Bands.Length;
                    for (int band = 0; band < numBands; band++)
                    {
                        Band bandData = reader.GetRasterBand(band + 1);

                        bandData.ReadRaster(0, 0, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                                            tempData, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                                            0, 0);

                        // add to averages
                        for (int i = 0; i < tempData.Length; i++)
                        {
                            avrData[i] += tempData[i];
                        }
                    }

                    // average data into final byte[]
                    for (int i = 0; i < avrData.Length; i++)
                    {
                        tempData[i] = (byte)(avrData[i] / numBands);
                    }
                    return(tempData);
                }
                return(null);
            }
            public object FilterData(IDataSourceReader dataSrc)
            {
                if (dataSrc is GDALReader)
                {
                    // get as many bands as available and average values
                    GDALReader reader = (GDALReader)dataSrc;
                    int[] avrData = new int[reader.Info.Resolution.Width * reader.Info.Resolution.Height];
                    byte[] tempData = new byte[reader.Info.Resolution.Width * reader.Info.Resolution.Height];
                    int numBands = reader.Info.Bands.Length;
                    for (int band = 0; band < numBands; band++)
                    {
                        Band bandData = reader.GetRasterBand(band + 1);
                        
                        bandData.ReadRaster(0, 0, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                                            tempData, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                                            0, 0);

                        // add to averages
                        for (int i = 0; i < tempData.Length; i++)
                        {
                            avrData[i] += tempData[i];
                        }
                    }

                    // average data into final byte[]
                    for (int i = 0; i < avrData.Length; i++)
                    {
                        tempData[i] = (byte)(avrData[i] / numBands);
                    }
                    return tempData;
                }
                return null;
            }
예제 #4
0
        private void ReadDataSource(string file)
        {
            // look for file-type
            foreach (FileType type in fileTypes)
            {
                if (type.IsFileType(file))
                {
                    fType = type;
                    break;
                }
            }
            if (fType == null)
            {
                throw new Exception(String.Format("Unable to match file type for {0}", fType));
            }

            // load data-source
            reader = new GDALReader();
            reader.OpenFile(file, fType);

            // build source layers for UI
            dsInfo = reader.Info;
            DataSourceControl.DataSourcePreviewInfo info = new DataSourceControl.DataSourcePreviewInfo();
            info.Dimensions = dsInfo.Resolution;
            info.Type       = fType.Name;
            info.DataType   = dsInfo.BppType;
            info.Groups     = new DataSourceControl.DataSourceImageGroup[2];
            DataSourceControl.DataSourcePreviewImage[] images = new DataSourceControl.DataSourcePreviewImage[dsInfo.Bands.Length];
            for (int i = 0; i < dsInfo.Bands.Length; i++)
            {
                images[i] = new DataSourceControl.DataSourcePreviewImage(dsInfo.Bands[i].Image,
                                                                         dsInfo.Bands[i].Name,
                                                                         new Size(64, 64));
            }
            DataSourceControl.DataSourcePreviewImage[] buildInImages = new DataSourceControl.DataSourcePreviewImage[2];
            buildInImages[0] = new DataSourceControl.DataSourcePreviewImage(null, "NormalMap", new Size(64, 64));
            buildInImages[1] = new DataSourceControl.DataSourcePreviewImage(/*Image.FromFile(file)*/ null, "TextureMap", new Size(64, 64));

            info.Groups[1] = new DataSourceControl.DataSourceImageGroup(images);
            info.Groups[0] = new DataSourceControl.DataSourceImageGroup(buildInImages);
            dataSourceControl1.DataSource = info;

            // load profiles for data-type
            List <DataProfile> profiles = new List <DataProfile>();

            foreach (DataProfile profile in dataProfiles)
            {
                if (profile.MatchProfile(fType))
                {
                    profiles.Add(profile);
                }
            }
            compatibleProfiles = profiles.ToArray();

            dataProfileControl1.Profiles = compatibleProfiles;
        }
예제 #5
0
        private void ReadDataSource(string file)
        {
            // look for file-type
            foreach (FileType type in fileTypes)
            {
                if (type.IsFileType(file))
                {
                    fType = type;
                    break;
                }
            }
            if (fType == null)
                throw new Exception(String.Format("Unable to match file type for {0}", fType));
            
            // load data-source
            reader = new GDALReader();
            reader.OpenFile(file, fType);
            
            // build source layers for UI
            dsInfo = reader.Info;
            DataSourceControl.DataSourcePreviewInfo info = new DataSourceControl.DataSourcePreviewInfo();
            info.Dimensions = dsInfo.Resolution;
            info.Type = fType.Name;
            info.DataType = dsInfo.BppType;
            info.Groups = new DataSourceControl.DataSourceImageGroup[2];
            DataSourceControl.DataSourcePreviewImage[] images = new DataSourceControl.DataSourcePreviewImage[dsInfo.Bands.Length];
            for (int i = 0; i < dsInfo.Bands.Length; i++)
            {
                images[i] = new DataSourceControl.DataSourcePreviewImage(dsInfo.Bands[i].Image,
                                                                         dsInfo.Bands[i].Name,
                                                                         new Size(64, 64));
            }
            DataSourceControl.DataSourcePreviewImage[] buildInImages = new DataSourceControl.DataSourcePreviewImage[2];
            buildInImages[0] = new DataSourceControl.DataSourcePreviewImage(null, "NormalMap", new Size(64, 64));
            buildInImages[1] = new DataSourceControl.DataSourcePreviewImage(/*Image.FromFile(file)*/null, "TextureMap", new Size(64, 64));

            info.Groups[1] = new DataSourceControl.DataSourceImageGroup(images);
            info.Groups[0] = new DataSourceControl.DataSourceImageGroup(buildInImages);
            dataSourceControl1.DataSource = info;
            
            // load profiles for data-type
            List<DataProfile> profiles = new List<DataProfile>();
            foreach (DataProfile profile in dataProfiles)
            {
                if (profile.MatchProfile(fType))
                    profiles.Add(profile);
            }
            compatibleProfiles = profiles.ToArray();

            dataProfileControl1.Profiles = compatibleProfiles;
        }
예제 #6
0
            public object FilterData(IDataSourceReader dataSrc)
            {
                if (dataSrc is GDALReader)
                {
                    GDALReader reader  = (GDALReader)dataSrc;
                    Band       redBand = reader.GetRasterBand(1);

                    byte[] data = new byte[reader.Info.Resolution.Width * reader.Info.Resolution.Height];
                    redBand.ReadRaster(0, 0, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                                       data, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                                       0, 0);
                    return(data);
                }
                return(null);
            }
 public object FilterData(IDataSourceReader dataSrc)
 {
     if (dataSrc is GDALReader)
     {
         GDALReader reader = (GDALReader)dataSrc;
         Band redBand = reader.GetRasterBand(1);
         
         byte[] data = new byte[reader.Info.Resolution.Width * reader.Info.Resolution.Height];
         redBand.ReadRaster(0, 0, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                            data, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                            0, 0);
         return data;
     }
     return null;
 }
예제 #8
0
        public object FilterData(IDataSourceReader dataSrc)
        {
            if (dataSrc is GDALReader)
            {
                GDALReader reader = (GDALReader)dataSrc;
                Band       band   = reader.GetRasterBand(1);

                float[] data = new float[reader.Info.Resolution.Width * reader.Info.Resolution.Height];
                band.ReadRaster(0, 0, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                                data, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                                0, 0);
                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] < 0 || data[i] > 32000)
                    {
                        data[i] = 0;
                    }
                }
                return(data);
            }
            return(null);
        }
        public object FilterData(IDataSourceReader dataSrc)
        {
            if (dataSrc is GDALReader)
            {
                GDALReader reader = (GDALReader)dataSrc;
                Band band = reader.GetRasterBand(1);

                float[] data = new float[reader.Info.Resolution.Width * reader.Info.Resolution.Height];
                band.ReadRaster(0, 0, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                                data, reader.Info.Resolution.Width, reader.Info.Resolution.Height,
                                0, 0);
                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] < 0 || data[i] > 32000)
                    {
                        data[i] = 0;
                    }
                }
                return data;
            }
            return null;
        }
        public override void Execute(List <DataCompareItem> addItems, List <DataCompareItem> updateItems, List <DataCompareItem> deleteItems, IDataSourceReader reader, IDataSynchronizationStatus status)
        {
            DataSourceReader = reader as WinSCPDatasourceReader;

            if (DataSourceReader != null)
            {
                using (Session = DataSourceReader.GetSession())
                {
                    Mapping = new DataSchemaMapping(SchemaMap, DataCompare);

                    //Process the Changed Items
                    if (addItems != null && status.ContinueProcessing)
                    {
                        AddItems(addItems, status);
                    }
                    if (updateItems != null && status.ContinueProcessing)
                    {
                        UpdateItems(updateItems, status);
                    }
                    if (deleteItems != null && status.ContinueProcessing)
                    {
                        DeleteItems(deleteItems, status);
                    }
                }
            }
        }
예제 #11
0
        public void LoadVisualization(DataProfile dataProfile, DataProfile.SubProfile subProfile,
                                      IDataSourceReader dataSrcReader, DataSourceInfo dataSrcInfo)
        {
            renderFrame = true;
            renderingThread.Start();

            controlStatus = ControlStatus.Loading;
            rContext.LoadingLayer.SetProgress(0);
            rContext.LoadingLayer.SetText("Loading... DEM Geometry");
            rContext.LoadingLayer.Visible = true;
            Render();

            // load data from dlg into database
            database = new RasterDatabase.RasterDatabase();
            object filteredData = subProfile.Filter.FilterData(dataSrcReader);

            if (filteredData is byte[])
            {
                DataLayer dataLayer = new DataLayer("DEM", 8, "byte");
                dataLayer.AddArea(new ByteArea(new Rectangle(new Point(), dataSrcReader.Info.Resolution),
                                               new RectangleF(0, 0, 1, 1),
                                               (byte[])filteredData, dataSrcReader.Info.Resolution));
                database.AddLayer(dataLayer);
            }
            else if (filteredData is float[])
            {
                DataLayer dataLayer = new DataLayer("DEM", 32, "float");
                dataLayer.AddArea(new FloatArea(new Rectangle(new Point(), dataSrcReader.Info.Resolution),
                                                new RectangleF(0, 0, 1, 1),
                                                (float[])filteredData, dataSrcReader.Info.Resolution));
                database.AddLayer(dataLayer);
            }

            // load data source(s)
            DataSourceItem item = new DataSourceItem(dataSrcInfo.BppType,
                                                     (Bitmap)PreviewRasterizer.DrawRotatedBandPreview(dataSrcInfo.Bands,
                                                                                                      64, dataSrcInfo));

            heightDataSrcs.Add(item);

            // load diffuse sources
            // grey-scale for height
            GreyScaleDEMSampler srcImgSampler = new GreyScaleDEMSampler();
            Bitmap srcImg = srcImgSampler.GenerateBitmap(new Size(64, 64), database.Layers[0].Areas[0]);

            item            = new DataSourceItem("Height", srcImg);
            item.DEMSampler = srcImgSampler;
            //(Bitmap)PreviewRasterizer.DrawRotatedBandPreview(new DataSourceInfo.DataBandInfo[] { new DataSourceInfo.DataBandInfo("Source", srcImg) },
            //64, null));
            diffuseDataSrcs.Add(item);

            // load colour image if possible as other source (i.e the original if an RGB img)
            if (dataSrcReader.Info.SupportsRGB())
            {
                item = new DataSourceItem("SourceRGB",
                                          SourceDataDiffuseSampler.SampleRGBDiffuseMap((GDALReader)dataSrcReader,
                                                                                       new Size(64, 64)));
                diffuseDataSrcs.Add(item);
                reader = (GDALReader)dataSrcReader;
            }

            // height band range
            HeightBandRange hbr = new HeightBandRange();

            hbr.AddBand(0, Color.DarkGreen);
            hbr.AddBand(0.25f, Color.Blue);
            hbr.AddBand(0.4f, Color.DarkGreen);
            hbr.AddBand(0.5f, Color.Green);
            hbr.AddBand(0.8f, Color.Gray);
            hbr.AddBand(1, Color.White);
            HeightBandDEMSampler hBandSampler = new HeightBandDEMSampler(hbr);

            item = new DataSourceItem("HeightBands",
                                      hBandSampler.GenerateBitmap(new Size(64, 64), database.Layers[0].Areas[0]));
            item.DEMSampler = hBandSampler;
            diffuseDataSrcs.Add(item);

            // load database into visualization
            dem = new DigitalElevationMap(database.Area.Size, database, rContext.DevIf, (GDALReader)dataSrcReader/*,
                                                                                                                  * hBandSampler.GenerateBitmap(new Size(512, 512),
                                                                                                                  * database.Layers[0].Areas[0])*/
                                          );
            rContext.SetDEM(dem);

            // setup geometry layers
            geometryLayers.Add(new GeometryVisLayer("Diffuse", item.Thumbnail, true));
            geometryLayers.Add(new GeometryVisLayer("Overlay Grid", null, true));

            rContext.DevIf.LocalSettings["GeometryVisLayer.Diffuse"] = geometryLayers[0];
            rContext.DevIf.LocalSettings["GeometryVisLayer.Overlay"] = geometryLayers[1];

            // now load default texture
            SetDiffuseSource(0);

            rContext.LoadingLayer.SetProgress(100);
            Render();
            Thread.Sleep(500);

            rContext.LoadingLayer.Visible = false;
            controlStatus = ControlStatus.Idle;
            Render();
        }
예제 #12
0
        public void LoadVisualization(DataProfile dataProfile, DataProfile.SubProfile subProfile,
                                      IDataSourceReader dataSrcReader, DataSourceInfo dataSrcInfo)
        {
            renderFrame = true;
            renderingThread.Start();

            controlStatus = ControlStatus.Loading;
            rContext.LoadingLayer.SetProgress(0);
            rContext.LoadingLayer.SetText("Loading... DEM Geometry");
            rContext.LoadingLayer.Visible = true;
            Render();

            // load data from dlg into database
            database = new RasterDatabase.RasterDatabase();
            object filteredData = subProfile.Filter.FilterData(dataSrcReader);
            if (filteredData is byte[])
            {
                DataLayer dataLayer = new DataLayer("DEM", 8, "byte");
                dataLayer.AddArea(new ByteArea(new Rectangle(new Point(), dataSrcReader.Info.Resolution),
                                  new RectangleF(0, 0, 1, 1),
                                  (byte[])filteredData, dataSrcReader.Info.Resolution));
                database.AddLayer(dataLayer);
            }
            else if (filteredData is float[])
            {
                DataLayer dataLayer = new DataLayer("DEM", 32, "float");
                dataLayer.AddArea(new FloatArea(new Rectangle(new Point(), dataSrcReader.Info.Resolution),
                                  new RectangleF(0, 0, 1, 1),
                                  (float[])filteredData, dataSrcReader.Info.Resolution));
                database.AddLayer(dataLayer);
            }

            // load data source(s)
            DataSourceItem item = new DataSourceItem(dataSrcInfo.BppType,
                                                     (Bitmap)PreviewRasterizer.DrawRotatedBandPreview(dataSrcInfo.Bands,
                                                                                                      64, dataSrcInfo));
            heightDataSrcs.Add(item);

            // load diffuse sources
            // grey-scale for height
            GreyScaleDEMSampler srcImgSampler = new GreyScaleDEMSampler();
            Bitmap srcImg = srcImgSampler.GenerateBitmap(new Size(64, 64), database.Layers[0].Areas[0]);
            item = new DataSourceItem("Height", srcImg);
            item.DEMSampler = srcImgSampler;
                                      //(Bitmap)PreviewRasterizer.DrawRotatedBandPreview(new DataSourceInfo.DataBandInfo[] { new DataSourceInfo.DataBandInfo("Source", srcImg) },
                                                                                       //64, null));
            diffuseDataSrcs.Add(item);

            // load colour image if possible as other source (i.e the original if an RGB img)
            if (dataSrcReader.Info.SupportsRGB())
            {
                item = new DataSourceItem("SourceRGB",
                                          SourceDataDiffuseSampler.SampleRGBDiffuseMap((GDALReader)dataSrcReader,
                                                                                       new Size(64, 64)));
                diffuseDataSrcs.Add(item);
                reader = (GDALReader)dataSrcReader;
            }

            // height band range
            HeightBandRange hbr = new HeightBandRange();
            hbr.AddBand(0, Color.DarkGreen);
            hbr.AddBand(0.25f, Color.Blue);
            hbr.AddBand(0.4f, Color.DarkGreen);
            hbr.AddBand(0.5f, Color.Green);
            hbr.AddBand(0.8f, Color.Gray);
            hbr.AddBand(1, Color.White);
            HeightBandDEMSampler hBandSampler = new HeightBandDEMSampler(hbr);
            item = new DataSourceItem("HeightBands",
                                      hBandSampler.GenerateBitmap(new Size(64, 64), database.Layers[0].Areas[0]));
            item.DEMSampler = hBandSampler;
            diffuseDataSrcs.Add(item);

            // load database into visualization
            dem = new DigitalElevationMap(database.Area.Size, database, rContext.DevIf, (GDALReader)dataSrcReader/*,
                                          hBandSampler.GenerateBitmap(new Size(512, 512),
                                          database.Layers[0].Areas[0])*/
                                                                        );
            rContext.SetDEM(dem);

            // setup geometry layers
            geometryLayers.Add(new GeometryVisLayer("Diffuse", item.Thumbnail, true));
            geometryLayers.Add(new GeometryVisLayer("Overlay Grid", null, true));

            rContext.DevIf.LocalSettings["GeometryVisLayer.Diffuse"] = geometryLayers[0];
            rContext.DevIf.LocalSettings["GeometryVisLayer.Overlay"] = geometryLayers[1];

            // now load default texture
            SetDiffuseSource(0);

            rContext.LoadingLayer.SetProgress(100);
            Render();
            Thread.Sleep(500);

            rContext.LoadingLayer.Visible = false;
            controlStatus = ControlStatus.Idle;
            Render();
        }
        public override void Execute(List <DataCompareItem> addItems, List <DataCompareItem> updateItems, List <DataCompareItem> deleteItems, IDataSourceReader reader, IDataSynchronizationStatus status)
        {
            DataSourceReader = reader as PipedriveDatasourceReader;

            if (DataSourceReader != null)
            {
                Mapping = new DataSchemaMapping(SchemaMap, DataCompare);

                WebRequestHelper = DataSourceReader.GetWebRequestHelper();
                DatasourceInfo   = DataSourceReader.GetDatasourceInfo();
                DataSchema       = DatasourceInfo.GetPipedriveDataSchema(WebRequestHelper);

                //Process the Changed Items
                if (addItems != null && status.ContinueProcessing)
                {
                    AddItems(addItems, status);
                }
                if (updateItems != null && status.ContinueProcessing)
                {
                    UpdateItems(updateItems, status);
                }
                if (deleteItems != null && status.ContinueProcessing)
                {
                    DeleteItems(deleteItems, status);
                }
            }
        }
예제 #14
0
        async Task ImportSingleRecordAsync(
            ImportingJob importingTask, ImportingTaskContext context, IRecordFinder recordFinder, IRecordImporter recordImporter, IDataSourceReader reader)
        {
            var propValues = new Dictionary <string, object>(importingTask.Descriptor.ImportEntity.Fields.Count);

            foreach (var fieldMapping in importingTask.Descriptor.ImportEntity.Fields)
            {
                var propertyValueExpression = reader.GetField(fieldMapping.Selector).ToString();
                var metaProperty            = importingTask.Entity.Fields[fieldMapping.Field];
                if (metaProperty.Type.TryParse(metaProperty, propertyValueExpression, out var propertyValue, fieldMapping.Format))
                {
                    propValues.Add(metaProperty.Name, propertyValue);
                }
 public MultiSelectListFieldEditorViewComponent(IDataSourceFactory dataSourceFactory, IDataSourceReader <KeyValuePair <string, string> > dataSourceReader)
 {
     this.dataSourceFactory = dataSourceFactory;
     this.dataSourceReader  = dataSourceReader;
 }
        public override void Execute(List<DataCompareItem> addItems, List<DataCompareItem> updateItems, List<DataCompareItem> deleteItems, IDataSourceReader reader, IDataSynchronizationStatus status)
        {
            DataSourceReader = reader as MailChimpListDatasourceReader;

            if (DataSourceReader != null)
            {
                Mapping = new DataSchemaMapping(SchemaMap, DataCompare);

                //Process the Changed Items
                if (addItems != null && status.ContinueProcessing) AddItems(addItems, status);
                if (updateItems != null && status.ContinueProcessing) UpdateItems(updateItems, status);
                if (deleteItems != null && status.ContinueProcessing) DeleteItems(deleteItems, status);

            }
        }        
        public override void Execute(List <DataCompareItem> addItems, List <DataCompareItem> updateItems, List <DataCompareItem> deleteItems, IDataSourceReader reader, IDataSynchronizationStatus status)
        {
            DataSourceReader = reader as MailChimpMemberDatasourceReader;

            if (DataSourceReader != null)
            {
                Mapping = new DataSchemaMapping(SchemaMap, DataCompare);

                MailChimpDataSchema = MailChimp.MailChimpDataSchema.MailChimpMemberSchema();
                WebRequestHelper    = DataSourceReader.GetWebRequestHelper();
                ListServiceUrl      = DataSourceReader.GetUriHelper().ListServiceUrl;

                //Process the Changed Items
                if (addItems != null && status.ContinueProcessing)
                {
                    AddItems(addItems, status);
                }
                if (updateItems != null && status.ContinueProcessing)
                {
                    UpdateItems(updateItems, status);
                }
                if (deleteItems != null && status.ContinueProcessing)
                {
                    DeleteItems(deleteItems, status);
                }
            }
        }