Nested Dynamic Module Help

Posted by Community Admin on 04-Aug-2018 21:55

Nested Dynamic Module Help

All Replies

Posted by Community Admin on 19-Oct-2016 00:00

Hi Everyone. 

I am kind of at my wits end at the moment and need some advice.  We are maintaining a legacy site that someone developed in 7.3.  One functionality that does not quite work right is the ability to send communications to the users.  They call them alerts and notifications.  They are both nearly the same except for the way that they are displayed to the users.  This could be from a handful to tens of thousands (possibly over 120k).  So I am only showing code for alerts.

The way they did it (note the code below), is that they create an alert.  Then then loop through the user list passed in and create an AlertUser for each one and attach that to the parent.  Once the list gets long enough, it never finishes.  There is a global error handler that is supposed to log any errors and nothing is logged.

So I have two problems to solve.  The first and foremost is to find a way to make this work.  The second is to give the user some kind of progress indicator (we have been trying the RadProgressArea, but it disappears way before the process stops - we have a ticket opened on that).  The latter could be eliminated if the former is quick enough.
Any suggestions would be appreciated.

protected static readonly Type AlertType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.MyAlert.Alert");
protected static readonly Type AlertUserType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.MyAlert.Alertuser");
 
public void CreateAlert(string text
    , DateTime startTime
    , DateTime expirationTime
    , Dictionary<Guid, string> userList
    , RadProgressContext progressContext
    , HttpResponse response)
    var processed = new List<Guid>();
    // Set the provider name for the DynamicModuleManager here. All available providers are listed in
    // Administration -> Settings -> Advanced -> DynamicModules -> Providers
    var providerName = string.Empty;
    var dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
    dynamicModuleManager.Provider.SuppressSecurityChecks = true;
    try
    
        var alertItem = dynamicModuleManager.CreateDataItem(AlertType);
        // This is how values for the properties are set
        alertItem.SetValue("AlertText", text);
        alertItem.SetValue("AlertExpiration", expirationTime);
        alertItem.SetValue("AlertStartTime", startTime);
        alertItem.SetString("UrlName", alertItem.Id.ToString());
        alertItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
        alertItem.SetValue("PublicationDate", DateTime.UtcNow);
        alertItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft");
        foreach (var user in userList)
        
            // Make sure we are going to be running this twice on anyone.
            if (processed.Contains(user.Key)) continue;
            processed.Add(user.Key);
            // Was the cancel button clicked or was the browser closed?  If so, cancel the operation
            // This is how we add child items
            var alertuserItem = CreateAlertUser(alertItem.Id, user.Key, user.Value);
            if (alertuserItem != null) alertItem.AddChildItem(alertuserItem);
        
        // You need to call SaveChanges() in order for the items to be actually persisted to data store
        dynamicModuleManager.SaveChanges();
        // We can now call the following to publish the item
        var publishedAlertItem = dynamicModuleManager.Lifecycle.Publish(alertItem);
        //You need to set appropriate workflow status
        alertItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");
        // You need to call SaveChanges() in order for the items to be actually persisted to data store
        dynamicModuleManager.SaveChanges();
    
    finally
    
        dynamicModuleManager.Provider.SuppressSecurityChecks = false;
    
 
public DynamicContent CreateAlertUser(Guid parentId, Guid userId, string userName)
    var providerName = string.Empty;
    var dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
    try
    
        // Set the provider name for the DynamicModuleManager here. All available providers are listed in
        // Administration -> Settings -> Advanced -> DynamicModules -> Providers
        dynamicModuleManager.Provider.SuppressSecurityChecks = true;
        var alertuserItem = dynamicModuleManager.CreateDataItem(AlertUserType);
        // This is how values for the properties are set
        alertuserItem.SetValue("UserName", userName);
        alertuserItem.SetValue("AlertId", parentId);
        alertuserItem.SetValue("UserId", userId);
        alertuserItem.SetString("UrlName", alertuserItem.Id.ToString());
        alertuserItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
        alertuserItem.SetValue("PublicationDate", DateTime.UtcNow);
        alertuserItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft");
        // Set item parent
        alertuserItem.SetParent(parentId, AlertType.FullName);
        // You need to call SaveChanges() in order for the items to be actually persisted to data store
        dynamicModuleManager.SaveChanges();
        // We can now call the following to publish the item
        var publishedAlertuserItem = dynamicModuleManager.Lifecycle.Publish(alertuserItem);
        //You need to set appropriate workflow status
        alertuserItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");
        // You need to call SaveChanges() in order for the items to be actually persisted to data store
        dynamicModuleManager.SaveChanges();
        return alertuserItem;
    
    finally
    
        dynamicModuleManager.Provider.SuppressSecurityChecks = false;
    

This thread is closed