コード例 #1
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                IMongoDbDialogVM dbDialog = UIUtils.GetDialogVM();

                ButtonInfo okBtn;
                okBtn.OnClick = (() =>
                {
                    string connString = dbDialog.File;

                    if (String.IsNullOrEmpty(connString))
                    {
                        return;
                    }

                    string selectedFC = dbDialog.GetSelectedFCName();

                    if (String.IsNullOrEmpty(selectedFC))
                    {
                        return;
                    }

                    //get the type using the ProgID
                    Type t = Type.GetTypeFromProgID("esriGeoDatabase.MongoDBPluginWorkspaceFactory");
                    //Use activator in order to create an instance of the workspace factory
                    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(t);
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(connString, 0);

                    //get a featureclass from the workspace
                    IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(selectedFC);
                    //create a new feature layer and add it to the map
                    IFeatureLayer featureLayer = new FeatureLayerClass();
                    featureLayer.Name = featureClass.AliasName;
                    featureLayer.FeatureClass = featureClass;
                    m_hookHelper.FocusMap.AddLayer((ILayer)featureLayer);
                    dbDialog.Close();
                });

                okBtn.IsEnabled = null;
                dbDialog.SetOk(okBtn);

                ButtonInfo cancelBtn;
                cancelBtn.OnClick = () =>
                {
                    dbDialog.Close();
                };
                cancelBtn.IsEnabled = null;
                dbDialog.SetCancel(cancelBtn);

                ButtonInfo browseBtn;
                browseBtn.OnClick = () =>
                {
                    string result = UIUtils.BrowseToFile(null, "Connection File to MongoDB (.mongoconn)|*.mongoconn", false);
                    if (String.IsNullOrEmpty(result))
                    {
                        return;
                    }

                    string          connInfoStr = ConnectionUtilities.DecodeConnFile(result);
                    MongoDBConnInfo connInfo    = ConnectionUtilities.ParseConnectionString(connInfoStr);
                    dbDialog.DatabaseText = connInfo.DBName;
                    dbDialog.ServerText   = connInfo.Connection.ToString();
                    dbDialog.File         = result;

                    //get the type using the ProgID
                    Type t = Type.GetTypeFromProgID("esriGeoDatabase.MongoDBPluginWorkspaceFactory");
                    //Use activator in order to create an instance of the workspace factory
                    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(t);
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(result, 0);

                    IEnumDatasetName ipNames = ((IWorkspace)featureWorkspace).get_DatasetNames(esriDatasetType.esriDTFeatureClass);

                    List <string> dsNames = new List <string>();
                    IDatasetName  ipCurr  = ipNames.Next();
                    while (ipCurr != null)
                    {
                        dsNames.Add(ipCurr.Name);
                        ipCurr = null;
                        ipCurr = ipNames.Next();
                    }

                    dbDialog.ClearFCList();
                    if (dsNames.Count > 0)
                    {
                        dbDialog.SetFCNames(dsNames);
                    }
                };
                browseBtn.IsEnabled = null;
                dbDialog.SetBrowse(browseBtn);

                UIUtils.DisplayMongoBrowseDialog(dbDialog);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                IMongoDbLoaderDlgVm dbDialog = UIUtils.GetLoaderVM();

                ButtonInfo browseBtn;
                browseBtn.OnClick = () =>
                {
                    string result = UIUtils.BrowseToFile(null, "Connection File to MongoDB (.mongoconn)|*.mongoconn", false);
                    if (String.IsNullOrEmpty(result))
                    {
                        return;
                    }

                    string          connInfoStr = ConnectionUtilities.DecodeConnFile(result);
                    MongoDBConnInfo connInfo    = ConnectionUtilities.ParseConnectionString(connInfoStr);
                    dbDialog.DatabaseText = connInfo.DBName;
                    dbDialog.ServerText   = connInfo.Connection.ToString();
                    dbDialog.File         = result;
                };
                browseBtn.IsEnabled = null;
                dbDialog.SetBrowse(browseBtn);


                IGxObject  ipSelectedItem = null;
                ButtonInfo browseToFC;
                browseToFC.OnClick = () =>
                {
                    IGxDialog ipBrowser = new GxDialog();
                    ipBrowser.ObjectFilter     = (IGxObjectFilter) new GxFilterPointFeatureClasses();
                    ipBrowser.AllowMultiSelect = false;
                    IEnumGxObject ipTempSelected;
                    if (ipBrowser.DoModalOpen(0, out ipTempSelected))
                    {
                        if (null != ipTempSelected)
                        {
                            ipSelectedItem  = ipTempSelected.Next();
                            dbDialog.FCConn = ipSelectedItem.FullName;
                        }
                    }
                };
                browseToFC.IsEnabled = null;
                dbDialog.SetSourceBrowse(browseToFC);

                ButtonInfo okBtn;
                okBtn.OnClick = (() =>
                {
                    if (ipSelectedItem == null)
                    {
                        return;
                    }

                    string connString = dbDialog.File;
                    if (String.IsNullOrEmpty(connString))
                    {
                        return;
                    }

                    dbDialog.Close();

                    IName ipSrcName = ipSelectedItem.InternalObjectName;
                    IFeatureClass ipSrc = (IFeatureClass)ipSrcName.Open();
                    IEnvelope ipExtent = ((IGeoDataset)ipSrc).Extent;

                    MongoDBWorkspacePluginFactory factory = new MongoDBWorkspacePluginFactory();
                    MongoDBWorkspace ws = factory.OpenMongoDBWorkspace(connString);

                    MongoDBDataset target = ws.CreateDataset(ipSelectedItem.BaseName, DataLoadUtilities.GetCreatableFields(ipSrc.Fields), ipExtent);

                    DataLoadUtilities.LoadData(ipSrc, target);
                });
                okBtn.IsEnabled = null;
                dbDialog.SetOk(okBtn);

                ButtonInfo cancelBtn;
                cancelBtn.OnClick = () =>
                {
                    dbDialog.Close();
                };
                cancelBtn.IsEnabled = null;
                dbDialog.SetCancel(cancelBtn);

                UIUtils.DisplayLoaderDialog(dbDialog);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }