Exemplo n.º 1
0
        internal static EdmSchemaError CreateErrorForException(ModelBuilderErrorCode errorCode, System.Exception exception, string sourceLocation)
        {
            Debug.Assert(exception != null);
            Debug.Assert(sourceLocation != null);

            return(new EdmSchemaError(exception.Message, (int)errorCode, EdmSchemaErrorSeverity.Error, sourceLocation, 0, 0, exception));
        }
        internal void AddError(string message, ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity, string parentIdentity, string itemIdentity)
        {
            int lineNumber, linePosition;

            ClientApiGenerator.GetElementLocationInfo(this._sourceSchema, parentIdentity, itemIdentity, out lineNumber, out linePosition);

            _errors.Add(new EdmSchemaError(message, (int)errorCode, severity, this._sourceSchema.Location, lineNumber, linePosition));
        }
Exemplo n.º 3
0
        private static EdmSchemaError ConvertToEdmSchemaError(CompilerError error, ModelBuilderErrorCode defaultErrorCode)
        {
            int    errorNumber;
            string message                  = error.ErrorText;
            bool   usePositionInfo          = true;
            EdmSchemaErrorSeverity severity = error.IsWarning ? EdmSchemaErrorSeverity.Warning : EdmSchemaErrorSeverity.Error;

            if (int.TryParse(error.ErrorNumber, out errorNumber))
            {
                if (error.Line == -1 && error.Column == -1)
                {
                    usePositionInfo = false;
                }
            }
            else
            {
                message     = String.Format(CultureInfo.InvariantCulture, "{0}({1})", error.ErrorText, error.ErrorNumber);
                errorNumber = (int)defaultErrorCode;
            }

            if (usePositionInfo)
            {
                return(new EdmSchemaError(message,
                                          errorNumber,
                                          severity,
                                          error.FileName,
                                          error.Line,
                                          error.Column));
            }
            else
            {
                return(new EdmSchemaError(message,
                                          errorNumber,
                                          severity));
            }
        }
 public void AddError(ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity, Exception ex)
 {
     _errors.Add(new EdmSchemaError(ex.Message, (int)errorCode, severity, ex));
 }
 public void AddError(string message, ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity)
 {
     _errors.Add(new EdmSchemaError(message, (int)errorCode, severity));
 }
Exemplo n.º 6
0
        private IList <EdmSchemaError> InternalGenerateCode(string sourceEdmSchemaFilePath, Version schemaVersion, LazyTextWriterCreator textWriter, IEnumerable <string> additionalEdmSchemaFilePaths, Version targetFrameworkVersion)
        {
            List <EdmSchemaError> errors = new List <EdmSchemaError>();

            try
            {
                if (targetFrameworkVersion == EntityFrameworkVersions.Version1)
                {
                    errors.Add(new EdmSchemaError(Strings.EntityCodeGenTargetTooLow, (int)ModelBuilderErrorCode.TargetVersionNotSupported, EdmSchemaErrorSeverity.Error));
                    return(errors);
                }

                if (!MetadataItemCollectionFactory.ValidateActualVersionAgainstTarget(targetFrameworkVersion, schemaVersion, errors))
                {
                    return(errors);
                }

                if (schemaVersion == EntityFrameworkVersions.EdmVersion1_1)
                {
                    return(GenerateCodeFor1_1Schema(sourceEdmSchemaFilePath, textWriter, additionalEdmSchemaFilePaths));
                }

                ReflectionAdapter codeGenerator = ReflectionAdapter.Create(_languageOption, targetFrameworkVersion);
                codeGenerator.SourceCsdlPath          = sourceEdmSchemaFilePath;
                codeGenerator.ReferenceCsdlPaths      = additionalEdmSchemaFilePaths;
                codeGenerator.EdmToObjectNamespaceMap = _edmToObjectNamespaceMap.AsDictionary();

                string code = codeGenerator.TransformText();

                if (codeGenerator.Errors.Count != 0)
                {
                    ModelBuilderErrorCode errorCode = ModelBuilderErrorCode.PreprocessTemplateTransformationError;
                    errors.AddRange(codeGenerator.Errors.OfType <CompilerError>().Select(c => ConvertToEdmSchemaError(c, errorCode)));

                    if (codeGenerator.Errors.HasErrors)
                    {
                        return(errors);
                    }
                }

                using (TextWriter writer = textWriter.GetOrCreateTextWriter())
                {
                    writer.Write(code);
                }
            }
            catch (System.UnauthorizedAccessException ex)
            {
                errors.Add(EntityClassGenerator.CreateErrorForException(ModelBuilderErrorCode.SecurityError, ex));
            }
            catch (System.IO.FileNotFoundException ex)
            {
                errors.Add(EntityClassGenerator.CreateErrorForException(ModelBuilderErrorCode.FileNotFound, ex));
            }
            catch (System.Security.SecurityException ex)
            {
                errors.Add(EntityClassGenerator.CreateErrorForException(ModelBuilderErrorCode.SecurityError, ex));
            }
            catch (System.IO.DirectoryNotFoundException ex)
            {
                errors.Add(EntityClassGenerator.CreateErrorForException(ModelBuilderErrorCode.DirectoryNotFound, ex));
            }
            catch (System.IO.IOException ex)
            {
                errors.Add(EntityClassGenerator.CreateErrorForException(ModelBuilderErrorCode.IOException, ex));
            }
            catch (Exception e)
            {
                if (MetadataUtil.IsCatchableExceptionType(e))
                {
                    errors.Add(EntityClassGenerator.CreateErrorForException(ModelBuilderErrorCode.PreprocessTemplateTransformationError, e, sourceEdmSchemaFilePath));
                }
                else
                {
                    throw;
                }
            }

            return(errors);
        }
 internal void AddError(string message, ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity, Exception e)
 {
     Debug.Assert(message != null, "message parameter is null");
     if (null == e)
     {
         Errors.Add(new EdmSchemaError(message, (int)errorCode, severity));
     }
     else
     {
         Errors.Add(new EdmSchemaError(message, (int)errorCode, severity, e));
     }
 }
        internal void AddError(string message, ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity, string parentIdentity, string itemIdentity)
        {
            int lineNumber, linePosition;
            ClientApiGenerator.GetElementLocationInfo(this._sourceSchema, parentIdentity, itemIdentity, out lineNumber, out linePosition);

            _errors.Add(new EdmSchemaError(message, (int)errorCode, severity, this._sourceSchema.Location, lineNumber, linePosition));
        }
 public void AddError(ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity, Exception ex)
 {
     _errors.Add(new EdmSchemaError(ex.Message, (int)errorCode, severity, ex));
 }
 public void AddError(string message, ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity)
 {
     _errors.Add(new EdmSchemaError(message, (int)errorCode, severity));
 }
Exemplo n.º 11
0
 internal void AddError(string message, ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity, Exception ex)
 {
 }
Exemplo n.º 12
0
 public void AddError(ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity, Exception ex)
 {
 }
Exemplo n.º 13
0
 public void AddError(string message, ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity)
 {
 }
Exemplo n.º 14
0
        private static EdmSchemaError ConvertToEdmSchemaError(CompilerError error, ModelBuilderErrorCode defaultErrorCode)
        {
            int errorNumber;
            string message = error.ErrorText;
            bool usePositionInfo = true;
            EdmSchemaErrorSeverity severity = error.IsWarning ? EdmSchemaErrorSeverity.Warning : EdmSchemaErrorSeverity.Error;
            if (int.TryParse(error.ErrorNumber, out errorNumber))
            {
                if (error.Line == -1 && error.Column == -1)
                {
                    usePositionInfo = false;
                }
            }
            else
            {
                message = String.Format(CultureInfo.InvariantCulture, "{0}({1})", error.ErrorText, error.ErrorNumber);
                errorNumber = (int)defaultErrorCode;
            }

            if (usePositionInfo)
            {
                return new EdmSchemaError(message,
                                        errorNumber,
                                        severity,
                                        error.FileName,
                                        error.Line,
                                        error.Column);
            }
            else
            {
                return new EdmSchemaError(message,
                                        errorNumber,
                                        severity);
            }
        }
 internal void AddError(string message, ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity, Exception ex)
 {
     _errors.Add(new EdmSchemaError(message, (int)errorCode, severity, ex));
 }
 internal void AddError(string message, ModelBuilderErrorCode errorCode, EdmSchemaErrorSeverity severity, Exception ex)
 {
     _errors.Add(new EdmSchemaError(message, (int)errorCode, severity, ex));
 }
Exemplo n.º 17
0
        internal static EdmSchemaError CreateErrorForException(ModelBuilderErrorCode errorCode, System.Exception exception)
        {
            Debug.Assert(exception != null);

            return new EdmSchemaError(exception.Message, (int)errorCode, EdmSchemaErrorSeverity.Error, null, 0, 0, exception);
        }