コード例 #1
0
        public override void Run()
        {
            string file = FileService.OpenFile(Res.GetString("TITLE_CONNECT_SQLITE"), Res.GetString("FILTER_SQLITE"));

            if (FileService.FileExists(file))
            {
                FdoConnection        conn  = ExpressUtility.CreateFlatFileConnection("OSGeo.SQLite", file);
                FdoConnectionManager mgr   = ServiceManager.Instance.GetService <FdoConnectionManager>();
                NamingService        namer = ServiceManager.Instance.GetService <NamingService>();

                string name = Msg.ShowInputBox(Res.GetString("TITLE_CONNECTION_NAME"), Res.GetString("PROMPT_ENTER_CONNECTION"), namer.GetDefaultConnectionName("OSGeo.SQLite"));
                if (name == null)
                {
                    return;
                }

                while (name == string.Empty || mgr.NameExists(name))
                {
                    Msg.ShowError(Res.GetString("ERR_CONNECTION_NAME_EMPTY_OR_EXISTS"));
                    name = Msg.ShowInputBox(Res.GetString("TITLE_CONNECTION_NAME"), Res.GetString("PROMPT_ENTER_CONNECTION"), name);

                    if (name == null)
                    {
                        return;
                    }
                }
                mgr.AddConnection(name, conn);
            }
        }
コード例 #2
0
        public override void Run()
        {
            string dir = FileService.GetDirectory(Res.GetString("TITLE_CONNECT_SHP_DIR"));

            if (FileService.DirectoryExists(dir))
            {
                FdoConnection        conn  = new FdoConnection("OSGeo.SHP", "DefaultFileLocation=" + dir);
                FdoConnectionManager mgr   = ServiceManager.Instance.GetService <FdoConnectionManager>();
                NamingService        namer = ServiceManager.Instance.GetService <NamingService>();

                string name = Msg.ShowInputBox(Res.GetString("TITLE_CONNECTION_NAME"), Res.GetString("PROMPT_ENTER_CONNECTION"), namer.GetDefaultConnectionName("OSGeo.SHP"));
                if (name == null)
                {
                    return;
                }

                while (string.IsNullOrEmpty(name) || mgr.NameExists(name))
                {
                    Msg.ShowError(Res.GetString("ERR_CONNECTION_NAME_EMPTY_OR_EXISTS"));
                    name = Msg.ShowInputBox(Res.GetString("TITLE_CONNECTION_NAME"), Res.GetString("PROMPT_ENTER_CONNECTION"), name);

                    if (name == null)
                    {
                        return;
                    }
                }
                mgr.AddConnection(name, conn);
            }
        }
コード例 #3
0
        public override void Run()
        {
            string path = FileService.OpenFile(Res.GetString("TITLE_LOAD_CONNECTION"), Res.GetString("FILTER_CONNECTION_FILE"));

            if (FileService.FileExists(path))
            {
                FdoConnection        conn = FdoConnection.LoadFromFile(path);
                FdoConnectionManager mgr  = ServiceManager.Instance.GetService <FdoConnectionManager>();

                string name = string.Empty;
                name = Msg.ShowInputBox(Res.GetString("TITLE_NEW_CONNECTION"), Res.GetString("PROMPT_ENTER_NEW_CONNECTION_NAME"), name);
                if (name == null)
                {
                    return;
                }

                while (name == string.Empty || mgr.NameExists(name))
                {
                    name = Msg.ShowInputBox(Res.GetString("TITLE_NEW_CONNECTION"), Res.GetString("PROMPT_ENTER_NEW_CONNECTION_NAME"), name);
                    if (name == null)
                    {
                        return;
                    }
                }

                using (TempCursor cur = new TempCursor(Cursors.WaitCursor))
                {
                    mgr.AddConnection(name, conn);
                }
            }
        }
