This works for me... This is some code I've started working on, at the moment it only gets all DNs for a switch.
public class GenCfg : IDisposable {
private ConfService cServ;
private ConfServerProtocol cProt;
private EventBrokerService ebs;
public GenCfg(string genServer, int genPort, string appName, string user, string pass) {
this.cProt = new ConfServerProtocol(new Endpoint("CRGM",genServer,genPort));
this.cProt.ClientName = appName;
this.cProt.UserName = user;
this.cProt.UserPassword = pass;
this.cProt.Open();
this.ebs = new EventBrokerService(this.cProt);
this.ebs.Activate();
this.cServ = ConfServiceFactory.CreateConfService(this.cProt);
this.ebs.Register(this.cServ);
}
public Collection<CfgDN> GetAllDNs(string switchName) {
CfgSwitchQuery sq = new CfgSwitchQuery();
sq.Name = switchName;
CfgSwitch sw = this.cServ.RetrieveObject<CfgSwitch>(sq);
if (sw == null) { throw new Exception("Switch not found"); }
CfgDNQuery dq = new CfgDNQuery();
dq.DnType = CfgDNType.CFGACDPosition;
dq.State = CfgObjectState.CFGEnabled;
dq.SwitchDbid = sw.DBID;
return this.cServ.RetrieveMultipleObjects<CfgDN>(dq);
}
public void Close() {
if (this.cProt != null) { this.cProt.Close(); }
this.cProt = null;
this.cServ = null;
this.ebs = null;
}
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing) {
if(disposing) {
this.Close();
}
}
}