出于相同目的,使用现有 .NET 程序集与命令行工具的优缺点
我在互联网上搜索过,似乎找不到与该主题相关的任何内容。我认为会有一些关于它的讨论。我就是找不到它。
基本上,我正在寻找的是使用现有的 .NET 程序集来执行(旧的)命令行可执行文件会执行的相同操作的充分理由。因此,如果我使用该程序集,我将包含它并开始在我的 C# 代码中使用它。对于我们旧的命令行工具,我会执行 Process.Start(...) 等等。
背景是:
我需要对传入和传出我们系统的文件执行 PGP 加密和解密。我当前的选择是使用命令行 GPG 工具 (http://www.gnupg.org/) 或 Bouncy Castle .NET 程序集。
有人问我为什么不在我的代码中“自动化”旧的 GPG 命令行工具。我想用一些智慧来回答这个问题。现在,我只能想到两个原因:
错误处理:我不仅应该能够使用 .NET 程序集获得更好的错误信息,而且还可以通过带有异常的 try/catch 等更好地处理它们。甚至根据需要滚动我自己的异常等。
代码可移植性:我使用 .NET 程序集构建的任何内容或多或少都是独立的。我不需要查找 GPG 可执行文件并将其复制到复制使用它编写的应用程序的每个位置。
性能:可能。我没有任何这方面的经验或数据。
如果您对此主题有任何意见,我将不胜感激。
I have searched the Internet and I can't seem to find anything related to this topic. I would think there would have been some discussion on it. I just can't find it.
Basically, what I'm looking for is good reasons to use an existing .NET assembly to do the same thing an (older) command-line executable would do. Therefore, if I used the assembly, I'd include it and begin using it in my C# code. To us the old command-line tool, I'd do a Process.Start(...)
and so forth.
Background on this is:
I have a requirement to perform PGP encryption and decryption on files transferred to and from our system. My current options are to use the command-line GPG tool (http://www.gnupg.org/) or the Bouncy Castle .NET assembly.
I have been asked why I don't just "automate" the old GPG command-line tool within my code. I'd like to answer this with some intelligence. Right now, I can only think of two reasons:
Error handling: I should be able to not only get better error information using the .NET assembly, but handle them better via the try/catch with exceptions, etc. I could even roll my own exceptions as needed, etc.
Code portability: Anything I build with the .NET assembly is more or less stand alone. I don't need to find and copy the GPG executable to each place I copy the application(s) I write using it.
Performance: Possibly. I don't have any experience or data regarding this.
I'd appreciate any input on this topic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
老实说,我会选择 .NET 程序集,因为与启动新进程相比,它似乎是一个更简单的解决方案,也是一个包含更紧密的解决方案。我有这种感觉的一些原因如下:
这些只是我脑海中的一些想法。我希望这有帮助。如果您有疑问,请告诉我,我将详细说明我的答案。祝你好运!!
Honestly, I would go with the .NET assembly as it seems to be a simpler solution and a more tightly contained solution than launching a new process. Some of the reasons I feel that way are as follows:
Those are just some thoughts off the top of my head. I hope this helps. If you have questions, let me know and I'll elaborate my answers. Good luck!!
如果可能的话,我个人会使用 .Net 程序集而不是命令行工具。
优点:
异常< /代码>,
事件
...等)I personally would use a .Net assembly instead of a command-line tool when possible.
Pros:
Exceptions
,events
...etc.)我同意 1、2 和 3。为每个加密/解密启动一个新进程肯定比在进程中执行它更昂贵。如果您需要同时执行多个加密/解密,这变得更加重要,阅读您的问题我希望您这样做。
另外,有64位版本的命令行工具吗?这可能会遭到反对。
I agree with 1, 2, and 3. Starting a new process for each encrypt/decrypt is definitely more expensive than performing it in process. This get even more crucial if you need to perform multiple encrypt/decrypt concurrently, which reading your question I expect you do.
In addition, is there a 64 bit version of the command line tool? This may be an argument against.
做起来比较简单。你的三件物品中的两件都回到了这一点。
第三种可能是正确的,因为需要运行的进程较少,并且不需要在它们之间进行通信;或者错误的,因为可执行文件恰好比程序集提供了更好的性能,并且超过了这种效果。
但简单性会带来很多好处,并且它会不断给予(您可能需要支持这个应用程序一段时间)。可能还有其他一些可以想到的“优点”最终归结为这一点。
确实,当某件事变得更简单(而且确实更简单,而不是过度简单的诱惑,从长远来看最终会变得更加复杂)时,你需要一些真正令人信服的反驳论点来权衡这一点。
It's simpler to do. Two of your three items all come back to this.
The third is possibly true, because there's less processes to have going and no need to communicate between them, or false because the executable happens to give much better performance than the assembly and that out-weighs this effect.
But simplicity buys a hell of a lot, and it keeps on giving (you may have to support this application for some time). Probably there are a good few other "pros" that can be thought of that come down to this in the end.
Really, when something is simpler (and really simpler, rather than the siren-call of the over-simple that ends up being more complicated in the long-run), you need some really compelling counter-arguments to out-weigh that.