Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add datamodificationexception class #914

Draft
wants to merge 3 commits into
base: release-8.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions src/Microsoft.AspNetCore.OData/DataModificationExceptionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//-----------------------------------------------------------------------------
// <copyright file="DataModificationExceptionType.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
// </copyright>
//------------------------------------------------------------------------------

using System;

namespace Org.OData.Core.V1
{
/// <summary>
/// Represents a message type.
/// </summary>
public class MessageType
{
/// <summary>
/// Code of message.
/// </summary>
public string Code { get; set; }

/// <summary>
/// Actual message.
/// </summary>
public string Message { get; set; }

/// <summary>
/// Severity of message.
/// </summary>
public string Severity { get; set; }

/// <summary>
/// Target of message.
/// </summary>
public string Target { get; set; }

/// <summary>
/// Details of message.
/// </summary>
public string Details { get; set; }
}

/// <summary>
/// Represents an exception type.
/// </summary>
public abstract class ExceptionType
{
/// <summary>
/// Represents a message type.
/// </summary>
public MessageType MessageType { get; set; }
}

/// <summary>
/// Represents the type of exception thrown during a data modification operation.
/// </summary>
public class DataModificationExceptionType : ExceptionType
{
/// <summary>
/// Initializes a new instance of the <see cref="DataModificationExceptionType"/> class.
/// </summary>
public DataModificationExceptionType(DataModificationOperationKind failedOperation)
{
this.FailedOperation = failedOperation;
}

/// <summary>
/// Represents the kind of data modification operation.
/// </summary>
public DataModificationOperationKind FailedOperation { get; }

/// <summary>
/// Represents the response code.
/// </summary>
public Int16 ResponseCode { get; set; }
}

/// <summary>
/// Enumerates the kind of data modification operations.
/// </summary>
public enum DataModificationOperationKind
{
/// <summary>
/// Represents an insert operation.
/// </summary>
Insert,

/// <summary>
/// Represents an update operation.
/// </summary>
Update,

/// <summary>
/// Represents an insert or update operation if item already exists.
/// </summary>
Upsert,

/// <summary>
/// Represents a delete data modification operation.
/// </summary>
Delete,

/// <summary>
/// Represents an action or function invocation.
/// </summary>
Invoke,

/// <summary>
/// Represents adding a link between entities.
/// </summary>
Link,

/// <summary>
/// Represents removing a link between entities.
/// </summary>
Unlink
}
}
3 changes: 3 additions & 0 deletions src/Microsoft.AspNetCore.OData/Deltas/Delta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public abstract class Delta : DynamicObject, IDelta
/// </summary>
public abstract DeltaItemKind Kind { get; }

/// <inheritdoc/>
public IODataInstanceAnnotationContainer TransientInstanceAnnotationContainer { get; set; }

/// <summary>
/// Clears the Delta and resets the underlying Entity.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.AspNetCore.OData/Deltas/DeltaLinkBaseOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@ protected DeltaLinkBase(Type structuralType)
/// The name of the relationship property on the parent object.
/// </summary>
public string Relationship { get; set; }

/// <inheritdoc/>
public IODataInstanceAnnotationContainer TransientInstanceAnnotationContainer { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}
}
5 changes: 5 additions & 0 deletions src/Microsoft.AspNetCore.OData/Deltas/IDeltaSetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ public interface IDeltaSetItem
/// Gets the delta item kind.
/// </summary>
DeltaItemKind Kind { get; }

/// <summary>
/// Gets or sets the annotation container to hold transient instance annotations.
/// </summary>
IODataInstanceAnnotationContainer TransientInstanceAnnotationContainer { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where and how can customer set this interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when they are creating the response. If there are operations in the DeltaSet that failed then you need to create DataModificationExceptions. This is the time customers will need this interface.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//-----------------------------------------------------------------------------
// <copyright file="IODataInstanceAnnotationContainer.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
// </copyright>
//------------------------------------------------------------------------------

using System.Collections.Generic;

namespace Microsoft.AspNetCore.OData
{
/// <summary>
/// Identifies a container for holding instance annotations. A default implementation is provided.
/// Customers can have their own implementation.
/// </summary>
public interface IODataInstanceAnnotationContainer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I don't like this interface and the methods defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest it be replaced with?

{
/// <summary>
/// Method to Add an Instance Annotation to the CLR type
/// </summary>
/// <param name="annotationName">Name of Annotation</param>
/// <param name="value">Value of Annotation</param>
void AddResourceAnnotation(string annotationName, object value);

/// <summary>
/// Method to Add an Instance Annotation to a property
/// </summary>
/// <param name="propertyName">Name of the property</param>
/// <param name="annotationName">Name of Annotation</param>
/// <param name="value">Value of Annotation</param>
void AddPropertyAnnotation(string propertyName, string annotationName, object value);

/// <summary>
/// Get an Instance Annotation from CLR Type
/// </summary>
/// <param name="annotationName">Name of Annotation</param>
/// <returns>Get Annotation value for the given annotation</returns>
object GetResourceAnnotation(string annotationName);

/// <summary>
/// Get an Instance Annotation from the Property
/// </summary>
/// <param name="propertyName">Name of the Property</param>
/// <param name="annotationName">Name of the Annotation</param>
/// <returns>Get Annotation value for the given annotation and property</returns>
object GetPropertyAnnotation(string propertyName, string annotationName);

/// <summary>
/// Get All Annotations from CLR Type
/// </summary>
/// <returns>Dictionary of string(annotation name) and object value(annotation value)</returns>
IDictionary<string, object> GetResourceAnnotations();

/// <summary>
/// Get all Annotations for a Property
/// </summary>
/// <param name="propertyName">Name of Property</param>
/// <returns>Dictionary of string(annotation name) and object value(annotation value)</returns>
IDictionary<string, object> GetPropertyAnnotations(string propertyName);
}
}
Loading