Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("server should create a monitored item (CreateMonitoredItems)", function (done) {
// CreateMonitoredItemsRequest
var request = new subscription_service.CreateMonitoredItemsRequest({
subscriptionId: subscriptionId,
timestampsToReturn: read_service.TimestampsToReturn.Both,
itemsToCreate: [
{
itemToMonitor: {
nodeId: ec.makeNodeId(VariableIds.Server_ServerStatus_CurrentTime)
},
monitoringMode: subscription_service.MonitoringMode.Sampling,
requestedParameters: {
clientHandle: 26,
samplingInterval: 100,
filter: null,
queueSize: 100,
discardOldest: true
}
}
ClientMonitoredItemBase._toolbox_monitor = function (subscription, timestampsToReturn, monitoredItems, done) {
assert(_.isFunction(done));
const itemsToCreate = [];
for (let i = 0; i < monitoredItems.length; i++) {
const monitoredItem = monitoredItems[i];
const itemToCreate = monitoredItem._prepare_for_monitoring(done);
if (_.isString(itemToCreate.error)) {
return done(new Error(itemToCreate.error));
}
itemsToCreate.push(itemToCreate);
}
const createMonitorItemsRequest = new subscription_service.CreateMonitoredItemsRequest({
subscriptionId: subscription.subscriptionId,
timestampsToReturn: timestampsToReturn,
itemsToCreate: itemsToCreate
});
assert(subscription.session);
subscription.session.createMonitoredItems(createMonitorItemsRequest, function (err, response) {
/* istanbul ignore next */
if (err) {
//xx console.log("ClientMonitoredItemBase#_toolbox_monitor: ERROR in createMonitoredItems ".red, err.message);
//xx console.log("ClientMonitoredItemBase#_toolbox_monitor: ERROR in createMonitoredItems ".red, err);
//xx console.log(createMonitorItemsRequest.toString());
} else {
assert(response instanceof subscription_service.CreateMonitoredItemsResponse);
assert(test === subscription);
// re-create monitored items
const itemsToCreate = [];
_.forEach(monitoredItems_old, function (monitoredItem /*, clientHandle*/) {
assert(monitoredItem.monitoringParameters.clientHandle > 0);
itemsToCreate.push({
itemToMonitor: monitoredItem.itemToMonitor,
monitoringMode: monitoredItem.monitoringMode,
requestedParameters: monitoredItem.monitoringParameters
});
});
const createMonitorItemsRequest = new subscription_service.CreateMonitoredItemsRequest({
subscriptionId: subscription.subscriptionId,
timestampsToReturn: TimestampsToReturn.Both, // self.timestampsToReturn,
itemsToCreate: itemsToCreate
});
subscription.session.createMonitoredItems(createMonitorItemsRequest, function (err, response) {
if (!err) {
assert(response instanceof subscription_service.CreateMonitoredItemsResponse);
const monitoredItemResults = response.results;
monitoredItemResults.forEach(function (monitoredItemResult, index) {
const clientHandle = itemsToCreate[index].requestedParameters.clientHandle;
const monitoredItem = subscription.monitoredItems[clientHandle];
monitoredItems: ClientMonitoredItemBase[],
done: ErrorCallback
) {
assert(_.isFunction(done));
const itemsToCreate: MonitoredItemCreateRequestOptions[] = [];
for (const monitoredItem of monitoredItems) {
const monitoredItemI = monitoredItem as ClientMonitoredItemImpl;
const itemToCreate = monitoredItemI._prepare_for_monitoring();
if (_.isString(itemToCreate.error)) {
return done(new Error(itemToCreate.error));
}
itemsToCreate.push(itemToCreate as MonitoredItemCreateRequestOptions);
}
const createMonitorItemsRequest = new CreateMonitoredItemsRequest({
itemsToCreate,
subscriptionId: subscription.subscriptionId,
timestampsToReturn,
});
const session = subscription.session as ClientSessionImpl;
assert(session,
"expecting a valid session attached to the subscription ");
session.createMonitoredItems(
createMonitorItemsRequest,
(err?: Error | null, response?: CreateMonitoredItemsResponse) => {
/* istanbul ignore next */
if (err) {
debugLog(chalk.red("ClientMonitoredItemBase#_toolbox_monitor: ERROR in createMonitoredItems "));
} else {