示例#1
0
        private void ConvertSaveActions(SCItem form, string tracking, SCItem buttonItem, bool saveToDatabaseActionCreated)
        {
            var formSaveActionField = form.Fields
                                      .FirstOrDefault(field => field.FieldId == new Guid(FormConstants.FormSaveActionFieldId));
            var formSaveActions = formSaveActionField?.Value;

            if (!string.IsNullOrEmpty(formSaveActions))
            {
                var saveActionElements            = XmlHelper.GetXmlElementNodeList(XmlHelper.GetXmlElementNode(formSaveActions, "g").InnerXml, "li");
                List <SaveAction> saveActionItems = new List <SaveAction>();
                if (saveActionElements != null)
                {
                    foreach (XmlNode saveActionElement in saveActionElements)
                    {
                        if (saveActionElement.Attributes != null)
                        {
                            var saveAction = new SaveAction()
                            {
                                Id         = saveActionElement.Attributes["id"].Value,
                                UnicId     = saveActionElement.Attributes["unicid"].Value,
                                Parameters = XmlHelper.GetXmlElementValue(saveActionElement.InnerXml, "parameters")
                            };
                            saveActionItems.Add(saveAction);
                        }
                    }

                    foreach (var saveActionItem in saveActionItems)
                    {
                        if (saveActionItem.Id == FormConstants.FormSaveAction_RegisterCampaignValue)
                        {
                            var trackingCampaign       = XmlHelper.GetXmlElementNodeList(tracking, "campaign");
                            var xmlAttributeCollection = trackingCampaign[0].Attributes;
                            if (xmlAttributeCollection != null)
                            {
                                var trackingCampaignId = trackingCampaign.Count > 0 ? xmlAttributeCollection["id"]?.Value : null;
                                if (trackingCampaignId != null)
                                {
                                    if (!_appSettings.enableReferencedItemCheck || _destMasterRepository.ItemExists(new Guid(trackingCampaignId)))
                                    {
                                        // Create Trigger Campaign Activity Save Action
                                        var triggerCampaignActivityValues = new Dictionary <Guid, string>();
                                        triggerCampaignActivityValues.Add(new Guid(SubmitActionConstants.SubmitActionFieldId),
                                                                          SubmitActionConstants.SubmitActionField_TriggerCampaignActivityActionValue);
                                        triggerCampaignActivityValues.Add(new Guid(SubmitActionConstants.ParametersFieldId),
                                                                          string.Format("{{\"referenceId\":\"{0}\"}}", trackingCampaignId));
                                        ConvertFieldsToSubmitActionItem("Trigger Campaign Activity", triggerCampaignActivityValues, buttonItem);
                                    }
                                }
                            }
                        }
                        else if (!saveToDatabaseActionCreated && saveActionItem.Id == FormConstants.FormSaveAction_SaveToDatabaseValue)
                        {
                            ConvertSaveDataAction(form, buttonItem);
                        }
                        else
                        {
                            // Convert other save actions if mapped in AppSettings.json
                            var submitAction =
                                _appSettings.submitActions.FirstOrDefault(s => s.sourceSaveActionId == Guid.Parse(saveActionItem.Id));

                            if (submitAction != null)
                            {
                                IFieldConverter converter          = IoC.CreateInstance(submitAction.destParametersConverterType);
                                var             submitActionValues = new Dictionary <Guid, string>();
                                submitActionValues.Add(new Guid(SubmitActionConstants.SubmitActionFieldId),
                                                       submitAction.destSubmitActionFieldValue);
                                try
                                {
                                    submitActionValues.Add(new Guid(SubmitActionConstants.ParametersFieldId),
                                                           converter.ConvertValue(
                                                               HttpUtility.HtmlDecode((saveActionItem.Parameters.Replace("&amp;", "&")))));
                                }
                                catch (Exception ex)
                                {
                                    _logger.Log(new LogEntry(LoggingEventType.Error,
                                                             string.Format("SubmitConverter - Failed to parse Xml value of Parameters field of Submit Action. FormID = {0} - FieldID = {1} - FieldValue = {2}",
                                                                           form.ID, formSaveActionField.Id, saveActionItem.Parameters), ex));
                                }

                                var destSubmitActionItemId = ConvertFieldsToSubmitActionItem(submitAction.destSubmitActionItemName, submitActionValues, buttonItem);

                                // Only if Save Action is Send Email
                                if (submitAction.sourceSaveActionId == Guid.Parse(FormConstants.FormSaveAction_SendEmailValue))
                                {
                                    CreateAddressBookSender(destSubmitActionItemId);
                                }
                            }
                            else
                            {
                                _analysisReporter.AddUnmappedSaveAction(formSaveActionField, form.ID, Guid.Parse(saveActionItem.Id));
                            }
                        }
                    }
                }
            }
        }