/// <summary> /// Evaluate a function. /// </summary> /// <param name="sourceLineNumbers">The source line information for the function.</param> /// <param name="prefix">The function prefix.</param> /// <param name="function">The function name.</param> /// <param name="args">The arguments for the function.</param> /// <returns>The function value or null if the function is not defined.</returns> public string EvaluateFunction(SourceLineNumber sourceLineNumbers, string prefix, string function, string[] args) { if (String.IsNullOrEmpty(prefix)) { throw new ArgumentNullException("prefix"); } if (String.IsNullOrEmpty(function)) { throw new ArgumentNullException("function"); } switch (prefix) { case "fun": switch (function) { case "AutoVersion": // Make sure the base version is specified if (args.Length == 0 || String.IsNullOrEmpty(args[0])) { throw new WixException(WixErrors.InvalidPreprocessorFunctionAutoVersion(sourceLineNumbers)); } // Build = days since 1/1/2000; Revision = seconds since midnight / 2 DateTime now = DateTime.UtcNow; TimeSpan build = now - new DateTime(2000, 1, 1); TimeSpan revision = now - new DateTime(now.Year, now.Month, now.Day); return(String.Join(".", args[0], (int)build.TotalDays, (int)(revision.TotalSeconds / 2))); default: return(null); } default: PreprocessorExtension extension = (PreprocessorExtension)this.extensionsByPrefix[prefix]; if (null != extension) { try { return(extension.EvaluateFunction(prefix, function, args)); } catch (Exception e) { throw new WixException(WixErrors.PreprocessorExtensionEvaluateFunctionFailed(sourceLineNumbers, prefix, function, String.Join(",", args), e.Message)); } } else { return(null); } } }
/// <summary> /// Evaluate a function. /// </summary> /// <param name="sourceLineNumbers">The source line information for the function.</param> /// <param name="prefix">The function prefix.</param> /// <param name="function">The function name.</param> /// <param name="args">The arguments for the function.</param> /// <returns>The function value or null if the function is not defined.</returns> public string EvaluateFunction(SourceLineNumber sourceLineNumbers, string prefix, string function, string[] args) { if (String.IsNullOrEmpty(prefix)) { throw new ArgumentNullException("prefix"); } if (String.IsNullOrEmpty(function)) { throw new ArgumentNullException("function"); } switch (prefix) { case "fun": switch (function) { // Add any core defined functions here default: return(null); } default: PreprocessorExtension extension = (PreprocessorExtension)this.extensionsByPrefix[prefix]; if (null != extension) { try { return(extension.EvaluateFunction(prefix, function, args)); } catch (Exception e) { throw new WixException(WixErrors.PreprocessorExtensionEvaluateFunctionFailed(sourceLineNumbers, prefix, function, String.Join(",", args), e.Message)); } } else { return(null); } } }