private static IFdoSpatialContext FindSpatialContext(FdoSpatialContextList spatialContexts, string scName)
 {
     foreach (IFdoSpatialContext sc in spatialContexts.SpatialContext)
     {
         if (sc.Name == scName)
         {
             return(sc);
         }
     }
     return(null);
 }
Beispiel #2
0
        /// <summary>
        /// Performs base resource validation
        /// </summary>
        /// <param name="context"></param>
        /// <param name="resource"></param>
        /// <param name="recurse"></param>
        /// <returns></returns>
        protected ValidationIssue[] ValidateBase(ResourceValidationContext context, IResource resource, bool recurse)
        {
            Check.ArgumentNotNull(context, nameof(context));

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

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

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

            IMapDefinition mdef = resource as IMapDefinition;

            if (string.IsNullOrEmpty(mdef.CoordinateSystem))
            {
                issues.Add(new ValidationIssue(mdef, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_MissingCoordinateSystem, Strings.MDF_NoCoordinateSystem));
            }

            foreach (IMapLayerGroup g in mdef.MapLayerGroup)
            {
                if (g.ShowInLegend && (g.LegendLabel == null || g.LegendLabel.Trim().Length == 0))
                {
                    issues.Add(new ValidationIssue(mdef, ValidationStatus.Information, ValidationStatusCode.Info_MapDefinition_GroupMissingLabelInformation, string.Format(Strings.MDF_GroupMissingLabelInformation, g.Name)));
                }
                else if (g.ShowInLegend && g.LegendLabel.Trim().ToLower() == "layer group") //NOXLATE
                {
                    issues.Add(new ValidationIssue(mdef, ValidationStatus.Information, ValidationStatusCode.Info_MapDefinition_GroupHasDefaultLabel, string.Format(Strings.MDF_GroupHasDefaultLabelInformation, g.Name)));
                }

                if (!string.IsNullOrEmpty(g.Group))
                {
                    var grp = mdef.GetGroupByName(g.Group);
                    if (grp == null)
                    {
                        issues.Add(new ValidationIssue(mdef, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_GroupWithNonExistentGroup, string.Format(Strings.MDF_GroupWithNonExistentGroup, g.Name, g.Group)));
                    }
                }
            }

            List <IBaseMapLayer> layers = new List <IBaseMapLayer>();

            foreach (IBaseMapLayer l in mdef.MapLayer)
            {
                layers.Add(l);
            }

            if (mdef.BaseMap != null && mdef.BaseMap.HasGroups())
            {
                if (mdef.BaseMap.ScaleCount == 0)
                {
                    issues.Add(new ValidationIssue(mdef, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_NoFiniteDisplayScales, Strings.MDF_NoFiniteDisplayScalesSpecified));
                }

                foreach (IBaseMapGroup g in mdef.BaseMap.BaseMapLayerGroups)
                {
                    foreach (IBaseMapLayer l in g.BaseMapLayer)
                    {
                        layers.Add(l);
                    }
                }
            }
            Dictionary <string, IBaseMapLayer> nameCounter = new Dictionary <string, IBaseMapLayer>();

            foreach (IBaseMapLayer l in layers)
            {
                if (nameCounter.ContainsKey(l.Name))
                {
                    issues.Add(new ValidationIssue(mdef, ValidationStatus.Warning, ValidationStatusCode.Error_MapDefinition_DuplicateLayerName, string.Format(Strings.MDF_LayerNameDuplicateWarning, l.Name, l.ResourceId, nameCounter[l.Name].ResourceId)));
                }
                else
                {
                    nameCounter.Add(l.Name, l);
                }

                var ml = l as IMapLayer;
                if (ml != null && !string.IsNullOrEmpty(ml.Group))
                {
                    var grp = mdef.GetGroupByName(ml.Group);
                    if (grp == null)
                    {
                        issues.Add(new ValidationIssue(mdef, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_LayerWithNonExistentGroup, string.Format(Strings.MDF_LayerWithNonExistentGroup, ml.Name, ml.Group)));
                    }
                }

                if (l.ShowInLegend && (string.IsNullOrEmpty(l.LegendLabel) || l.LegendLabel.Trim().Length == 0))
                {
                    issues.Add(new ValidationIssue(mdef, ValidationStatus.Information, ValidationStatusCode.Warning_MapDefinition_LayerMissingLegendLabel, string.Format(Strings.MDF_LayerMissingLabelInformation, l.Name)));
                }

                var mapEnv = ObjectFactory.CreateEnvelope(mdef.Extents.MinX, mdef.Extents.MinY, mdef.Extents.MaxX, mdef.Extents.MaxY);

                try
                {
                    ILayerDefinition layer = null;
                    IResource        res   = context.GetResource(l.ResourceId);
                    if (!ResourceValidatorSet.HasValidator(res.ResourceType, res.ResourceVersion))
                    {
                        //Need to trap the no registered validator message
                        issues.AddRange(ResourceValidatorSet.Validate(context, res, true));
                        continue;
                    }

                    layer = (ILayerDefinition)res;
                    if (recurse)
                    {
                        issues.AddRange(ResourceValidatorSet.Validate(context, layer, recurse));
                    }

                    IVectorLayerDefinition vl = null;
                    if (layer.SubLayer.LayerType == LayerType.Vector)
                    {
                        vl = (IVectorLayerDefinition)layer.SubLayer;
                    }

                    if (vl != null)
                    {
                        try
                        {
                            IFeatureSource fs = (IFeatureSource)context.GetResource(vl.ResourceId);
                            if (l.Selectable)
                            {
                                //Test selectability requirement
                                string[] idProps = fs.GetIdentityProperties(this.Connection, vl.FeatureName);
                                if (idProps == null || idProps.Length == 0)
                                {
                                    issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_UnselectableLayer, string.Format(Strings.MDF_UnselectableLayer, l.Name, vl.FeatureName, fs.ResourceID)));
                                }
                            }

                            try
                            {
                                FdoSpatialContextList scList = context.GetSpatialContexts(fs.ResourceID);

                                if (scList.SpatialContext == null || scList.SpatialContext.Count == 0)
                                {
                                    issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_MissingSpatialContext, string.Format(Strings.MDF_MissingSpatialContextWarning, fs.ResourceID)));
                                }
                                else
                                {
                                    if (scList.SpatialContext.Count > 1)
                                    {
                                        issues.Add(new ValidationIssue(resource, ValidationStatus.Information, ValidationStatusCode.Info_MapDefinition_MultipleSpatialContexts, string.Format(Strings.MDF_MultipleSpatialContextsInformation, fs.ResourceID)));
                                    }

                                    bool skipGeomCheck = false;

                                    //TODO: Switch to the correct version (2.1), once released
                                    if (scList.SpatialContext[0].CoordinateSystemWkt != mdef.CoordinateSystem)
                                    {
                                        if (layer.SubLayer.LayerType == LayerType.Raster && this.Connection.SiteVersion <= SiteVersions.GetVersion(OSGeo.MapGuide.MaestroAPI.KnownSiteVersions.MapGuideOS2_0_2))
                                        {
                                            issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_RasterReprojection, string.Format(Strings.MDF_RasterReprojectionError, fs.ResourceID)));
                                        }
                                        else
                                        {
                                            issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_LayerReprojection, string.Format(Strings.MDF_DataReprojectionWarning, fs.ResourceID)));
                                        }

                                        skipGeomCheck = true;
                                    }

                                    if (vl.Geometry != null && !skipGeomCheck)
                                    {
                                        var env = this.Connection.FeatureService.GetSpatialExtent(fs.ResourceID, vl.FeatureName, vl.Geometry);
                                        if (!env.Intersects(mapEnv))
                                        {
                                            issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_DataOutsideMapBounds, string.Format(Strings.MDF_DataOutsideMapWarning, fs.ResourceID)));
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                var nex = ex as NullExtentException;
                                if (nex != null)
                                {
                                    issues.Add(new ValidationIssue(resource, ValidationStatus.Warning, ValidationStatusCode.Warning_MapDefinition_FeatureSourceWithNullExtent, string.Format(Strings.MDF_LayerWithNullExtent, fs.ResourceID)));
                                }
                                else
                                {
                                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                                    issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_ResourceRead, string.Format(Strings.MDF_ResourceReadError, fs.ResourceID, msg)));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                            issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_FeatureSourceRead, string.Format(Strings.MDF_FeatureSourceReadError, l.ResourceId, msg)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    issues.Add(new ValidationIssue(resource, ValidationStatus.Error, ValidationStatusCode.Error_MapDefinition_LayerRead, string.Format(Strings.MDF_LayerReadError, l.ResourceId, msg)));
                }
            }

            context.MarkValidated(resource.ResourceID);

            return(issues.ToArray());
        }
