예제 #1
0
        /// <summary>
        /// Map the information sent back by Campaign into a format which can be saved as a file to disk.
        /// </summary>
        /// <param name="requestHandler">Request handler, which can be used if further information from Campaign is required for the mapping.</param>
        /// <param name="rawQueryResponse">Raw response from Campaign.</param>
        /// <returns>Class containing file content and metadata</returns>
        public override Template ParseQueryResponse(IRequestHandler requestHandler, string rawQueryResponse)
        {
            var doc = new XmlDocument();

            doc.LoadXml(rawQueryResponse);

            var metadata = new TemplateMetadata
            {
                Schema = InternalName.Parse(IncludeView.EntitySchema),
                Name   = new InternalName(null, doc.DocumentElement.Attributes["name"].InnerText),
                Label  = doc.DocumentElement.Attributes["label"].InnerText,
            };

            var folderInternalName = doc.DocumentElement.SelectSingleNode("folder").Attributes["name"].InnerText;

            metadata.AdditionalProperties.Add(AdditionalData_Folder, folderInternalName);

            var visibleAttribute = doc.DocumentElement.Attributes["visible"];

            if (visibleAttribute != null)
            {
                metadata.AdditionalProperties.Add(AdditionalData_Visible, (visibleAttribute.InnerText == "1").ToString());
            }

            var textCodeNode = doc.DocumentElement.SelectSingleNode("source/text");
            var rawTextCode  = textCodeNode == null
                          ? string.Empty
                          : textCodeNode.InnerText;

            var htmlCodeNode = doc.DocumentElement.SelectSingleNode("source/html");
            var rawHtmlCode  = htmlCodeNode == null
                          ? string.Empty
                          : htmlCodeNode.InnerText;

            var dependOnFormat          = false;
            var dependOnFormatAttribute = doc.DocumentElement.SelectSingleNode("source/@dependOnFormat");

            if (dependOnFormatAttribute != null)
            {
                dependOnFormat = dependOnFormatAttribute.InnerText == "true";
            }

            var rawCode = dependOnFormat
                ? string.Concat(rawTextCode, Environment.NewLine, Environment.NewLine, FormatSeparator, Environment.NewLine, Environment.NewLine, rawHtmlCode)
                : rawTextCode;

            return(new Template
            {
                Code = rawCode,
                Metadata = metadata,
                FileExtension = FileTypes.Jssp,
            });
        }
예제 #2
0
        /// <summary>
        /// Map the information sent back by Campaign into a format which can be saved as a file to disk.
        /// </summary>
        /// <param name="requestHandler">Request handler, which can be used if further information from Campaign is required for the mapping.</param>
        /// <param name="rawQueryResponse">Raw response from Campaign.</param>
        /// <returns>Class containing file content and metadata</returns>
        public override Template ParseQueryResponse(IRequestHandler requestHandler, string rawQueryResponse)
        {
            var doc = new XmlDocument();

            doc.LoadXml(rawQueryResponse);

            var metadata = new TemplateMetadata
            {
                Schema = InternalName.Parse(Schema),
                Name   = new InternalName(null, doc.DocumentElement.Attributes["name"].InnerText),
            };

            var option = new Option
            {
                DataType    = (DataType)int.Parse(doc.DocumentElement.Attributes["dataType"].InnerText),
                StringValue = doc.DocumentElement.Attributes["stringValue"].InnerText,
                MemoValue   = doc.DocumentElement.SelectSingleNode("memoValue").InnerText,
            };

            long longValue;

            if (long.TryParse(doc.DocumentElement.Attributes["longValue"].InnerText, out longValue))
            {
                option.LongValue = longValue;
            }

            double doubleValue;

            if (double.TryParse(doc.DocumentElement.Attributes["doubleValue"].InnerText, out doubleValue))
            {
                option.DoubleValue = doubleValue;
            }

            DateTime timeStampValue;

            if (DateTime.TryParse(doc.DocumentElement.Attributes["timeStampValue"].InnerText, out timeStampValue))
            {
                option.TimeStampValue = timeStampValue;
            }

            metadata.AdditionalProperties.Add(AdditionalData_DataType, option.DataType.ToString());
            return(new Template
            {
                Code = Convert.ToString(option.GetValue()),
                Metadata = metadata,
                FileExtension = FileTypes.Jssp,
            });
        }
        public void TemplateMetadataReader_GeTags_ReturnsTagsWithDefaultValues()
        {
            var sut = new TemplateMetadataReader(new List <ITemplateSource> {
                new GitTemplateSource()
            });

            var metadata = new TemplateMetadata
            {
                Tags = new List <Tag>
                {
                    new Tag {
                        Key = "text1", DefaultValue = "abc"
                    },
                    new Tag {
                        Key = "text2", DefaultValue = "xyz"
                    },
                    new Tag {
                        Key = "dropdown", DefaultValue = "option1", Options = new string[] { "option1", "option2" }
                    }
                },
                ConditionalTags = new List <ConditionalTag>
                {
                    new ConditionalTag {
                        Key = "cond1", DefaultValue = true
                    },
                    new ConditionalTag {
                        Key = "cond2", DefaultValue = false
                    }
                },
                ComputedTags = new List <ComputedTag>
                {
                    new ComputedTag {
                        Key = "computed1", Expression = "cond1 || cond2"
                    }
                }
            };

            var result = sut.GetTags(metadata);

            Assert.AreEqual(3, result.Count);
            Assert.AreEqual("abc", result["text1"]);
            Assert.AreEqual("xyz", result["text2"]);
            Assert.AreEqual("option1", result["dropdown"]);
        }
        public void TemplateMetadataReader_GetFilesToExclude_ReturnsFilesToExcludeString()
        {
            var sut = new TemplateMetadataReader(new List <ITemplateSource> {
                new GitTemplateSource()
            });

            var metadata = new TemplateMetadata
            {
                ConditionalTags = new List <ConditionalTag>
                {
                    new ConditionalTag {
                        Key = "cond1", DefaultValue = true, FilesToInclude = "cond1_file"
                    },
                    new ConditionalTag {
                        Key = "cond2", DefaultValue = false, FilesToInclude = "cond2_file1,cond2_file2"
                    }
                },
                ComputedTags = new List <ComputedTag>
                {
                    new ComputedTag {
                        Key = "computed1", Expression = "!cond1 && !cond2", FilesToInclude = "computed1_file"
                    }
                }
            };

            var result = sut.GetFilesToExclude(metadata, new Dictionary <string, bool> {
                { "cond1", true }
            });

            Assert.AreEqual("cond2_file1,cond2_file2,computed1_file", result);

            result = sut.GetFilesToExclude(metadata, new Dictionary <string, bool> {
                { "cond1", false }, { "cond2", true }
            });
            Assert.AreEqual("cond1_file,computed1_file", result);

            result = sut.GetFilesToExclude(metadata, new Dictionary <string, bool> {
                { "cond1", false }, { "cond2", false }, { "computed1", true }
            });
            Assert.AreEqual("cond1_file,cond2_file1,cond2_file2", result);
        }
