예제 #1
0
 public void ChangeVersion(IMap imap_0, IFeatureWorkspace ifeatureWorkspace_0,
                           IFeatureWorkspace ifeatureWorkspace_1)
 {
     try
     {
         if ((((imap_0 != null) && (ifeatureWorkspace_0 != null)) && (ifeatureWorkspace_1 != null)) &&
             !this.method_6(ifeatureWorkspace_0))
         {
             ICollectionTableVersionChanges changes = new EnumTableVersionChangesClass();
             (ifeatureWorkspace_1 as IVersion).RefreshVersion();
             imap_0.ClearSelection();
             IMapAdmin2 admin = imap_0 as IMapAdmin2;
             admin.FireChangeVersion(ifeatureWorkspace_0 as IVersion, ifeatureWorkspace_1 as IVersion);
             this.method_5(imap_0, ifeatureWorkspace_0, ifeatureWorkspace_1, changes);
             this.method_4(imap_0 as IStandaloneTableCollection, ifeatureWorkspace_0, ifeatureWorkspace_1,
                           changes);
             this.method_0(admin, changes as IEnumTableVersionChanges);
             changes.RemoveAll();
             (imap_0 as IActiveView).Refresh();
         }
     }
     catch
     {
     }
 }
예제 #2
0
        private void method_0(IMapAdmin2 imapAdmin2_0, IEnumTableVersionChanges ienumTableVersionChanges_0)
        {
            ITable table;
            ITable table1;

            try
            {
                ienumTableVersionChanges_0.Reset();
                ienumTableVersionChanges_0.Next(out table, out table1);
                while (true)
                {
                    if ((table == null ? true : table1 == null))
                    {
                        break;
                    }
                    if (!(table is IFeatureClass))
                    {
                        imapAdmin2_0.FireChangeTable(table, table1);
                    }
                    else
                    {
                        imapAdmin2_0.FireChangeFeatureClass(table as IFeatureClass, table1 as IFeatureClass);
                    }
                    ienumTableVersionChanges_0.Next(out table, out table1);
                }
            }
            catch
            {
            }
        }
예제 #3
0
        public bool CreateMxd(string sMxdTemplate,
                              string sPathToMXD,
                              string ArcGISServer,
                              string sMxdFile,
                              string sDBConn,
                              string sDataSet,
                              bool bSde)
        {
            if (sMxdTemplate.Length > 0)
            {
                _sMxdTemplate = sMxdTemplate;
            }

            _sPathToMXD   = sPathToMXD;
            _ArcGISServer = ArcGISServer;
            ESRI.ArcGIS.Carto.IMap pMap   = null;
            IFeatureClass          pOldFC = null;
            string fcName  = String.Empty;
            string sSuffix = String.Empty;

            IWorkspaceFactory2 wsf = null;
            IWorkspace2        ws2 = null;
            IFeatureWorkspace  fws = null;
            IWorkspace         ws  = null;

            try
            {
                if (bSde)
                {
                    // Get WS for SDE
                    ws = ArcSdeWorkspaceFromFile(sDBConn);
                }
                else
                {
                    // Get WS from file GDB.
                    wsf = new FileGDBWorkspaceFactoryClass() as IWorkspaceFactory2;
                    //if locks on gdb only path is passed in
                    string fileGdb = sDBConn.Contains(".gdb") ? sDBConn : sDBConn;

                    if (wsf.IsWorkspace(fileGdb))
                    {
                        ws = wsf.OpenFromFile(fileGdb, 0);
                    }
                }

                if (ws == null)
                {
                    return(false);
                }

                // Check if Mxd already exists
                if (File.Exists(sMxdFile))
                {
                    return(false);
                }

                // Create a Mxd from Overlays Template
                pMap = PrivateCreateMxd(sMxdFile);

                ws2 = (IWorkspace2)ws;
                fws = (IFeatureWorkspace)ws;

                // Loop through all layers in MXD and repoint data source to OverlayGDB Features
                IEnumLayer pEnumLayer = pMap.get_Layers(null, true);
                pEnumLayer.Reset();
                ILayer pLayer = pEnumLayer.Next();
                while (pLayer != null)
                {
                    if (!(pLayer is IFeatureLayer))
                    {
                        pLayer = pEnumLayer.Next();
                        continue;
                    }

                    // Cast pLayer to featurelayer
                    IFeatureLayer pMapFeatureLayer = (IFeatureLayer)pLayer;
                    pOldFC = pMapFeatureLayer.FeatureClass;

                    if (pOldFC == null)
                    {
                        pLayer = pEnumLayer.Next();
                        continue;
                    }

                    // Get FC name
                    IDataset pDS = (IDataset)pOldFC;
                    fcName = pDS.Name;

                    // Feature Class: <Dataset>_osm_pt, <Dataset>_osm_ln, <Dataset>_osm_ply
                    sSuffix = fcName.Substring(fcName.IndexOf("_osm_"));

                    if (String.IsNullOrEmpty(sSuffix))
                    {
                        continue;
                    }

                    // Check if feature class exists in GDB
                    if (ws2.get_NameExists(esriDatasetType.esriDTFeatureClass, sDataSet + sSuffix))
                    {
                        // Get feature class
                        IFeatureClass ipFC = fws.OpenFeatureClass(sDataSet + sSuffix);
                        IFeatureLayer ipFL = (IFeatureLayer)pLayer;

                        // Create IMapAdmin2 from pMap
                        IMapAdmin2 pMapAdmin2 = (IMapAdmin2)pMap;

                        // Change FeatureClass of layer to FC in FGDB
                        ipFL.FeatureClass = ipFC;
                        pMapAdmin2.FireChangeFeatureClass(pOldFC, ipFC);

                        COMUtil.ReleaseObject(ipFC);
                        ipFC = null;

                        COMUtil.ReleaseObject(ipFL);
                        ipFL = null;
                    }
                    else
                    {
                        // Remove layer from map
                        pMap.DeleteLayer(pLayer);
                    }

                    pLayer = pEnumLayer.Next();
                }

                SaveMXD(sMxdFile, pMap);

                return(true);
            }
            catch (System.Runtime.InteropServices.COMException cx)
            {
                throw cx;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                COMUtil.ReleaseObject(pOldFC);
                COMUtil.ReleaseObject(fws);
                COMUtil.ReleaseObject(ws2);
                COMUtil.ReleaseObject(ws);
                COMUtil.ReleaseObject(pMap);
                COMUtil.ReleaseObject(wsf);
                pOldFC        = null;
                fws           = null;
                ws2           = null;
                ws            = null;
                wsf           = null;
                pMap          = null;
                _pMapDocument = null;

                //Do not make any call to ArcObjects after ShutDownApplication()
                if (m_AOLicenseInitializer != null)
                {
                    m_AOLicenseInitializer.ShutdownApplication();
                }
                m_AOLicenseInitializer = null;
            }
        }