Beispiel #3
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());
        }
Beispiel #4
0
        private string[] ExecuteBaseProcedure(LengthyOperationProgressCallBack cb, IBaseLoadProcedure proc, ref bool firstExecution)
        {
            List <string> resCreatedOrUpdated = new List <string>();

            var files     = proc.SourceFile;
            int pcPerFile = (int)(100 / files.Count);
            int current   = 0;

            string root = proc.RootPath;

            if (!root.EndsWith("/")) //NOXLATE
            {
                root += "/";         //NOXLATE
            }
            string sdp = proc.SpatialDataSourcesPath;
            string lp  = proc.LayersPath;

            if (!string.IsNullOrEmpty(sdp))
            {
                if (!sdp.EndsWith("/")) //NOXLATE
                {
                    sdp += "/";         //NOXLATE
                }
            }

            if (!string.IsNullOrEmpty(lp))
            {
                if (!lp.EndsWith("/")) //NOXLATE
                {
                    lp += "/";         //NOXLATE
                }
            }

            string fsRoot    = (string.IsNullOrEmpty(sdp) ? root : sdp) + proc.SpatialDataSourcesFolder;
            string layerRoot = (string.IsNullOrEmpty(lp) ? root : lp) + proc.LayersFolder;

            if (!fsRoot.EndsWith("/"))    //NOXLATE
            {
                fsRoot += "/";            //NOXLATE
            }
            if (!layerRoot.EndsWith("/")) //NOXLATE
            {
                layerRoot += "/";         //NOXLATE
            }
            List <string> resToUpdate = new List <string>();

            if (proc.ResourceId != null && proc.ResourceId.Count > 0)
            {
                resToUpdate.AddRange(proc.ResourceId);
                firstExecution = false;
            }
            else
            {
                firstExecution = true;
            }

            foreach (string file in files)
            {
                bool success = false;
                if (System.IO.File.Exists(file))
                {
                    //GOTCHA: We are assuming these SDF files are not SDF2 files. This is
                    //because there is no multi-platform solution to convert SDF2 files to SDF3

                    string resName  = System.IO.Path.GetFileNameWithoutExtension(file);
                    string dataName = System.IO.Path.GetFileName(file);
                    string dsId     = fsRoot + resName + ".DrawingSource";      //NOXLATE
                    string fsId     = fsRoot + resName + ".FeatureSource";      //NOXLATE
                    string lyrId    = layerRoot + resName + ".LayerDefinition"; //NOXLATE

                    if (proc.GenerateSpatialDataSources)
                    {
                        //Skip only if we have an update list and this resource id is not in it
                        bool skip = (resToUpdate.Count > 0 && !resToUpdate.Contains(fsId));
                        if (!skip)
                        {
                            if (proc.Type == LoadType.Dwf)
                            {
                                //Process is as follows:
                                //
                                // 1. Create and save drawing source document.
                                // 2. Upload dwf file as resource data for this document.

                                //Step 1: Create and save drawing source document.
                                IDrawingSource ds = ObjectFactory.CreateDrawingSource();
                                ds.SourceName      = dataName;
                                ds.CoordinateSpace = proc.CoordinateSystem;
                                ds.ResourceID      = dsId;
                                this.Parent.ResourceService.SaveResource(ds);
                                resCreatedOrUpdated.Add(dsId);
                                cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateCreated, dsId), current));

                                //Step 2: Load resource data for document
                                this.Parent.ResourceService.SetResourceData(dsId, dataName, ResourceDataType.File, System.IO.File.OpenRead(file));
                                cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateLoaded, file), current));

                                ds.RegenerateSheetList(this.Parent);
                                this.Parent.ResourceService.SaveResource(ds);
                                ds.UpdateExtents(this.Parent);
                                this.Parent.ResourceService.SaveResource(ds);
                            }
                            else
                            {
                                //Process is as follows:
                                //
                                // 1. Create and save feature source document.
                                // 2. Upload sdf file as resource data for this document.
                                // 3. Test the connection, it should check out.
                                // 4. If no spatial contexts are detected, assign a default one from the load procedure and save the modified feature source.

                                //Step 1: Create feature source document
                                string provider = "OSGeo.SDF"; //NOXLATE

                                switch (proc.Type)
                                {
                                case LoadType.Sqlite:
                                    provider = "OSGeo.SQLite";     //NOXLATE
                                    break;
                                }
                                var conp = new NameValueCollection();
                                conp["File"] = StringConstants.MgDataFilePath + dataName;
                                var fs = ObjectFactory.CreateFeatureSource(provider, conp);
                                fs.ResourceID = fsId;

                                this.Parent.ResourceService.SaveResource(fs);
                                resCreatedOrUpdated.Add(fsId);
                                cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateCreated, fsId), current));

                                //TODO: When the infrastructure is available to us (ie. A portable .net FDO/MG Feature Service API wrapper)
                                //Maybe then we can actually implement the generalization and duplicate record handling properties. Until then, we skip
                                //these options

                                //Step 2: Load resource data for document
                                this.Parent.ResourceService.SetResourceData(fsId, dataName, ResourceDataType.File, System.IO.File.OpenRead(file));

                                cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateCreated, file), current));

                                //Step 3: Test to make sure we're all good so far
                                string result = this.Parent.FeatureService.TestConnection(fsId);

                                //LocalNativeConnection returns this string, so I'm assuming this is the "success" result
                                if (result == "No errors" || result.ToLower() == "true") //NOXLATE
                                {
                                    //Step 4: Test to see if default cs needs to be specified
                                    FdoSpatialContextList spatialContexts = this.Parent.FeatureService.GetSpatialContextInfo(fsId, false);
                                    if (!string.IsNullOrEmpty(proc.CoordinateSystem))
                                    {
                                        //Case 1: No spatial contexts. Register one using SupplementalContextInfo
                                        if (spatialContexts.SpatialContext.Count == 0)
                                        {
                                            //Register the default CS from the load procedure
                                            fs.AddSpatialContextOverride(new OSGeo.MapGuide.ObjectModels.FeatureSource.v1_0_0.SpatialContextType()
                                            {
                                                Name             = "Default", //NOXLATE
                                                CoordinateSystem = proc.CoordinateSystem
                                            });

                                            //Update this feature source
                                            this.Parent.ResourceService.SaveResource(fs);

                                            cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateSetSpatialContext, fsId), current));
                                        }
                                        else if (spatialContexts.SpatialContext.Count == 1) //Case 2: One spatial context, but its WKT is blank. Override using SupplementalContextInfo
                                        {
                                            var sc = spatialContexts.SpatialContext[0];
                                            if (string.IsNullOrEmpty(sc.CoordinateSystemWkt))
                                            {
                                                //Register the default CS from the load procedure
                                                fs.AddSpatialContextOverride(new OSGeo.MapGuide.ObjectModels.FeatureSource.v1_0_0.SpatialContextType()
                                                {
                                                    Name             = sc.Name,
                                                    CoordinateSystem = proc.CoordinateSystem
                                                });

                                                //Update this feature source
                                                this.Parent.ResourceService.SaveResource(fs);

                                                cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateSetSpatialContext, fsId), current));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (proc.GenerateLayers)
                    {
                        //Skip only if we have an update list and this resource id is not in it
                        bool skip = (resToUpdate.Count > 0 && !resToUpdate.Contains(lyrId));
                        if (!skip)
                        {
                            if (proc.Type == LoadType.Dwf)
                            {
                                //Process is as follows
                                //
                                // 1. Enumerate the sheets on the drawing source
                                // 2. Set the referenced sheet to the first known sheet

                                var dwSvc = (IDrawingService)Parent.GetService((int)ServiceType.Drawing);
                                var list  = dwSvc.EnumerateDrawingSections(dsId);
                                if (list.Section.Count > 0)
                                {
                                    //Create drawing layer
                                    var ld = ObjectFactory.CreateDefaultLayer(LayerType.Drawing, new Version(1, 0, 0));
                                    var dl = ld.SubLayer as IDrawingLayerDefinition;
                                    dl.ResourceId = dsId;
                                    //Use the first one
                                    dl.Sheet = list.Section[0].Name;

                                    ld.ResourceID = lyrId;

                                    this.Parent.ResourceService.SaveResource(ld);
                                    resCreatedOrUpdated.Add(lyrId);
                                    cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateCreated, lyrId), current));
                                }
                            }
                            else
                            {
                                //NOTE: Because we are working against 1.0.0 object types this will always create 1.0.0 Layer Definition
                                //resources

                                //Process is as follows
                                //
                                // 1. Describe the schema of the feature source
                                // 2. If it contains at least one feature class, create a layer definition
                                // 3. Set the following layer definition properties:
                                //    - Feature Source: the feature source id
                                //    - Feature Class: the first feature class in the schema
                                //    - Geometry: the first geometry property in the first feature class
                                // 4. Infer the supported geometry types for this feature class. Toggle supported styles accordingly.

                                //Step 1: Describe the schema
                                //
                                //NOTE: I think we can get away with the full schema walk here. It's very unlikely we will be uploading a flat
                                //file with hundreds of classes. Even then, flat-file schema walk performance blows RDBMS walking performance
                                //out of the water anyway.
                                FeatureSourceDescription desc = this.Parent.FeatureService.DescribeFeatureSource(fsId);

                                if (desc.HasClasses())
                                {
                                    //Step 2: Find the first feature class with a geometry property
                                    ClassDefinition             clsDef = null;
                                    GeometricPropertyDefinition geom   = null;

                                    bool done = false;

                                    foreach (ClassDefinition cls in desc.AllClasses)
                                    {
                                        if (done)
                                        {
                                            break;
                                        }

                                        foreach (PropertyDefinition prop in cls.Properties)
                                        {
                                            if (done)
                                            {
                                                break;
                                            }

                                            if (prop.Type == OSGeo.MapGuide.MaestroAPI.Schema.PropertyDefinitionType.Geometry)
                                            {
                                                clsDef = cls;
                                                geom   = (GeometricPropertyDefinition)prop;
                                                done   = true;
                                            }
                                        }
                                    }

                                    if (clsDef != null && geom != null)
                                    {
                                        var ld = ObjectFactory.CreateDefaultLayer(LayerType.Vector, new Version(1, 0, 0));

                                        //Step 3: Assign default properties
                                        ld.ResourceID = lyrId;
                                        var vld = ld.SubLayer as IVectorLayerDefinition;
                                        vld.ResourceId  = fsId;
                                        vld.FeatureName = clsDef.QualifiedName;
                                        vld.Geometry    = geom.Name;

                                        //Step 4: Infer geometry storage support and remove unsupported styles
                                        var geomTypes = geom.GetIndividualGeometricTypes();
                                        var scale     = vld.GetScaleRangeAt(0);

                                        var remove = new List <string>();
                                        if (Array.IndexOf(geomTypes, FeatureGeometricType.Point) < 0)
                                        {
                                            remove.Add(FeatureGeometricType.Point.ToString().ToLower());
                                        }
                                        if (Array.IndexOf(geomTypes, FeatureGeometricType.Curve) < 0)
                                        {
                                            remove.Add(FeatureGeometricType.Curve.ToString().ToLower());
                                        }
                                        if (Array.IndexOf(geomTypes, FeatureGeometricType.Surface) < 0)
                                        {
                                            remove.Add(FeatureGeometricType.Surface.ToString().ToLower());
                                        }

                                        scale.RemoveStyles(remove);

                                        this.Parent.ResourceService.SaveResource(ld);
                                        resCreatedOrUpdated.Add(lyrId);
                                        cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateCreated, lyrId), current));
                                    }
                                }
                            }
                        }
                    }
                    success = true;
                }
                else
                {
                    cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateFileNotFound, file), current));
                }

                //This file is now fully processed, so increment progress
                current += pcPerFile;

                if (success)
                {
                    cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateFileProcessed, file), current));
                }
            }
            return(resCreatedOrUpdated.ToArray());
        }
