重新应用 FilterDefinition

发布于 2024-10-18 17:56:45 字数 1051 浏览 1 评论 0原文

我有一个应用程序,它对系统的配电进行建模,如果某些组件出现故障,则路由会自动重新路由。我通过添加一个连接实体来对此进行建模,该连接实体具有父组件的 ID 和子组件的 ID。这个想法是,对于可能失败的项目,有一个用于正常工作条件的连接,另一个用于每个失败情况的连接。例如,如果有 40 个组件,其中 9 个可能会发生故障,那么每个组件有 2^9 (512) 个可能的故障和 2^9 个连接实体。每个连接都根据它所代表的故障模式来命名。

到目前为止,一切都很好,非常灵活并且有效。

然而,每次加载总线图时,都会加载所有连接,从而导致 40 * 512 (20480) 个连接实体,而当前故障模式只需要 40 个连接实体,毫不奇怪,这会导致应用程序占用资源并运行慢慢地。

因此,我定义了一个 FilterDefinition 来限制加载到所需命名连接(如果组件属于特定类型)和普通连接(如果组件是任何其他类型)的连接,并将其添加到启用了过滤器的组件的连接集合映射中设置参数。

public FailureModeFilter()
{
    WithName("FailureName")
        .WithCondition("((Name = :name and ObjectType <> 8) or 
                         (Name = 'Normal' and ObjectType = 8))")
        .AddParameter("name", NHibernateUtil.String);
}

毫不奇怪,这种方法有效。

但是,你知道会有一个障碍,不是吗?

但是,当选择新的故障模式并重新加载图表时,它不会应用新的过滤器,而是保留旧的过滤器。我尝试设置新参数,禁用过滤器,再次启用它并设置参数,但均无济于事。

那么,我做错了什么/没有做/误解(如适用,删除),或者如果失败,有什么关于如何解决这个问题的建议吗?

图表打开时正在使用相同的会话。是的,我知道这不是建议的最佳实践,但出于其他原因,它是应用程序这部分的最佳解决方案。请不要岔开话题,告诉我这是一种糟糕的做法,因为我已经知道,这种做法会带来厄运、沮丧和沮丧。问题是关于更换过滤器。

I have an application which models the electrical distribution of a system whereby if certain of the components fail the routing is automatically rerouted. I've modelled this by adding a connection entity that has an ID to the parent component and an ID to the child component. The idea is that for the items that may fail there is a connection for the normal working condition and another connection for each failed situation. For example, if there are 40 components of which 9 may fail then I have 2^9 (512) possible failures and 2^9 connection entities for each component. Each connection is named for the failure mode that it represents.

So far, so good, very flexible and works.

However, every time that the bus diagram is loaded all the connections are loaded resulting in 40 * 512 (20480) connection entities when only 40 are needed for the current failure mode and, not surprisingly, this is causing the application to hog resources and run slowly.

So, I have defined a FilterDefinition to restrict the connections loaded to the required named connection if the component is of a particular type and the normal connection if it is any other type and added this to the connections collection mapping of the component enabled the filter and set the parameter.

public FailureModeFilter()
{
    WithName("FailureName")
        .WithCondition("((Name = :name and ObjectType <> 8) or 
                         (Name = 'Normal' and ObjectType = 8))")
        .AddParameter("name", NHibernateUtil.String);
}

And not at all surprisingly, this works.

But, and you knew there was going to be a snag didn't you?

But, when a new failure mode is chosen and the diagram reloaded, it doesn't apply the new filter but retains the old one. I've tried setting the new parameter, disabling the filter, enabling it again and setting the pararmeter all to no avail.

So, what am I doing wrong/failing to do/misunderstanding (delete as applicable) or, failing that, any suggestions as to how to solve this?

The same session is being used while the diagram is open. Yes, I know that isn't the suggested best practise, but for other reasons it is the best solution for this part of the application. Please don't get side-tracked about this telling me about how this is bad practise with doom, gloom and depondency as I already know. The question is about the changing of the filter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

写给空气的情书 2024-10-25 17:56:45

回答了我自己的问题以进行更改。

这个答案是刷新组件以强制从数据库重新加载。

session.Refresh(entity);

当你弄清楚时就这么简单!

Answered my own question for a change.

This answer is to refresh the component to force a reload from the database.

session.Refresh(entity);

So simple when you figure it out!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文