English 中文(简体)
修改 C# 既与司机合作,又不与司机合作
原标题:Modifying C# code to work both with and without device drivers

目前,Im公司正在实施一项方案,该方案可以与我们的客户可能或无法购买的外围设备互动。 这一装置是痛苦的线索;我们从购买该装置的公司想要我们的客户使用公司自己可以起诉的装置司机。

然而,由于并非所有客户都将购买这一装置,因此,如果他们总是不得不经营第二批可起诉的软件,就是有益的。 为了做到这一点,我需要修改我们的方案,与司机一起工作,不与司机合作。

主动X控制被用于与装置接口。 需要利用Windows Form Designer将这些控制放在地盘上;手工操作使得它容易坠毁,令人痛心。

Is there any "best" way that one could set up a program to detect missing drivers and avoid crashing? The only ideas that I have thought of are:

  1. Instantiate the controls manually and use try/catch statements to detect and handle missing drivers, but I don t think that this solution is feasible.
  2. Create 2 versions of each form that may use the device. This is a poor idea because it would require careful copying when changes are made on one version of the form.
最佳回答

通常,在类似情况下,最佳选择是使用法学院或调适者模式,通常与工厂结合使用。

建立支持现有装置的接口,然后实施两个接口,一个是功能性的,另一个是没有功能的。

Then each UI which uses it will call a factory to create the instance object (one of the two choices above as needed) and query that to object via the interface to show controls or surface functionality.

金融情报股的其余部分将保持不变,不需要在两个地点维持。

问题回答

My method would be to determine driver or no on startup (install would be an option if the the device cannot be added later).

之后,你设立了“全球变量”(我的目的是为这种类型的应用价值建立一个单一州),说明是否有司机。 然后,你可以根据这一价值是真实的还是虚假的来推断该守则。

What I don t understand is why the User Interface is tied to the driver being present. You should be able to shape the data for the presentation layer deeper in the stack and avoid "the UI blows up when the driver isn t present". You may still need some logic specific to "the driver data is present", but that is fairly easy to handle without worrying about walking a minefield.

System.Management.SelectQuery("Win32_SystemDriver");




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签