示例#1
0
    //-----------------------------------------------------------------------------------------------------
    public static IWorkspace openSDEWorkspace(String connectionString)
    {
        //ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 workspaceFactory;
        //workspaceFactory = (ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2)new
        //ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
        IWorkspaceFactory2 workspaceFactory = new SdeWorkspaceFactoryClass();

        return(workspaceFactory.OpenFromString(connectionString, 0));
    }
示例#2
0
        private IStandaloneTable GetLayerfromSDE(string FClassName)
        {
            string strSDEConnString = String.Format("server={0};instance={1};user={2};password={3};version={4}", strServer, strInstance, strUser, strPasswd, strVersion);

            IWorkspaceFactory2 pWorkFact        = new SdeWorkspaceFactoryClass();
            IFeatureWorkspace  pFWorkspace      = pWorkFact.OpenFromString(strSDEConnString, 0) as IFeatureWorkspace;
            ITable             ptable           = pFWorkspace.OpenTable(FClassName);
            IStandaloneTable   pStandAloneTable = new StandaloneTableClass();

            pStandAloneTable.Table = ptable;
            return(pStandAloneTable);
        }
示例#3
0
 /// <summary>
 /// 通过sde连接信息打开工作空间
 /// 格式:"SERVER=Kona;DATABASE=sde;INSTANCE=5151;USER=Editor;PASSWORD=Editor;VERSION=sde.DEFAULT"
 /// </summary>
 /// <param name="connstr">sde连接信息</param>
 /// <returns></returns>
 public static IWorkspace OpenSdeWorkspace(string connstr)
 {
     try
     {
         IWorkspaceFactory2 workspaceFactory = new SdeWorkspaceFactoryClass();
         IWorkspace         workspace        = workspaceFactory.OpenFromString(connstr, 0);
         return(workspace);
     }
     catch (Exception ex)
     {
         LOG.Error("SDE空间数据库打开错误,详情:" + ex.Message);
         // Console.WriteLine("SDE空间数据库打开错误,详情:"+ex.Message);
         return(null);
     }
 }
        /// <summary>
        /// synchronizes all 2 way child replicas with parent given sde conneciton string
        /// </summary>
        /// <param name="sdeConnection">connection string</param>
        /// <param name="syncConflicts">conflict type</param>
        /// <param name="syncDirection">sync direction</param>
        /// <returns>true if success otherwise false</returns>
        public bool SynchronizeReplica(string sdeConnection, esriReplicationAgentReconcilePolicy syncConflicts,esriReplicaSynchronizeDirection syncDirection)
        {
            Console.WriteLine("Starting Synchronization");
            bool x = true;
            try
            {

                IWorkspace cwks = OpenWorkSpace(sdeConnection);
                if (cwks != null)
                {

                    IGeoDataServer childGDS = new GeoDataServerClass();
                    IGeoDataServerInit childGDSInit = (IGeoDataServerInit)childGDS;
                    childGDSInit.InitWithWorkspace(cwks);
                    IReplicationAgent replicationAgent = new ReplicationAgentClass();
                    //need to get parent GDS and replica names
                    IGPReplicas childReps = childGDS.Replicas;
                    IGPReplica childRep = null;
                    IGPReplicas parentReps = null;
                    IGPReplica parentRep = null;
                    IGeoDataServer parentGDS = new GeoDataServerClass();
                    IWorkspaceFactory2 pWksFact = null;
                    IWorkspace pwks = null;
                    IGeoDataServerInit parentGDSInit = null;
                    bool repFind = false;
                    string msg = "";
                    string pConnectStr = null;
                    if (childReps.Count == 0)
                    {
                        Console.WriteLine("Could not find any Replicas in local database");
                    }
                    for (int i = 0; i < childReps.Count; i++)
                    {
                        childRep = childReps.get_Element(i);
                        if (childRep.Role == esriReplicaRole.esriReplicaRoleChild)
                        {
                            repFind = false;
                            msg = "";
                            pConnectStr = childRep.SibConnectionString;
                            Console.WriteLine(pConnectStr);
                            pWksFact = new SdeWorkspaceFactoryClass();
                            pwks = pWksFact.OpenFromString(pConnectStr, 0);
                            parentGDSInit = (IGeoDataServerInit)parentGDS;
                            parentGDSInit.InitWithWorkspace(pwks);
                            parentReps = parentGDS.Replicas;
                            if (parentReps.Count == 0)
                            {
                                Console.WriteLine("Could not find any replicas in Parent database");
                            }
                            for (int j = 0; j < parentReps.Count; j++)
                            {
                                parentRep = parentReps.get_Element(j);
                                if (j == 0)
                                {
                                    msg = parentRep.Name;
                                }
                                else
                                {
                                    msg = msg + "; " + parentRep.Name;
                                }
                                //use ubound
                                string[] prNameArr, crNameArr;
                                prNameArr = parentRep.Name.Split(new char[] { '.' });
                                crNameArr = childRep.Name.Split(new char[] { '.' });
                                string prName, crName;
                                prName = prNameArr[prNameArr.GetUpperBound(0)];
                                crName = crNameArr[crNameArr.GetUpperBound(0)];
                                Console.WriteLine("prName = " + prName + "\ncrName = " + crName);
                                if (prName.ToLower() == crName.ToLower())
                                {
                                    try
                                    {
                                        Console.WriteLine("\tSynchronizing with parent database");
                                        replicationAgent.SynchronizeReplica(childGDS, parentGDS, childRep, parentRep, syncConflicts, syncDirection, false);
                                        x = true;
                                        repFind = true;
                                        break;
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine("Error: Could not sync Replica " + childRep.Name + " error message = " + e.ToString());
                                        x = false;
                                        break;
                                    }
                                }
                            }
                            if (!repFind)
                            {
                                Console.WriteLine("\tCould not find Recplica named " + childRep.Name + " in Parent Database.\n\tValid names in parent include: " + msg);
                                x = false;
                            }
                        }
                        else
                        {
                            Console.WriteLine("\t" + childRep.Name + " is a parent replica. Skipping Synchronization.");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Workspace not valid");
                    x = false;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                x = false;
            }
            return x;
        }
示例#5
0
        private IStandaloneTable GetLayerfromSDE(string FClassName)
        {
            string strSDEConnString = String.Format("server={0};instance={1};user={2};password={3};version={4}",strServer,strInstance,strUser,strPasswd,strVersion);

            IWorkspaceFactory2 pWorkFact = new SdeWorkspaceFactoryClass();
            IFeatureWorkspace pFWorkspace = pWorkFact.OpenFromString(strSDEConnString, 0) as IFeatureWorkspace;
            ITable ptable = pFWorkspace.OpenTable(FClassName);
            IStandaloneTable pStandAloneTable = new StandaloneTableClass();
            pStandAloneTable.Table = ptable;
            return pStandAloneTable;
        }