Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / Structures / ErrorLog.cs / 1 / ErrorLog.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Text;
using System.Data.Common.Utils;
using System.Data.EntityModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Data.Mapping.ViewGeneration.Utils;
using System.Data.Metadata.Edm;
using System.Data.Entity;
using System.Linq;
namespace System.Data.Mapping.ViewGeneration.Structures {
internal class ErrorLog : InternalBase {
#region Constructors
internal ErrorLog() {
m_log = new List();
}
#endregion
#region Fields
private List m_log;
#endregion
#region Properties
internal int Count {
get { return m_log.Count;}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] // referenced (indirectly) by System.Data.Entity.Design.dll
internal IEnumerable Errors {
get {
foreach (Record record in m_log) {
yield return record.Error;
}
}
}
#endregion
#region Methods
internal void AddEntry(Record record) {
EntityUtil.CheckArgumentNull(record, "record");
m_log.Add(record);
}
internal void Merge(ErrorLog log) {
foreach (Record record in log.m_log) {
m_log.Add(record);
}
}
internal void PrintTrace()
{
StringBuilder builder = new StringBuilder();
ToCompactString(builder);
Helpers.StringTraceLine(builder.ToString());
}
internal override void ToCompactString(StringBuilder builder) {
foreach (Record record in m_log) {
record.ToCompactString(builder);
}
}
internal string ToUserString() {
StringBuilder builder = new StringBuilder();
foreach (Record record in m_log) {
string recordString = record.ToUserString();
builder.AppendLine(recordString);
}
return builder.ToString();
}
#endregion
#region Nested classes/struct
internal class Record : InternalBase {
#region Constructor
// effects: Creates an error record for wrappers, a debug message
// and an error message given by "message". Note: wrappers cannot
// be null
internal Record(bool isError, ViewGenErrorCode errorCode, string message,
IEnumerable wrappers, string debugMessage) {
Debug.Assert(wrappers != null);
IEnumerable cells = LeftCellWrapper.GetInputCellsForWrappers(wrappers);
Init(isError, errorCode, message, cells, debugMessage);
}
internal Record(bool isError, ViewGenErrorCode errorCode, string message, Cell sourceCell, string debugMessage) {
Init(isError, errorCode, message, new Cell[] {sourceCell}, debugMessage);
}
internal Record(bool isError, ViewGenErrorCode errorCode, string message, IEnumerable sourceCells,
string debugMessage) {
Init(isError, errorCode, message, sourceCells, debugMessage);
}
//There are cases when we want to create a ViewGen error that is not specific to any mapping fragment
//In this case, it is better to just create the EdmSchemaError directly and hold on to it.
internal Record(EdmSchemaError error)
{
m_debugMessage = error.ToString();
m_mappingError = error;
}
private void Init(bool isError, ViewGenErrorCode errorCode, string message,
IEnumerable sourceCells, string debugMessage) {
m_sourceCells = new List(sourceCells);
Debug.Assert(m_sourceCells.Count > 0, "Error record must have at least one cell");
// For certain foreign key messages, we may need the SSDL line numbers and file names
CellLabel label = m_sourceCells[0].CellLabel;
string sourceLocation = label.SourceLocation;
int lineNumber = label.StartLineNumber;
int columnNumber = label.StartLinePosition;
string userMessage = InternalToString(message, debugMessage, m_sourceCells, sourceLocation, errorCode, isError, false);
m_debugMessage = InternalToString(message, debugMessage, m_sourceCells, sourceLocation, errorCode, isError, true);
m_mappingError = new EdmSchemaError(userMessage, (int) errorCode, EdmSchemaErrorSeverity.Error, sourceLocation,
lineNumber, columnNumber);
}
#endregion
#region Fields
private EdmSchemaError m_mappingError;
private List m_sourceCells;
private string m_debugMessage;
#endregion
#region Properties
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] // referenced (indirectly) by System.Data.Entity.Design.dll
internal EdmSchemaError Error {
get { return m_mappingError; }
}
#endregion
#region Methods
internal override void ToCompactString(StringBuilder builder) {
builder.Append(m_debugMessage);
}
// effects: adds a comma-separated list of line numbers to the string builder
private static void GetUserLinesFromCells(IEnumerable sourceCells, StringBuilder lineBuilder, bool isInvariant)
{
var orderedCells = sourceCells.OrderBy(cell => cell.CellLabel.StartLineNumber, Comparer.Default);
bool isFirst = true;
// Get the line numbers
foreach (Cell cell in orderedCells)
{
if (isFirst == false)
{
lineBuilder.Append(isInvariant ? EntityRes.GetString(EntityRes.ViewGen_CommaBlank) : ", ");
}
isFirst = false;
lineBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", cell.CellLabel.StartLineNumber);
}
Debug.Assert(isFirst == false, "No cells");
}
// effects: Converts the message/debugMessage to a user-readable
// message using resources (if isInvariant is false) or a test
// message (if isInvariant is true)
static private string InternalToString(string message, string debugMessage,
List sourceCells, string sourceLocation, ViewGenErrorCode errorCode,
bool isError, bool isInvariant) {
StringBuilder builder = new StringBuilder();
if (isInvariant)
{
builder.AppendLine(debugMessage);
builder.Append(isInvariant ? "ERROR" : System.Data.Entity.Strings.ViewGen_Error);
StringUtil.FormatStringBuilder(builder, " ({0}): ", (int)errorCode);
}
StringBuilder lineBuilder = new StringBuilder();
GetUserLinesFromCells(sourceCells, lineBuilder, isInvariant);
if (isInvariant) {
if (sourceCells.Count > 1)
{
StringUtil.FormatStringBuilder(builder, "Problem in Mapping Fragments starting at lines {0}: ", lineBuilder.ToString());
}
else
{
StringUtil.FormatStringBuilder(builder, "Problem in Mapping Fragment starting at line {0}: ", lineBuilder.ToString());
}
} else {
if (sourceCells.Count > 1)
{
builder.Append(Strings.ViewGen_ErrorLog_1(lineBuilder.ToString()));
}
else
{
builder.Append(Strings.ViewGen_ErrorLog_0(lineBuilder.ToString()));
}
}
builder.AppendLine(message);
return builder.ToString();
}
internal string ToUserString() {
return m_mappingError.ToString();
}
#endregion
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Text;
using System.Data.Common.Utils;
using System.Data.EntityModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Data.Mapping.ViewGeneration.Utils;
using System.Data.Metadata.Edm;
using System.Data.Entity;
using System.Linq;
namespace System.Data.Mapping.ViewGeneration.Structures {
internal class ErrorLog : InternalBase {
#region Constructors
internal ErrorLog() {
m_log = new List();
}
#endregion
#region Fields
private List m_log;
#endregion
#region Properties
internal int Count {
get { return m_log.Count;}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] // referenced (indirectly) by System.Data.Entity.Design.dll
internal IEnumerable Errors {
get {
foreach (Record record in m_log) {
yield return record.Error;
}
}
}
#endregion
#region Methods
internal void AddEntry(Record record) {
EntityUtil.CheckArgumentNull(record, "record");
m_log.Add(record);
}
internal void Merge(ErrorLog log) {
foreach (Record record in log.m_log) {
m_log.Add(record);
}
}
internal void PrintTrace()
{
StringBuilder builder = new StringBuilder();
ToCompactString(builder);
Helpers.StringTraceLine(builder.ToString());
}
internal override void ToCompactString(StringBuilder builder) {
foreach (Record record in m_log) {
record.ToCompactString(builder);
}
}
internal string ToUserString() {
StringBuilder builder = new StringBuilder();
foreach (Record record in m_log) {
string recordString = record.ToUserString();
builder.AppendLine(recordString);
}
return builder.ToString();
}
#endregion
#region Nested classes/struct
internal class Record : InternalBase {
#region Constructor
// effects: Creates an error record for wrappers, a debug message
// and an error message given by "message". Note: wrappers cannot
// be null
internal Record(bool isError, ViewGenErrorCode errorCode, string message,
IEnumerable wrappers, string debugMessage) {
Debug.Assert(wrappers != null);
IEnumerable cells = LeftCellWrapper.GetInputCellsForWrappers(wrappers);
Init(isError, errorCode, message, cells, debugMessage);
}
internal Record(bool isError, ViewGenErrorCode errorCode, string message, Cell sourceCell, string debugMessage) {
Init(isError, errorCode, message, new Cell[] {sourceCell}, debugMessage);
}
internal Record(bool isError, ViewGenErrorCode errorCode, string message, IEnumerable sourceCells,
string debugMessage) {
Init(isError, errorCode, message, sourceCells, debugMessage);
}
//There are cases when we want to create a ViewGen error that is not specific to any mapping fragment
//In this case, it is better to just create the EdmSchemaError directly and hold on to it.
internal Record(EdmSchemaError error)
{
m_debugMessage = error.ToString();
m_mappingError = error;
}
private void Init(bool isError, ViewGenErrorCode errorCode, string message,
IEnumerable sourceCells, string debugMessage) {
m_sourceCells = new List(sourceCells);
Debug.Assert(m_sourceCells.Count > 0, "Error record must have at least one cell");
// For certain foreign key messages, we may need the SSDL line numbers and file names
CellLabel label = m_sourceCells[0].CellLabel;
string sourceLocation = label.SourceLocation;
int lineNumber = label.StartLineNumber;
int columnNumber = label.StartLinePosition;
string userMessage = InternalToString(message, debugMessage, m_sourceCells, sourceLocation, errorCode, isError, false);
m_debugMessage = InternalToString(message, debugMessage, m_sourceCells, sourceLocation, errorCode, isError, true);
m_mappingError = new EdmSchemaError(userMessage, (int) errorCode, EdmSchemaErrorSeverity.Error, sourceLocation,
lineNumber, columnNumber);
}
#endregion
#region Fields
private EdmSchemaError m_mappingError;
private List m_sourceCells;
private string m_debugMessage;
#endregion
#region Properties
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] // referenced (indirectly) by System.Data.Entity.Design.dll
internal EdmSchemaError Error {
get { return m_mappingError; }
}
#endregion
#region Methods
internal override void ToCompactString(StringBuilder builder) {
builder.Append(m_debugMessage);
}
// effects: adds a comma-separated list of line numbers to the string builder
private static void GetUserLinesFromCells(IEnumerable sourceCells, StringBuilder lineBuilder, bool isInvariant)
{
var orderedCells = sourceCells.OrderBy(cell => cell.CellLabel.StartLineNumber, Comparer.Default);
bool isFirst = true;
// Get the line numbers
foreach (Cell cell in orderedCells)
{
if (isFirst == false)
{
lineBuilder.Append(isInvariant ? EntityRes.GetString(EntityRes.ViewGen_CommaBlank) : ", ");
}
isFirst = false;
lineBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", cell.CellLabel.StartLineNumber);
}
Debug.Assert(isFirst == false, "No cells");
}
// effects: Converts the message/debugMessage to a user-readable
// message using resources (if isInvariant is false) or a test
// message (if isInvariant is true)
static private string InternalToString(string message, string debugMessage,
List| sourceCells, string sourceLocation, ViewGenErrorCode errorCode,
bool isError, bool isInvariant) {
StringBuilder builder = new StringBuilder();
if (isInvariant)
{
builder.AppendLine(debugMessage);
builder.Append(isInvariant ? "ERROR" : System.Data.Entity.Strings.ViewGen_Error);
StringUtil.FormatStringBuilder(builder, " ({0}): ", (int)errorCode);
}
StringBuilder lineBuilder = new StringBuilder();
GetUserLinesFromCells(sourceCells, lineBuilder, isInvariant);
if (isInvariant) {
if (sourceCells.Count > 1)
{
StringUtil.FormatStringBuilder(builder, "Problem in Mapping Fragments starting at lines {0}: ", lineBuilder.ToString());
}
else
{
StringUtil.FormatStringBuilder(builder, "Problem in Mapping Fragment starting at line {0}: ", lineBuilder.ToString());
}
} else {
if (sourceCells.Count > 1)
{
builder.Append(Strings.ViewGen_ErrorLog_1(lineBuilder.ToString()));
}
else
{
builder.Append(Strings.ViewGen_ErrorLog_0(lineBuilder.ToString()));
}
}
builder.AppendLine(message);
return builder.ToString();
}
internal string ToUserString() {
return m_mappingError.ToString();
}
#endregion
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
| | | | | | | | | | | | | | | |
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WebBrowserDesigner.cs
- SelectingProviderEventArgs.cs
- RadioButtonPopupAdapter.cs
- RadioButtonAutomationPeer.cs
- CellLabel.cs
- LoadMessageLogger.cs
- Button.cs
- DesignerSerializationVisibilityAttribute.cs
- BehaviorEditorPart.cs
- TemplateBamlRecordReader.cs
- RelatedImageListAttribute.cs
- MutexSecurity.cs
- SqlProviderManifest.cs
- tooltip.cs
- LogLogRecordHeader.cs
- FakeModelItemImpl.cs
- RegistryKey.cs
- BitmapImage.cs
- FactoryMaker.cs
- TimeSpanValidator.cs
- CellIdBoolean.cs
- OleDbErrorCollection.cs
- TransformGroup.cs
- DataGridTextBoxColumn.cs
- TemplatePagerField.cs
- ColumnResult.cs
- WebPartZoneBase.cs
- MappingModelBuildProvider.cs
- CustomAttributeFormatException.cs
- XmlSchemaSimpleType.cs
- MarshalByRefObject.cs
- StructuralCache.cs
- BufferedStream2.cs
- MatrixIndependentAnimationStorage.cs
- ComponentDispatcherThread.cs
- DebuggerAttributes.cs
- GenericParameterDataContract.cs
- ScrollBarAutomationPeer.cs
- Geometry3D.cs
- NameValuePair.cs
- CompModSwitches.cs
- SessionState.cs
- SiteMapNodeItem.cs
- RecognitionEventArgs.cs
- BuildProvidersCompiler.cs
- MatrixCamera.cs
- ItemChangedEventArgs.cs
- RootBrowserWindowAutomationPeer.cs
- InvalidEnumArgumentException.cs
- WebPartCollection.cs
- EventMappingSettingsCollection.cs
- TextTreeInsertElementUndoUnit.cs
- ListViewGroupConverter.cs
- CodeCompiler.cs
- Polyline.cs
- ListViewDeletedEventArgs.cs
- DbConnectionInternal.cs
- WebPartMovingEventArgs.cs
- BinaryFormatter.cs
- JsonServiceDocumentSerializer.cs
- ShaperBuffers.cs
- IisTraceListener.cs
- NotCondition.cs
- Message.cs
- SchemaTableColumn.cs
- Automation.cs
- ManagedWndProcTracker.cs
- QilLiteral.cs
- UIElement3DAutomationPeer.cs
- GradientSpreadMethodValidation.cs
- DropShadowBitmapEffect.cs
- FocusWithinProperty.cs
- HostingEnvironmentException.cs
- NameValueCollection.cs
- RawUIStateInputReport.cs
- ListCollectionView.cs
- CursorEditor.cs
- TextEditorLists.cs
- ListViewCommandEventArgs.cs
- ChameleonKey.cs
- EntityDataSourceColumn.cs
- ConfigurationElement.cs
- CodeSubDirectory.cs
- GenericXmlSecurityToken.cs
- HtmlInputText.cs
- ValidationErrorEventArgs.cs
- AttributeAction.cs
- TimeStampChecker.cs
- OleDbErrorCollection.cs
- Color.cs
- XmlSchemaObjectTable.cs
- XmlBufferReader.cs
- Size.cs
- TimeSpan.cs
- SpeechRecognizer.cs
- UnorderedHashRepartitionStream.cs
- CellRelation.cs
- SchemaCollectionCompiler.cs
- LayoutInformation.cs
- Dictionary.cs