Example #1
0
 protected override string ProcessContent(string content, IStringTagModel tags)
 {
     tags = new TagModel {
         Inner = tags, File = this
     };
     return(base.ProcessContent(content, tags));
 }
Example #2
0
        public static string Parse(string input, IStringTagModel customTags)
        {
            StringBuilder result = new StringBuilder(input.Length);
            int           i      = 0;

            while (i < input.Length)
            {
                if (input [i] == '$')
                {
                    i++;
                    if (i >= input.Length ||  input[i] != '{')
                    {
                        result.Append('$');
                        continue;
                    }
                    i++;
                    int start = i;
                    while (i < input.Length && input [i] != '}')
                    {
                        i++;
                    }
                    string tag      = input.Substring(start, i - start);
                    string tagValue = Replace(tag, customTags) ?? "${" + tag + (i < input.Length ? "}" : "");
                    result.Append(tagValue);
                }
                else
                {
                    result.Append(input [i]);
                }
                i++;
            }
            return(result.ToString());
        }
Example #3
0
 internal override void SetProjectTagModel(IStringTagModel tagModel)
 {
     base.SetProjectTagModel(tagModel);
     foreach (FileDescriptionTemplate fdt in innerTemplate.Files)
     {
         fdt.SetProjectTagModel(tagModel);
     }
 }
Example #4
0
 protected override string ProcessContent(string content, IStringTagModel tags)
 {
     tags = new TagModel {
         InnerModels = new [] { tags, Outer.ProjectTagModel }, File = Outer
     };
     tagModel = tags;
     return(base.ProcessContent(content, tags));
 }
Example #5
0
        public static CombinedTagModel GetTagModel(IStringTagModel projectTagModel, SolutionFolderItem policyParent, Project project, string language, string identifier, string fileName)
        {
            var model = new CombinedTagModel {
                BaseModel = projectTagModel
            };

            FileTemplateTagsModifier.ModifyTags(policyParent, project, language, identifier, fileName, ref model.OverrideTags);
            return(model);
        }
        static string Replace(string tag, IStringTagModel customTags)
        {
            string tname, tformat;
            int    n = tag.IndexOf(':');

            if (n != -1)
            {
                tname   = tag.Substring(0, n);
                tformat = tag.Substring(n + 1);
            }
            else
            {
                tname   = tag;
                tformat = string.Empty;
            }

            tname = tname.ToUpperInvariant();
            object val = customTags.GetValue(tname);

            if (val != null)
            {
                return(FormatValue(val, tformat));
            }

            if (properties.ContainsKey(tname))
            {
                return(FormatValue(properties [tname], tformat));
            }

            GenerateString genString;

            if (stringGenerators.TryGetValue(tname, out genString))
            {
                return(genString(tname, tformat));
            }

            if (tformat.Length > 0)
            {
                switch (tname)
                {
                case "ENV":
                    foreach (DictionaryEntry variable in Environment.GetEnvironmentVariables())
                    {
                        if (string.Equals(variable.Key.ToString(), tformat, StringComparison.OrdinalIgnoreCase))
                        {
                            return(variable.Value.ToString());
                        }
                    }
                    break;

                case "PROPERTY":
                    return(PropertyService.Get <string> (tformat));
                }
            }
            return(null);
        }
            bool IsConditionTrue(IStringTagModel parameters)
            {
                string value = parameters.GetValue(Condition.ParameterName) as string;

                if (value != null)
                {
                    return(String.Equals(value, Condition.ParameterValue, StringComparison.OrdinalIgnoreCase));
                }
                return(false);
            }
		public static bool EvaluateCondition (IStringTagModel model, string condition)
		{
			if (string.IsNullOrWhiteSpace (condition))
				return true;

			condition = condition.Trim ();

			string parameter = GetNotConditionParameterName (condition);
			if (parameter != null) {
				return !model.GetBoolValue (parameter);
			}

			return model.GetBoolValue (condition);
		}
Example #9
0
		protected override string ProcessContent (string content, IStringTagModel tags)
		{
			using (var host = new FileTemplateHost (tags)) {
				string s = srcFile;
				string output;
				host.ProcessTemplate (s, content, ref s, out output);
				if (host.Errors.HasErrors) {
					foreach (var err in host.Errors)
						LoggingService.LogError ("Error in template generator: {0}", err.ToString());
					throw new Exception ("Failed to generate file");
				}
				return output;
			}
		}
			public string GetReplacementText (string input, IStringTagModel parameters)
			{
				if (IsConditionTrue (parameters)) {
					int start = Condition.End + 1;
					int end = GetTrueConditionEnd ();
					return input.Substring (start, end - start);
				} else if (ElseStatement != null) {
					int start = ElseStatement.End + 1;
					int end = EndIfStatement.Start;
					return input.Substring (start, end - start);
				}

				return String.Empty;
			}
		protected override string ProcessContent (string content, IStringTagModel tags)
		{
			using (var host = new FileTemplateHost (tags)) {
				string s = srcFile;
				string output;
				host.ProcessTemplate (s, content, ref s, out output);
				if (host.Errors.HasErrors) {
					foreach (var err in host.Errors)
						LoggingService.LogError ("Error in template generator: {0}", err.ToString());
					var firstError = host.Errors.OfType<CompilerError> ().First (f => !f.IsWarning);
					throw new Exception (GettextCatalog.GetString ("Failed to generate file: {0}", firstError.ErrorText));
				}
				return output;
			}
		}
		public static bool EvaluateCondition (IStringTagModel model, string condition)
		{
			// This logic is duplicated in the ProjectCreateInformation.ShouldCreate method.
			if (string.IsNullOrWhiteSpace (condition))
				return true;

			condition = condition.Trim ();

			string parameter = GetNotConditionParameterName (condition);
			if (parameter != null) {
				return !model.GetBoolValue (parameter);
			}

			return model.GetBoolValue (condition);
		}
