1. Home
  2. Workflow & Automation
  3. Windows Services
  4. Updating the AM Process List Using a Windows Service

Updating the AM Process List Using a Windows Service

This article will describe how the windows service maintains the automated email process list. To learn how to create and publish automated emails, please refer to this article. Everything in this article depends on a service using the trellispark generic windows service template. To learn how to create your own generic service, please refer to this article.

There is no configuration for this part of the service. It will maintain the Email Managers for each workspace automatically.

The first step is to get the list of Email Managers that exist in the database.

 ExecuteSQL tSQLCommand = new(myDB);
 AutomatedMessaging messaging = new(myDB);
 ExecuteSQLInformation tSQLCommandData = new()
 {
     SessionGUID = userData.SessionGUID,
     UserGUID = userData.UserGUID
 };

 XElement result = await ExecuteTSQL(userData, ServiceGUID, "GI_ListAllEmailManagers", myDB);

All following code is iterated for each Email Manager. The next step is to retrieve the Email Manager information from the database and retrieve its’ target list.

 Instance myInstance = new(myDB);

 InstanceInformation mailSequencedata = new()
 {
     SessionGUID = userData.SessionGUID,
     UserGUID = userData.UserGUID,
     InstanceGUID = manager.GetElementGUID("InstanceGUID"),
     Check = false,
     FormGeneration = false
 };
 await myInstance.ReadInstance(mailSequencedata, true);

 XElement mailSequenceXML = XElement.Parse(mailSequencedata.DataDB);

 XElement newTargetList = await messaging.GetTargetList(mailSequencedata);

If email targets are found, the service retrieves the list of initial emails from the mail sequence. For each email, it pulls a list of email addresses that have previously retrieved this email. Then for each email address that is in the current target list but not in the old target list, it queues the mail sequence.

 tSQLCommandData = new()
 {
     SessionGUID = tSQLCommandData.SessionGUID,
     UserGUID = tSQLCommandData.UserGUID,
     CommandName = "GI_ReadPreviousEmailTargets",
     CurrentInstanceGUID = Guid.Parse(initialEmail.Guid),
     NewSQLVersion = false,
     ReturnsDataset = true
 };
 await tSQLCommand.CallSQL(tSQLCommandData);
 
 if (tSQLCommandData.ErrorMessage == "")
 {
      XElement previousTargetList = XElement.Parse(tSQLCommandData.Result);
      List<string> emailAddresses = new();
      foreach (XElement User in newTargetList.Elements("Table"))
      {
           if (!previousTargetList.ToString().ToLower().Contains(
               User.GetElement("EmailAddress").ToLower()))
           {
                Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                Match match = regex.Match(User.GetElement("EmailAddress"));

                if (!emailAddresses.Contains(
                    User.GetElement("EmailAddress").ToUpper())&& match.Success)
                {
                     emailAddresses.Add(User.GetElement("EmailAddress").ToUpper());
                     await messaging.QueueMailSequence(myDB.UserGUID, User.GetElementGUID("UserGUID"), Guid.Empty, User.GetElement("EmailAddress"), Guid.Parse(initialEmail.Guid), false);
                }
           }
      }
 }
Updated on November 30, 2022

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support

Leave a Comment