public BindByPosition ( |
||
baseAddress | ||
return |
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; }
private void ConstructFastPathTable() { this.noTemplateHasQueryPart = true; foreach (KeyValuePair <UriTemplate, object> pair in this.templates) { UriTemplate key = pair.Key; if (!UriTemplateHelpers.CanMatchQueryTrivially(key)) { this.noTemplateHasQueryPart = false; } if (key.HasNoVariables && !key.HasWildcard) { if (this.fastPathTable == null) { this.fastPathTable = new Dictionary <string, FastPathInfo>(); } Uri uri = key.BindByPosition(this.originalUncanonicalizedBaseAddress, new string[0]); string uriPath = UriTemplateHelpers.GetUriPath(uri); if (!this.fastPathTable.ContainsKey(uriPath)) { FastPathInfo info = new FastPathInfo(); if (this.ComputeRelativeSegmentsAndLookup(uri, info.RelativePathSegments, info.Candidates)) { info.Freeze(); this.fastPathTable.Add(uriPath, info); } } } } }
public SerializedCompetition(Competition x, Uri Prefix, UriTemplate CompetitionTemplate, UriTemplate CompetitionResultTemplate) { ID = x.CompetitionID; Title = x.Title; Venue = x.Venue; ReferenceURI = CompetitionTemplate.BindByPosition(Prefix, ID.ToString()); CompetitionResultsURI = CompetitionResultTemplate.BindByPosition(Prefix, ID.ToString()); }
public SerializedResult(Result x, Uri Prefix, UriTemplate ResultResourceTemplate, UriTemplate FencerResourceTemplate,UriTemplate CompetitionResourceTemplate) { ID = x.ResultID; Placing = x.Placing; ReferenceURI = ResultResourceTemplate.BindByPosition(Prefix, ID.ToString()); FencerURI = FencerResourceTemplate.BindByPosition(Prefix, x.FencerID.ToString()); CompetitionURI = CompetitionResourceTemplate.BindByPosition(Prefix, x.CompetitionID.ToString()); }
public SerializedFencer(Fencer x, Uri Prefix, UriTemplate FencerTemplate, UriTemplate FencerResultTemplate) { ID = x.FencerID; LastName = x.LastName; FirstName = x.FirstName; Club = x.Club; ReferenceURI = FencerTemplate.BindByPosition(Prefix, ID.ToString()); FencerResultsURI = FencerResultTemplate.BindByPosition(Prefix, ID.ToString()); }
public SerializedResultArrayV1(List<Result> x, UriTemplateMatch templateMatch, Uri Prefix, UriTemplate ResultResourceTemplate, UriTemplate ResourceArrayTemplate) { Pagination = createPagination(x.Count,templateMatch, Prefix, ResourceArrayTemplate); List<SerializedResultArrayEntry> r = new List<SerializedResultArrayEntry>(); foreach (Result result in x) { r.Add(new SerializedResultArrayEntry(result, Prefix, ResultResourceTemplate)); } Results = filterResults(r); ReferenceURI = ResourceArrayTemplate.BindByPosition(Prefix,templateMatch.BoundVariables["id"]); }
private void formatUrls(UriTemplate resourceUri, Uri prefix, int ID) { dynamic dynamicUrls = new ExpandoObject(); //First if (page != 1) { Uri first = resourceUri.BindByPosition(prefix, ID.ToString(), "1"); dynamicUrls.first = first; Uri previous = resourceUri.BindByPosition(prefix, ID.ToString(), (page - 1).ToString()); dynamicUrls.previous = previous; } if (page != pages) { Uri last = resourceUri.BindByPosition(prefix, ID.ToString(), pages.ToString()); dynamicUrls.last = last; Uri next = resourceUri.BindByPosition(prefix, ID.ToString(), (page + 1).ToString()); dynamicUrls.next = next; } urls = dynamicUrls; }
public static void Main() { Uri prefix = new Uri("http://localhost/"); //A UriTemplate is a "URI with holes". It describes a set of URI's that //are structurally similar. This UriTemplate might be used for organizing //weather reports: UriTemplate template = new UriTemplate("weather/{state}/{city}"); //You can convert a UriTemplate into a Uri by filling //the holes in the template with parameters. //BindByPosition moves left-to-right across the template Uri positionalUri = template.BindByPosition(prefix, "Washington", "Redmond"); Console.WriteLine("Calling BindByPosition..."); Console.WriteLine(positionalUri); Console.WriteLine(); //BindByName takes a NameValueCollection of parameters. //Each parameter gets substituted into the UriTemplate "hole" //that has the same name as the parameter. NameValueCollection parameters = new NameValueCollection(); parameters.Add("state", "Washington"); parameters.Add("city", "Redmond"); Uri namedUri = template.BindByName(prefix, parameters); Console.WriteLine("Calling BindByName..."); Console.WriteLine(namedUri); Console.WriteLine(); //The inverse operation of Bind is Match(), which extrudes a URI //through the template to produce a set of name/value pairs. Uri fullUri = new Uri("http://localhost/weather/Washington/Redmond"); UriTemplateMatch results = template.Match(prefix, fullUri); Console.WriteLine(String.Format("Matching {0} to {1}", template.ToString(), fullUri.ToString())); if (results != null) { foreach (string variableName in results.BoundVariables.Keys) { Console.WriteLine(String.Format(" {0}: {1}", variableName, results.BoundVariables[variableName])); } } Console.WriteLine("Press any key to terminate"); Console.ReadLine(); }
public void Create(Movie movie) { WebOperationContext context = WebOperationContext.Current; UriTemplateMatch match = context.IncomingRequest.UriTemplateMatch; UriTemplate template = new UriTemplate("/movie/{id}"); index++; // generate new ID movie.ID = index; movies.Add(index, movie); Uri uri = template.BindByPosition(match.BaseUri, movie.ID.ToString()); context.OutgoingResponse.SetStatusAsCreated(uri); context.OutgoingResponse.StatusDescription = String.Format("Movie id '{0}' created", movie.ID); }
public Customer AddCustomer(Customer customer) { lock (writeLock) { counter++; UriTemplateMatch match = WebOperationContext.Current.IncomingRequest.UriTemplateMatch; UriTemplate template = new UriTemplate("{id}"); customer.Uri = template.BindByPosition(match.BaseUri, counter.ToString()); customers[counter.ToString()] = customer; WebOperationContext.Current.OutgoingResponse.SetStatusAsCreated(customer.Uri); } return customer; }
public string get_UV_Index(String zipcode) { String uvIndex = ""; try { Uri baseUri = new Uri("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVDAILY"); UriTemplate myTemplate = new UriTemplate("/ZIP/{zipCode}"); Uri completeUri = myTemplate.BindByPosition(baseUri, zipcode); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(completeUri.ToString()); uvIndex =uvIndex+ xmlDoc.GetElementsByTagName("UV_INDEX")[0].InnerText; int indexAsInt = Int32.Parse(uvIndex); if(uvIndex=="") { uvIndex="Invalid zipcode. Please try againg"; } else if(indexAsInt<=5) { uvIndex = "Uv Index value is " + uvIndex + " \n 0-5 is moderate"; } else if(indexAsInt<=8) { //6-8 is high uvIndex = "Today UV Index value in this location is " + uvIndex + " (6-8 is high)"; } else { //above 8 better stay inside uvIndex = "UV Index value in this location is " + uvIndex + " ( 8-11 is very high take necessary precautions)"; } //A character indicating if there is a UV Index alert issued for this area on the forecast day. } catch(Exception e) { } return uvIndex; }
void ConstructFastPathTable() { this.noTemplateHasQueryPart = true; foreach (KeyValuePair <UriTemplate, object> kvp in this.templates) { UriTemplate ut = kvp.Key; if (!UriTemplateHelpers.CanMatchQueryTrivially(ut)) { this.noTemplateHasQueryPart = false; } if (ut.HasNoVariables && !ut.HasWildcard) { // eligible for fast path if (this.fastPathTable == null) { this.fastPathTable = new Dictionary <string, FastPathInfo>(); } Uri uri = ut.BindByPosition(this.originalUncanonicalizedBaseAddress); string uriPath = UriTemplateHelpers.GetUriPath(uri); if (this.fastPathTable.ContainsKey(uriPath)) { // nothing to do, we've already seen it } else { FastPathInfo fpInfo = new FastPathInfo(); if (ComputeRelativeSegmentsAndLookup(uri, fpInfo.RelativePathSegments, fpInfo.Candidates)) { fpInfo.Freeze(); this.fastPathTable.Add(uriPath, fpInfo); } } } } }
public void BindByPositionNullBaseAddress () { var t = new UriTemplate ("http://localhost:8080/"); t.BindByPosition (null); }
/// <summary> /// Gets the torrent file download Uri with which other peers can download /// the torrent file from this server. /// </summary> /// <param name="nameSpace">The name space.</param> /// <param name="name">The name.</param> public string GetTorrentFileUrlToPublish(string nameSpace, string name) { var template = new UriTemplate("TorrentData/{namespace}/{name}/TorrentFile"); var baseAddr = string.Format("http://{0}:{1}", _hostIP, _gsserverPort); Uri retVal = template.BindByPosition(new Uri(baseAddr), nameSpace, name); return retVal.ToString(); }
public IEnumerable<Uri> GetValidURIs() { var _context = SelectedAssets.FirstOrDefault().GetMediaContext(); IEnumerable<Uri> ValidURIs; IAsset asset = SelectedAssets.FirstOrDefault(); var ismFile = asset.AssetFiles.AsEnumerable().Where(f => f.Name.EndsWith(".ism")).OrderByDescending(f => f.IsPrimary).FirstOrDefault(); if (ismFile != null) { var locators = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin && l.ExpirationDateTime > DateTime.UtcNow).OrderByDescending(l => l.ExpirationDateTime); var template = new UriTemplate("{contentAccessComponent}/{ismFileName}/manifest"); ValidURIs = locators.SelectMany(l => _context .StreamingEndpoints .AsEnumerable() .Where(o => (o.State == StreamingEndpointState.Running) && (o.ScaleUnits > 0)) .OrderByDescending(o => o.CdnEnabled) .Select( o => template.BindByPosition(new Uri("http://" + o.HostName), l.ContentAccessComponent, ismFile.Name))) .ToArray(); return ValidURIs; } else { return null; } }
public SerializedResultArrayEntry(Result x, Uri Prefix, UriTemplate ResultResourceTemplate) { ID = x.ResultID; ReferenceURI = ResultResourceTemplate.BindByPosition(Prefix, ID.ToString()); }
public void CreateXElement(XElement user) { WebOperationContext context = WebOperationContext.Current; UriTemplateMatch match = context.IncomingRequest.UriTemplateMatch; UriTemplate template = new UriTemplate("/user/xml/{id}"); MediaType mediaType = MediaType.Parse(context.IncomingRequest.ContentType); if (user.Element("ID") != null && !String.IsNullOrEmpty(user.Element("ID").Value)) { context.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest; context.OutgoingResponse.StatusDescription = String.Format("User id '{0}' already exists", user.Element("ID")); return; } User newUser = new User(); newUser.ID = (users.Count + 1).ToString(); // generate new ID newUser.Name = user.Element("Name").Value; users.Add(newUser); Uri uri = template.BindByPosition(match.BaseUri, newUser.ID); context.OutgoingResponse.SetStatusAsCreated(uri); context.OutgoingResponse.StatusDescription = String.Format("User id '{0}' created with '{1}'", newUser.ID, newUser.Name); }
public static XElement SearchFromFingerprint(int duration, string fingerprint) { var ut = new UriTemplate("v2/lookup?client=JnD0gnNt&meta=recordings&format=xml&duration={0}&fingerprint={1}"); Uri url = ut.BindByPosition(new Uri("http://api.acoustid.org"), duration.ToString(), fingerprint); using (var web = new WebClient()) { web.Encoding = Encoding.UTF8; return XElement.Parse(web.DownloadString(url)); } }
public static System.Collections.Generic.List<System.Uri> ReturnMainStreamingURLs(string aChannelName) { //Set Azure credentials if (_context == null) SetMediaServicesCredentials(); // _context.Assets.Where(a => a.Name == aAssetName).FirstOrDefault(); // var asset = _context.Assets.Where(a => a.Name == aAssetName).FirstOrDefault(); var asset = _context.Channels.Where(c => c.Name == aChannelName).FirstOrDefault().Programs.FirstOrDefault().Asset; //context.Channels.Where(c=> c.Name == aChannelName).FirstOrDefault().Programs.FirstOrDefault().Asset; var locators = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin); var ismFile = asset.AssetFiles.AsEnumerable().FirstOrDefault(a => a.Name.EndsWith(".ism")); var template = new UriTemplate("{contentAccessComponent}/{ismFileName}/manifest"); return locators.SelectMany(l => _context .StreamingEndpoints .AsEnumerable() .Where(se => se.State == StreamingEndpointState.Running) .Select( se => template.BindByPosition(new Uri("http://" + se.HostName), l.ContentAccessComponent, ismFile.Name))) .ToList(); }
public void BindByPosition () { var t = new UriTemplate ("/{foo}/{bar}/"); var u = t.BindByPosition (new Uri ("http://localhost/"), "value1", "value2"); Assert.AreEqual ("http://localhost/value1/value2/", u.ToString ()); }
public void BindByPositionFileExtraValues () { var t = new UriTemplate ("http://localhost:8080/"); t.BindByPosition (new Uri ("http://localhost/"), "value"); }
public void BindByPositionRelativeBaseAddress () { var t = new UriTemplate ("http://localhost:8080/"); t.BindByPosition (new Uri ("", UriKind.Relative)); }
[Category ("NotWorking")] // not worthy public void BindByPositionFileUriBaseAddress () { var t = new UriTemplate ("http://localhost:8080/"); Assert.AreEqual (new Uri ("file:///http://localhost:8080/"), t.BindByPosition (new Uri ("file:///"))); }
//[WebGet(UriTemplate="help")] public Atom10FeedFormatter GetFeed() { List<SyndicationItem> items = new List<SyndicationItem>(); foreach (OperationDescription od in this.Description.Operations) { WebGetAttribute get; WebInvokeAttribute invoke; GetWebGetAndInvoke(od, out get, out invoke); string method = GetMethod(get, invoke); string requestFormat = null; if (invoke != null) { requestFormat = GetRequestFormat(invoke, od); } string responseFormat = GetResponseFormat(get, invoke, od); string uriTemplate = GetUriTemplate(get, invoke, od); WebMessageBodyStyle bodyStyle = GetBodyStyle(get, invoke); string requestSchemaLink = null; string responseSchemaLink = null; string requestExampleLink = null; string responseExampleLink = null; if (bodyStyle == WebMessageBodyStyle.Bare) { UriTemplate responseSchemaTemplate = new UriTemplate(OperationResponseSchemaTemplate); responseSchemaLink = responseSchemaTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri; UriTemplate responseExampleTemplate = new UriTemplate(OperationResponseExampleTemplate); responseExampleLink = responseExampleTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri; if (invoke != null) { UriTemplate requestSchemaTemplate = new UriTemplate(OperationRequestSchemaTemplate); requestSchemaLink = requestSchemaTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri; UriTemplate requestExampleTemplate = new UriTemplate(OperationRequestExampleTemplate); requestExampleLink = requestExampleTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri; } } uriTemplate = String.Format("{0}/{1}", this.BaseUri.AbsoluteUri, uriTemplate); uriTemplate = HttpUtility.HtmlEncode(uriTemplate); string xhtmlDescription = String.Format("<div xmlns=\"http://www.w3.org/1999/xhtml\"><table border=\"5\"><tr><td>UriTemplate</td><td>{0}</td></tr><tr><td>Method</td><td>{1}</td></tr>", uriTemplate, method); if (!string.IsNullOrEmpty(requestFormat)) { xhtmlDescription += String.Format("<tr><td>Request Format</td><td>{0}</td></tr>", requestFormat); } if (requestSchemaLink != null) { xhtmlDescription += String.Format("<tr><td>Request Schema</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(requestSchemaLink)); } if (requestExampleLink != null) { xhtmlDescription += String.Format("<tr><td>Request Example</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(requestExampleLink)); } xhtmlDescription += String.Format("<tr><td>Response Format</td><td>{0}</td></tr>", responseFormat); if (responseSchemaLink != null) { xhtmlDescription += String.Format("<tr><td>Response Schema</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(responseSchemaLink)); } if (responseExampleLink != null) { xhtmlDescription += String.Format("<tr><td>Response Example</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(responseExampleLink)); } WebHelpAttribute help = od.Behaviors.Find<WebHelpAttribute>(); if (help != null && !string.IsNullOrEmpty(help.Comment)) { xhtmlDescription += String.Format("<tr><td>Description</td><td>{0}</td></tr>", help.Comment); } xhtmlDescription += "</table></div>"; SyndicationItem item = new SyndicationItem() { Id = "http://tmpuri.org/" + od.Name, Content = new TextSyndicationContent(xhtmlDescription, TextSyndicationContentKind.XHtml), LastUpdatedTime = DateTime.UtcNow, Title = new TextSyndicationContent(String.Format("{0}: {1}", Description.Name, od.Name)), }; items.Add(item); } SyndicationFeed feed = new SyndicationFeed() { Title = new TextSyndicationContent("Service help page"), Id = feedId, LastUpdatedTime = DateTime.UtcNow, Items = items }; WebOperationContext.Current.OutgoingResponse.ContentType = "application/atom+xml"; return feed.GetAtom10Formatter(); }
public void BindByPositionFileMissingValues () { var t = new UriTemplate ("/{foo}/"); t.BindByPosition (new Uri ("http://localhost/")); }
public Stream Post(Stream stream) { WebOperationContext context = WebOperationContext.Current; UriTemplateMatch match = context.IncomingRequest.UriTemplateMatch; UriTemplate template = new UriTemplate("/user/{id}"); MediaType mediaType = MediaType.Parse(context.IncomingRequest.ContentType); Encoding encoding = (mediaType == null) ? Encoding.UTF8 : mediaType.CharSet; string id = (users.Count + 1).ToString(); // generate new ID string name; using (StreamReader reader = new StreamReader(stream, encoding)) { name = reader.ReadToEnd(); } if (String.IsNullOrEmpty(name)) { context.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest; context.OutgoingResponse.StatusDescription = "Content cannot be null or empty"; return CreateTextResponse(context, ""); } users.Add(id, name); Uri uri = template.BindByPosition(match.BaseUri, id); context.OutgoingResponse.SetStatusAsCreated(uri); context.OutgoingResponse.StatusDescription = String.Format("User id '{0}' created with '{1}'", id, name); return CreateTextResponse(context, id); }
[ExpectedException (typeof (FormatException))] // it does not allow default values public void BindByPositionWithDefaults () { var d = new Dictionary<string,string> (); d ["baz"] = "value3"; var t = new UriTemplate ("/{foo}/{bar}/{baz}", d); t.BindByPosition (new Uri ("http://localhost/"), "value1", "value2"); }
private Uri GetUserLink(string username) { Uri baseUri = OperationContext.Current.Host.BaseAddresses[0]; UriTemplate template = new UriTemplate("users/{username}"); Uri userUri = template.BindByPosition(baseUri, username); return userUri; }
public static void GetLocatorsInAllStreamingEndpoints(IAsset asset) { var locators = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin); var ismFile = asset.AssetFiles.AsEnumerable().FirstOrDefault(a => a.Name.EndsWith(".ism")); var template = new UriTemplate("{contentAccessComponent}/{ismFileName}/manifest"); var urls = locators.SelectMany(l => _context .StreamingEndpoints .AsEnumerable() .Where(se => se.State == StreamingEndpointState.Running) .Select( se => template.BindByPosition(new Uri("http://" + se.HostName), l.ContentAccessComponent, ismFile.Name))) .ToArray(); foreach (var url in urls) { Console.WriteLine(url); } }
public IEnumerable<Uri> GetNotValidURIs() { IEnumerable<Uri> NotValidURIs; IAsset asset = _context.Assets.Where(a => a.Id == SelectedPrograms.FirstOrDefault().AssetId).Single(); var ismFile = asset.AssetFiles.AsEnumerable().FirstOrDefault(f => f.Name.EndsWith(".ism")); if (ismFile != null) { var locators = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin); var template = new UriTemplate("{contentAccessComponent}/{ismFileName}/manifest"); NotValidURIs = locators.SelectMany(l => _context .StreamingEndpoints .AsEnumerable() .Where(o => (o.State != StreamingEndpointState.Running) || (o.ScaleUnits == 0)) .Select( o => template.BindByPosition(new Uri("http://" + o.HostName), l.ContentAccessComponent, ismFile.Name))) .ToArray(); return NotValidURIs; } else { return null; } }
private void Register(string route, string verb) { if (_router == null) { _http.RegisterControllerAction(new ControllerAction(route, verb, Codec.NoCodecs, SupportedCodecs), (x, y) => { x.Reply(new byte[0], 200, "", "", Helper.UTF8NoBom, null, e => new Exception()); CountdownEvent.Signal(); }); } else { _router.RegisterControllerAction(new ControllerAction(route, verb, Codec.NoCodecs, SupportedCodecs), (x, y) => { CountdownEvent.Signal(); }); } var uriTemplate = new UriTemplate(route); var bound = uriTemplate.BindByPosition(new Uri("http://localhost:12345/"), Enumerable.Range(0, uriTemplate.PathSegmentVariableNames.Count + uriTemplate.QueryValueVariableNames.Count) .Select(x => "abacaba") .ToArray()); BoundRoutes.Add(Tuple.Create(bound.AbsoluteUri, verb)); }
public void CreateDataContract(User user) { WebOperationContext context = WebOperationContext.Current; UriTemplateMatch match = context.IncomingRequest.UriTemplateMatch; UriTemplate template = new UriTemplate("/user/dc/{id}"); MediaType mediaType = MediaType.Parse(context.IncomingRequest.ContentType); if (!String.IsNullOrEmpty(user.ID)) { context.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest; context.OutgoingResponse.StatusDescription = String.Format("User id '{0}' already exists", user.ID); return; } user.ID = (users.Count + 1).ToString(); // generate new ID users.Add(user); Uri uri = template.BindByPosition(match.BaseUri, user.ID); context.OutgoingResponse.SetStatusAsCreated(uri); context.OutgoingResponse.StatusDescription = String.Format("User id '{0}' created with '{1}'", user.ID, user.Name); }