Example #13
0
            public string GetReplacementText(string input, IStringTagModel parameters)
            {
                if (IsConditionTrue(parameters))
                {
                    int start = Condition.End + 1;
                    int end   = GetTrueConditionEnd();
                    return(input.Substring(start, end - start));
                }
                else if (ElseStatement != null)
                {
                    int start = ElseStatement.End + 1;
                    int end   = EndIfStatement.Start;
                    return(input.Substring(start, end - start));
                }

                return(String.Empty);
            }
Example #14
0
 protected override string ProcessContent(string content, IStringTagModel tags)
 {
     using (var host = new FileTemplateHost(tags)) {
         string s = srcFile;
         string output;
         host.ProcessTemplate(s, content, ref s, out output);
         if (host.Errors.HasErrors)
         {
             foreach (var err in host.Errors)
             {
                 LoggingService.LogError("Error in template generator: {0}", err.ToString());
             }
             throw new Exception("Failed to generate file");
         }
         return(output);
     }
 }
Example #15
0
 protected override string ProcessContent(string content, IStringTagModel tags)
 {
     using (var host = new FileTemplateHost(tags)) {
         string s = srcFile;
         string output;
         host.ProcessTemplate(s, content, ref s, out output);
         if (host.Errors.HasErrors)
         {
             foreach (var err in host.Errors)
             {
                 LoggingService.LogError("Error in template generator: {0}", err.ToString());
             }
             var firstError = host.Errors.OfType <CompilerError> ().First(f => !f.IsWarning);
             throw new Exception("Failed to generate file: " + firstError.ErrorText);
         }
         return(output);
     }
 }
        public static bool EvaluateCondition(IStringTagModel model, string condition)
        {
            if (string.IsNullOrWhiteSpace(condition))
            {
                return(true);
            }

            condition = condition.Trim();

            string parameter = GetNotConditionParameterName(condition);

            if (parameter != null)
            {
                return(!model.GetBoolValue(parameter));
            }

            return(model.GetBoolValue(condition));
        }
Example #17
0
        public static bool EvaluateCondition(IStringTagModel model, string condition)
        {
            // This logic is duplicated in the ProjectCreateInformation.ShouldCreate method.
            if (string.IsNullOrWhiteSpace(condition))
            {
                return(true);
            }

            condition = condition.Trim();

            string parameter = GetNotConditionParameterName(condition);

            if (parameter != null)
            {
                return(!model.GetBoolValue(parameter));
            }

            return(model.GetBoolValue(condition));
        }
        public static string Parse(string input, IStringTagModel customTags)
        {
            StringBuilder result = new StringBuilder(input.Length);
            int           brace;
            int           i = 0;

            while (i < input.Length)
            {
                if (input [i] == '$')
                {
                    i++;

                    if (i >= input.Length ||  (brace = OpenBraces.IndexOf(input[i])) == -1)
                    {
                        result.Append('$');
                        continue;
                    }

                    i++;
                    int start = i;
                    while (i < input.Length && input [i] != CloseBraces[brace])
                    {
                        i++;
                    }

                    string tag   = input.Substring(start, i - start);
                    char   close = CloseBraces[brace];
                    char   open  = OpenBraces[brace];

                    string tagValue = Replace(tag, customTags) ?? string.Format("${0}{1}{2}", open, tag, i < input.Length ? close.ToString() : "");
                    result.Append(tagValue);
                }
                else
                {
                    result.Append(input [i]);
                }
                i++;
            }
            return(result.ToString());
        }
        public static bool GetBoolValue(this IStringTagModel model, string name, bool defaultValue = false)
        {
            object value = model.GetValue(name);

            if (value is bool)
            {
                return((bool)value);
            }

            var stringValue = value as string;

            if (!string.IsNullOrEmpty(stringValue))
            {
                bool result;
                if (bool.TryParse(stringValue, out result))
                {
                    return(result);
                }
            }

            return(defaultValue);
        }
