本文整理汇总了C#中ODataValidator.RuleEngine.ExtensionRuleViolationInfo类的典型用法代码示例。如果您正苦于以下问题:C# ExtensionRuleViolationInfo类的具体用法?C# ExtensionRuleViolationInfo怎么用?C# ExtensionRuleViolationInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExtensionRuleViolationInfo类属于ODataValidator.RuleEngine命名空间,在下文中一共展示了ExtensionRuleViolationInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
info = null;
List<ExtensionRuleResultDetail> details = new List<ExtensionRuleResultDetail>();
ExtensionRuleViolationInfo info1 = null, info2 = null;
bool? isVerifySortEntitiesOrderByAsc = VerificationHelper.VerifySortEntities(context, SortedType.ASC, out info1);
bool? isVerifySortEntitiesOrderByDesc = VerificationHelper.VerifySortEntities(context, SortedType.DESC, out info2);
if (info1 != null)
{
details.AddRange(info1.Details);
}
if (info2 != null)
{
details.AddRange(info2.Details);
}
info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, details);
info.SetDetailsName(this.Name);
return true == isVerifySortEntitiesOrderByAsc && true == isVerifySortEntitiesOrderByDesc;
}
示例2: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
info = null;
// Verify the lambda operator "any".
HttpStatusCode? statusCode1 = VerificationHelper.VerifyLambdaOperators(context, LambdaOperatorType.Any, out passed, out info);
if (true != passed)
{
if (info != null)
{
info.SetDetailsName(this.Name);
}
return passed;
}
// Verify the lambda operator "all".
HttpStatusCode? statusCode2 = VerificationHelper.VerifyLambdaOperators(context, LambdaOperatorType.All, out passed, out info);
if (info != null)
{
info.SetDetailsName(this.Name);
}
return passed;
}
示例3: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
info = null;
HttpStatusCode? statusCode1 = VerificationHelper.VerifySortEntities(context, SortedType.ASC, out passed, out info);
if (info != null)
{
info.SetDetailsName(this.Name);
}
if (true != passed)
{
return passed;
}
HttpStatusCode? statusCode2 = VerificationHelper.VerifySortEntities(context, SortedType.DESC, out passed, out info);
if (info != null)
{
info.SetDetailsName(this.Name);
}
return passed;
}
示例4: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
info = null;
HttpStatusCode? statusCode1 = VerificationHelper.VerifyCanonicalFunction(context, CanonicalFunctionType.Supported, out passed, out info);
if (true != passed)
{
if (info != null)
{
info.SetDetailsName(this.Name);
}
return passed;
}
HttpStatusCode? statusCode2 = VerificationHelper.VerifyCanonicalFunction(context, CanonicalFunctionType.Unsupported, out passed, out info);
passed = statusCode2 == HttpStatusCode.NotImplemented ? true : false;
if (info != null)
{
info.SetDetailsName(this.Name);
}
return passed;
}
示例5: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
Uri metadataServiceUrl = new Uri(context.Destination.AbsoluteUri.TrimEnd('/') + @"/$metadata" + @"/");
var req = WebRequest.Create(metadataServiceUrl) as HttpWebRequest;
Response response = WebHelper.Get(req, RuleEngineSetting.Instance().DefaultMaximumPayloadSize);
ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, metadataServiceUrl.AbsoluteUri, "GET", string.Empty, response);
if (response != null && response.StatusCode == HttpStatusCode.OK && response.ResponsePayload.IsMetadata())
{
passed = true;
}
else
{
passed = false;
detail.ErrorMessage = "The response is not the metadata service document. Please refer to section 15 of [OData-CSDL].";
}
info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
return passed;
}
示例6: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
var response = WebHelper.Get(context.Destination, string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, context.Destination.AbsoluteUri, "GET", StringHelper.MergeHeaders(string.Empty, context.RequestHeaders), response);
if (response != null && response.StatusCode != null)
{
if (context.PayloadFormat == RuleEngine.PayloadFormat.JsonLight)
{
passed = true;
}
else
{
passed = false;
detail.ErrorMessage = "Get above URI with accept header 'application/json', the response is not JSON format.";
}
}
else
{
passed = false;
detail.ErrorMessage = String.Format("No response returned from above URI with accept header 'application/json'.");
}
info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
return passed;
}
示例7: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name);
var restrictions = AnnotationsHelper.GetChangeTracking(context.MetadataDocument, context.VocCapabilities);
if (string.IsNullOrEmpty(restrictions.Item1) ||
null == restrictions.Item2 || !restrictions.Item2.Any() ||
null == restrictions.Item3 || !restrictions.Item3.Any())
{
detail.ErrorMessage = "Cannot find an entity-container or any entity-sets which support the change tracking function.";
info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
return passed;
}
string url = string.Format("{0}/{1}", context.ServiceBaseUri, restrictions.Item1);
List<KeyValuePair<string, string>> requestHeaders = new List<KeyValuePair<string,string>>();
foreach (KeyValuePair<string, string> kvp in context.RequestHeaders)
{
requestHeaders.Add(new KeyValuePair<string, string>(kvp.Key, kvp.Value));
}
// Add odata.track-changes preference in request header.
KeyValuePair<string, string> prefer = new KeyValuePair<string, string>("Prefer", "odata.track-changes");
requestHeaders.Add(prefer);
Response response = WebHelper.Get(new Uri(url), Constants.V4AcceptHeaderJsonFullMetadata, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, requestHeaders);
detail = new ExtensionRuleResultDetail(this.Name, url, "GET", StringHelper.MergeHeaders(Constants.V4AcceptHeaderJsonFullMetadata, requestHeaders), response);
if (response != null && !string.IsNullOrEmpty(response.ResponseHeaders))
{
string preferHeader = response.ResponseHeaders.GetHeaderValue("Preference-Applied");
if (string.IsNullOrEmpty(preferHeader))
{
passed = false;
detail.ErrorMessage = "The response header returned by the service does not contain 'odata.track-changes', when request with the header 'Prefer:odata.track-changes'.";
}
else if (preferHeader.Contains("odata.track-changes"))
{
passed = true;
}
}
else
{
passed = false;
detail.ErrorMessage = "The service does not support Delta change tracking.";
}
info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
return passed;
}
示例8: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
string selectedName = string.Empty;
string functionactionName = "forFunctionAction";
// Use the XPath query language to access the metadata document and get all Namespace and Alias value.
XElement metadata = XElement.Parse(context.MetadataDocument);
string xpath = @"//*[local-name()='DataServices']/*[local-name()='Schema']";
List<string> appropriateNamespace = MetadataHelper.GetPropertyValues(context, xpath, "Namespace");
// Use the XPath query language to access the metadata document and get all Function names and all Action names.
xpath = @"//*[local-name()='EntityContainer']/*[local-name()='FunctionImport']";
List<string> functionImportNames = MetadataHelper.GetPropertyValues(context, xpath, "Name");
xpath = @"//*[local-name()='EntityContainer']/*[local-name()='ActionImport']";
List<string> actionImportNames = MetadataHelper.GetPropertyValues(context, xpath, "Name");
if (!functionImportNames.Contains(functionactionName) && !actionImportNames.Contains(functionactionName))
{
selectedName = functionactionName;
}
else
{
selectedName = functionactionName + "New";
}
string url = string.Format("{0}/?$select={1}.{2}", context.Destination, appropriateNamespace[0], selectedName);
var req = WebRequest.Create(url) as HttpWebRequest;
var response = WebHelper.Get(req, RuleEngineSetting.Instance().DefaultMaximumPayloadSize);
ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, url, "GET", string.Empty, response);
if (response != null && response.StatusCode != null)
{
if (response.StatusCode != HttpStatusCode.OK)
{
passed = true;
}
else
{
passed = false;
detail.ErrorMessage = "The OData service MUST fail any request that contains actions or functions that it does not understand.";
}
}
else
{
passed = false;
detail.ErrorMessage = String.Format("No response returned from above URI.");
}
info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
return passed;
}
示例9: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
bool? passed = null;
info = null;
HttpStatusCode? statusCode = VerificationHelper.VerifyCount(context, out passed, out info);
if (info != null)
{
info.SetDetailsName(this.Name);
}
return passed;
}
示例10: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
info = null;
return passed;
}
示例11: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name);
detail.ErrorMessage = @"This negative rule is not verified.";
info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
return passed;
}
示例12: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
var response = WebHelper.Get(context.Destination, Constants.AcceptHeaderJson, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, context.Destination.AbsoluteUri, "GET", StringHelper.MergeHeaders(Constants.AcceptHeaderJson, context.RequestHeaders), response);
if (response != null && response.StatusCode != null)
{
// Extracts OData-Version value from ResponseHttpHeaders.
string oDataVersion = context.ResponseHttpHeaders.GetHeaderValue(Constants.ODataVersion).TrimEnd(';');
if (!string.IsNullOrEmpty(oDataVersion))
{
float version = float.Parse(oDataVersion);
// The minimal OData version of conformance validation is 4.0.
if (version >= 4.0)
{
passed = true;
}
else
{
passed = false;
detail.ErrorMessage = string.Format(@"The OData version is {0} which should be not less than minimal version 4.0.", version);
}
}
else
{
passed = false;
detail.ErrorMessage = @"Can not get the OData-Version header from response headers.";
}
}
else
{
passed = null;
detail.ErrorMessage = "Cannot get response from above URI.";
}
info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
return passed;
}
示例13: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
info = null;
VerificationHelper.VerifySearch(context, out passed, out info);
if (info != null)
{
info.SetDetailsName(this.Name);
}
return passed;
}
示例14: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool? passed = null;
string url = context.Destination.AbsoluteUri.TrimEnd('/') + @"/$metadata";
var response = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, url, "GET", StringHelper.MergeHeaders(string.Empty, context.RequestHeaders), response);
if (response != null && response.StatusCode != null)
{
// Get EntityContainer from metadata payload.
string xpath = @"//*[local-name()='EntityContainer']";
XElement metadata = XElement.Parse(response.ResponsePayload);
IEnumerable<XElement> entityContainer = metadata.XPathSelectElements(xpath, ODataNamespaceManager.Instance);
List<string> propNames = new List<string>();
foreach (var prop in entityContainer)
{
propNames.Add(prop.Attribute("Name").Value);
}
if (propNames.Count > 0)
{
passed = true;
}
else
{
passed = false;
detail.ErrorMessage = "There is no EntityContainer in metadata document.";
}
}
else
{
passed = false;
detail.ErrorMessage = String.Format("No response returned from above URI.");
}
info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
return passed;
}
示例15: Verify
/// <summary>
/// Verifies the extension rule.
/// </summary>
/// <param name="context">The Interop service context</param>
/// <param name="info">out parameter to return violation information when rule does not pass</param>
/// <returns>true if rule passes; false otherwise</returns>
public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
bool svcDocResult = false;
bool metadataResult = false;
bool errorResponseResult = false;
bool feedAndEntryResult = false;
ExtensionRuleViolationInfo infoForOne = null;
List<ExtensionRuleResultDetail> details = new List<ExtensionRuleResultDetail>();
svcDocResult = VerificationHelper.VerifySvcDoc(context, out infoForOne);
if (infoForOne != null)
{
details.AddRange(infoForOne.Details);
}
metadataResult = VerificationHelper.VerifyMetadata(context, out infoForOne);
if (infoForOne != null)
{
details.AddRange(infoForOne.Details);
}
errorResponseResult = VerificationHelper.VerifyError(context, out infoForOne);
if (infoForOne != null)
{
details.AddRange(infoForOne.Details);
}
feedAndEntryResult = VerificationHelper.VerifyFeedAndEntry(context, out infoForOne);
if (infoForOne != null)
{
details.AddRange(infoForOne.Details);
}
info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, details);
info.SetDetailsName(this.Name);
return svcDocResult && metadataResult && feedAndEntryResult && errorResponseResult;
}