首页 > 数据库 >ArcGIS Pro SDK (八)地理数据库 6 版本控制

ArcGIS Pro SDK (八)地理数据库 6 版本控制

时间:2024-07-11 11:57:47浏览次数:17  
标签:版本控制 Pro versionManager ArcGIS Version 版本 new using geodatabase

ArcGIS Pro SDK (八)地理数据库 6 版本控制

文章目录

环境:Visual Studio 2022 + .NET6 + ArcGIS Pro SDK 3.0

1 连接到版本

public Geodatabase ConnectToVersion(Geodatabase geodatabase, string versionName)
{
    Geodatabase connectedVersion = null;

    if (geodatabase.IsVersioningSupported())
    {
        using (VersionManager versionManager = geodatabase.GetVersionManager())
            using (Version version = versionManager.GetVersion(versionName))
        {
            connectedVersion = version.Connect();
        }
    }
    return connectedVersion;
}

2 在单独的编辑会话中协调版本并将其与其父级进行核对和提交

public void ReconcileAndPost(Geodatabase geodatabase)
{
    // 获取当前版本及其父版本的引用
    if (geodatabase.IsVersioningSupported())
    {
        using (VersionManager versionManager = geodatabase.GetVersionManager())
        using (Version currentVersion = versionManager.GetCurrentVersion())
        using (Version parentVersion = currentVersion.GetParent())
        {
            // 创建 ReconcileOptions 对象
            var reconcileOptions = new ReconcileOptions(parentVersion)
            {
                ConflictResolutionMethod = ConflictResolutionMethod.Continue, // 发现冲突时继续
                ConflictDetectionType = ConflictDetectionType.ByRow, // 默认值
                ConflictResolutionType = ConflictResolutionType.FavorTargetVersion // 或者 FavorEditVersion
            };

            // 执行协调
            ReconcileResult reconcileResult = currentVersion.Reconcile(reconcileOptions);
            if (!reconcileResult.HasConflicts)
            {
                // 无冲突,执行过账
                var postOptions = new PostOptions(parentVersion)
                {
                    ServiceSynchronizationType = ServiceSynchronizationType.Synchronous // 默认值
                };
                currentVersion.Post(postOptions);
            }
        }
    }
}

3 在同一编辑会话中协调版本并将其与其父级提交

public void ReconcileAndPost2(Geodatabase geodatabase)
{
    // 获取当前版本及其父版本的引用
    if (geodatabase.IsVersioningSupported())
    {
        using (VersionManager versionManager = geodatabase.GetVersionManager())
        using (Version currentVersion = versionManager.GetCurrentVersion())
        using (Version parentVersion = currentVersion.GetParent())
        {
            // 创建 ReconcileOptions 对象
            var reconcileOptions = new ReconcileOptions(parentVersion)
            {
                ConflictResolutionMethod = ConflictResolutionMethod.Continue, // 发现冲突时继续
                ConflictDetectionType = ConflictDetectionType.ByRow, // 默认值
                ConflictResolutionType = ConflictResolutionType.FavorTargetVersion // 或者 FavorEditVersion
            };

            // 创建 PostOptions 对象
            var postOptions = new PostOptions(parentVersion)
            {
                ServiceSynchronizationType = ServiceSynchronizationType.Synchronous // 默认值
            };

            // 执行协调和过账
            ReconcileResult reconcileResult = currentVersion.Reconcile(reconcileOptions, postOptions);
            if (reconcileResult.HasConflicts)
            {
                // 处理冲突
                // TODO 解决冲突
            }
        }
    }
}

4 使用版本

public async Task WorkingWithVersions()
{
    await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(
        () =>
        {
            using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
                using (VersionManager versionManager = geodatabase.GetVersionManager())
            {
                IReadOnlyList<Version> versionList = versionManager.GetVersions();

                // 默认版本的父版本为 null
                Version defaultVersion = versionList.First(version => version.GetParent() == null);

                IEnumerable<Version> publicVersions = versionList.Where(
                    version => version.GetAccessType() == VersionAccessType.Public);
                Version qaVersion = defaultVersion.GetChildren().First(
                    version => version.GetName().Contains("QA"));

                Geodatabase qaVersionGeodatabase = qaVersion.Connect();

                FeatureClass currentFeatureClass = geodatabase.OpenDataset<FeatureClass>("featureClassName");
                FeatureClass qaFeatureClass = qaVersionGeodatabase.OpenDataset<FeatureClass>("featureClassName");
            }
        });
}

5 使用默认版本

// 检查当前版本是否为默认版本
// 适用于分支和传统版本管理
public bool IsDefaultVersion(Version version)
{
    Version parentVersion = version.GetParent();
    if (parentVersion == null)
    {
        return true;
    }
    parentVersion.Dispose();
    return false;
}

public bool IsDefaultVersion(Geodatabase geodatabase)
{
    if (!geodatabase.IsVersioningSupported()) return false;
    using (VersionManager versionManager = geodatabase.GetVersionManager())
        using (Version currentVersion = versionManager.GetCurrentVersion())
    {
        return IsDefaultVersion(currentVersion);
    }
}

