当前位置: 首页>>代码示例>>C#>>正文


C# RuleEngine.ServiceContext类代码示例

本文整理汇总了C#中ODataValidator.RuleEngine.ServiceContext的典型用法代码示例。如果您正苦于以下问题:C# ServiceContext类的具体用法?C# ServiceContext怎么用?C# ServiceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ServiceContext类属于ODataValidator.RuleEngine命名空间,在下文中一共展示了ServiceContext类的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");
            }

            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;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:35,代码来源:IntermediateConformance100704.cs

示例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");
            }

            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;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:33,代码来源:AdvancedConformance100904.cs

示例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;

            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;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:33,代码来源:AdvancedConformance1016.cs

示例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.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;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:34,代码来源:AdvancedConformance1008.cs

示例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;
            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;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:38,代码来源:MinimalConformance1002.cs

示例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;
            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;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:38,代码来源:IntermediateConformance1015.cs

示例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;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:65,代码来源:AdvancedConformance1014.cs

示例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;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:64,代码来源:MinimalConformance100611.cs

示例9: Verify

        /// <summary>
        /// Verifies whether the payload of current request session complies to the specified RelaxNG schema or not
        /// </summary>
        /// <param name="context">Context object representing the current OData interop session</param>
        /// <param name="result">Output parameter of validation result</param>
        /// <returns>True if passed; false if failed</returns>
        public bool Verify(ServiceContext context, out TestResult result)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            return this.Verify(context.ResponsePayload, out result);
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:15,代码来源:RngVerifier.cs

示例10: SimpleJobPlanner

 public SimpleJobPlanner(ServiceContext rootCtx, string formatHint, int maxPayloadSize, string category="core")
 {
     this.rootCtx = rootCtx;
     this.metaResource = rootCtx.DestinationBasePath + "/$metadata";
     this.acceptHeaderValue = formatHint.MapFormatToAcceptValue();
     this.maxPayloadSize = maxPayloadSize;
     this.category = category;
     var payloadFormat = this.rootCtx.ServiceDocument.GetFormatFromPayload();
     this.feeds = ContextHelper.GetFeeds(this.rootCtx.ServiceDocument, payloadFormat).ToArray();
 }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:10,代码来源:SimpleJobPlanner.cs

示例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)
        {
            bool? passed = null;
            info = null;
            HttpStatusCode? statusCode = VerificationHelper.VerifyCount(context, out passed, out info);
            if (info != null)
            {
                info.SetDetailsName(this.Name);
            }

            return passed;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:18,代码来源:AdvancedConformance1007.cs

示例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;
            info = null;

            return passed;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:18,代码来源:MinimalConformance1006.cs

示例13: RuleEngineWrapper

 /// <summary>
 /// Create a facade view of interop validation engine for the current context 
 /// </summary>
 /// <param name="context">the current request context object</param>
 /// <param name="resultProvider">consumer of validation results generated by interop rule engine</param>
 /// <param name="logger">logger object</param>
 /// <param name="ruleList">Pre-set rule list</param>
 public RuleEngineWrapper(ServiceContext context, IResultProvider resultProvider, ILogger logger, List<string> ruleList = null)
 {
     this.context = context;
     this.resultConsumer = resultProvider;
     this.logger = logger;
     this.rules = this.context.GetRules().ToList();
     if (null != ruleList && ruleList.Count > 0)
     {
         this.rules = (from r in this.rules where ruleList.Contains(r.Name) select r).ToList();
     }
     this.categories = (from r in this.rules select r.Category).Distinct().ToList();
 }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:19,代码来源:RuleEngineWrapper.cs

示例14: Verify

        /// <summary>
        /// Verifies the specified payload of interop request context against current regular expression rule
        /// </summary>
        /// <param name="context">interop request session whose payload is to be verified</param>
        /// <param name="result">output parameter of verification result</param>
        /// <returns>true if passed; false if failed</returns>
        /// <exception cref="ArgumentNullExption">Throws excpetion when context parameter is null</exception>
        /// <exception cref="ArgumentException">Throws exception when context payload is not of Json</exception>
        public bool Verify(ServiceContext context, out TestResult result)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (context.PayloadFormat != PayloadFormat.Json
                && context.PayloadFormat != PayloadFormat.JsonLight)
            {
                throw new ArgumentException(Resource.PayloadFormatUnexpected);
            }

            return this.Verify(context.ResponsePayload, out result);
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:23,代码来源:JsonSchemaVerifier.cs

示例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? 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;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:21,代码来源:MinimalConformance1011.cs


注:本文中的ODataValidator.RuleEngine.ServiceContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。