Beispiel #5
0
        private string[] ExecuteShpLoadProcedure(LengthyOperationProgressCallBack cb, IShpLoadProcedure shpl, ref bool firstExecution)
        {
            List <string> resCreatedOrUpdated = new List <string>();

            var shpFiles  = shpl.SourceFile;
            int pcPerFile = (int)(100 / shpFiles.Count);
            int current   = 0;

            string root = shpl.RootPath;

            if (!root.EndsWith("/")) //NOXLATE
            {
                root += "/";         //NOXLATE
            }
            string sdp = shpl.SpatialDataSourcesPath;
            string lp  = shpl.LayersPath;

            if (!string.IsNullOrEmpty(sdp))
            {
                if (!sdp.EndsWith("/")) //NOXLATE
                {
                    sdp += "/";         //NOXLATE
                }
            }

            if (!string.IsNullOrEmpty(lp))
            {
                if (!lp.EndsWith("/")) //NOXLATE
                {
                    lp += "/";         //NOXLATE
                }
            }

            string fsRoot    = (string.IsNullOrEmpty(sdp) ? root : sdp) + shpl.SpatialDataSourcesFolder;
            string layerRoot = (string.IsNullOrEmpty(lp) ? root : lp) + shpl.LayersFolder;

            if (!fsRoot.EndsWith("/"))    //NOXLATE
            {
                fsRoot += "/";            //NOXLATE
            }
            if (!layerRoot.EndsWith("/")) //NOXLATE
            {
                layerRoot += "/";         //NOXLATE
            }
            List <string> resToUpdate = new List <string>();

            if (shpl.ResourceId != null)
            {
                resToUpdate.AddRange(shpl.ResourceId);
                firstExecution = false;
            }
            else
            {
                firstExecution = true;
            }

            Dictionary <string, List <string> > extraFiles = new Dictionary <string, List <string> >();

            //Unlike SDF, a SHP file actually consists of multiple files
            foreach (string shp in shpFiles)
            {
                if (!extraFiles.ContainsKey(shp))
                {
                    extraFiles[shp] = new List <string>();
                }
                //we want to preserve casing for everything before the extension
                string prefix = shp.Substring(0, shp.LastIndexOf(".") + 1); //NOXLATE
                extraFiles[shp].Add(prefix + "shx");                        //NOXLATE
                extraFiles[shp].Add(prefix + "dbf");                        //NOXLATE
                extraFiles[shp].Add(prefix + "idx");                        //NOXLATE
                extraFiles[shp].Add(prefix + "prj");                        //NOXLATE
                extraFiles[shp].Add(prefix + "cpg");                        //NOXLATE

                //TODO: Are we missing anything else?
            }

            foreach (string file in shpFiles)
            {
                bool success = false;
                if (System.IO.File.Exists(file))
                {
                    string resName  = System.IO.Path.GetFileNameWithoutExtension(file);
                    string dataName = System.IO.Path.GetFileName(file);

                    string fsId  = fsRoot + resName + ".FeatureSource";      //NOXLATE
                    string lyrId = layerRoot + resName + ".LayerDefinition"; //NOXLATE

                    if (shpl.GenerateSpatialDataSources)
                    {
                        //Skip only if we have an update list and this resource id is not in it
                        bool skip = (resToUpdate.Count > 0 && !resToUpdate.Contains(fsId));
                        if (!skip)
                        {
                            //Process is as follows:
                            //
                            // 1. Create and save feature source document.
                            // 2. Upload sdf file as resource data for this document.
                            // 3. Test the connection, it should check out.
                            // 4. If no spatial contexts are detected, assign a default one from the load procedure and save the modified feature source.

                            //Step 1: Create feature source document
                            var conp = new NameValueCollection();
                            conp["DefaultFileLocation"] = StringConstants.MgDataFilePath + dataName; //NOXLATE
                            var fs = ObjectFactory.CreateFeatureSource("OSGeo.SHP", conp);           //NOXLATE
                            fs.ResourceID = fsId;

                            this.Parent.ResourceService.SaveResource(fs);
                            resCreatedOrUpdated.Add(fsId);
                            cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateCreated, fsId), current));

                            //TODO: When the infrastructure is available to us (ie. A portable .net FDO/MG Feature Service API wrapper)
                            //Maybe then we can actually implement the generalization and conversion properties. Until then, we skip
                            //these options

                            //Step 2: Load resource data for document
                            this.Parent.ResourceService.SetResourceData(fsId, dataName, ResourceDataType.File, System.IO.File.OpenRead(file));

                            cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateLoaded, file), current));

                            //Load supplementary files
                            foreach (string extraFile in extraFiles[file])
                            {
                                string dn = System.IO.Path.GetFileName(extraFile);
                                if (System.IO.File.Exists(extraFile))
                                {
                                    this.Parent.ResourceService.SetResourceData(fsId, dn, ResourceDataType.File, System.IO.File.OpenRead(extraFile));
                                    cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateLoaded, extraFile), current));
                                }
                            }

                            //Step 3: Test to make sure we're all good so far
                            string result = this.Parent.FeatureService.TestConnection(fsId);

                            if (Utility.IsSuccessfulConnectionTestResult(result))
                            {
                                //Step 4: Test to see if default cs needs to be specified
                                FdoSpatialContextList spatialContexts = this.Parent.FeatureService.GetSpatialContextInfo(fsId, false);
                                if (!string.IsNullOrEmpty(shpl.CoordinateSystem))
                                {
                                    bool hasPrj = false;
                                    //If there is no prj file, we can just upload one with the specified WKT
                                    var resData = this.Parent.ResourceService.EnumerateResourceData(fs.ResourceID);
                                    foreach (var resd in resData.ResourceData)
                                    {
                                        if (resd.Name == resName + ".prj") //NOXLATE
                                        {
                                            hasPrj = true;
                                            break;
                                        }
                                    }
                                    //Case 1: No .prj file. Most probable
                                    if (!hasPrj)
                                    {
                                        string tmp = System.IO.Path.GetTempFileName();
                                        System.IO.File.WriteAllText(tmp, shpl.CoordinateSystem);

                                        using (var fsr = System.IO.File.OpenRead(tmp))
                                        {
                                            this.Parent.ResourceService.SetResourceData(fs.ResourceID, resName + ".prj", ResourceDataType.File, fsr); //NOXLATE
                                            cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateUploadedPrj, resName), current));
                                        }

                                        try
                                        {
                                            System.IO.File.Delete(tmp);
                                        }
                                        catch { }
                                    }
                                    else if (spatialContexts.SpatialContext.Count == 0) //Case 2: No Spatial contexts. Declare one using SupplementalContextInfo
                                    {
                                        //Register the default CS from the load procedure
                                        fs.AddSpatialContextOverride(new OSGeo.MapGuide.ObjectModels.FeatureSource.v1_0_0.SpatialContextType()
                                        {
                                            Name             = "Default", //NOXLATE
                                            CoordinateSystem = shpl.CoordinateSystem
                                        });

                                        //Update this feature source
                                        this.Parent.ResourceService.SaveResource(fs);

                                        cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateSetSpatialContext, fsId), current));
                                    }
                                    else if (spatialContexts.SpatialContext.Count == 1) //Case 3: One spatial context with blank WKT. Override it using the SupplementalContextInfo
                                    {
                                        var sc = spatialContexts.SpatialContext[0];
                                        if (string.IsNullOrEmpty(sc.CoordinateSystemWkt))
                                        {
                                            //Register the default CS from the load procedure
                                            fs.AddSpatialContextOverride(new OSGeo.MapGuide.ObjectModels.FeatureSource.v1_0_0.SpatialContextType()
                                            {
                                                Name             = sc.Name,
                                                CoordinateSystem = shpl.CoordinateSystem
                                            });

                                            //Update this feature source
                                            this.Parent.ResourceService.SaveResource(fs);

                                            cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateSetSpatialContext, fsId), current));
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (shpl.GenerateLayers)
                    {
                        //Skip only if we have an update list and this resource id is not in it
                        bool skip = (resToUpdate.Count > 0 && !resToUpdate.Contains(lyrId));
                        if (!skip)
                        {
                            //NOTE: Because we are working against 1.0.0 object types this will always create 1.0.0 Layer Definition
                            //resources

                            //Process is as follows
                            //
                            // 1. Describe the schema of the feature source
                            // 2. If it contains at least one feature class, create a layer definition
                            // 3. Set the following layer definition properties:
                            //    - Feature Source: the feature source id
                            //    - Feature Class: the first feature class in the schema
                            //    - Geometry: the first geometry property in the first feature class
                            // 4. Infer the supported geometry types for this feature class. Toggle supported styles accordingly.

                            //Step 1: Describe the schema
                            //
                            //NOTE: I think we can get away with the full schema walk here. It's very unlikely we will be uploading a flat
                            //file with hundreds of classes. Even then, flat-file schema walk performance blows RDBMS walking performance
                            //out of the water anyway.
                            FeatureSourceDescription desc = this.Parent.FeatureService.DescribeFeatureSource(fsId);

                            //Step 2: Find the first feature class with a geometry property
                            ClassDefinition             clsDef = null;
                            GeometricPropertyDefinition geom   = null;

                            bool done = false;

                            foreach (ClassDefinition cls in desc.AllClasses)
                            {
                                if (done)
                                {
                                    break;
                                }

                                foreach (PropertyDefinition prop in cls.Properties)
                                {
                                    if (done)
                                    {
                                        break;
                                    }

                                    if (prop.Type == OSGeo.MapGuide.MaestroAPI.Schema.PropertyDefinitionType.Geometry)
                                    {
                                        clsDef = cls;
                                        geom   = (GeometricPropertyDefinition)prop;
                                        done   = true;
                                    }
                                }
                            }

                            if (clsDef != null && geom != null)
                            {
                                var ld = ObjectFactory.CreateDefaultLayer(LayerType.Vector, new Version(1, 0, 0));

                                //Step 3: Assign default properties
                                ld.ResourceID = lyrId;
                                var vld = ld.SubLayer as IVectorLayerDefinition;
                                vld.ResourceId  = fsId;
                                vld.FeatureName = clsDef.QualifiedName;
                                vld.Geometry    = geom.Name;

                                //Step 4: Infer geometry storage support and remove unsupported styles
                                var scale     = vld.GetScaleRangeAt(0);
                                var geomTypes = geom.GetIndividualGeometricTypes();
                                var remove    = new List <string>();
                                if (Array.IndexOf(geomTypes, FeatureGeometricType.Point) < 0)
                                {
                                    remove.Add(FeatureGeometricType.Point.ToString().ToLower());
                                }
                                if (Array.IndexOf(geomTypes, FeatureGeometricType.Curve) < 0)
                                {
                                    remove.Add(FeatureGeometricType.Curve.ToString().ToLower());
                                }
                                if (Array.IndexOf(geomTypes, FeatureGeometricType.Surface) < 0)
                                {
                                    remove.Add(FeatureGeometricType.Surface.ToString().ToLower());
                                }

                                scale.RemoveStyles(remove);

                                this.Parent.ResourceService.SaveResource(ld);
                                resCreatedOrUpdated.Add(lyrId);
                                cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateCreated, lyrId), current));
                            }
                        }
                    }
                    success = true;
                }
                else
                {
                    cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateFileNotFound, file), current));
                }

                //This file is now fully processed, so increment progress
                current += pcPerFile;

                if (success)
                {
                    cb(this, new LengthyOperationProgressArgs(string.Format(Strings.TemplateSuccess, file), current));
                }
            }

            return(resCreatedOrUpdated.ToArray());
        }