// 获取默认版本
// 适用于分支和传统版本管理
// 此方法依赖于 IsDefaultVersion() 方法
public Version GetDefaultVersion(Version version)
{
    if (IsDefaultVersion(version))
    {
        return version;
    }
    else
    {
        Version parent = version.GetParent();
        Version ancestor = GetDefaultVersion(parent);
        if (parent != ancestor)
        {
            parent.Dispose(); // 如果版本树超过两层深,释放中间版本对象
        }
        return ancestor;
    }
}

public Version GetDefaultVersion(Geodatabase geodatabase)
{
    if (!geodatabase.IsVersioningSupported()) return null;

    using (VersionManager versionManager = geodatabase.GetVersionManager())
    {
        Version currentVersion = versionManager.GetCurrentVersion();
        Version defaultVersion = GetDefaultVersion(currentVersion);
        if (currentVersion != defaultVersion)
        {
            currentVersion.Dispose(); // 如果当前版本不是默认版本,释放当前版本对象
        }
        return defaultVersion;
    }
}

6 创建版本

public Version CreateVersion(Geodatabase geodatabase, string versionName, string description, VersionAccessType versionAccessType)
{
    if (!geodatabase.IsVersioningSupported()) return null;

    using (VersionManager versionManager = geodatabase.GetVersionManager())
    {
        VersionDescription versionDescription = new VersionDescription(versionName, description, versionAccessType);
        return versionManager.CreateVersion(versionDescription);
    }
}

7 创建历史版本

public HistoricalVersion CreateHistoricalVersion(Geodatabase geodatabase, string versionName)
{
    using (VersionManager versionManager = geodatabase.GetVersionManager())
    {
        HistoricalVersionDescription historicalVersionDescription = new HistoricalVersionDescription(versionName, DateTime.Now);
        HistoricalVersion historicalVersion = versionManager.CreateHistoricalVersion(historicalVersionDescription);

        return historicalVersion;
    }
}

8 在版本之间切换

public void ChangeVersions(Geodatabase geodatabase, string toVersionName)
{
    using (VersionManager versionManager = geodatabase.GetVersionManager())
    {
        VersionBaseType versionBaseType = versionManager.GetCurrentVersionBaseType();

        if (versionBaseType == VersionBaseType.Version)
        {
            Version fromVersion = versionManager.GetCurrentVersion();
            Version toVersion = versionManager.GetVersion(toVersionName);

            // 在版本之间切换
            MapView.Active.Map.ChangeVersion(fromVersion, toVersion);
        }

        if (versionBaseType == VersionBaseType.HistoricalVersion)
        {
            HistoricalVersion fromHistoricalVersion = versionManager.GetCurrentHistoricalVersion();
            HistoricalVersion toHistoricalVersion = versionManager.GetHistoricalVersion(toVersionName);

            // 在历史版本之间切换
            MapView.Active.Map.ChangeVersion(fromHistoricalVersion, toHistoricalVersion);
        }

        // 从历史版本切换到版本,反之亦然
        // MapView.Active.Map.ChangeVersion(fromHistoricalVersion, toVersion);
        // MapView.Active.Map.ChangeVersion(fromVersion, toHistoricalVersion);
    }
}

9 部分过账

// 部分过账允许开发人员提交版本中的部分更改。
// 一个示例用例是电力公用事业公司使用版本来设计新的住宅细分区的设施。
// 在流程的某个阶段,一个街区的新房屋已经建成,而细分区的其余部分尚未建造。
// 部分过账允许用户提交已完成的工作,同时保留版本中尚未建成的要素,以便以后提交。
// 部分过账需要使用 ArcGIS Enterprise 10.9 及更高版本的分支版本化要素服务。

// 指定已构建的要素集合
QueryFilter constructedFilter = new QueryFilter()
{
    WhereClause = "ConstructedStatus = 'True'"
};

// 此选择表示我们希望提交到支持结构要素类的插入和更新
using (Selection constructedSupportStructures = supportStructureFeatureClass.Select(
    constructedFilter, SelectionType.ObjectID, SelectionOption.Normal))
{
    // 指定要提交的删除要素稍微复杂,因为无法发出查询来获取已删除要素的集合,必须使用 ObjectIDs 的列表。
    using (Selection deletedSupportStructures = supportStructureFeatureClass.Select(
        null, SelectionType.ObjectID, SelectionOption.Empty))
    {
        deletedSupportStructures.Add(deletedSupportStructureObjectIDs);  // deletedSupportStructureObjectIDs 定义为 List<long>

        // 执行带有部分过账的协调
        // 在 2.x 版本中 -
        // ReconcileDescription reconcileDescription = new ReconcileDescription();
        // reconcileDescription.ConflictDetectionType = ConflictDetectionType.ByColumn;
        // reconcileDescription.ConflictResolutionMethod = ConflictResolutionMethod.Continue;
        // reconcileDescription.ConflictResolutionType = ConflictResolutionType.FavorEditVersion;
        // reconcileDescription.PartialPostSelections = new List<Selection>() { constructedSupportStructures, deletedSupportStructures };
        // reconcileDescription.WithPost = true;

        // ReconcileResult reconcileResult = designVersion.Reconcile(reconcileDescription);

        var reconcileOptions = new ReconcileOptions();  // 协调选项,针对默认版本
        reconcileOptions.ConflictDetectionType = ConflictDetectionType.ByColumn;
        reconcileOptions.ConflictResolutionMethod = ConflictResolutionMethod.Continue;
        reconcileOptions.ConflictResolutionType = ConflictResolutionType.FavorEditVersion;

        var postOptions = new PostOptions();  // 提交选项,针对默认版本
        postOptions.PartialPostSelections = new List<Selection>() { 
            constructedSupportStructures, deletedSupportStructures 
        };
        postOptions.ServiceSynchronizationType = ServiceSynchronizationType.Synchronous;

        var reconcileResult = designVersion.Reconcile(reconcileOptions, postOptions);

        // 处理结果
        // TODO 处理结果的逻辑
    }
}

