public static void DisplayMongoBrowseDialog(IMongoDbDialogVM mod) { MongoDbDialogVM model = (MongoDbDialogVM)mod; MongoBrowserDlg dlg = new MongoBrowserDlg(); EventHandler tmp = (o, e) => dlg.Close(); dlg.DataContext = model; model.Closing += tmp; dlg.ShowDialog(); model.Closing -= tmp; dlg.DataContext = null; }
/// <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); } }