本文整理汇总了C#中XUri类的典型用法代码示例。如果您正苦于以下问题:C# XUri类的具体用法?C# XUri怎么用?C# XUri使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XUri类属于命名空间,在下文中一共展示了XUri类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Can_roundtrip_DispatchItem_with_complex_event
public void Can_roundtrip_DispatchItem_with_complex_event()
{
var body = new XDoc("msg").Elem("foo", "bar");
var channel = new XUri("channel://foo.com/bar");
var resource = new XUri("http://foo.com/baz/0");
var origin1 = new XUri("http://foo.com/baz/1");
var origin2 = new XUri("http://foo.com/baz/2");
var recipient1 = new DispatcherRecipient(new XUri("http://recipient1"));
var recipient2 = new DispatcherRecipient(new XUri("http://recipient2"));
var via1 = new XUri("http://via1");
var via2 = new XUri("http://via2");
var ev = new DispatcherEvent(body, channel, resource, origin1, origin2);
ev = ev.WithRecipient(false, recipient1, recipient2).WithVia(via1).WithVia(via2);
var item = new DispatchItem(
new XUri("http://foo"),
ev,
"abc"
);
var serializer = new DispatchItemSerializer();
var stream = serializer.ToStream(item);
var item2 = serializer.FromStream(stream);
Assert.AreEqual(item.Uri, item2.Uri, "uri mismatch");
Assert.AreEqual(item.Location, item2.Location, "location mismatch");
Assert.AreEqual(item.Event.Id, item2.Event.Id, "id mismatch");
Assert.AreEqual(body.ToCompactString(), item2.Event.AsDocument().ToCompactString(), "body mismatch");
Assert.AreEqual(channel, item2.Event.Channel, "channel mismatch");
Assert.AreEqual(resource, item2.Event.Resource, "resource mismatch");
Assert.AreEqual(origin1, item2.Event.Origins[0], "first origin mismatch");
Assert.AreEqual(origin2, item2.Event.Origins[1], "second origin mismatch");
Assert.AreEqual(recipient1.Uri, item2.Event.Recipients[0].Uri, "first recipient mismatch");
Assert.AreEqual(recipient2.Uri, item2.Event.Recipients[1].Uri, "second recipient mismatch");
Assert.AreEqual(via1, item2.Event.Via[0], "first via mismatch");
Assert.AreEqual(via2, item2.Event.Via[1], "second via mismatch");
}
开发者ID:sdether,项目名称:DReAM,代码行数:34,代码来源:DispatchItemSerializerTests.cs
示例2: Can_roundtrip_AtPath_via_GetRelativePathTo_with_trailing_slash_on_base
public void Can_roundtrip_AtPath_via_GetRelativePathTo_with_trailing_slash_on_base()
{
var relative = "b/c";
var baseUri = new XUri("http://foo/a/");
var combined = baseUri.AtPath(relative);
Assert.AreEqual(relative, combined.GetRelativePathTo(baseUri));
}
开发者ID:maximmass,项目名称:DReAM,代码行数:7,代码来源:XUri-Test.cs
示例3: Deregister
public void Deregister(XUri uri)
{
lock(_registry) {
if(!_registry.ContainsKey(uri)) {
return;
}
_registry.Remove(uri);
_map.Remove(uri);
}
}
开发者ID:nataren,项目名称:DReAM,代码行数:10,代码来源:MockEndpoint.cs
示例4: Exact_Match
public void Exact_Match()
{
XUriMap<string> map = new XUriMap<string>();
string key = "foo/bar";
map[new XUri("test://foo/bar")] = key;
string match;
int similarity;
XUri test = new XUri("test://foo/bar");
map.TryGetValue(test, out match, out similarity);
Assert.AreEqual(key, match);
Assert.AreEqual(test.MaxSimilarity, similarity);
}
开发者ID:nataren,项目名称:DReAM,代码行数:12,代码来源:XUriMapTests.cs
示例5: HttpTransport
//--- Constructors ---
public HttpTransport(IDreamEnvironment env, XUri uri, AuthenticationSchemes authenticationSheme)
{
if(env == null) {
throw new ArgumentNullException("env");
}
if(uri == null) {
throw new ArgumentNullException("uri");
}
_env = env;
_uri = uri.WithoutCredentialsPathQueryFragment();
_minSimilarity = _uri.MaxSimilarity;
_sourceInternal = _uri + " (internal)";
_sourceExternal = _uri.ToString();
_authenticationSheme = authenticationSheme;
}
开发者ID:sdether,项目名称:DReAM,代码行数:16,代码来源:httptransport.cs
示例6: GetScoreWithNormalizedUri
//--- Methods ---
public int GetScoreWithNormalizedUri(XUri uri, out XUri normalized)
{
normalized = uri;
switch(uri.Scheme.ToLowerInvariant()) {
case "http":
case "https":
return 1;
case "ext-http":
normalized = normalized.WithScheme("http");
return int.MaxValue;
case "ext-https":
normalized = normalized.WithScheme("https");
return int.MaxValue;
default:
return 0;
}
}
开发者ID:danice,项目名称:DReAM,代码行数:18,代码来源:HttpPlugEndpoint.cs
示例7: HttpTransport
//--- Constructors ---
public HttpTransport(IDreamEnvironment env, XUri uri, AuthenticationSchemes authenticationSheme, string dreamInParamAuthtoken)
{
if(env == null) {
throw new ArgumentNullException("env");
}
if(uri == null) {
throw new ArgumentNullException("uri");
}
_env = env;
_uri = uri.WithoutCredentialsPathQueryFragment();
_minSimilarity = _uri.MaxSimilarity;
_sourceInternal = _uri + " (internal)";
_sourceExternal = _uri.ToString();
_authenticationSheme = authenticationSheme;
_dreamInParamAuthtoken = dreamInParamAuthtoken;
this.ServerSignature = "Dream-HTTPAPI/" + DreamUtil.DreamVersion;
}
开发者ID:nataren,项目名称:DReAM,代码行数:18,代码来源:httptransport.cs
示例8: Can_roundtrip_DispatchItem
public void Can_roundtrip_DispatchItem()
{
var msg = new XDoc("msg");
var channel = new XUri("channel://foo.com/bar");
var origin = new XUri("http://foo.com/baz");
var ev = new DispatcherEvent(msg, channel, origin);
var item = new DispatchItem(
new XUri("http://foo"),
ev,
"abc"
);
var serializer = new DispatchItemSerializer();
var stream = serializer.ToStream(item);
var item2 = serializer.FromStream(stream);
Assert.AreEqual(item.Uri, item2.Uri, "uri mismatch");
Assert.AreEqual(item.Location, item2.Location, "location mismatch");
Assert.AreEqual(item.Event.Id, item2.Event.Id, "id mismatch");
}
开发者ID:sdether,项目名称:DReAM,代码行数:18,代码来源:DispatchItemSerializerTests.cs
示例9: Add_via_to_event
public void Add_via_to_event()
{
XDoc msg = new XDoc("msg");
XUri via1 = new XUri("http://foo.com/route1");
XUri via2 = new XUri("http://foo.com/route2");
DispatcherEvent ev1 = new DispatcherEvent(msg, new XUri("channel://foo.com/bar"), new XUri("http://foo.com/baz"));
DispatcherEvent ev2 = ev1.WithVia(via1);
Assert.AreEqual(0, ev1.Via.Length);
Assert.AreEqual(1, ev2.Via.Length);
Assert.AreEqual(via1, ev2.Via[0]);
DispatcherEvent ev3 = ev2.WithVia(via2);
Assert.AreEqual(2, ev3.Via.Length);
Assert.AreEqual(via1, ev3.Via[0]);
Assert.AreEqual(via2, ev3.Via[1]);
DreamMessage ev3msg = ev3.AsMessage();
Assert.AreEqual(msg, ev3msg.ToDocument());
Assert.AreEqual(ev1.Id, ev3.Id);
Assert.AreEqual("channel://foo.com/bar", ev3msg.Headers.DreamEventChannel);
Assert.AreEqual("http://foo.com/baz", ev3msg.Headers.DreamEventOrigin[0]);
Assert.AreEqual(via1.ToString(), ev3msg.Headers.DreamEventVia[0]);
}
开发者ID:sdether,项目名称:DReAM,代码行数:21,代码来源:EventTests.cs
示例10: Adding_new_sub_will_push_combined_set_to_upstream_subscriber
public void Adding_new_sub_will_push_combined_set_to_upstream_subscriber()
{
var downstream = CreatePubSubService().WithInternalKey().AtLocalHost;
var upstreamUri = new XUri("http://upstream/");
var upstreamMock = MockPlug.Register(upstreamUri);
XDoc downstreamSet = null;
upstreamMock.Expect().Verb("POST").RequestDocument(_ => {
downstreamSet = _;
return true;
}).Response(DreamMessage.Ok());
var subscribeToDownstream = new XDoc("subscription-set")
.Elem("uri.owner", upstreamUri)
.Start("subscription")
.Attr("id", "1")
.Elem("channel", "pubsub://*/*")
.Start("recipient").Elem("uri", upstreamUri).End()
.End();
// subscribe to set updates from downstream, expect most recent version to be pushed
var downstreamResponse = downstream.At("subscribers").PostAsync(subscribeToDownstream).Wait();
Assert.IsTrue(downstreamResponse.IsSuccessful, downstreamResponse.ToText());
Assert.IsTrue(upstreamMock.WaitAndVerify(TimeSpan.FromSeconds(10)), upstreamMock.VerificationFailure);
// someone else posts a subscription, expect a new push including that sub
upstreamMock.Expect().Verb("POST").RequestDocument(_ => {
downstreamSet = _;
return true;
}).Response(DreamMessage.Ok());
var subscription = new XDoc("subscription-set")
.Elem("uri.owner", "http://foo/")
.Start("subscription")
.Attr("id", "1")
.Elem("channel", "foo://bar/baz")
.Start("recipient").Elem("uri", "http://foo/bar").End()
.End();
var subResponse = downstream.At("subscribers").PostAsync(subscription).Wait();
Assert.IsTrue(subResponse.IsSuccessful, subResponse.ToText());
Assert.IsTrue(upstreamMock.WaitAndVerify(TimeSpan.FromSeconds(10)), upstreamMock.VerificationFailure);
Assert.AreEqual(1, downstreamSet["subscription[channel='foo://bar/baz']"].ListLength);
}
开发者ID:sdether,项目名称:DReAM,代码行数:40,代码来源:PubSubServiceTests.cs
示例11: convert
public Yield convert(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
string methodStr = context.GetParam("method", string.Empty);
string aliasStr = context.GetParam("id", string.Empty);
XUri secPage = new XUri( context.ServerUri ).At( "deki", "pages", "=Convert:" + methodStr );
Plug _dekiSec = Plug.New( secPage );
XDoc secDoc = _dekiSec.Get().ToDocument();
string userURL = secDoc["user.author/@href"].AsInnerText;
Plug _dekiUser = Plug.New( userURL );
XDoc userDoc = _dekiUser.Get().ToDocument();
string perms = userDoc["permissions.user"]["operations"].AsInnerText;
if ( !perms.Contains("UNSAFECONTENT") ) {
response.Return( DreamMessage.Forbidden("UNSAFECONTENT not enabled") );
yield break;
}
XUri codePage = new XUri( context.ServerUri ).At( "deki","pages", "=Convert:" + methodStr,"contents");
Plug _deki = Plug.New( codePage, new TimeSpan(0,0,15) );
string bodyText = _deki.With("format", "xhtml").Get().ToDocument()["body"]["pre"].Contents;
for ( int i = 0; i < toHTML.GetLength(0); i++ ) {
bodyText = Regex.Replace( bodyText, toHTML[i,0], toHTML[i,1] );
}
//string codeStr = HttpUtility.HtmlDecode( bodyText );
//XDoc doc = XDocFactory.From( codeStr, MimeType.ANY );
//response.Return( DreamMessage.Ok( MimeType.TEXT, bodyText ) );
Assembly scriptCode = CompileCode( bodyText, response );
if ( scriptCode != null ) {
XmlDocument outDoc = runScript( scriptCode, aliasStr );
response.Return( DreamMessage.Ok( MimeType.XML, new XDoc(outDoc) ) );
}
yield break;
}
开发者ID:kellrott,项目名称:ConvertPort,代码行数:36,代码来源:ConvertPort.cs
示例12: Can_mock_a_request_with_a_stream_body
public void Can_mock_a_request_with_a_stream_body()
{
var tmp = Path.GetTempFileName();
var payload = "blahblah";
File.WriteAllText(tmp, payload);
var message = DreamMessage.FromFile(tmp);
var uri = new XUri("http://mock/post/stream");
MockPlug.Setup(uri).Verb("POST")
.WithMessage(m => m.ToText() == payload)
.ExpectAtLeastOneCall();
var response = Plug.New(uri).Post(message, new Result<DreamMessage>()).Wait();
response.AssertSuccess();
MockPlug.VerifyAll(1.Seconds());
}
开发者ID:heran,项目名称:DReAM,代码行数:14,代码来源:MockPlugTests.cs
示例13: Deregister_allows_reregister_of_uri
public void Deregister_allows_reregister_of_uri()
{
XUri uri = new XUri("http://www.mindtouch.com/foo");
int firstCalled = 0;
MockPlug.Register(uri, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
firstCalled++;
r2.Return(DreamMessage.Ok());
});
Assert.IsTrue(Plug.New(uri).GetAsync().Wait().IsSuccessful);
Assert.AreEqual(1, firstCalled);
MockPlug.Deregister(uri);
int secondCalled = 0;
MockPlug.Register(uri, delegate(Plug p, string v, XUri u, DreamMessage r, Result<DreamMessage> r2) {
secondCalled++;
r2.Return(DreamMessage.Ok());
});
Assert.IsTrue(Plug.New(uri).GetAsync().Wait().IsSuccessful);
Assert.AreEqual(1, firstCalled);
Assert.AreEqual(1, secondCalled);
}
开发者ID:maximmass,项目名称:DReAM,代码行数:20,代码来源:MockPlugTests.cs
示例14: MockPlugInvocation
//--- Constructors ---
internal MockPlugInvocation(string verb, XUri uri, DreamMessage request, DreamHeaders responseHeaders) {
Verb = verb;
Uri = uri;
Request = request;
ResponseHeaders = responseHeaders;
}
开发者ID:sdether,项目名称:DReAM,代码行数:7,代码来源:MockPlugInvocation.cs
示例15: SyncUri
public DreamMessage SyncUri(XUri uri)
{
return Response(new XDoc("r").Elem("uri", uri.WithoutQuery()));
}
开发者ID:aaronmars,项目名称:DReAM,代码行数:4,代码来源:DreamFeatureTests.cs
示例16: PubSubSubscriptionSet
/// <summary>
/// Create a new subscription set from a subscription set document.
/// </summary>
/// <param name="setDoc">Set Xml document.</param>
/// <param name="location">location id.</param>
/// <param name="accessKey">secret key for accessing the set.</param>
public PubSubSubscriptionSet(XDoc setDoc, string location, string accessKey)
{
try {
// Note: not using AsUri to avoid automatic local:// translation
Owner = new XUri(setDoc["uri.owner"].AsText);
MaxFailureDuration = (setDoc["@max-failure-duration"].AsDouble ?? 0).Seconds();
var subscriptions = new List<PubSubSubscription>();
foreach(XDoc sub in setDoc["subscription"]) {
subscriptions.Add(new PubSubSubscription(sub, this));
}
Version = setDoc["@version"].AsLong;
Subscriptions = subscriptions.ToArray();
Location = location;
AccessKey = accessKey;
MaxFailures = UsesFailureDuration ? int.MaxValue : setDoc["@max-failures"].AsInt ?? MAX_FAILURES;
} catch(Exception e) {
throw new ArgumentException("Unable to parse subscription set: " + e.Message, e);
}
}
开发者ID:sdether,项目名称:DReAM,代码行数:25,代码来源:PubSubSubscriptionSet.cs
示例17: Invoke
public IEnumerator<IYield> Invoke(Plug plug, string verb, XUri uri, DreamMessage request, Result<DreamMessage> response)
{
var match = GetBestMatch(uri);
yield return AsyncUtil.Fork(() => match.Invoke(plug, verb, uri, MemorizeAndClone(request), response), new Result(TimeSpan.MaxValue));
}
开发者ID:nataren,项目名称:DReAM,代码行数:5,代码来源:MockEndpoint.cs
示例18: PubSub_downstream_chaining_and_subscription_propagation
public void PubSub_downstream_chaining_and_subscription_propagation()
{
XUri downstreamUri = new XUri("http://localhost/downstream");
var mock = MockPlug.Register(downstreamUri);
XDoc downstreamDoc = null;
mock.Expect().Verb("GET").Uri(downstreamUri).Response(DreamMessage.Ok(new XDoc("subscription-set")
.Elem("uri.owner", downstreamUri)
.Start("subscription")
.Attr("id", "1")
.Elem("channel", "channel:///foo/*")
.Elem("uri.proxy", downstreamUri.At("publish"))
.Start("recipient").Elem("uri", "http:///foo/sub1").End()
.End()));
mock.Expect().Verb("POST").Uri(downstreamUri).RequestDocument(doc => {
downstreamDoc = doc;
return true;
});
// create service, which should subscribe to the upstream one
Plug upstreamPubSub = CreatePubSubService(new XDoc("config").Start("downstream").Elem("uri", downstreamUri).End()).WithInternalKey().AtLocalHost;
Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(10)), mock.VerificationFailure);
var subUri = downstreamDoc["subscription/recipient/uri"].AsUri.AsPublicUri();
Plug.GlobalCookies.Update(DreamCookie.ParseAllSetCookieNodes(downstreamDoc["subscription/set-cookie"]), subUri);
Assert.AreEqual("pubsub://*/*", downstreamDoc["subscription/channel"].AsText);
Assert.AreEqual(upstreamPubSub.Uri.WithoutQuery(), downstreamDoc["uri.owner"].AsUri);
Assert.AreEqual(upstreamPubSub.Uri.At("subscribers").WithoutQuery(), subUri.WithoutLastSegment());
// check that our set is properly represented by the upstream service
DreamMessage upstreamSet = upstreamPubSub.At("subscribers").GetAsync().Wait();
Assert.IsTrue(upstreamSet.IsSuccessful);
XDoc upstreamDoc = upstreamSet.ToDocument();
Assert.AreEqual(1, upstreamDoc["subscription"].ListLength);
Assert.AreEqual("channel:///foo/*", upstreamDoc["subscription/channel"].AsText);
// update the subscription set on the upstream service
XDoc set2 = new XDoc("subscription-set")
.Elem("uri.owner", downstreamUri)
.Start("subscription")
.Attr("id", "1")
.Elem("channel", "channel:///bar/*")
.Elem("uri.proxy", downstreamUri.At("publish"))
.Start("recipient").Elem("uri", "http:///foo/sub1").End()
.End();
DreamMessage subPush = Plug.New(subUri).PostAsync(set2).Wait();
Assert.IsTrue(subPush.IsSuccessful);
upstreamSet = upstreamPubSub.At("subscribers").GetAsync().Wait();
Assert.IsTrue(upstreamSet.IsSuccessful);
upstreamDoc = upstreamSet.ToDocument();
Assert.AreEqual(1, upstreamDoc["subscription"].ListLength);
Assert.AreEqual("channel:///bar/*", upstreamDoc["subscription/channel"].AsText);
}
开发者ID:sdether,项目名称:DReAM,代码行数:51,代码来源:PubSubServiceTests.cs
示例19: GetBestMatch
private MockPlug.IMockInvokee GetBestMatch(XUri uri)
{
MockPlug.IMockInvokee invokee;
// using _registry as our guard for both _map and _registry, since they are always modified in sync
lock(_registry) {
int result;
_map.TryGetValue(uri, out invokee, out result);
}
if(invokee != null) {
return invokee;
}
return uri.SchemeHostPort.EqualsInvariant(DEFAULT) ? DefaultInvokee : null;
}
开发者ID:nataren,项目名称:DReAM,代码行数:14,代码来源:MockEndpoint.cs
示例20: Subscribing_to_pubsub_channel_results_in_combined_set_being_pushed
public void Subscribing_to_pubsub_channel_results_in_combined_set_being_pushed()
{
var downstream = CreatePubSubService().WithInternalKey().AtLocalHost;
var upstreamUri = new XUri("http://upstream/");
var upstreamMock = MockPlug.Register(upstreamUri);
XDoc downstreamSet = null;
upstreamMock.Expect().Verb("POST").RequestDocument(_ => {
downstreamSet = _;
return true;
}).Response(DreamMessage.Ok());
var subscribeToDownstream = new XDoc("subscription-set")
.Elem("uri.owner", upstreamUri)
.Start("subscription")
.Attr("id", "1")
.Elem("channel", "foo://bar/baz/*")
.Start("recipient").Elem("uri", upstreamUri).End()
.End()
.Start("subscription")
.Attr("id", "1")
.Elem("channel", "pubsub://*/*")
.Start("recipient").Elem("uri", upstreamUri).End()
.End();
// subscribe to set updates from downstream, expect most recent version to be pushed
var downstreamResponse = downstream.At("subscribers").PostAsync(subscribeToDownstream).Wait();
var location = downstreamResponse.Headers.Location;
Assert.IsTrue(downstreamResponse.IsSuccessful, downstreamResponse.ToText());
Assert.IsTrue(upstreamMock.WaitAndVerify(TimeSpan.FromSeconds(10)), upstreamMock.VerificationFailure);
Assert.AreEqual(1, downstreamSet["subscription[channel='foo://bar/baz/*']"].ListLength);
subscribeToDownstream
.Start("subscription")
.Attr("id", "3")
.Elem("channel", "foo://bar/bob")
.Start("recipient").Elem("uri", upstreamUri).End()
.End();
// change subscription, expect most recent version to be pushed
upstreamMock.Expect().Verb("POST").RequestDocument(_ => {
downstreamSet = _;
return true;
}).Response(DreamMessage.Ok());
downstreamResponse = Plug.New(location).PutAsync(subscribeToDownstream).Wait();
Assert.IsTrue(downstreamResponse.IsSuccessful, downstreamResponse.ToText());
Assert.IsTrue(upstreamMock.WaitAndVerify(TimeSpan.FromSeconds(10)), upstreamMock.VerificationFailure);
Assert.AreEqual(1, downstreamSet["subscription[channel='foo://bar/baz/*']"].ListLength);
Assert.AreEqual(1, downstreamSet["subscription[channel='foo://bar/bob']"].ListLength);
}
开发者ID:sdether,项目名称:DReAM,代码行数:48,代码来源:PubSubServiceTests.cs
注:本文中的XUri类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论