The client can get existing classifications for items and reclassify them if the items are a certain age or the content has changed since the classifications were made. Or the client can classify content that has not been classified before. Although you can do these tasks with two calls to the CCS service, the following example shows how it can be done with a single call.
For the case of 'classifying if necessary', the client code is almost the same as for retrieving the classifications. Change the action to ‘MayAnalyze’, and indicate that the content identifier can be used to access the content.
classifyArgs.AnalyzeDataAction = CCS.AnalyzeDataActionType.MayAnalyze; item.CanAccessContent = true;
Because you have extended the request, the processing is now more complex:
The URL exists in the CCS, and there are classifications.
The URL exists in the CCS, but no classifications matched.
The URL is not found in the cache or the classifications are no longer valid. The CCS retrieves and classifies the data.
Errors can occur in multiple places in this process. For example, there may be a failure to access the data. The full list of errors is in CCS API Error Codes chapter.
The full code example is as follows:
// Create the proxy class that connects to the remote service.
CCS.CCSClassifyClient proxyClassify = new CCS.CCSClassifyClient();
// Create the arguments object and set options
CCS.ClassificationArgs classifyArgs = new CCS.ClassificationArgs();
// Set the locale if required
classifyArgs.Locale = "en-gb";
// Set action so to classify if required
classifyArgs.AnalyzeDataAction = CCS.AnalyzeDataActionType.MayAnalyze;
// Should the CCS timeout and return early if it doesn't have result
classifyArgs. TimeOutMilliseconds = 0;
// We may not always want to know the classification results
classifyArgs.ReturnClassifications = true;
// Is the data passed by reference or included in this object
classifyArgs.DataLocation = CCS.DataLocationType.Reference;
// Add identifier
CCS.ContentIdentifierList itemList = new CCS.ContentIdentifierList();
CCS.ContentIdentifier item = new CCS.ContentIdentifier();
item.IdentifierType = CCS.ContentIdentifierType.URL;
item.Identifier = "http://myserver.com/Shared Documents/important.doc";
item.CanAccessContent = true;
item.CanRetrieveLastModifiedDate = false;
item.DoNotCacheIdentifier = false;
itemList.Add(item);
// Add the item list to the args object
classifyArgs.IdentifierList = itemList;
// Call the classifier
CCS.ClassifyResult csResult = proxyClassify.Classify(classifyArgs);
// Process the results
Console.WriteLine("Severity: {0} ErrorCode: {1} = {2}",
csResult.Severity.ToString(), csResult.ErrorCode.ToString(),
csResult.ErrorMessage);
if (csResult.ErrorCode.Equals(0))
{
// Process the classifications
foreach (var classItem in csResult. Classifications)
{
Console.WriteLine("ClassificationID: {0}", classItem.ClassificationID);
}
}
// The proxy instance can be used for multiple calls but should
// be closed when no longer required.
proxyClassify.Close();
|
Copyright © 2015 CA Technologies.
All rights reserved.
|
|