本文整理汇总了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();
}
示例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;
}
示例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");
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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();
}
示例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);
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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");
}
示例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();
}
示例14: UriConfiguration
public UriConfiguration(Uri baseAddress, UriTemplate recentFeedTemplate, UriTemplate feedTemplate, UriTemplate entryTemplate)
{
this.baseAddress = baseAddress;
this.recentFeedTemplate = recentFeedTemplate;
this.feedTemplate = feedTemplate;
this.entryTemplate = entryTemplate;
}
示例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;
}