Example #20
0
        public static string Parse(string input, IStringTagModel parameters)
        {
            var builder = new StringBuilder(input.Length);

            int i = 0;

            while (i < input.Length)
            {
                char ch = input [i];
                if ('$' == ch)
                {
                    IfStatement ifStatement = FindIfStatement(input, i);
                    if (ifStatement != null)
                    {
                        string text = ifStatement.GetReplacementText(input, parameters)
                                      .Replace("$$", "$");
                        builder.Append(text);
                        i = ifStatement.EndIfStatement.End;
                    }
                    else if (IsEscaped(input, i))
                    {
                        builder.Append(ch);
                        i++;
                    }
                    else
                    {
                        builder.Append(ch);
                    }
                }
                else
                {
                    builder.Append(ch);
                }

                i++;
            }

            return(builder.ToString());
        }
		public static string Parse (string input, IStringTagModel parameters)
		{
			var builder = new StringBuilder (input.Length);

			int i = 0;

			while (i < input.Length) {

				char ch = input [i];
				if ('$' == ch) {
					IfStatement ifStatement = FindIfStatement (input, i);
					if (ifStatement != null) {
						string text = ifStatement.GetReplacementText (input, parameters)
							.Replace ("$$", "$");
						builder.Append (text);
						i = ifStatement.EndIfStatement.End;
					} else if (IsEscaped (input, i)) {
						builder.Append (ch);
						i++;
					} else {
						builder.Append (ch);
					}

				} else {
					builder.Append (ch);
				}

				i++;
			}

			return builder.ToString ();
		}
Example #22
0
 // FIXME: maybe these should be public/protected, not 100% happy committing to this API right now though
 // AddProjectTags is called before AddToProject, then called with null afterwards
 internal virtual void SetProjectTagModel(IStringTagModel tagModel)
 {
     ProjectTagModel = tagModel;
 }
		internal override void SetProjectTagModel (IStringTagModel tagModel)
		{
			base.SetProjectTagModel (tagModel);
			foreach (FileDescriptionTemplate fdt in innerTemplate.Files) {
				fdt.SetProjectTagModel (tagModel);
			}
		}
Example #24
0
		protected override string ProcessContent(string content, IStringTagModel tags)
		{
			tags = new TagModel { Inner = tags, File = this };
			return base.ProcessContent(content, tags);
		}
		public static CombinedTagModel GetTagModel (IStringTagModel projectTagModel, SolutionFolderItem policyParent, Project project, string language, string identifier, string fileName)
		{
			var model = new CombinedTagModel { BaseModel = projectTagModel };
			FileTemplateTagsModifier.ModifyTags (policyParent, project, language, identifier, fileName, ref model.OverrideTags);
			return model;
		}
 protected virtual string ProcessContent(string content, IStringTagModel tags)
 {
     return(StringParserService.Parse(content, tags));
 }
		// FIXME: maybe these should be public/protected, not 100% happy committing to this API right now though
		// AddProjectTags is called before AddToProject, then called with null afterwards
		internal virtual void SetProjectTagModel (IStringTagModel tagModel)
		{
			ProjectTagModel = tagModel;
		}
        public static IDictionary <string, string> Parse(IDictionary <string, string> input, IStringTagModel customTags)
        {
            Dictionary <string, string> res = new Dictionary <string, string> ();

            foreach (var e in input)
            {
                res [e.Key] = Parse(e.Value, customTags);
            }
            return(res);
        }
Example #29
0
 protected override string ProcessContent(string content, IStringTagModel tags)
 {
     return(content);
 }
Example #30
0
        public FileTemplateHost(IStringTagModel tags)
        {
            this.tags = tags;

            Refs.Add(typeof(FileTemplateHost).Assembly.Location);
        }
		protected override string ProcessContent (string content, IStringTagModel tags)
		{
			content = FileTemplateParser.Parse (content, tags);
			return base.ProcessContent (content, tags);
		}
		public FileTemplateHost (IStringTagModel tags)
		{
			this.tags = tags;

			Refs.Add (typeof (FileTemplateHost).Assembly.Location);
		}
			bool IsConditionTrue (IStringTagModel parameters)
			{
				string value = parameters.GetValue (Condition.ParameterName) as string;
				if (value != null) {
					return String.Equals (value, Condition.ParameterValue, StringComparison.OrdinalIgnoreCase);
				}
				return false;
			}
		protected virtual string ProcessContent (string content, IStringTagModel tags)
		{
			return StringParserService.Parse (content, tags);
		}
Example #35
0
 protected override string ProcessContent(string content, IStringTagModel tags)
 {
     content = FileTemplateParser.Parse(content, tags);
     return(base.ProcessContent(content, tags));
 }
Example #36
0
			protected override string ProcessContent(string content, IStringTagModel tags)
			{
				tags = new TagModel { InnerModels = new [] { tags, Outer.ProjectTagModel }, File = Outer };
				tagModel = tags;
				return base.ProcessContent(content, tags);
			}