Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var senddata = function () {
node.log('Saving data into Azure Table Storage :\n data: ' + entityClass.partitionKey + " - " + entityClass.rowKey + " - " + entityClass.data + " - " + entityClass.tableName);
// Create a message and send it to the Azure Table Storage
var entGen = Client.TableUtilities.entityGenerator;
node.log('creating entity...');
var entity = {
PartitionKey: entGen.String(entityClass.partitionKey),
RowKey: entGen.String(entityClass.rowKey),
data: entGen.String(JSON.stringify(entityClass.data)),
};
node.log('entity created successfully');
clientTableService.insertEntity(entityClass.tableName, entity, function(err, result, response) {
node.log('trying to insert');
if (err) {
node.error('Error while trying to save data:' + err.toString());
setStatus(statusEnum.error);
} else {
node.log('data saved.');
setStatus(statusEnum.sent);
node.send('data saved.');
const getEdmValue = (entityValue) => {
return entityValue.$ === azure.TableUtilities.EdmType.INT64
? Number(entityValue._)
: entityValue._;
}
function BasicAzureTableSamples() {
entityGen = storage.TableUtilities.entityGenerator;
storageClient = storage.createTableService(config.connectionString);
tableName = "Customers" + guid.v1().replace(/-/g, '');
return scenarios = [
{
action: basicTableOperations,
message: 'Azure Table Basic Sample\n'
}
];
}
if (!this._storageAccountName) {
throw new Error('Storage account name required');
}
const storageAccountKey = options.key;
if (!storageAccountKey) {
throw new Error('Storage account key required');
}
this._prefix = options.prefix || '';
this._fixedPartitionKeyMapping = Object.assign(defaultFixedPartitionKeys(this._prefix), (options.metadataTypeToFixedPartitionKeyMapping || {}));
this._rowKeyPrefixMapping = Object.assign(defaultRowKeyPrefixes(), (options.metadataTypeToRowKeyPrefixMapping || {}));
this._typeToEncryptedColumnsMapping = Object.assign(defaultEncryptionColumns(), (options.metadataTypeToEncryptedColumnsMapping || {}));
this._typeToEncryptionOptions = new Map();
this._encryptionOptions = options.encryption;
try {
this._table = azure.createTableService(this._storageAccountName, storageAccountKey);
this._entityGenerator = azure.TableUtilities.entityGenerator;
} catch (storageAccountError) {
throw storageAccountError;
}
this._initializedTables = new Map();
}
/**
* @module botbuilder-azure
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { Storage, StoreItems, StoreItem } from 'botbuilder';
import * as azure from 'azure-storage';
import { flatten, unflatten } from 'flat';
import { Host } from './blobStorage';
const EntityGenerator = azure.TableUtilities.entityGenerator;
/**
* Additional settings for configuring an instance of `TableStorage`.
*/
export interface TableStorageSettings {
/**
* Name of the table to use for storage.
*
* @remarks
* Check table name rules: https://docs.microsoft.com/en-us/rest/api/storageservices/Understanding-the-Table-Service-Data-Model?redirectedfrom=MSDN#table-names
*/
tableName: string;
/** (Optional) storage access key. */
storageAccessKey?: string;
initialize(callback) {
const options = this._options || {};
let table = null;
try {
table = azure.createTableService(options.account, options.key);
} catch (storageAccountError) {
return callback(storageAccountError);
}
this._table = table;
this._entityGenerator = azure.TableUtilities.entityGenerator;
this._tableNamePrefix = options.prefix || '';
this._tableName = options.tableName || `${this._tableNamePrefix}${defaultTableName}`;
if (options.encryption) {
try {
configureTableEncryption(this, options);
} catch (encryptionInitializationError) {
return callback(encryptionInitializationError);
}
}
const tableClient = this._table;
if (options.throwIfTableMissing) {
tableClient.doesTableExist(this._tableName, (tableError, tableInfo) => {
function createBatches() {
var batches = [];
var entGen = azure.TableUtilities.entityGenerator
for (var batchIndex = 0; batchIndex < 20; batchIndex++) {
var batch = new azure.TableBatch()
var partitionKey = new Date().getTime().toString()
var rowKeySeed = new Date().getTime()
for (var index = 0; index < 99; index++) {
rowKeySeed++
var check = createPupilCheck(partitionKey, rowKeySeed.toString())
batch.insertEntity(check)
}
batches.push(batch)
}
return batches;
}
function mapUserAccessRightToEntity(projectId, right) {
const generator = azureStorage.TableUtilities.entityGenerator;
return {
PartitionKey: generator.String(right.userId.toLowerCase()),
RowKey: generator.String(projectId),
email: generator.String(right.email),
role: generator.String(right.role)
};
}
try {
entity = await getEntry(partitionKey, rowKey);
operation = 'replace';
} catch (error) {
context.log(error);
operation = 'insert';
}
if (operation === 'replace') {
newConnectionCount = parseInt(entity.Count._) + (eventGridEvent.eventType == 'Microsoft.SignalRService.ClientConnectionConnected' ? 1 : -1);
entity.Count._ = newConnectionCount;
await replaceEntity(entity);
token = false;
} else if (operation === 'insert') {
newConnectionCount = eventGridEvent.eventType == 'Microsoft.SignalRService.ClientConnectionConnected' ? 1 : 0;
let entryGen = azure.TableUtilities.entityGenerator;
entity = {
PartitionKey: entryGen.String(partitionKey),
RowKey: entryGen.String(rowKey),
Count: entryGen.Int32(newConnectionCount),
};
await insertEntity(entity);
token = false;
}
} catch (error) {
context.log(error);
}
}
if (eventGridEvent.eventType == 'Microsoft.SignalRService.ClientConnectionConnected') {
let message = new Map();
message.text = 'Welcome to Serverless Chat';
function mapProjectToEntity(project) {
const generator = azureStorage.TableUtilities.entityGenerator;
const projectId = project.projectId || project.id;
const labels = project.labels.join(',');
const entity = Object.assign(
{
PartitionKey: generator.String(projectId),
RowKey: generator.String(projectId),
},
project
);
entity.labels = generator.String(labels);
return entity;
}