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


C# System.UriTemplate类代码示例

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


UriTemplate类属于System命名空间,在下文中一共展示了UriTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildUriString

 public string BuildUriString(NancyContext context, string routeName, dynamic parameters)
 {
     var baseUri = new Uri(context.Request.BaseUri().TrimEnd('/'));
       var pathTemplate = AllRoutes.Single(r => r.Name == routeName).Path;
       var uriTemplate = new UriTemplate(pathTemplate, true);
       return uriTemplate.BindByName(baseUri, ToDictionary(parameters ?? new {})).ToString();
 }
开发者ID:horsdal,项目名称:Restbucks-on-Nancy,代码行数:7,代码来源:ResourceLinker.cs

示例2: TryUriTemplateMatch

 private bool TryUriTemplateMatch(string uri, out UriTemplateMatch uriTemplateMatch)
 {
     var uriTemplate = new UriTemplate(uri);
     var serverPath = Request.Url.GetServerBaseUri();
     uriTemplateMatch = uriTemplate.Match(new Uri(serverPath), Request.Url);
     return uriTemplateMatch != null;
 }
开发者ID:JamesTryand,项目名称:minimods,代码行数:7,代码来源:HttpContext.cs

示例3: ExpandVarArgsDuplicateVariables

 public void ExpandVarArgsDuplicateVariables()
 {
     UriTemplate template = new UriTemplate("http://example.com/order/{c}/{c}/{c}");
     Assert.AreEqual(new string[] { "c" }, template.VariableNames, "Invalid variable names");
     Uri result = template.Expand("cheeseburger");
     Assert.AreEqual(new Uri("http://example.com/order/cheeseburger/cheeseburger/cheeseburger"), result, "Invalid expanded template");
 }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:7,代码来源:UriTemplateTests.cs

示例4: when_validating_a_uri_template_with_url_encoded_chars

 public void when_validating_a_uri_template_with_url_encoded_chars()
 {
     var template = new UriTemplate("/streams/$all?embed={embed}");
     var uri = new Uri("http://127.0.0.1/streams/$all");
     var baseaddress = new Uri("http://127.0.0.1");
     Assert.IsTrue(template.Match(baseaddress, uri) != null);
 }        
开发者ID:thinkbeforecoding,项目名称:EventStore,代码行数:7,代码来源:mono_filestream_bug.cs

示例5: CreateFromUriTemplate

        public static UriTemplatePathSegment CreateFromUriTemplate(string segment, UriTemplate template)
        {
            // Identifying the type of segment - Literal|Compound|Variable
            switch (UriTemplateHelpers.IdentifyPartType(segment))
            {
                case UriTemplatePartType.Literal:
                    return UriTemplateLiteralPathSegment.CreateFromUriTemplate(segment, template);

                case UriTemplatePartType.Compound:
                    return UriTemplateCompoundPathSegment.CreateFromUriTemplate(segment, template);

                case UriTemplatePartType.Variable:
                    if (segment.EndsWith("/", StringComparison.Ordinal))
                    {
                        string varName = template.AddPathVariable(UriTemplatePartType.Variable,
                            segment.Substring(1, segment.Length - 3));
                        return new UriTemplateVariablePathSegment(segment, true, varName);
                    }
                    else
                    {
                        string varName = template.AddPathVariable(UriTemplatePartType.Variable,
                            segment.Substring(1, segment.Length - 2));
                        return new UriTemplateVariablePathSegment(segment, false, varName);
                    }

                default:
                    Fx.Assert("Invalid value from IdentifyStringNature");
                    return null;
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:30,代码来源:UriTemplatePathSegment.cs

示例6: CreateFromUriTemplate

        public static UriTemplateQueryValue CreateFromUriTemplate(string value, UriTemplate template)
        {
            // Checking for empty value
            if (value == null)
            {
                return UriTemplateQueryValue.Empty;
            }
            // Identifying the type of value - Literal|Compound|Variable
            switch (UriTemplateHelpers.IdentifyPartType(value))
            {
                case UriTemplatePartType.Literal:
                    return UriTemplateLiteralQueryValue.CreateFromUriTemplate(value);

                case UriTemplatePartType.Compound:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(
                        SR.UTQueryCannotHaveCompoundValue, template.originalTemplate)));

                case UriTemplatePartType.Variable:
                    return new UriTemplateVariableQueryValue(template.AddQueryVariable(value.Substring(1, value.Length - 2)));

                default:
                    Fx.Assert("Invalid value from IdentifyStringNature");
                    return null;
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:25,代码来源:UriTemplateQueryValue.cs

示例7: CompetitionResultAppelRequestHandler

 public CompetitionResultAppelRequestHandler(HttpRequest Request, HttpResponse Response, Uri Prefix, UriTemplate CompetitionResultsTemplate, UriTemplate ResultResourceTemplate, string AcceptHeader)
     : base(Request, Response, Prefix, AcceptHeader)
 {
     this.CompetitionResultsTemplate = CompetitionResultsTemplate;
     this.ResultResourceTemplate = ResultResourceTemplate;
     processRequest();
 }
开发者ID:TheHandsomeCoder,项目名称:SOFT512RestAPI,代码行数:7,代码来源:CompetitionResultAppelRequestHandler.cs

示例8: BindUri

        public static Uri BindUri(this ISession session, Uri url, object parameters = null)
        {
            Uri baseUri = new Uri(url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped));
              UriTemplate template = new UriTemplate(url.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped));

              return BindTemplate(baseUri, template, parameters);
        }
