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;
        }
    }
 /// <summary>
 /// Transforms given external object to internal (to TreeNode or GeneralizedInfo).
 /// </summary>
 /// <param name="obj">Object or document to transform</param>
 /// <param name="taskType">Type of task</param>
 /// <param name="dataType">Type of input data</param>
 /// <param name="siteName">Name of site</param>
 public override ICMSObject PrepareInternalObject(object obj, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName)
 {
     // This method is called withing IntegrationHelper.ProcessExternalTask and it provides you with space where you can easily transform
     // external object (possibly some kind of data container) to TreeNode (document) or GeneralizedInfo (object - eg. UserInfo)
     return(null);
 }
    /// <summary>
    /// Processes given object according to task type.
    /// It is expected that you use TranslateColumnsToExternal method before you process the task.
    /// The TranslateColumnsToExternal needs GetExternalObjectID and GetExternalDocumentID to be implemented.
    /// It traverses the given object and tries to translate foreign keys to match external (your) application.
    /// </summary>
    /// <param name="infoObj">Info object to process</param>
    /// <param name="translations">Translation helper object containing translations for given object</param>
    /// <param name="taskType">Type of task</param>
    /// <param name="dataType">Type of data</param>
    /// <param name="siteName">Name of site</param>
    /// <param name="errorMessage">Possible error message</param>
    /// <returns>Result of processing</returns>
    public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
    {
        try
        {
            // If object is of 'user' type
            // You can also use following condition: (((BaseInfo)infoObj) is CMS.SiteProvider.UserInfo)
            if (infoObj.ObjectType == PredefinedObjectType.USER)
            {
                bool log = false;
                // Create simple message
                string message = "User with username '" + infoObj.ObjectCodeName + "' has been";
                switch (taskType)
                {
                case TaskTypeEnum.CreateObject:
                    log      = true;
                    message += " created.";
                    break;

                case TaskTypeEnum.UpdateObject:
                    log      = true;
                    message += " updated.";
                    break;

                case TaskTypeEnum.DeleteObject:
                    log      = true;
                    message += " deleted.";
                    break;
                }
                if (log)
                {
                    EventLogProvider eventLog = new EventLogProvider();
                    // Log the message
                    eventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, ConnectorName, taskType.ToString(), 0, null, 0, null, null, message, 0, null);
                }
            }
            errorMessage = null;
            return(IntegrationProcessResultEnum.OK);
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
            return(IntegrationProcessResultEnum.Error);
        }
        finally
        {
            // Clear translations cached during TranslateColumnsToExternal which internally calls GetExternalObjectID, GetExternalDocumentID
            // This call is optional but recommended in the case where eg. collision of code names can occur
            ClearInternalTranslations();
        }
    }
    /// <summary>
    /// Processes given document according to task type.
    /// It is expected that you use TranslateColumnsToExternal method before you process the task.
    /// The TranslateColumnsToExternal needs GetExternalObjectID and GetExternalDocumentID to be implemented.
    /// It traverses the given object and tries to translate foreign keys to match external (your) application.
    /// </summary>
    /// <param name="node">Document to process</param>
    /// <param name="translations">Translation helper object containing translations for given document</param>
    /// <param name="taskType">Type of task</param>
    /// <param name="dataType">Type of data</param>
    /// <param name="siteName">Name of site</param>
    /// <param name="errorMessage">Possible error message</param>
    /// <returns>Result of processing</returns>
    public override IntegrationProcessResultEnum ProcessInternalTaskAsync(TreeNode node, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
    {
        try
        {
            bool log = false;
            // Create simple message
            string message = "Document named '" + node.NodeName + "' located at '" + node.NodeAliasPath + "' has been";
            switch (taskType)
            {
            case TaskTypeEnum.CreateDocument:
                log      = true;
                message += " created.";
                break;

            case TaskTypeEnum.UpdateDocument:
                log      = true;
                message += " updated.";
                break;

            case TaskTypeEnum.DeleteDocument:
                log      = true;
                message += " deleted.";
                break;
            }
            if (log)
            {
                EventLogProvider eventLog = new EventLogProvider();
                // Log the message
                eventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, ConnectorName, taskType.ToString(), 0, null, node.NodeID, node.DocumentName, null, message, node.NodeSiteID, null);
            }
            errorMessage = null;
            return(IntegrationProcessResultEnum.OK);
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
            return(IntegrationProcessResultEnum.Error);
        }
        finally
        {
            // Clear translations cached during TranslateColumnsToExternal which internally calls GetExternalObjectID, GetExternalDocumentID
            // This call is optional but recommended in the case where eg. collision of code names can occur
            ClearInternalTranslations();
        }
    }
    /// <summary>
    /// Processes given document according to task type.
    /// It is expected that you use TranslateColumnsToExternal method before you process the task.
    /// The TranslateColumnsToExternal needs GetExternalObjectID and GetExternalDocumentID to be implemented.
    /// It traverses the given object and tries to translate foreign keys to match external (your) application.
    /// </summary>
    /// <param name="node">Document to process</param>
    /// <param name="translations">Translation helper object containing translations for given document</param>
    /// <param name="taskType">Type of task</param>
    /// <param name="dataType">Type of data</param>
    /// <param name="siteName">Name of site</param>
    /// <param name="errorMessage">Possible error message</param>
    /// <returns>Result of processing</returns>
    public override IntegrationProcessResultEnum ProcessInternalTaskAsync(TreeNode node, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
    {
        try
        {
            bool log = false;
            // Create simple message
            string message = "Document named '" + node.NodeName + "' located at '" + node.NodeAliasPath + "' has been";
            switch (taskType)
            {
                case TaskTypeEnum.CreateDocument:
                    log = true;
                    message += " created.";
                    break;

                case TaskTypeEnum.UpdateDocument:
                    log = true;
                    message += " updated.";
                    break;

                case TaskTypeEnum.DeleteDocument:
                    log = true;
                    message += " deleted.";
                    break;
            }
            if (log)
            {
                EventLogProvider eventLog = new EventLogProvider();
                // Log the message
                eventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, ConnectorName, taskType.ToString(), 0, null, node.NodeID, node.DocumentName, null, message, node.NodeSiteID, null);
            }
            errorMessage = null;
            return IntegrationProcessResultEnum.OK;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
            return IntegrationProcessResultEnum.Error;
        }
        finally
        {
            // Clear translations cached during TranslateColumnsToExternal which internally calls GetExternalObjectID, GetExternalDocumentID
            // This call is optional but recommended in the case where eg. collision of code names can occur
            ClearInternalTranslations();
        }
    }
    /// <summary>
    /// Processes given object according to task type.
    /// It is expected that you use TranslateColumnsToExternal method before you process the task.
    /// The TranslateColumnsToExternal needs GetExternalObjectID and GetExternalDocumentID to be implemented.
    /// It traverses the given object and tries to translate foreign keys to match external (your) application.
    /// </summary>
    /// <param name="infoObj">Info object to process</param>
    /// <param name="translations">Translation helper object containing translations for given object</param>
    /// <param name="taskType">Type of task</param>
    /// <param name="dataType">Type of data</param>
    /// <param name="siteName">Name of site</param>
    /// <param name="errorMessage">Possible error message</param>
    /// <returns>Result of processing</returns>
    public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
    {
        try
        {
            // If object is of 'user' type
            // You can also use following condition: (((BaseInfo)infoObj) is CMS.SiteProvider.UserInfo)
            if (infoObj.ObjectType == PredefinedObjectType.USER)
            {
                bool log = false;
                // Create simple message
                string message = "User with username '" + infoObj.ObjectCodeName + "' has been";
                switch (taskType)
                {
                    case TaskTypeEnum.CreateObject:
                        log = true;
                        message += " created.";
                        break;

                    case TaskTypeEnum.UpdateObject:
                        log = true;
                        message += " updated.";
                        break;

                    case TaskTypeEnum.DeleteObject:
                        log = true;
                        message += " deleted.";
                        break;
                }
                if (log)
                {
                    EventLogProvider eventLog = new EventLogProvider();
                    // Log the message
                    eventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, ConnectorName, taskType.ToString(), 0, null, 0, null, null, message, 0, null);
                }
            }
            errorMessage = null;
            return IntegrationProcessResultEnum.OK;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
            return IntegrationProcessResultEnum.Error;
        }
        finally
        {
            // Clear translations cached during TranslateColumnsToExternal which internally calls GetExternalObjectID, GetExternalDocumentID
            // This call is optional but recommended in the case where eg. collision of code names can occur
            ClearInternalTranslations();
        }
    }
 /// <summary>
 /// Transforms given external object to internal (to TreeNode or GeneralizedInfo).
 /// </summary>
 /// <param name="obj">Object or document to transform</param>
 /// <param name="taskType">Type of task</param>
 /// <param name="dataType">Type of input data</param>
 /// <param name="siteName">Name of site</param>
 public override ICMSObject PrepareInternalObject(object obj, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName)
 {
     // This method is called withing IntegrationHelper.ProcessExternalTask and it provides you with space where you can easily transform
     // external object (possibly some kind of data container) to TreeNode (document) or GeneralizedInfo (object - eg. UserInfo)
     return null;
 }
Exemplo n.º 8
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);
        }
    }