IEnumStyleGalleryItem get_Items

本文介绍如何使用ArcGIS API通过C#代码定制符号库,包括获取特定类别的符号项及添加自定义符号的过程。文中详细解释了参数含义,并提供了具体的代码实现。

 IEnumStyleGalleryItem ipEnum = ipGallery.get_Items("Marker Symbols", "styles//focusmode.serverstyle", "DEFAULT");

 

[C#]
public IEnumStyleGalleryItem get_Items (
    string ClassName,
    string styleSet,
    string Category
);

解释

class name是你的的符号的类别名,比如如果你的符号是点符号,那么他就是marker symbols,线符号就是Line Symbols,打开Style Manager可以清楚的看到所有的类别.因此,你查询会得到很多符号,可以根据名字进行判断(不过,有的ipGalleryItem.Name是重复的,添加的时候自己保证不重复吧)

 styleSet, 是文件所在的路径

最后一个是自己定义的类别.

下面是我们添加的代码

            ISimpleMarkerSymbol ipMarker = new SimpleMarkerSymbolClass();
            ipGalleryItem.Category = "DEFAULT";
            ipGalleryItem.Name = "Marker1";
            ipGalleryItem.Item = ipMarker;

            ipGallery.AddItem(ipGalleryItem);

### 关于 `sr_oper_get_items_subscribe` 函数 #### 功能描述 `sr_sysrepo.h` 中定义的 `sr_oper_get_items_subscribe` 是 Sysrepo 提供的一个 API,用于订阅操作数据树中的节点。当客户端请求获取特定路径下的操作型数据时,该函数允许应用程序注册回调来处理这些请求[^1]。 --- #### 参数详解 以下是 `sr_oper_get_items_subscribe` 的参数列表及其功能: | **参数名称** | **类型** | **说明** | |----------------------|--------------------------|-------------------------------------------------------------------------| | session | const struct sr_session_ctx_t * | 表示当前会话的上下文对象,由 `sr_session_start()` 创建并返回。 | | module_name | const char * | 要订阅的操作数据所属模块的名称。 | | xpath | const char * | XPath 表达式,指定要监听的数据节点范围。如果为空字符串,则表示整个模块。 | | callback | sr_oper_get_items_cb | 用户实现的回调函数指针,在有匹配的 GET 请求时被调用。 | | private_data | void * | 应用程序自定义的私有数据,会在每次回调中传递给用户定义的回调函数。 | | priority | uint8_t | 订阅优先级,默认值为 0。高优先级意味着更早执行回调逻辑。 | | timeout_ms | uint32_t | 处理超时时间(毫秒),设置为 0 则无超时限制。 | --- #### 返回值 成功时返回 `SR_ERR_OK`;失败时返回其他错误码,具体可参见 [Sysrepo 错误代码](https://sysrepo.org/static/doc/html/group__errors.html)。 --- #### 示例代码 以下是一个完整的 C 语言示例,展示如何使用 `sr_oper_get_items_subscribe` 进行订阅以及编写相应的回调函数。 ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <libyang/libyang.h> #include <sysrepo/sysrepo.h> // 定义回调函数原型 static int oper_get_items_callback(sr_session_ctx_t *session, uint32_t subscription_id, const char *module_name, const char *path, const char *request_xpath, uint32_t request_id, lyd_node **parent, void *private_data); int main(int argc, char **argv) { sr_conn_ctx_t *connection = NULL; sr_session_ctx_t *session = NULL; // 初始化连接到 sysrepo if (sr_connect("example_app", SR_CONN_DEFAULT, &connection) != SR_ERR_OK) { fprintf(stderr, "Error by connecting to sysrepo.\n"); return EXIT_FAILURE; } // 启动会话 if (sr_session_start(connection, SR_DS_OPERATIONAL, SR_SESS_DEFAULT, &session) != SR_ERR_OK) { fprintf(stderr, "Error by starting session.\n"); goto cleanup; } // 注册订阅者 if (sr_oper_get_items_subscribe(session, "ietf-interfaces", "/ietf-interfaces:interfaces-state/interface[name='eth0']", oper_get_items_callback, NULL, 0, 0) != SR_ERR_OK) { fprintf(stderr, "Error subscribing to operational data tree items.\n"); goto cleanup; } printf("Subscription successful. Waiting for requests...\n"); cleanup: sr_session_stop(session); sr_disconnect(connection); return EXIT_SUCCESS; } // 实现回调函数 static int oper_get_items_callback(sr_session_ctx_t *session, uint32_t subscription_id, const char *module_name, const char *path, const char *request_xpath, uint32_t request_id, lyd_node **parent, void *private_data) { printf("Callback triggered with path '%s'\n", path); // 构造响应数据 lyd_new_leaf(*parent, NULL, "name", "eth0"); lyd_new_leaf(*parent, NULL, "admin-status", "up"); return SR_ERR_OK; } ``` 上述代码展示了如何通过 `sr_oper_get_items_subscribe` 来订阅 `/ietf-interfaces:interfaces-state/interface[name='eth0']` 下的操作型数据,并提供了一个简单的回调函数来动态生成所需的内容。 --- #### 注意事项 1. 如果未正确初始化会话或连接,可能导致无法正常工作。 2. 回调函数应尽可能快速完成其任务,以免阻塞后续请求。 3. 对于复杂场景,建议仔细设计 XPath 和回调逻辑以满足需求。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值