コード例 #1
0
        /// <summary>
        /// Copies the spatial contexts given in the list
        /// </summary>
        /// <param name="source">The source connection</param>
        /// <param name="target">The target connection</param>
        /// <param name="overwrite">If true will overwrite any existing spatial contexts</param>
        /// <param name="spatialContextNames">The list of spatial contexts to copy</param>
        public virtual void Execute(FdoConnection source, FdoConnection target, bool overwrite, string[] spatialContextNames)
        {
            if (spatialContextNames.Length == 0)
            {
                return;
            }

            using (FdoFeatureService sService = source.CreateFeatureService())
                using (FdoFeatureService tService = target.CreateFeatureService())
                {
                    bool supportsMultipleScs = target.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsMultipleSpatialContexts);
                    bool supportsDestroySc   = target.Capability.HasArrayCapability(CapabilityType.FdoCapabilityType_CommandList, (int)OSGeo.FDO.Commands.CommandType.CommandType_DestroySpatialContext);
                    if (supportsMultipleScs)
                    {
                        //Get all contexts in target
                        ReadOnlyCollection <SpatialContextInfo> contexts = tService.GetSpatialContexts();

                        List <string> updated = new List <string>();
                        //Destroy any clashing ones
                        if (overwrite && supportsDestroySc)
                        {
                            foreach (SpatialContextInfo c in contexts)
                            {
                                if (SpatialContextInSpecifiedList(c, spatialContextNames))
                                {
                                    tService.DestroySpatialContext(c);
                                }
                            }
                        }

                        //Then overwrite them
                        foreach (SpatialContextInfo c in contexts)
                        {
                            if (SpatialContextInSpecifiedList(c, spatialContextNames))
                            {
                                tService.CreateSpatialContext(c, overwrite);
                                updated.Add(c.Name);
                            }
                        }

                        //Now create the rest
                        var sourceScs = sService.GetSpatialContexts();
                        foreach (var sc in sourceScs)
                        {
                            if (!updated.Contains(sc.Name))
                            {
                                tService.CreateSpatialContext(sc, overwrite);
                            }
                        }
                    }
                    else
                    {
                        tService.CreateSpatialContext(sService.GetActiveSpatialContext(), true);
                    }
                }
        }