예제 #5
0
            /// <summary>
            /// Tries to load the root element from the provided edmxDocument
            /// </summary>
            private bool TryLoadRootElementFromEdmx(XElement edmxDocument, SchemaConstants schemaConstants, string sectionName, string rootElementName, out XElement rootElement)
            {
                rootElement = null;

                XNamespace edmxNs    = schemaConstants.EdmxNamespace;
                XNamespace sectionNs = GetNamespace(schemaConstants);

                XElement runtime = edmxDocument.Element(edmxNs + "Runtime");

                if (runtime == null)
                {
                    return(false);
                }

                XElement section = runtime.Element(edmxNs + sectionName);

                if (section == null)
                {
                    return(false);
                }

                string templateVersion;

                if (!TemplateMetadata.TryGetValue(MetadataConstants.TT_TEMPLATE_VERSION, out templateVersion))
                {
                    templateVersion = MetadataConstants.DEFAULT_TEMPLATE_VERSION;
                }

                if (schemaConstants.MinimumTemplateVersion > new Version(templateVersion))
                {
                    _textTransformation.Errors.Add(new CompilerError(
                                                       _textTransformation.Host.TemplateFile ?? CodeGenerationTools.GetResourceString("Template_CurrentlyRunningTemplate"), 0, 0, string.Empty,
                                                       CodeGenerationTools.GetResourceString("Template_UnsupportedSchema"))
                    {
                        IsWarning = true
                    });
                }

                rootElement = section.Element(sectionNs + rootElementName);
                return(rootElement != null);
            }
