Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Can anyone help me understand why this below would not remove named cals. It seems to work fine until the very last line where it does the save. I don't get any exceptions or error messages.
When i look in QV Management console under System>Licenses i still see the ones that were supposed to be removed (Named user CALs)
Client Build Number: 11.20.13314.0
QMSClient Client;
string QMS = "http://localhost:4799/QMS/Service";
Client = new QMSClient("BasicHttpBinding_IQMS", QMS);
string key = Client.GetTimeLimitedServiceKey();
ServiceKeyClientMessageInspector.ServiceKey = key;
List<ServiceInfo> MyQVS = Client.GetServices(ServiceTypes.QlikViewServer);
Client.ClearQVSCache(QVSCacheObjects.All);
CALConfiguration myCALs = Client.GetCALConfiguration(MyQVS[0].ID, CALConfigurationScope.NamedCALs);
List<AssignedNamedCAL> currentNamedCALs = myCALs.NamedCALs.AssignedCALs.ToList();
List<int> indexToRemove = new List<int>();
int cnt = 1;
for (int i = 0; i < currentNamedCALs.Count; i++)
{
if ((currentNamedCALs.QuarantinedUntil < System.DateTime.Now)
&& (currentNamedCALs.LastUsed < DateTime.Now.AddDays(daysFromToday)))
{
Console.WriteLine("[" + cnt + "] " + currentNamedCALs.UserName +
"; Last used: " + currentNamedCALs.LastUsed);
indexToRemove.Add(i);
cnt++;
}
}
Console.WriteLine();
for (int i = indexToRemove.Count; i > 0; i--)
{
if (currentNamedCALs[indexToRemove[i - 1]] != null)
{
currentNamedCALs.RemoveAt(indexToRemove[i - 1]);
}
}
Console.WriteLine("\nDone");
myCALs.NamedCALs.AssignedCALs = currentNamedCALs;
Client.SaveCALConfiguration(myCALs);
With QV11.20 SR13 the API was changed. Since them removed CALs has to be added to the RemovedAssignedCALs List:
QMSClient Client;
string QMS = "http://localhost:4799/QMS/Service";
Client = new QMSClient("BasicHttpBinding_IQMS", QMS);
string key = Client.GetTimeLimitedServiceKey();
ServiceKeyClientMessageInspector.ServiceKey = key;
List<ServiceInfo> MyQVS = Client.GetServices(ServiceTypes.QlikViewServer);
Client.ClearQVSCache(QVSCacheObjects.All);
CALConfiguration myCALs = Client.GetCALConfiguration(MyQVS[0].ID, CALConfigurationScope.NamedCALs);
List<AssignedNamedCAL> currentNamedCALs = myCALs.NamedCALs.AssignedCALs.ToList();
List<AssignedNamedCAL> removedCALs = new List<AssignedNamedCAL>();
List<int> indexToRemove = new List<int>();
int cnt = 1;
for (int i = 0; i < currentNamedCALs.Count; i++)
{
if ((currentNamedCALs.QuarantinedUntil < System.DateTime.Now)
&& (currentNamedCALs.LastUsed < DateTime.Now.AddDays(daysFromToday)))
{
Console.WriteLine("[" + cnt + "] " + currentNamedCALs.UserName +
"; Last used: " + currentNamedCALs.LastUsed);
indexToRemove.Add(i);
cnt++;
}
}
Console.WriteLine();
for (int i = indexToRemove.Count; i > 0; i--)
{
if (currentNamedCALs[indexToRemove[i - 1]] != null)
{
removedCALs.Add(currentNamedCALs[indexToRemove[i - 1]]);
currentNamedCALs.RemoveAt(indexToRemove[i - 1]);
}
}
Console.WriteLine("\nDone");
myCALs.NamedCALs.AssignedCALs = currentNamedCALs.ToArray();
myCALs.NamedCALs.RemovedAssignedCALs = removedCALs.ToArray();
Client.SaveCALConfiguration(myCALs);
That makes sense but when on this line:
myCALs.NamedCALs.RemovedAssignedCALs = removedCALs.ToArray();
i get this message:
'CALConfiguration.CALConfigurationNamedCALs' does not contain a definition for 'RemovedAssignedCALs' and no extension method 'RemovedAssignedCALs' accepting a first argument of type 'CALConfiguration.CALConfigurationNamedCALs' could be found (are you missing a using directive or an assembly reference?)
Any idea why
Sorry, maybe it was my mistake. It seems the change of the API came with SR15 (with I work) and not SR13, but I don't know exactly. But then your code should work.
have you try it also without an conversion to array:
myCALs.NamedCALs.RemovedAssignedCALs = removedCALs;
?
RemovedAssignedCALs does not exist for me at all.
But i did try myCALs.NamedCALs.AssignedCALs = currentNamedCALs; both with and without the conversion to array.
I tried with Service Reference/QMSAPIService being both Array (like in your code) and System.Collections.Generic.List (like in my original code) I was getting same behavior.
Moving this to a different forum location.
(replying as proxy for the original poster)
Thanks, this appears to correct the original issue using SR15 server and regenerated web service client code (very important). I am begging you for the sanity of your customers, update the document (as well as the provided sample code) at the following linked URL, maybe notating the api change and what SR started requiring the additional code:
QlikView Management API - #3 Export / Add / Delete Named CALs