コード例 #4
0
        public bool CreateSqlite()
        {
            if (_view.CreateConnection && string.IsNullOrEmpty(_view.ConnectionName))
            {
                _view.ShowError("Specify a connection name");
                return(false);
            }

            if (ExpressUtility.CreateFlatFileDataSource("OSGeo.SQLite", _view.SQLiteFile))
            {
                FdoConnection conn = ExpressUtility.CreateFlatFileConnection("OSGeo.SQLite", _view.SQLiteFile);
                if (FileService.FileExists(_view.FeatureSchemaDefinition))
                {
                    conn.Open();
                    using (FdoFeatureService service = conn.CreateFeatureService())
                    {
                        service.LoadSchemasFromXml(_view.FeatureSchemaDefinition, _view.FixIncompatibilities);
                    }
                }
                if (_view.CreateConnection)
                {
                    _connMgr.AddConnection(_view.ConnectionName, conn);
                }
                else
                {
                    conn.Dispose();
                }
            }
            return(true);
        }
コード例 #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var schema = _schema;

            //Remove elements that have been unchecked.
            foreach (TreeNode clsNode in treeSchema.Nodes)
            {
                string className = clsNode.Name;
                int    index     = schema.Classes.IndexOf(className);
                if (!clsNode.Checked)
                {
                    if (index >= 0)
                    {
                        schema.Classes.RemoveAt(index);
                    }
                }
                else
                {
                    if (index >= 0)
                    {
                        ClassDefinition clsDef = schema.Classes[index];
                        foreach (TreeNode propNode in clsNode.Nodes)
                        {
                            if (!propNode.Checked)
                            {
                                string propName = propNode.Text;
                                int    pidx     = clsDef.Properties.IndexOf(propName);
                                if (pidx >= 0)
                                {
                                    clsDef.Properties.RemoveAt(pidx);
                                    if (clsDef.IdentityProperties.Contains(propName))
                                    {
                                        int idpdx = clsDef.IdentityProperties.IndexOf(propName);
                                        clsDef.IdentityProperties.RemoveAt(idpdx);
                                    }
                                    if (clsDef.ClassType == ClassType.ClassType_FeatureClass)
                                    {
                                        FeatureClass fc = (FeatureClass)clsDef;
                                        if (fc.GeometryProperty.Name == propName)
                                        {
                                            fc.GeometryProperty = null;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (rdXml.Checked)
            {
                using (var ios = new IoFileStream(txtXml.Text, "w"))
                {
                    using (var writer = new XmlWriter(ios, false, XmlWriter.LineFormat.LineFormat_Indent))
                    {
                        schema.WriteXml(writer);
                        writer.Close();
                    }
                    ios.Close();
                }

                MessageService.ShowMessage("Schema saved to: " + txtXml.Text);
                this.DialogResult = DialogResult.OK;
            }
            else if (rdFile.Checked)
            {
                string fileName = txtFile.Text;
                if (ExpressUtility.CreateFlatFileDataSource(fileName))
                {
                    FdoConnection conn        = ExpressUtility.CreateFlatFileConnection(fileName);
                    bool          disposeConn = true;
                    using (FdoFeatureService svc = conn.CreateFeatureService())
                    {
                        svc.ApplySchema(schema);
                        if (MessageService.AskQuestion("Schema saved to: " + txtFile.Text + " connect to it?", "Saved"))
                        {
                            FdoConnectionManager mgr = ServiceManager.Instance.GetService <FdoConnectionManager>();
                            string name = MessageService.ShowInputBox(ResourceService.GetString("TITLE_CONNECTION_NAME"), ResourceService.GetString("PROMPT_ENTER_CONNECTION"), "");
                            if (name == null)
                            {
                                return;
                            }

                            while (name == string.Empty || mgr.NameExists(name))
                            {
                                MessageService.ShowError(ResourceService.GetString("ERR_CONNECTION_NAME_EMPTY_OR_EXISTS"));
                                name = MessageService.ShowInputBox(ResourceService.GetString("TITLE_CONNECTION_NAME"), ResourceService.GetString("PROMPT_ENTER_CONNECTION"), name);

                                if (name == null)
                                {
                                    return;
                                }
                            }
                            disposeConn = false;
                            mgr.AddConnection(name, conn);
                        }
                    }
                    if (disposeConn)
                    {
                        conn.Close();
                        conn.Dispose();
                    }
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
コード例 #6
0
        public bool CreateSdf()
        {
            if (_view.CreateConnection && string.IsNullOrEmpty(_view.ConnectionName))
            {
                _view.ShowError("Specify a connection name");
                return(false);
            }

            if (ExpressUtility.CreateFlatFileDataSource("OSGeo.SDF", _view.SdfFile))
            {
                FdoDataStoreConfiguration dstore = null;
                if (FileService.FileExists(_view.FeatureSchemaDefinition))
                {
                    dstore = FdoDataStoreConfiguration.FromFile(_view.FeatureSchemaDefinition);

                    //SDF only permits the following:
                    // 1 feature schema
                    // 1 spatial context

                    if (dstore.Schemas.Count > 1)
                    {
                        _view.ShowError("Multiple schemas were found in this document. SDF only allows 1 feature schema");
                        return(false);
                    }
                    if (dstore.SpatialContexts.Length > 1)
                    {
                        _view.ShowError("Multiple spatial contexts were found in this doucment. SDF only allows 1 spatial context");
                        return(false);
                    }
                }
                FdoConnection conn = ExpressUtility.CreateFlatFileConnection("OSGeo.SDF", _view.SdfFile);
                if (dstore != null)
                {
                    using (var svc = conn.CreateFeatureService())
                    {
                        if (dstore.SpatialContexts.Length == 1)
                        {
                            //Overwrite existing spatial context if it exists
                            var sc  = dstore.SpatialContexts[0];
                            var asc = svc.GetActiveSpatialContext();
                            if (asc != null)
                            {
                                sc.Name = asc.Name;
                            }

                            svc.CreateSpatialContext(sc, (asc != null));
                        }

                        var schema = dstore.Schemas[0];
                        if (_view.FixIncompatibilities)
                        {
                            IncompatibleSchema incS;
                            if (!svc.CanApplySchema(schema, out incS))
                            {
                                schema = svc.AlterSchema(schema, incS);
                            }
                        }
                        svc.ApplySchema(schema);
                    }
                }

                if (_view.CreateConnection)
                {
                    _connMgr.AddConnection(_view.ConnectionName, conn);
                }
                else
                {
                    conn.Dispose();
                }
            }
            return(true);
        }
コード例 #7
0
        public bool CreateShp()
        {
            if (_view.CreateConnection && string.IsNullOrEmpty(_view.ConnectionName))
            {
                _view.ShowError("Specify a connection name");
                return(false);
            }
            //Creating SHP files is as follows
            //
            // 1. Connect to the *parent* directory of the shape file we want to create
            // 2. Apply the schema to this connection

            if (FileService.FileExists(_view.FeatureSchemaDefinition))
            {
                try
                {
                    FdoConnection             conn   = ExpressUtility.CreateFlatFileConnection("OSGeo.SHP", _view.ShpDirectory);
                    FdoDataStoreConfiguration config = FdoDataStoreConfiguration.FromFile(_view.FeatureSchemaDefinition);

                    //SHP allows the following:
                    // 1 feature schema
                    // Multiple spatial contexts
                    if (config.Schemas.Count > 1)
                    {
                        _view.ShowError("More than 1 feature schema was found in the document. SHP only allows 1 feature schema");
                        return(false);
                    }
                    var schema = config.Schemas[0];
                    using (var svc = conn.CreateFeatureService())
                    {
                        foreach (var sc in config.SpatialContexts)
                        {
                            svc.CreateSpatialContext(sc, true);
                        }

                        if (_view.FixIncompatibilities)
                        {
                            IncompatibleSchema incs;
                            if (!svc.CanApplySchema(schema, out incs))
                            {
                                schema = svc.AlterSchema(schema, incs);
                            }
                        }

                        svc.ApplySchema(schema);
                    }
                    conn.Dispose();
                    if (_view.CreateConnection)
                    {
                        conn = ExpressUtility.CreateFlatFileConnection("OSGeo.SHP", _view.ShpDirectory);
                        conn.Open();
                        _connMgr.AddConnection(_view.ConnectionName, conn);
                    }
                }
                catch (OSGeo.FDO.Common.Exception ex)
                {
                    _view.ShowError(ex);
                    LoggingService.Error("Failed to create SHP", ex);
                    return(false);
                }
            }
            return(true);
        }
コード例 #8
0
ファイル: HostApplication.cs プロジェクト: beritec/fdotoolbox
        /// <summary>
        /// Creates the fdo connection.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="name">The name.</param>
        public static void CreateFdoFileConnection(string file, string name)
        {
            FdoConnection conn = ExpressUtility.CreateFlatFileConnection(file);

            ConnectionManager.AddConnection(name, conn);
        }