Ejemplo n.º 1
0
		private Model.Statements TranslateLibrary(SQLTranslationContext context, String localName, Library library)
		{
			var result = new Model.Statements();

			if (!translatedLibraries.ContainsKey(library.Name))
			{
				context.StartArtifact(localName);
				try
				{
					// Libraries
					foreach (LibraryRef libraryRef in library.Libraries)
					{
						TranslateLibrary(context, libraryRef.Name, LibraryFactory.ResolveLibrary(libraryRef, null));
					}

					// TODO: CodeSystems
					// TODO: ValueSets
					// TODO: Parameters
				
					// ExpressionDefs
					foreach (ExpressionDef expressionDef in library.Expressions)
					{
						result.Add(TranslateExpressionDef(context, localName, expressionDef));
					}

					// TODO: Functions
				}
				finally
				{
					context.EndArtifact();
				}
			}

			return result;
		}
		public IEnumerable<VerificationException> Verify(Library library)
		{
			// Parameters must be validated without access to parameter definitions, or expression definitions
			var initialContext = new VerificationContext(library.Models, library.Libraries, null, null, null, null, null);

			// Resolve parameter types and verify default expressions
			foreach (var parameter in library.Parameters)
			{
				try
				{
					parameter.ParameterType = initialContext.ResolveType(parameter.TypeName);

					if (parameter.Default != null)
					{
						Verifier.Verify(initialContext, parameter.Default);
					    initialContext.VerifyType(parameter.Default.ResultType, parameter.ParameterType);
					}
				}
				catch (Exception e)
				{
					initialContext.ReportMessage(new VerificationException(String.Format("Exceptions occurred verifying parameter {0}.", parameter.Name), e), null);
				}
			}

			var context = new VerificationContext(library.Models, library.Libraries, library.Parameters, library.Expressions, library.CodeSystems, library.ValueSets, initialContext.Messages);

			// Verify expressions
			foreach (var expression in library.Expressions)
			{
				// If the result type is already set, this expression ref has already been resolved.
				if (expression.Expression.ResultType == null)
				{
					Verifier.Verify(context, expression.Expression);
				}
			}

            return context.Messages;
		}