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);
        }
        /// <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 static void SetConnectionToolTip(TreeNode connNode, FdoConnection conn)
 {
     using (FdoFeatureService service = conn.CreateFeatureService())
     {
         List <string> ctxStrings = new List <string>();
         try
         {
             ICollection <SpatialContextInfo> contexts = service.GetSpatialContexts();
             foreach (SpatialContextInfo sci in contexts)
             {
                 if (sci.IsActive)
                 {
                     ctxStrings.Add("- " + sci.Name + " (Active)");
                 }
                 else
                 {
                     ctxStrings.Add("- " + sci.Name);
                 }
             }
         }
         catch
         {
             ctxStrings.Add("Could not retrieve spatial contexts");
         }
         string configStatus = conn.HasConfiguration ? "(This connection has custom configuration applied)" : string.Empty;
         connNode.ToolTipText = string.Format(
             "Provider: {0}{4}Type: {1}{4}Connection String: {2}{4}Spatial Contexts:{4}{3}{4}{5}",
             conn.Provider,
             conn.DataStoreType,
             conn.SafeConnectionString,
             ctxStrings.Count > 0 ? string.Join("\n", ctxStrings.ToArray()) : "none",
             Environment.NewLine,
             configStatus);
     }
 }
        public override int Execute()
        {
            IConnection conn = null;

            try
            {
                conn = CreateConnection(_provider, _connstr);
                conn.Open();
            }
            catch (OSGeo.FDO.Common.Exception ex)
            {
                WriteException(ex);
                return((int)CommandStatus.E_FAIL_CONNECT);
            }

            using (FdoFeatureService service = new FdoFeatureService(conn))
            {
                ReadOnlyCollection <SpatialContextInfo> contexts = service.GetSpatialContexts();
                Console.WriteLine("\nSpatial Contexts in connection: {0}", contexts.Count);
                foreach (SpatialContextInfo ctx in contexts)
                {
                    Console.WriteLine("\nName: {0}\n", ctx.Name);
                    Console.WriteLine("\tDescriptionn: {0}", ctx.Description);
                    Console.WriteLine("\tXY Tolerance: {0}\n\tZ Tolerance: {1}", ctx.XYTolerance, ctx.ZTolerance);
                    Console.WriteLine("\tCoordinate System: {0}\n\tCoordinate System WKT:\n\t\t{1}", ctx.CoordinateSystem, ctx.CoordinateSystemWkt);
                    Console.WriteLine("\tExtent Type: {0}", ctx.ExtentType);
                    if (ctx.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Static)
                    {
                        Console.WriteLine("\tExtent:\n\t\t{0}", ctx.ExtentGeometryText);
                    }
                }
            }
            conn.Close();
            return((int)CommandStatus.E_OK);
        }
        public override int Execute()
        {
            IConnection conn = null;
            try
            {
                conn = CreateConnection(_provider, _connstr);
                conn.Open();
            }
            catch (OSGeo.FDO.Common.Exception ex)
            {
                WriteException(ex);
                return (int)CommandStatus.E_FAIL_CONNECT;
            }

            using (FdoFeatureService service = new FdoFeatureService(conn))
            {
                ReadOnlyCollection<SpatialContextInfo> contexts = service.GetSpatialContexts();
                Console.WriteLine("\nSpatial Contexts in connection: {0}", contexts.Count);
                foreach (SpatialContextInfo ctx in contexts)
                {
                    Console.WriteLine("\nName: {0}\n", ctx.Name);
                    Console.WriteLine("\tDescriptionn: {0}", ctx.Description);
                    Console.WriteLine("\tXY Tolerance: {0}\n\tZ Tolerance: {1}", ctx.XYTolerance, ctx.ZTolerance);
                    Console.WriteLine("\tCoordinate System: {0}\n\tCoordinate System WKT:\n\t\t{1}", ctx.CoordinateSystem, ctx.CoordinateSystemWkt);
                    Console.WriteLine("\tExtent Type: {0}", ctx.ExtentType);
                    if (ctx.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Static)
                        Console.WriteLine("\tExtent:\n\t\t{0}", ctx.ExtentGeometryText);
                }
            }
            conn.Close();
            return (int)CommandStatus.E_OK;
        }
 public FdoSpatialContextBrowserDlg(FdoConnection conn)
     : this()
 {
     using (FdoFeatureService service = conn.CreateFeatureService())
     {
         grdSpatialContexts.DataSource = service.GetSpatialContexts();
     }
 }
示例#7
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);
                    }
                }
        }
示例#8
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);
                    }
                }
            }
        }
示例#9
0
        /// <summary>
        /// Copies all spatial contexts
        /// </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>
        public virtual void Execute(FdoConnection source, FdoConnection target, bool overwrite)
        {
            List <string> names = new List <string>();

            using (FdoFeatureService service = source.CreateFeatureService())
            {
                ReadOnlyCollection <SpatialContextInfo> contexts = service.GetSpatialContexts();
                if (contexts.Count == 0)
                {
                    return;
                }

                foreach (SpatialContextInfo ctx in contexts)
                {
                    names.Add(ctx.Name);
                }
            }
            Execute(source, target, overwrite, names.ToArray());
        }
        public void Init()
        {
            List <string> names = new List <string>(_connMgr.GetConnectionNames());

            names.Remove(_view.SourceConnectionName);

            _view.TargetConnectionNames = names;
            FdoConnection conn = _connMgr.GetConnection(_view.SourceConnectionName);

            using (FdoFeatureService service = conn.CreateFeatureService())
            {
                ICollection <SpatialContextInfo> contexts = service.GetSpatialContexts();
                List <string> scn = new List <string>();
                foreach (SpatialContextInfo sc in contexts)
                {
                    scn.Add(sc.Name);
                }
                _view.SpatialContexts = scn;
            }
        }
        /// <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);
        }