public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
    {
        try
        {
            //Determine if the record exists in Azure Storage
            // Retrieve the storage account from the connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(SettingsKeyInfoProvider.GetValue("Custom.AzureStorageConnectionString"));

            // Create the table client.
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            // Create the CloudTable object that represents the "kenticousers" table.
            CloudTable table = tableClient.GetTableReference("kenticousers");

            // Create a retrieve operation that takes a customer entity.
            TableOperation retrieveOperation = TableOperation.Retrieve<KenticoUserEntity>(ValidationHelper.GetString(infoObj["UserGUID"], ""), ValidationHelper.GetString(infoObj["LastName"], ""));

            // Execute the operation.
            TableResult retrievedResult = table.Execute(retrieveOperation);

            // Assign the result to a CustomerEntity object.
            KenticoUserEntity existinguser = (KenticoUserEntity)retrievedResult.Result;

            //Check if the record already exists
            if (existinguser == null)
            {
                // create a new record
                KenticoUserEntity newuser = new KenticoUserEntity(ValidationHelper.GetString(infoObj["UserGUID"], ""), ValidationHelper.GetString(infoObj["LastName"], ""));
                newuser.firstname = ValidationHelper.GetString(infoObj["FirstName"], "");
                newuser.lastname = ValidationHelper.GetString(infoObj["LastName"], "");
                newuser.email = ValidationHelper.GetString(infoObj["Email"], "");

                // Create the Insert TableOperation
                TableOperation insertOperation = TableOperation.Insert(newuser);

                // Execute the operation.
                table.Execute(insertOperation);

                EventLogProvider.LogEvent("I", "CustomIntegrationConnector", "Information", "Record inserted!");
            }
            else
            {
                //update the record
                existinguser.firstname = ValidationHelper.GetString(infoObj["FirstName"], "");
                existinguser.lastname = ValidationHelper.GetString(infoObj["LastName"], "");
                existinguser.email = ValidationHelper.GetString(infoObj["Email"], "");

                // Create the Update TableOperation
                TableOperation updateOperation = TableOperation.Replace(existinguser);

                // Execute the operation.
                table.Execute(updateOperation);

                EventLogProvider.LogEvent("I", "CustomIntegrationConnector", "Information", "Record updated!");
            }

            //Set the error message to null and the response to OK
            errorMessage = null;
            return IntegrationProcessResultEnum.OK;
        }
        catch (Exception ex)
        {
            //There was a problem.
            errorMessage = ex.Message;
            return IntegrationProcessResultEnum.ErrorAndSkip;
        }
    }
Esempio n. 2
0
    public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
    {
        try
        {
            //Determine if the record exists in Azure Storage
            // Retrieve the storage account from the connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(SettingsKeyInfoProvider.GetValue("Custom.AzureStorageConnectionString"));

            // Create the table client.
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            // Create the CloudTable object that represents the "kenticousers" table.
            CloudTable table = tableClient.GetTableReference("kenticousers");

            // Create a retrieve operation that takes a customer entity.
            TableOperation retrieveOperation = TableOperation.Retrieve <KenticoUserEntity>(ValidationHelper.GetString(infoObj["UserGUID"], ""), ValidationHelper.GetString(infoObj["LastName"], ""));

            // Execute the operation.
            TableResult retrievedResult = table.Execute(retrieveOperation);

            // Assign the result to a CustomerEntity object.
            KenticoUserEntity existinguser = (KenticoUserEntity)retrievedResult.Result;

            //Check if the record already exists
            if (existinguser == null)
            {
                // create a new record
                KenticoUserEntity newuser = new KenticoUserEntity(ValidationHelper.GetString(infoObj["UserGUID"], ""), ValidationHelper.GetString(infoObj["LastName"], ""));
                newuser.firstname = ValidationHelper.GetString(infoObj["FirstName"], "");
                newuser.lastname  = ValidationHelper.GetString(infoObj["LastName"], "");
                newuser.email     = ValidationHelper.GetString(infoObj["Email"], "");

                // Create the Insert TableOperation
                TableOperation insertOperation = TableOperation.Insert(newuser);

                // Execute the operation.
                table.Execute(insertOperation);

                EventLogProvider.LogEvent("I", "CustomIntegrationConnector", "Information", "Record inserted!");
            }
            else
            {
                //update the record
                existinguser.firstname = ValidationHelper.GetString(infoObj["FirstName"], "");
                existinguser.lastname  = ValidationHelper.GetString(infoObj["LastName"], "");
                existinguser.email     = ValidationHelper.GetString(infoObj["Email"], "");

                // Create the Update TableOperation
                TableOperation updateOperation = TableOperation.Replace(existinguser);

                // Execute the operation.
                table.Execute(updateOperation);

                EventLogProvider.LogEvent("I", "CustomIntegrationConnector", "Information", "Record updated!");
            }

            //Set the error message to null and the response to OK
            errorMessage = null;
            return(IntegrationProcessResultEnum.OK);
        }
        catch (Exception ex)
        {
            //There was a problem.
            errorMessage = ex.Message;
            return(IntegrationProcessResultEnum.ErrorAndSkip);
        }
    }