/// <summary> /// Returns true if the specified file path is valid /// </summary> private static bool ValidateInputPath(string sourcePath, DynamicTextTransformation textTransformation) { if (String.IsNullOrEmpty(sourcePath)) { throw new ArgumentException("sourcePath"); } if (sourcePath == "$edmxInputFile$") { textTransformation.Errors.Add(new CompilerError(textTransformation.Host.TemplateFile ?? CodeGenerationTools.GetResourceString("Template_CurrentlyRunningTemplate"), 0, 0, string.Empty, CodeGenerationTools.GetResourceString("Template_ReplaceVsItemTemplateToken"))); return(false); } return(true); }
/// <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); }
/// <summary> /// Creates a set of FunctionImportParameter objects from the parameters passed in. /// </summary> public static IEnumerable <FunctionImportParameter> Create(IEnumerable <FunctionParameter> parameters, CodeGenerationTools code, MetadataTools ef) { if (parameters == null) { throw new ArgumentNullException("parameters"); } if (code == null) { throw new ArgumentNullException("code"); } if (ef == null) { throw new ArgumentNullException("ef"); } UniqueIdentifierService unique = new UniqueIdentifierService(); List <FunctionImportParameter> importParameters = new List <FunctionImportParameter>(); foreach (FunctionParameter parameter in parameters) { FunctionImportParameter importParameter = new FunctionImportParameter(); importParameter.Source = parameter; importParameter.RawFunctionParameterName = unique.AdjustIdentifier(code.CamelCase(parameter.Name)); importParameter.FunctionParameterName = code.Escape(importParameter.RawFunctionParameterName); if (parameter.Mode == ParameterMode.In) { TypeUsage typeUsage = parameter.TypeUsage; importParameter.NeedsLocalVariable = true; importParameter.FunctionParameterType = code.GetTypeName(typeUsage); importParameter.EsqlParameterName = parameter.Name; Type clrType = ef.UnderlyingClrType(parameter.TypeUsage.EdmType); importParameter.RawClrTypeName = typeUsage.EdmType is EnumType?code.GetTypeName(typeUsage.EdmType) : code.Escape(clrType); importParameter.IsNullableOfT = clrType.IsValueType; } else { importParameter.NeedsLocalVariable = false; importParameter.FunctionParameterType = "ObjectParameter"; importParameter.ExecuteParameterName = importParameter.FunctionParameterName; } importParameters.Add(importParameter); } // we save the local parameter uniquification for a second pass to make the visible parameters // as pretty and sensible as possible for (int i = 0; i < importParameters.Count; i++) { FunctionImportParameter importParameter = importParameters[i]; if (importParameter.NeedsLocalVariable) { importParameter.LocalVariableName = unique.AdjustIdentifier(importParameter.RawFunctionParameterName + "Parameter"); importParameter.ExecuteParameterName = importParameter.LocalVariableName; } } return(importParameters); }