标签:版本控制,Pro,versionManager,ArcGIS,Version,版本,new,using,geodatabase
From: https://blog.csdn.net/szy13323042191/article/details/140348150

相关文章

  • Marking criteria for COMP9444 project
    Marking criteria for COMP9444 projectTotal marks for the project work:35 marks.1.   Project Notebook(s):20 Marks2.   Summary Report (max 4pages): 5 marks3.   Project Presentation: 10 MarksBreakdownofmarksforeachcompon......
  • ES6 之 Proxy(代理)总结(二)
    ES6引入了Proxy对象,它用于创建一个对象的代理,从而可以拦截并自定义对象的基本操作,如属性查找、赋值、枚举、函数调用等。主要特性:拦截操作:可以拦截对象的各种操作,如获取属性、设置属性、属性是否存在等。自定义行为:通过拦截操作,可以自定义对象的行为。撤销代理:可以撤......
  • daima8资源网整站数据打包完整代码(集成了ripro9.1主题,开箱即用)
    基于ripro9.1完全明文无加密后门版本定制开发,无需独立服务器,虚拟主机也可以完美运营,只要主机支持php和mysql即可。整合了微信登录和几款第三方的主题文件,看起来更美观一些。站长本人就是程序员,所以本站的代码资源数据基本上都是精选的,没有重复数据,更没有滥竽充数的垃圾资源。......
  • GOLLIE : ANNOTATION GUIDELINES IMPROVE ZERO-SHOT INFORMATION-EXTRACTION
    文章目录题目摘要引言方法实验消融题目Gollie:注释指南改进零样本信息提取论文地址:https://arxiv.org/abs/2310.03668摘要    大型语言模型(LLM)与指令调优相结合,在泛化到未见过的任务时取得了重大进展。然而,它们在信息提取(IE)方面不太成功,落后于特定任......
  • promise回调地狱
    回调地狱:在回调函数中调用回调函数缺点:可维护性差,可读性差引入axios 省份  <select>    <optionvalue=""class="province"></option>  </select>城市  <select>    <optionvalue=""class="city">&......
  • c++ protobuf安装记录
    googleprotobuf是一个灵活的、高效的用于序列化数据的协议。相比较XML和JSON格式,protobuf更小、更快、更便捷。googleprotobuf是跨语言的,并且自带了一个编译器(protoc),只需要用它进行编译,可以编译成Java、python、C++、C#、Go等代码,然后就可以直接使用,不需要再写其他代码,自带有......
  • Modbus转Profinet网关模块连PLC与流量计通讯案例
    一、案例背景在饮品加工厂中,会涉及到流量计的使用,然而达到对流量计的精准控制和数据采集需要用到PLC,由于PLC和流量计可能使用不同的通信协议(如Profinet和Modbus),造成两者不能自接进行通讯和数据传输。在不增加编程工作量的情况下,可使用Modbus转Profinet网关模块来实现。二、Mo......
  • Profinet转ModbusTCP网关模块连发那科机器人与DCS通讯
    一、现场要求:发那科机器人作为服务器端,DCS作为客户端向发那科机器人发送读写请求,发那科机器人应答后DCS接收发那科机器人的数据,实现数据的传递。二、解决方案:在不增加编程任务的前提下只需在DCS与机器人中间添加巴图自动化Profinet转ModbusTCP网关(BT-ETHPN20)就可实现。本文将介......
  • 471、基于51单片机的自行车(速度,里程,电机,LCD1602)(程序+Proteus仿真+原理图+流程图+元器
    毕设帮助、开题指导、技术解答(有偿)见文未目录方案选择单片机的选择显示器选择方案一、设计功能二、Proteus仿真图单片机模块设计三、原理图四、程序源码资料包括:需要完整的资料可以点击下面的名片加下我,找我要资源压缩包的百度网盘下载地址及提取码。方案选择......
  • 使用Java9 Flow API进行Reactive Programming
    importjava.util.concurrent.Flow;importjava.util.concurrent.Flow.Publisher;importjava.util.concurrent.Flow.Subscriber;publicclassReactiveExample{publicstaticvoidmain(String[]args){//创建一个发布者,发布一系列的数字Publisher......