开发者ID:prearrangedchaos,项目名称:Ramone,代码行数:7,代码来源:BindingExtensions.cs

示例9: MethodAndUriTemplateOperationSelector

        public MethodAndUriTemplateOperationSelector(ServiceEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            this.delegates =
                new Dictionary<string, UriTemplateOperationSelector>();

            var operations = endpoint.Contract.Operations.Select(od => new HttpOperationDescription(od));

            foreach (var methodGroup in operations.GroupBy(od => od.GetWebMethod()))
            {
                UriTemplateTable table = new UriTemplateTable(endpoint.ListenUri);
                foreach (var operation in methodGroup)
                {
                    UriTemplate template = new UriTemplate(operation.GetUriTemplateString());
                    table.KeyValuePairs.Add(
                        new KeyValuePair<UriTemplate, object>(template, operation.Name));

                }

                table.MakeReadOnly(false);
                UriTemplateOperationSelector templateSelector =
                    new UriTemplateOperationSelector(table);
                this.delegates.Add(methodGroup.Key, templateSelector);
            }
        }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:29,代码来源:MethodAndUriTemplateOperationSelector.cs

示例10: HtmlFormRequestDispatchFormatter

        public HtmlFormRequestDispatchFormatter(OperationDescription operation, UriTemplate uriTemplate, QueryStringConverter converter, IDispatchMessageFormatter innerFormatter)
            : base(operation, uriTemplate, converter, innerFormatter)
        {
            // This formatter will only support deserializing form post data to a type if:
            //  (1) The type can be converted via the QueryStringConverter or...
            //  (2) The type meets the following requirements:
            //      (A) The type is decorated with the DataContractAttribute
            //      (B) Every public field or property that is decorated with the DataMemberAttribute is of a type that
            //          can be converted by the QueryStringConverter

            this.canConvertBodyType = this.QueryStringConverter.CanConvert(this.BodyParameterType);

            if (!this.canConvertBodyType)
            {
                if (this.BodyParameterType.GetCustomAttributes(typeof(DataContractAttribute), false).Length == 0)
                {
                    throw new NotSupportedException(
                        string.Format("Body parameter '{0}' from operation '{1}' is of type '{2}', which is not decorated with a DataContractAttribute.  " +
                                      "Only body parameter types decorated with the DataContractAttribute are supported.",
                        this.BodyParameterName,
                        operation.Name,
                        this.BodyParameterType));
                }

                // For the body type, we'll need to cache information about each of the public fields/properties
                //  that is decorated with the DataMemberAttribute; we'll store this info in the bodyMembers dictionary
                //  where the member name is the dictionary key
                bodyMembers = new Dictionary<string, BodyMemberData>();

                GetBobyMemberDataForFields(operation.Name);
                GetBodyMemberDataForProperties(operation.Name);

                requiredBodyMembers = bodyMembers.Where(p => p.Value.IsRequired == true).Select(p => p.Key).ToArray();
            }
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:35,代码来源:HtmlFormRequestDispatchFormatter.cs

示例11: TestCompoundFragmentExpansionAssociativeMapVariable

        public void TestCompoundFragmentExpansionAssociativeMapVariable()
        {
            string template = "{#keys*}";
            UriTemplate uriTemplate = new UriTemplate(template);
            Uri uri = uriTemplate.BindByName(variables);
            string[] allowed =
                {
                    "#comma=,,dot=.,semi=;",
                    "#comma=,,semi=;,dot=.",
                    "#dot=.,comma=,,semi=;",
                    "#dot=.,semi=;,comma=,",
                    "#semi=;,comma=,,dot=.",
                    "#semi=;,dot=.,comma=,"
                };

            CollectionAssert.Contains(allowed, uri.ToString());

            UriTemplateMatch match = uriTemplate.Match(uri, new[] { "list" }, new[] { "keys" });
            Assert.IsNotNull(match);
            CollectionAssert.AreEqual((ICollection)variables["keys"], (ICollection)match.Bindings["keys"].Value);

            match = uriTemplate.Match(uri, requiredVariables, new[] { "list" }, new[] { "keys" });
            Assert.IsNotNull(match);
            CollectionAssert.AreEqual((ICollection)variables["keys"], (ICollection)match.Bindings["keys"].Value);
        }
开发者ID:gitter-badger,项目名称:dotnet-uritemplate,代码行数:25,代码来源:Level4Tests.cs

示例12: MultipleExpandVarArgs

 public void MultipleExpandVarArgs()
 {
     UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
     Uri result = template.Expand("2", 21);
     result = template.Expand(1, "42");
     Assert.AreEqual(new Uri("http://example.com/hotels/1/bookings/42"), result, "Invalid expanded template");
 }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:7,代码来源:UriTemplateTests.cs

示例13: BuildUriString

        public string BuildUriString(string prefix, string template, dynamic parameters)
        {
            var newBaseUri = new Uri(baseUri.TrimEnd('/') + prefix);
              var uriTemplate = new UriTemplate(template, true);

              return uriTemplate.BindByName(newBaseUri, ToDictionary(parameters ?? new {})).ToString();
        }
开发者ID:saberone,项目名称:RestBench,代码行数:7,代码来源:ResourceLinker.cs

示例14: UriConfiguration

 public UriConfiguration(Uri baseAddress, UriTemplate recentFeedTemplate, UriTemplate feedTemplate, UriTemplate entryTemplate)
 {
     this.baseAddress = baseAddress;
     this.recentFeedTemplate = recentFeedTemplate;
     this.feedTemplate = feedTemplate;
     this.entryTemplate = entryTemplate;
 }
开发者ID:JunctionBoxca,项目名称:Rest-In-Practise-Product-Catalog-Service,代码行数:7,代码来源:UriConfiguration.cs

示例15: EncryptionButtonInValidateCard_Click

        protected void EncryptionButtonInValidateCard_Click(object sender, EventArgs e)
        {
            Uri baseUri = new Uri("http://webstrar49.fulton.asu.edu/page3/Service1.svc");
            UriTemplate myTemplate = new UriTemplate("encrypt?plainText={plainText}");

            String plainText = PlainText_TextBox1.Text;
            Uri completeUri = myTemplate.BindByPosition(baseUri, plainText);

            System.Net.WebClient webClient = new System.Net.WebClient();
            byte[] content = webClient.DownloadData(completeUri);

            //EncryptionService.Service1Client encryptionClient = new EncryptionService.Service1Client();
            // String cipher=encryptionClient.encrypt(plainText);

            String contentinString = Encoding.UTF8.GetString(content, 0, content.Length);

            String pattern = @"(?<=\>)(.*?)(?=\<)";
            Regex r = new Regex(pattern);
            Match m = r.Match(contentinString);

            String cipher = "";
            if (m.Success)
            {
                cipher = m.Groups[1].ToString();
            }

            cipherTextBox.Enabled = true;
            cipherTextBox.Text = cipher;
            cipherTextBox.Enabled = false;
        }
开发者ID:jvutukur,项目名称:DistributedSoftwareDevelopmentProject,代码行数:30,代码来源:Payment.aspx.cs


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