/// <summary> /// Tries to create a hyperlink from the given text description. /// </summary> /// <param name="hyperlink">The text description of a hyperlink in HTML anchor format.</param> /// <param name="ownerId">The identifier of the object that owns the object opened with the hyperlink.</param> /// <returns>The hyperlink, if the given description of a hyperlink is valid; otherwise null.</returns> public ShellHyperlink TryParseHyperlink(string hyperlink, int ownerId) { var matches = Shell._HyperLinkRegex.Matches(hyperlink); if (matches.Count == 0) { return(null); } // If the text matches the hyperlink template // then return a hyperlink. var match = matches[0]; var uri = new Uri(match.Groups[1].Value); var title = match.Groups[2].Value; if (uri.IsUriShell()) { // Add owner ID to the view URI. var builder = new ShellUriBuilder(uri); builder.OwnerId = ownerId; uri = builder.Uri; } return(new ShellHyperlink(uri, title, null)); }
/// <summary> /// Creates an object from the given URI. /// </summary> /// <param name="uri">The URI that describes an object to be created.</param> /// <param name="attachmentSelector">The selector for acccess to attached to the given URI objects.</param> /// <returns>The object created from the given URI.</returns> public object Resolve(Uri uri, UriAttachmentSelector attachmentSelector) { var uriBuilder = new ShellUriBuilder(uri); var title = uriBuilder.Parameters["title"] ?? uri.ToString(); return(this._entitledItemFactory(title)); }
public void ParsesUriParametersWhenCreatedWithUri() { var builder = new ShellUriBuilder(new Uri("tst://testplacement:102/testmodule/testitem?p1=test Param1&p2=test Param2")); Assert.AreEqual(2, builder.Parameters.Count); Assert.AreEqual("test Param1", builder.Parameters["p1"]); Assert.AreEqual("test Param2", builder.Parameters["p2"]); }
public void ParsesUriWhenCreatedWithUri() { var builder = new ShellUriBuilder(new Uri("tst://testplacement:102/testmodule/testitem")); Assert.AreEqual("testplacement", builder.Placement); Assert.AreEqual(102, builder.OwnerId); Assert.AreEqual("testmodule", builder.Module); Assert.AreEqual("testitem", builder.Item); }
public void ParsesUriParametersWhenCreatedWithUri() { var builder = new ShellUriBuilder( new Uri("tst://testplacement:102/testmodule/testitem?p1=test Param1&p2=test Param2")); builder.Parameters .Should().HaveCount(2) .And.Contain("p1", "test Param1") .And.Contain("p2", "test Param2"); }
public void ParsesUriWhenCreatedWithUri() { var builder = new ShellUriBuilder( new Uri("tst://testplacement:102/testmodule/testitem")); builder.Placement.Should().Be("testplacement"); builder.OwnerId.Should().Be(102); builder.Module.Should().Be("testmodule"); builder.Item.Should().Be("testitem"); }
public void BuildsUriWhenCreatedEmpty() { var builder = new ShellUriBuilder(); builder.Placement = "newPlacement"; builder.OwnerId = 405; builder.Module = "newModule"; builder.Item = "newItem"; Assert.AreEqual(new Uri("tst://newPlacement:405/newModule/newItem"), builder.Uri); }
/// <summary> /// Determines an object's placement from the given URI. /// </summary> /// <param name="resolved">The object to be placed with the given URI.</param> /// <param name="uri">The URI used to determine an object's placement.</param> /// <param name="attachmentSelector">The selector for acccess to attached to the given URI objects.</param> /// <returns>The <see cref="IUriPlacementConnector"/> that allows to connect the given object to the /// user interface, if the placement was determined successfully; otherwise null.</returns> public IUriPlacementConnector Resolve(object resolved, Uri uri, UriAttachmentSelector attachmentSelector) { var builder = new ShellUriBuilder(uri); if (builder.Placement == "external" && resolved is Process) { return(this); } return(null); }
public void BuildsUriFluently() { var uri = ShellUriBuilder .StartUri() .Placement("fluentPlacement") .OwnerId(134) .Module("fluentModule") .Item("fluentItem") .End(); uri.Should().Be(new Uri("tst://fluentPlacement:134/fluentModule/fluentItem")); }
public void BuildsUriWhenCreatedEmpty() { var builder = new ShellUriBuilder() { Placement = "newPlacement", OwnerId = 405, Module = "newModule", Item = "newItem" }; builder.Uri.Should().Be(new Uri("tst://newPlacement:405/newModule/newItem")); }
public void BuildsUriFluently() { var uri = ShellUriBuilder .StartUri() .Placement("fluentPlacement") .OwnerId(134) .Module("fluentModule") .Item("fluentItem") .End(); Assert.AreEqual(new Uri("tst://fluentPlacement:134/fluentModule/fluentItem"), uri); }
public void BuildsUriWithParametersAndAttachmentsFluently() { var uri = ShellUriBuilder .StartUri() .Placement("fluentPlacement") .Module("fluentModule") .Item("fluentItem") .Parameter("p1", "v1") .Attachment("a1", 0) .Attachment("a2", 1) .End(); Assert.AreEqual(new Uri("tst://fluentPlacement/fluentModule/fluentItem?p1=v1&a1={0}&a2={1}"), uri); }
/// <summary> /// Creates an object from the given URI. /// </summary> /// <param name="uri">The URI that describes an object to be created.</param> /// <param name="attachmentSelector">The selector for acccess to attached to the given URI objects.</param> /// <returns>The object created from the given URI.</returns> public object Resolve(Uri uri, UriAttachmentSelector attachmentSelector) { var builder = new ShellUriBuilder(uri); var fileName = builder.Parameters["fileName"]; if (string.IsNullOrWhiteSpace(fileName)) { return(null); } return(new Process { StartInfo = new ProcessStartInfo(fileName), }); }
public void BuildsUriWithParametersWhenCreatedEmpty() { var builder = new ShellUriBuilder(); builder.Placement = "newPlacement"; builder.OwnerId = 405; builder.Module = "newModule"; builder.Item = "newItem"; builder.Parameters.Set("n1", "v10"); builder.Parameters.Set("n2", "v20"); builder.Parameters.Set("n3", "\t"); Assert.AreEqual(new Uri("tst://newPlacement:405/newModule/newItem?n1=v10&n2=v20&n3=%09"), builder.Uri); }
/// <summary> /// Creates a hyperlink for openening of the given <see cref="Uri"/>. /// </summary> /// <param name="uri">The URI, for which a hyperlink is created.</param> /// <returns>The hyperlink created for openening of the given <see cref="Uri"/>.</returns> public ShellHyperlink CreateHyperlink(Uri uri) { var builder = new ShellUriBuilder(uri); var title = builder.Parameters["title"]; var iconParameter = builder.Parameters["icon"]; Uri icon = null; if (!Uri.TryCreate(iconParameter, UriKind.Absolute, out icon)) { throw new ArgumentException(string.Format(Properties.Resources.InvalidIconUri, iconParameter)); } return(new ShellHyperlink(uri, title, icon)); }
public void BuildsUriWithParametersWhenCreatedEmpty() { var builder = new ShellUriBuilder() { Placement = "newPlacement", OwnerId = 405, Module = "newModule", Item = "newItem" }; builder.Parameters["n1"] = "v10"; builder.Parameters["n2"] = "v20"; builder.Parameters["n3"] = "\t"; builder.Uri.Should().Be(new Uri("tst://newPlacement:405/newModule/newItem?n1=v10&n2=v20&n3=%09")); }
public ResolvedIdBroadcastArgs(int resolvedId) { ShellUriBuilder.CheckOwnerId(resolvedId); ResolvedId = resolvedId; }