コード例 #1
0
        public WmsAdvancedConfigurationDialog(IEditorService service)
        {
            InitializeComponent();
            grdSpatialContexts.AutoGenerateColumns = false;
            _service = service;
            _fs = (IFeatureSource)_service.GetEditedResource();
            txtFeatureServer.Text = _fs.GetConnectionProperty("FeatureServer"); //NOXLATE
            string xml = _fs.GetConfigurationContent();
            if (!string.IsNullOrEmpty(xml))
            {
                try
                {
                    _config = (WmsConfigurationDocument)ConfigurationDocument.LoadXml(xml);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format(Strings.ErrorLoadingWmsConfig, ex.Message), Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MakeDefaultDocument();
                }
            }
            else
            {
                MakeDefaultDocument();
            }

            lstFeatureClasses.DataSource = _config.RasterOverrides;
            grdSpatialContexts.DataSource = _config.SpatialContexts;
        }
コード例 #2
0
        public WmsAdvancedConfigurationDialog(IEditorService service)
        {
            InitializeComponent();
            grdSpatialContexts.AutoGenerateColumns = false;
            _service = service;
            _fs      = (IFeatureSource)_service.GetEditedResource();
            txtFeatureServer.Text = _fs.GetConnectionProperty("FeatureServer"); //NOXLATE
            string xml = _fs.GetConfigurationContent(service.CurrentConnection);

            if (!string.IsNullOrEmpty(xml))
            {
                try
                {
                    _config = (WmsConfigurationDocument)ConfigurationDocument.LoadXml(xml);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format(Strings.ErrorLoadingWmsConfig, ex.Message), Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MakeDefaultDocument();
                }
            }
            else
            {
                MakeDefaultDocument();
            }

            lstFeatureClasses.DataSource  = _config.RasterOverrides;
            grdSpatialContexts.DataSource = _config.SpatialContexts;
        }
コード例 #3
0
        public override void Bind(IEditorService service)
        {
            try
            {
                _init = true;
                _bSupportsResample = false;
                _service           = service;
                _fs = (IFeatureSource)_service.GetEditedResource();

                var provInfo = _service.CurrentConnection.FeatureService.GetFeatureProvider("OSGeo.Gdal"); //NOXLATE
                foreach (var prop in provInfo.ConnectionProperties)
                {
                    if (prop.Name == "ResamplingMethod") //NOXLATE
                    {
                        chkResamplingMethod.Visible         =
                            cmbResamplingMethod.Visible     =
                                cmbResamplingMethod.Enabled = true;

                        cmbResamplingMethod.DataSource = new List <string>(prop.Value);
                        var method = _fs.GetConnectionProperty("ResamplingMethod"); //NOXLATE
                        if (!string.IsNullOrEmpty(method))
                        {
                            chkResamplingMethod.Checked      = true;
                            cmbResamplingMethod.SelectedItem = method;
                        }
                        else
                        {
                            cmbResamplingMethod.SelectedIndex = 0;
                            chkResamplingMethod.Checked       = false;
                        }
                        _bSupportsResample = true;
                        break;
                    }
                }

                cmbResamplingMethod.Enabled = chkResamplingMethod.Checked;

                _sing.Bind(service);
                _comp.Bind(service);
                if (!string.IsNullOrEmpty(_fs.GetConfigurationContent(service.CurrentConnection)))
                {
                    rdComposite.Checked = true;
                }
                else
                {
                    OnTypeCheckedChanged(null, null); //It is already checked by default
                }
            }
            finally
            {
                _init = false;
            }
        }
コード例 #4
0
        private void btnEditConfiguration_Click(object sender, EventArgs e)
        {
            var content = _fs.GetConfigurationContent(_edsvc.CurrentConnection);
            var dlg     = new XmlEditorDialog(_edsvc);

            dlg.OnlyValidateWellFormedness = true;
            dlg.XmlContent = content;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                content = dlg.XmlContent;
                _fs.SetConfigurationContent(_edsvc.CurrentConnection, content);
                OnResourceChanged();
            }
        }
