我的Firefox扩展和C#code在同一台机器上运行之间用什么方法IPC?我的、方法、在同一、机器上

2023-09-03 02:12:29 作者:夜风§来兮

我有一个关于如何构建一个(新的)Firefox扩展和现有的C#code之间的通讯问题。

I have a question about how to structure communication between a (new) Firefox extension and existing C# code.

Firefox扩展将使用配置数据,并会产生其他数据,因此需要从什么地方得到的配置数据并保存其输出的地方。数据产生/由现有的C#code消耗,所以我需要决定如何扩展应与C#code交互。

The firefox extension will use configuration data and will produce other data, so needs to get the config data from somewhere and save it's output somewhere. The data is produced/consumed by existing C# code, so I need to decide how the extension should interact with the C# code.

一些相关的因素:

这只是在Windows上运行,在一个相对可控的企业环境。 在我的机器上运行Windows服务,以C#。 在本地数据存储(如SQLite的)存储数据将是其他原因很有用。 数据量低时,例如uncom $ P $的10KB pssed XML每隔几分钟,而且也不是很健谈。 的数据交换可以是异步的大部分如果不是完全。 对于所有的项目,我有限的资源,因此希望有一个选项,那是比较容易的。 它并不必须是超高性能,但是不应该添加显著开销。 在我计划建设中的JavaScript扩展(尽管可以相信否则,如果真的有必要)

有些选项我考虑:

使用的XPCOM到.NET / COM桥。 使用一个SQLite数据库:扩展将读取并保存到它。在C#code将在服务运行,填充数据库,然后处理由该服务创建的数据。 使用TCP套接字的扩展和服务之间的通信。让服务管理本地数据存储。

我的问题(1)是我认为这将是棘手的,不是那么容易的。但我可能是完全错误的?我与(2)看到的主要问题是的SQLite的锁定:只有一个进程可以一次写入数据,因此会出现一些阻塞。然而,这将是很好通常有一个本地数据存储,所以这是一个有吸引力的选择,如果对性能的影响不是太大。我不知道是不是(3)将特别容易还是难...或者承担协议何种方法:定制的东西或HTTP

My problem with (1) is I think this will be tricky and not so easy. But I could be completely wrong? The main problem I see with (2) is the locking of sqlite: only a single process can write data at a time so there'd be some blocking. However, it would be nice generally to have a local datastore so this is an attractive option if the performance impact isn't too great. I don't know whether (3) would be particularly easy or hard ... or what approach to take on the protocol: something custom or http.

这些想法或其他任何建议,意见?

Any comments on these ideas or other suggestions?

更新:我正计划建立扩展的JavaScript,而不是C ++

UPDATE: I was planning on building the extension in javascript rather than c++

推荐答案

我选择的选项是#2:使用一个SQLite数据库。主要优点是:

The option I selected was #2: use a sqlite db. Main advantages being:

在可能的JavaScript来实现 在使用的SQLite数据库可用于其他原因 在异步通信提高性能:C#code能够缓存的Firefox扩展需要的所有信息,而不必prepare它点播。 FF的扩展能够保存所有数据传回的SQLite数据库,而不是需要它采用C#code马上处理。 在单独的层提供了一个很好的测试点,如:它可能需要一个测试工具,工作跨越FF和C#的运行只有FF code和验证SQLite中预期的结果,而不是。

显然,其中有些是场景相关的,所以我绝对不会说这是最好的通用选项FF分机和C#服务之间的通信。

Clearly some of these are scenario-dependant, so I would definitely not say this is the best general-purpose option for communication between FF extn and C# service.

更新:我们使用的只是一个SQLite数据库开始了,当时就想一定的同步沟通,后来从被调用的FF扩展的C#窗口服务暴露HTTP Web服务。此Web服务现在由FF扩展和其他浏览器扩展既消耗。真的很高兴,这是一个Web服务,它可以很容易在不同的语言不同的应用程序消耗。

UPDATE: We used just a sqlite db initially, and then wanted some synchronous communication so later exposed an http web service from the C# windows service that is called by the FF extension. This web service is now consumed by both the FF extension and other browser extensions. It's nice that it's a web service as it makes it easy to consume by different apps in different languages.