예제 #6
0
        /// <summary>
        /// Map the information sent back by Campaign into a format which can be saved as a file to disk.
        /// </summary>
        /// <param name="requestHandler">Request handler, which can be used if further information from Campaign is required for the mapping.</param>
        /// <param name="rawQueryResponse">Raw response from Campaign.</param>
        /// <returns>Class containing file content and metadata</returns>
        public override Template ParseQueryResponse(IRequestHandler requestHandler, string rawQueryResponse)
        {
            var doc = new XmlDocument();

            doc.LoadXml(rawQueryResponse);

            var metadata = new TemplateMetadata
            {
                Schema = InternalName.Parse(Schema),
                Name   = new InternalName(null, doc.DocumentElement.Attributes["name"].InnerText),
                Label  = doc.DocumentElement.Attributes["label"].InnerText,
            };

            doc.DocumentElement.RemoveAllAttributesExcept(_attributesToKeep);

            return(new Template
            {
                Code = doc.DocumentElement.OuterXml,
                Metadata = metadata,
                FileExtension = FileTypes.Xml,
            });
        }
        public void TemplateMetadataReader_GetComputedTags_ReturnsValidTags()
        {
            var sut = new TemplateMetadataReader(new List <ITemplateSource> {
                new GitTemplateSource()
            });

            var metadata = new TemplateMetadata
            {
                ConditionalTags = new List <ConditionalTag>
                {
                    new ConditionalTag {
                        Key = "cond1", DefaultValue = true
                    },
                    new ConditionalTag {
                        Key = "cond2", DefaultValue = false
                    }
                },
                ComputedTags = new List <ComputedTag>
                {
                    new ComputedTag {
                        Key = "computed1", Expression = "cond1 || cond2"
                    },
                    new ComputedTag {
                        Key = "computed2", Expression = "cond1 && cond2"
                    }
                }
            };

            var result1 = sut.GetComputedTags(metadata, new Dictionary <string, object> {
                { "cond1", false }, { "cond2", true }
            });
            var result2 = sut.GetComputedTags(metadata, new Dictionary <string, object> {
                { "cond1", true }, { "cond2", true }
            });

            Assert.AreEqual(2, result1.Count);
            Assert.AreEqual(2, result2.Count);
        }
예제 #8
0
        /// <summary>
        /// Format metadata sent from Campaign into a format in which it can be stored locally in a file on disk.
        /// </summary>
        /// <param name="metadata">Metadata</param>
        /// <returns>String representation of the metadata</returns>
        public string Format(TemplateMetadata metadata)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }

            var items = new Dictionary <string, string> {
                { "Schema", metadata.Schema.ToString() },
                { "Name", metadata.Name.ToString() },
            };

            if (!string.IsNullOrEmpty(metadata.Label))
            {
                items.Add("Label", metadata.Label);
            }

            foreach (var item in metadata.AdditionalProperties.Where(i => !items.ContainsKey(i.Key)))
            {
                items.Add(item.Key, item.Value);
            }

            return(string.Format("Adobe Campaign metadata:{0}{1}", Environment.NewLine, string.Join(Environment.NewLine, items.Select(i => string.Format("{0}: {1}", i.Key, i.Value)))));
        }
예제 #9
0
 public RoslynMergeConfig(TemplateMetadata templateMetadata, params ITemplateMigration[] migrations)
 {
     TemplateMetadata = templateMetadata;
     Migrations       = migrations;
 }
예제 #10
0
        private IEnumerable<KeyValuePair<InputType, string>> BuildProjectMetadataProperties(TemplateMetadata metadata)
        {
            var fieldIds = new List<KeyValuePair<InputType, string>>();

            if (metadata.Tags != null)
            {
                foreach (var tag in metadata.Tags)
                {
                    string name = tag.Key;
                    RemoveExistingProperty(name);

                    if (tag.Options?.Length > 0)
                    {
                        fieldIds.Add(KeyValuePair.Create(InputType.Dropdown, name));

                        if (!string.IsNullOrEmpty(tag.DefaultValue) && !tag.Options.Any(x => x == tag.DefaultValue))
                            tag.Options = tag.Options.Append(tag.DefaultValue).ToArray();

                        var prop = AddProperty(name, tag.DefaultValue ?? tag.Options.First())
                          .WithAttribute(new DropdownListAttribute
                          {
                              Label = tag.Name,
                              Placeholder = tag.Description,
                              Options = tag.Options.Select(x => KeyValuePair.Create(x, x)).ToArray()
                          });
                    }
                    else if (tag.RadioOptions?.Length > 0)
                    {
                        fieldIds.Add(KeyValuePair.Create(InputType.Radio, name));

                        if (!string.IsNullOrEmpty(tag.DefaultValue) && !tag.RadioOptions.Any(x => x == tag.DefaultValue))
                            tag.RadioOptions = tag.RadioOptions.Append(tag.DefaultValue).ToArray();

                        var prop = AddProperty(name, tag.DefaultValue ?? tag.RadioOptions.First())
                          .WithAttribute(new RadioGroupAttribute
                          {
                              Label = tag.Name,
                              Options = tag.RadioOptions.Select(x => KeyValuePair.Create(x, x)).ToArray()
                          });
                    }
                    else
                    {
                        fieldIds.Add(KeyValuePair.Create(InputType.Text, name));

                        var prop = AddProperty(name, tag.DefaultValue)
                           .WithAttribute(new TextFieldAttribute
                           {
                               Label = tag.Name,
                               Placeholder = tag.Description
                           });

                        if (tag.IsRequired)
                            prop.WithRequiredValidation();

                        if (!string.IsNullOrEmpty(tag.ValidationRegex))
                            prop.WithPatternValidation(tag.ValidationRegex, tag.ValidationError);
                    }

                    RegisterPropertyAttributes(name);
                }
            }

            return fieldIds;
        }