c#SDK使用多个对象初始化一个接口

时间:2018-06-22 08:05:38

标签: c# wpf

我目前正在开发基于c# SDK COM库的应用程序,由于我有多个设备要控制,因此任何人都可以建议如何基于一个库对多个对象进行编程:

我现在正在做什么:

private libraryOpenInterface _libraryOI1;
private libraryOpenInterface _libraryOI2;
private libraryOpenInterface _libraryOI3;
private libraryOpenInterface _libraryOI4;

我需要使用不同的登录帐户与每个接口链接,我有20多种设备,我认为有更好的方法来实现此目的:

_libraryOI1.connect ( 192.168.1.1, admin,admin);
_libraryOI2.connect ( 192.168.1.2, admin,admin);
_libraryOI3.connect ( 192.168.1.3, admin,admin);
_libraryOI4.connect ( 192.168.1.4, admin,admin);

1 个答案:

答案 0 :(得分:0)

首先,您需要存储登录信息:在某些配置中的IP,用户,密码.. ZipInputStream zipInputStream = new ZipInputStream(inputStream); ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { modelFolderName = <somefoldername> modelFileName = <somefilename> String FILE_STORAGE_LOCATION = env.getProperty("workspacePath"); File folder = new File(FILE_STORAGE_LOCATION + "/" + modelFolderName ); if(!folder.exists()) { folder.mkdirs(); } try (FileOutputStream fout=new FileOutputStream(FILE_STORAGE_LOCATION + "/" + modelFolderName + "/" + modelFileName)) { try (BufferedInputStream in = new BufferedInputStream(zipInputStream)) { byte[] buffer = new byte[8096]; while (true) { int count = in.read(buffer); if (count == -1) { break; } fout.write(buffer, 0, count); } } } zipEntry = zipInputStream.getNextEntry(); } ,或者看起来更像app.config或其他任何东西。密码。

秘密代码应类似于:

database

我仍然不明白为什么您在同一接口中有多个实例!请解释一下那部分

如果您确实真的希望每个private libraryOpenInterface m_LibraryOI1; private IEnumrable<DeviceCredentialsModel> getDevicesCredentials() { #get from db of configuration } void connectToAllDevices() { var devices = getDevicesCredentials(); foreach(device in devices) { var encryptedPassword = device.password; var decryptedPassword = ...decrypt; m_LibraryOI1.connect(device.ip, v.user, decryptedPassword); } } 都使用单独的Connector Service,那么您还需要使用某种工厂:

machine