/// <summary>
        /// Copies all spatial contexts
        /// </summary>
        /// <param name="spatialContexts">The spatial contexts.</param>
        /// <param name="target">The target.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        public override void Execute(ICollection <SpatialContextInfo> spatialContexts, FdoConnection target, bool overwrite)
        {
            //MySQL supports multiple spatial contexts and IDestorySpatialContext
            //so in this case if overwrite == true, we want to destroy any ones that
            //already exist in the target before creating new ones in its place. This does not
            //prevent creating a series of spatial contexts if overwrite == false and one of
            //the spatial contexts being copied already exists. This is an unfortunate leaky
            //abstraction in the FDO API.

            using (FdoFeatureService service = target.CreateFeatureService())
            {
                if (overwrite)
                {
                    ReadOnlyCollection <SpatialContextInfo> targetContexts = service.GetSpatialContexts();

                    foreach (SpatialContextInfo sc in spatialContexts)
                    {
                        //Only destroy spatial context if it exists in target connection
                        if (SpatialContextExists(targetContexts, sc))
                        {
                            service.DestroySpatialContext(sc);
                        }
                    }
                }

                foreach (SpatialContextInfo sc in spatialContexts)
                {
                    service.CreateSpatialContext(sc, false);
                }
            }
        }
        private void CreateDefaultSpatialContext(FdoFeatureService svc)
        {
            var sc = _view.CreateDefaultSpatialContext();

            //You would've thought ICreateSpatialContext with updateExisting = true
            //would do the job, but noooo we have to actually destroy the existing
            //one first. Annoying!
            bool destroy = false;
            var  spcs    = svc.GetSpatialContexts();

            foreach (var spc in spcs)
            {
                if (spc.Name == sc.Name)
                {
                    destroy = true;
                    break;
                }
            }
            if (destroy)
            {
                svc.DestroySpatialContext(sc.Name);
            }

            svc.CreateSpatialContext(sc, false);
        }
Example #3
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);
                    }
                }
        }
Example #4
0
        /// <summary>
        /// Copies all spatial contexts
        /// </summary>
        /// <param name="spatialContexts">The spatial contexts.</param>
        /// <param name="target">The target.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        public virtual void Execute(ICollection <SpatialContextInfo> spatialContexts, FdoConnection target, bool overwrite)
        {
            bool supportsMultipleScs = target.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsMultipleSpatialContexts);
            bool supportsDestroySc   = target.Capability.HasArrayCapability(CapabilityType.FdoCapabilityType_CommandList, (int)OSGeo.FDO.Commands.CommandType.CommandType_DestroySpatialContext);

            using (FdoFeatureService service = target.CreateFeatureService())
            {
                if (supportsMultipleScs)
                {
                    if (overwrite && supportsDestroySc)
                    {
                        ReadOnlyCollection <SpatialContextInfo> targetContexts = service.GetSpatialContexts();

                        foreach (SpatialContextInfo sc in spatialContexts)
                        {
                            //Only destroy spatial context if it exists in target connection
                            if (SpatialContextExists(targetContexts, sc))
                            {
                                service.DestroySpatialContext(sc);
                            }
                        }
                    }
                    foreach (SpatialContextInfo sc in spatialContexts)
                    {
                        service.CreateSpatialContext(sc, overwrite);
                    }
                }
                else
                {
                    List <SpatialContextInfo> contexts = new List <SpatialContextInfo>(spatialContexts);
                    //Copy either the active spatial context in the list or the first
                    //spatial context (if no active one is found)
                    SpatialContextInfo active = null;
                    if (contexts.Count > 0)
                    {
                        foreach (SpatialContextInfo sc in contexts)
                        {
                            if (sc.IsActive)
                            {
                                active = sc;
                                break;
                            }
                        }
                        if (active == null)
                        {
                            active = contexts[0];
                        }
                    }
                    if (active != null)
                    {
                        service.CreateSpatialContext(active, overwrite);
                    }
                }
            }
        }
        /// <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 override void Execute(FdoConnection source, FdoConnection target, bool overwrite, string[] spatialContextNames)
        {
            if (spatialContextNames.Length == 0)
            {
                return;
            }

            FdoFeatureService srcService  = source.CreateFeatureService();
            FdoFeatureService destService = target.CreateFeatureService();
            ReadOnlyCollection <SpatialContextInfo> srcContexts  = srcService.GetSpatialContexts();
            ReadOnlyCollection <SpatialContextInfo> destContexts = destService.GetSpatialContexts();

            foreach (SpatialContextInfo ctx in srcContexts)
            {
                if (SpatialContextInSpecifiedList(ctx, spatialContextNames))
                {
                    try
                    {
                        //Find target spatial context of the same name
                        SpatialContextInfo sci = destService.GetSpatialContext(ctx.Name);
                        if (sci != null && overwrite)
                        {
                            //If found, destroy then create
                            destService.DestroySpatialContext(ctx.Name);
                            destService.CreateSpatialContext(ctx, false);
                        }
                        else
                        {
                            destService.CreateSpatialContext(ctx, false);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
        private void CreateDefaultSpatialContext(FdoFeatureService svc)
        {
            var sc = _view.CreateDefaultSpatialContext();

            //You would've thought ICreateSpatialContext with updateExisting = true
            //would do the job, but noooo we have to actually destroy the existing
            //one first. Annoying!
            bool destroy = false;
            var spcs = svc.GetSpatialContexts();
            foreach (var spc in spcs)
            {
                if (spc.Name == sc.Name)
                {
                    destroy = true;
                    break;
                }
            }
            if (destroy)
                svc.DestroySpatialContext(sc.Name);

            svc.CreateSpatialContext(sc, false);
        }