コード例 #5
0
        private void btnEditSchema_Click(object sender, EventArgs e)
        {
            if (CheckValidConnection())
            {
                if (string.IsNullOrEmpty(_defaultSchemaName))
                {
                    var names = _service.CurrentConnection.FeatureService.GetSchemas(_fs.ResourceID);
                    if (names.Length == 1)
                    {
                        _defaultSchemaName = names[0];
                    }
                    else
                    {
                        MessageBox.Show(Strings.NoSchemasInFeatureSource);
                        return;
                    }
                }

                string xml = _fs.GetConfigurationContent(_service.CurrentConnection);
                if (!string.IsNullOrEmpty(xml))
                {
                    _doc = (OdbcConfigurationDocument)ConfigurationDocument.LoadXml(xml);
                }
                else
                {
                    if (_doc == null)
                    {
                        BuildDefaultDocument();
                    }
                }

                var diag = new TableConfigurationDialog(_service, _doc, _defaultSchemaName);
                if (diag.ShowDialog() == DialogResult.OK)
                {
                    _doc.ClearMappings();
                    foreach (var table in diag.ConfiguredTables)
                    {
                        _doc.AddOverride(table);
                    }
                    foreach (var sc in _doc.SpatialContexts)
                    {
                        sc.CoordinateSystemWkt = diag.CoordinateSystemWkt;
                    }
                    string updatedContent = _doc.ToXml();
                    _fs.SetConfigurationContent(_service.CurrentConnection, updatedContent);
                    OnResourceChanged();
                }
            }
        }
コード例 #6
0
        internal void InitDefaults()
        {
            string xml = _fs.GetConfigurationContent(_service.CurrentConnection);

            if (!string.IsNullOrEmpty(xml))
            {
                try
                {
                    _conf = (GdalConfigurationDocument)ConfigurationDocument.LoadXml(xml);
                }
                catch
                {
                    BuildDefaultDocument();
                }

                lstView.Items.Clear();
                List <string> files = new List <string>();
                foreach (var loc in _conf.RasterLocations)
                {
                    AddRasterItems(loc.Location, loc.Items);
                }
            }
        }
コード例 #7
0
ファイル: GdalProviderCtrl.cs プロジェクト: kanbang/Colt
        public override void Bind(IEditorService service)
        {
            try
            {
                _init = true;
                _bSupportsResample = false;
                _service = service;
                _fs = (IFeatureSource)_service.GetEditedResource();

                var provInfo = _service.FeatureService.GetFeatureProvider("OSGeo.Gdal"); //NOXLATE
                foreach (var prop in provInfo.ConnectionProperties)
                {
                    if (prop.Name == "ResamplingMethod") //NOXLATE
                    {
                        chkResamplingMethod.Visible =
                            cmbResamplingMethod.Visible =
                                cmbResamplingMethod.Enabled = true;

                        cmbResamplingMethod.DataSource = new List<string>(prop.Value);
                        var method = _fs.GetConnectionProperty("ResamplingMethod"); //NOXLATE
                        if (!string.IsNullOrEmpty(method))
                        {
                            chkResamplingMethod.Checked = true;
                            cmbResamplingMethod.SelectedItem = method;
                        }
                        else
                        {
                            cmbResamplingMethod.SelectedIndex = 0;
                            chkResamplingMethod.Checked = false;
                        }
                        _bSupportsResample = true;
                        break;
                    }
                }

                cmbResamplingMethod.Enabled = chkResamplingMethod.Checked;

                _sing.Bind(service);
                _comp.Bind(service);
                if (!string.IsNullOrEmpty(_fs.GetConfigurationContent()))
                    rdComposite.Checked = true;
                else
                    OnTypeCheckedChanged(null, null); //It is already checked by default
            }
            finally
            {
                _init = false;
            }
        }