Beispiel #6
0
        public MapGuideLayer(ServerConnectionI con, string layername)
        {
            m_con = con;

            m_layerDef = m_con.GetLayerDefinition(layername);
            if (!(m_layerDef.Item is VectorLayerDefinitionType))
            {
                throw new Exception("The resource " + layername + " is not a vector layer");
            }

            VectorLayerDefinitionType vldef = m_layerDef.Item as VectorLayerDefinitionType;

            m_columnnames = new Dictionary <string, string>();

            m_columnnames[vldef.Geometry] = null;

            ExtractColumnNames(vldef.Url, m_columnnames);
            ExtractColumnNames(vldef.ToolTip, m_columnnames);

            try
            {
                FeatureSource         fs  = m_con.GetFeatureSource(vldef.ResourceId);
                FdoSpatialContextList lst = fs.GetSpatialInfo();
                if (lst != null && lst.SpatialContext != null && lst.SpatialContext.Count > 0)
                {
                    Topology.CoordinateSystems.CoordinateSystemFactory cf = new Topology.CoordinateSystems.CoordinateSystemFactory();
                    m_coordSys = cf.CreateFromWkt(lst.SpatialContext[0].CoordinateSystemWkt);
                }
            }
            catch
            {
            }

            foreach (VectorScaleRangeType vsr in vldef.VectorScaleRange)
            {
                ScaleRange sr = new ScaleRange(vsr.MinScaleSpecified ? vsr.MinScale : 0, vsr.MaxScaleSpecified ? vsr.MaxScale : double.MaxValue);

                foreach (object style in vsr.Items)
                {
                    if (style is PointTypeStyleType)
                    {
                        if (((PointTypeStyleType)style).PointRule != null)
                        {
                            foreach (PointRuleType rule in ((PointTypeStyleType)style).PointRule)
                            {
                                if (rule.Item != null && rule.Item.Item != null)
                                {
                                    OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                    if (rule.Label != null)
                                    {
                                        ExtractColumnNames(rule.Label.Text, m_columnnames);
                                    }

                                    LittleSharpRenderEngine.Style.Point p = new LittleSharpRenderEngine.Style.Point();
                                    p.Center = new System.Drawing.Point(
                                        (int)(rule.Item.Item.InsertionPointXSpecified ? rule.Item.Item.InsertionPointX : 0.5),
                                        (int)(rule.Item.Item.InsertionPointYSpecified ? rule.Item.Item.InsertionPointY : 0.5));

                                    p.Rotation = double.Parse(rule.Item.Item.Rotation, System.Globalization.CultureInfo.InvariantCulture);
                                    p.Size     = new System.Drawing.Size(
                                        (int)double.Parse(rule.Item.Item.SizeX, System.Globalization.CultureInfo.InvariantCulture),
                                        (int)double.Parse(rule.Item.Item.SizeY, System.Globalization.CultureInfo.InvariantCulture));

                                    if (rule.Item.Item is MarkSymbolType)
                                    {
                                        MarkSymbolType mark = rule.Item.Item as MarkSymbolType;
                                        switch (mark.Shape)
                                        {
                                        case ShapeType.Circle:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                            break;

                                        case ShapeType.Square:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Square;
                                            break;

                                        case ShapeType.Triangle:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Triangle;
                                            break;

                                        default:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                            break;
                                        }

                                        if (mark.Fill != null)
                                        {
                                            p.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                            p.Fill.BackgroundColor = mark.Fill.BackgroundColor;
                                            p.Fill.ForegroundColor = mark.Fill.ForegroundColor;
                                            //p.Fill.Pattern = mark.Fill.FillPattern;
                                            //TODO: Deal with unit/sizecontext
                                        }

                                        if (mark.Edge != null)
                                        {
                                            p.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                            p.Outline.ForegroundColor = mark.Edge.Color;
                                            //p.Outline.DashStyle = mark.Edge.LineStyle;
                                            //p.Outline.Pattern = mark.Edge.LineStyle;
                                            p.Outline.Width = (int)double.Parse(mark.Edge.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                            //TODO: Deal with unit/sizecontext
                                        }
                                    }
                                    else
                                    {
                                        p.Type    = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                        p.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        p.Fill    = new LittleSharpRenderEngine.Style.Base.Fill();
                                        p.Fill.BackgroundColor = System.Drawing.Color.Red;
                                        p.Fill.ForegroundColor = System.Drawing.Color.Black;

                                        p.Outline.ForegroundColor = System.Drawing.Color.Black;
                                    }

                                    sr.PointRules.Add(new KeyValuePair <OperationOrParameter, IPointStyle>(op, p));
                                }
                            }
                        }
                    }
                    else if (style is LineTypeStyleType)
                    {
                        if (((LineTypeStyleType)style).LineRule != null)
                        {
                            foreach (LineRuleType rule in ((LineTypeStyleType)style).LineRule)
                            {
                                if (rule.Items != null && rule.Items.Count > 0)
                                {
                                    List <IOutline>      lines = new List <IOutline>();
                                    OperationOrParameter op    = ExtractColumnNames(rule.Filter, m_columnnames);
                                    if (rule.Label != null)
                                    {
                                        ExtractColumnNames(rule.Label.Text, m_columnnames);
                                    }

                                    foreach (StrokeType st in rule.Items)
                                    {
                                        LittleSharpRenderEngine.Style.Base.Outline outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        outline.ForegroundColor = st.Color;
                                        outline.Width           = (int)double.Parse(st.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                        //outline.Pattern = st.LineStyle;
                                        //outline.DashStyle = st.LineStyle;
                                        //TODO: Deal with unit/sizecontext

                                        lines.Add(outline);
                                    }

                                    sr.LineRules.Add(new KeyValuePair <OperationOrParameter, ILineStyle>(op, new LittleSharpRenderEngine.Style.Line(lines)));
                                }
                            }
                        }
                    }
                    else if (style is AreaTypeStyleType)
                    {
                        if (((AreaTypeStyleType)style).AreaRule != null)
                        {
                            foreach (AreaRuleType rule in ((AreaTypeStyleType)style).AreaRule)
                            {
                                OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                if (rule.Label != null)
                                {
                                    ExtractColumnNames(rule.Label.Text, m_columnnames);
                                }

                                LittleSharpRenderEngine.Style.Area a = new Area();
                                if (rule.Item != null)
                                {
                                    if (rule.Item.Fill != null)
                                    {
                                        a.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                        a.Fill.BackgroundColor = rule.Item.Fill.BackgroundColor;
                                        a.Fill.ForegroundColor = rule.Item.Fill.ForegroundColor;
                                        //p.Fill.Pattern = rule.Item.Fill.FillPattern;
                                        //TODO: Deal with unit/sizecontext
                                    }

                                    if (rule.Item.Stroke != null)
                                    {
                                        a.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        a.Outline.ForegroundColor = rule.Item.Stroke.Color;
                                        //p.Outline.DashStyle = rule.Item.Stroke.LineStyle;
                                        //p.Outline.Pattern = rule.Item.Stroke.LineStyle;
                                        a.Outline.Width = (int)double.Parse(rule.Item.Stroke.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                        //TODO: Deal with unit/sizecontext
                                    }

                                    sr.AreaRules.Add(new KeyValuePair <OperationOrParameter, IAreaStyle>(op, a));
                                }
                            }
                        }
                    }
                }

                if (sr.PointRules.Count + sr.LineRules.Count + sr.AreaRules.Count > 0)
                {
                    m_scaleRanges.Add(sr);
                }
            }
        }