コード例 #8
0
        /// <summary>
        /// Validats the specified resources for common issues associated with this
        /// resource type
        /// </summary>
        /// <param name="context"></param>
        /// <param name="resource"></param>
        /// <param name="recurse"></param>
        /// <returns></returns>
        public ValidationIssue[] Validate(ResourceValidationContext context, IResource resource, bool recurse)
        {
            Check.ArgumentNotNull(context, nameof(context));

            if (context.IsAlreadyValidated(resource.ResourceID))
            {
                return(null);
            }

            if (resource.ResourceType != ResourceTypes.FeatureSource.ToString())
            {
                return(null);
            }

            List <ValidationIssue> issues = new List <ValidationIssue>();

            IFeatureSource  feature = (IFeatureSource)resource;
            IFeatureService featSvc = this.Connection.FeatureService;

            //Feature Join Optimization check
            foreach (var ext in feature.Extension)
            {
                foreach (var rel in ext.AttributeRelate)
                {
                    if (string.IsNullOrEmpty(rel.Name))
                    {
                        issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_EmptyJoinPrefix, string.Format(Strings.FS_EmptyJoinPrefix, ext.Name)));
                    }

                    if (rel.RelatePropertyCount > 0)
                    {
                        if (rel.RelatePropertyCount == 1)
                        {
                            var srcFs = feature;
                            var dstFs = (IFeatureSource)context.GetResource(rel.ResourceId);

                            var leftProvider  = srcFs.Provider.ToUpper();
                            var rightProvider = dstFs.Provider.ToUpper();

                            //FDO Join optimization check
                            if (leftProvider.Contains("OSGEO.SQLITE") && rightProvider.Contains("OSGEO.SQLITE") && srcFs.ResourceID == rel.ResourceId) //NOXLATE
                            {
                                continue;
                            }

                            //FDO Join optimization check
                            if (leftProvider.Contains("OSGEO.SQLSERVERSPATIAL") && rightProvider.Contains("OSGEO.SQLSERVERSPATIAL") && srcFs.ResourceID == rel.ResourceId) //NOXLATE
                            {
                                continue;
                            }

                            //TODO: Fix the capabilities response. Because it's not telling us enough information!
                            //Anyways, these are the providers known to provide sorted query results.
                            bool bLeftSortable = leftProvider.Contains("OSGEO.SDF") ||               //NOXLATE
                                                 leftProvider.Contains("OSGEO.SHP") ||               //NOXLATE
                                                 leftProvider.Contains("OSGEO.SQLITE") ||            //NOXLATE
                                                 leftProvider.Contains("OSGEO.ODBC") ||              //NOXLATE
                                                 leftProvider.Contains("OSGEO.SQLSERVERSPATIAL") ||  //NOXLATE
                                                 leftProvider.Contains("OSGEO.MYSQL") ||             //NOXLATE
                                                 leftProvider.Contains("OSGEO.POSTGRESQL");          //NOXLATE

                            bool bRightSortable = leftProvider.Contains("OSGEO.SDF") ||              //NOXLATE
                                                  leftProvider.Contains("OSGEO.SHP") ||              //NOXLATE
                                                  leftProvider.Contains("OSGEO.SQLITE") ||           //NOXLATE
                                                  leftProvider.Contains("OSGEO.ODBC") ||             //NOXLATE
                                                  leftProvider.Contains("OSGEO.SQLSERVERSPATIAL") || //NOXLATE
                                                  leftProvider.Contains("OSGEO.MYSQL") ||            //NOXLATE
                                                  leftProvider.Contains("OSGEO.POSTGRESQL");         //NOXLATE

                            if (!bLeftSortable || !bRightSortable)
                            {
                                issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_Potential_Bad_Join_Performance, string.Format(Strings.FS_PotentialBadJoinPerformance, ext.Name, bLeftSortable, bRightSortable)));
                            }
                        }
                        else
                        {
                            issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_Potential_Bad_Join_Performance, string.Format(Strings.FS_PotentialBadJoinPerformance2, ext.Name)));
                        }
                    }
                }
            }

            //Plaintext credential check
            string providerNameUpper = feature.Provider.ToUpper();
            string fsXml             = feature.Serialize().ToUpper();

            //You'll get warnings either way
            if (providerNameUpper == "OSGEO.SQLSERVERSPATIAL" || //NOXLATE
                providerNameUpper == "OSGEO.MYSQL" ||            //NOXLATE
                providerNameUpper == "OSGEO.POSTGRESQL" ||       //NOXLATE
                providerNameUpper == "OSGEO.ODBC" ||             //NOXLATE
                providerNameUpper == "OSGEO.ARCSDE" ||           //NOXLATE
                providerNameUpper == "OSGEO.WFS" ||              //NOXLATE
                providerNameUpper == "OSGEO.WMS" ||              //NOXLATE
                providerNameUpper == "KING.ORACLE" ||            //NOXLATE
                providerNameUpper == "AUTODESK.ORACLE")          //NOXLATE
            {
                //Fortunately, all the above providers are universal in the naming choice of credential connection parameters
                if ((fsXml.Contains("<NAME>USERNAME</NAME>") && !fsXml.Contains(StringConstants.MgUsernamePlaceholder)) || (fsXml.Contains("<NAME>PASSWORD</NAME>") && !fsXml.Contains(StringConstants.MgPasswordPlaceholder))) //NOXLATE
                {
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_Plaintext_Credentials, Strings.FS_PlaintextCredentials));
                }
                else
                {
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_Cannot_Package_Secured_Credentials, Strings.FS_CannotPackageSecuredCredentials));
                }

                //Has the placeholder token(s)
                if (fsXml.Contains(StringConstants.MgUsernamePlaceholder) || fsXml.Contains(StringConstants.MgPasswordPlaceholder))
                {
                    //Find the MG_USER_CREDENTIALS resource data item
                    bool bFound  = false;
                    var  resData = this.Connection.ResourceService.EnumerateResourceData(feature.ResourceID);
                    foreach (var data in resData.ResourceData)
                    {
                        if (data.Name == StringConstants.MgUserCredentialsResourceData)
                        {
                            bFound = true;
                        }
                    }

                    if (!bFound)
                    {
                        issues.Add(new ValidationIssue(feature, ValidationStatus.Error, ValidationStatusCode.Error_FeatureSource_SecuredCredentialTokensWithoutSecuredCredentialData, Strings.FS_SecuredCredentialTokensWithoutSecuredCredentialData));
                    }
                }
            }

            //Note: Must be saved!
            string s = featSvc.TestConnection(feature.ResourceID);

            if (s.Trim().ToUpper() != true.ToString().ToUpper())
            {
                issues.Add(new ValidationIssue(feature, ValidationStatus.Error, ValidationStatusCode.Error_FeatureSource_ConnectionTestFailed, string.Format(Strings.FS_ConnectionTestFailed, s)));
                return(issues.ToArray());
            }

            try
            {
                System.Globalization.CultureInfo ci  = System.Globalization.CultureInfo.InvariantCulture;
                FdoSpatialContextList            lst = context.GetSpatialContexts(feature.ResourceID);
                if (lst == null || lst.SpatialContext == null || lst.SpatialContext.Count == 0)
                {
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_NoSpatialContext, Strings.FS_NoSpatialContextWarning));
                }
                else
                {
                    foreach (FdoSpatialContextListSpatialContext c in lst.SpatialContext)
                    {
                        if (c.Extent == null || c.Extent.LowerLeftCoordinate == null || c.Extent.UpperRightCoordinate == null)
                        {
                            issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_EmptySpatialContext, Strings.FS_EmptySpatialContextWarning));
                        }
                        else if (double.Parse(c.Extent.LowerLeftCoordinate.X, ci) <= -1000000 && double.Parse(c.Extent.LowerLeftCoordinate.Y, ci) <= -1000000 && double.Parse(c.Extent.UpperRightCoordinate.X, ci) >= 1000000 && double.Parse(c.Extent.UpperRightCoordinate.Y, ci) >= 1000000)
                        {
                            issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_DefaultSpatialContext, Strings.FS_DefaultSpatialContextWarning));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                issues.Add(new ValidationIssue(feature, ValidationStatus.Error, ValidationStatusCode.Error_FeatureSource_SpatialContextReadError, string.Format(Strings.FS_SpatialContextReadError, msg)));
            }

            List <string> classes = new List <string>();

            try
            {
                var schemaNames = featSvc.GetSchemas(feature.ResourceID);
                if (schemaNames.Length == 0)
                {
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_NoSchemasFound, Strings.FS_SchemasMissingWarning));
                }
            }
            catch (Exception ex)
            {
                var wex = ex as System.Net.WebException;
                if (wex != null) //Most likely timeout due to really large schema
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Warning, ValidationStatusCode.Warning_FeatureSource_Validation_Timeout, string.Format(Strings.FS_ValidationTimeout, msg)));
                }
                else
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    issues.Add(new ValidationIssue(feature, ValidationStatus.Error, ValidationStatusCode.Error_FeatureSource_SchemaReadError, string.Format(Strings.FS_SchemaReadError, msg)));
                }
            }

            string configDocXml = feature.GetConfigurationContent(Connection);

            if (!string.IsNullOrEmpty(configDocXml))
            {
                var doc     = ConfigurationDocument.LoadXml(configDocXml);
                var odbcDoc = doc as OdbcConfigurationDocument;
                if (odbcDoc != null)
                {
                    issues.AddRange(ValidateOdbcDoc(feature, odbcDoc));
                }
            }

            context.MarkValidated(resource.ResourceID);

            return(issues.ToArray());
        }