本文整理汇总了C#中Service.addMediaType方法的典型用法代码示例。如果您正苦于以下问题:C# Service.addMediaType方法的具体用法?C# Service.addMediaType怎么用?C# Service.addMediaType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Service
的用法示例。
在下文中一共展示了Service.addMediaType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: createAuthRoot
// creates an XRD obj that contains an authority resolution service endpoint with the given URI
public static XRD createAuthRoot(string uri)
{
XRD xrd = new XRD();
// construct an authority resolution service
Service srv = new Service();
TrustType tt = new TrustType(); // default trust type
string authMediaType = Tags.CONTENT_TYPE_XRDS + ";" + tt.getParameterPair();
srv.addMediaType(authMediaType, SEPElement.MATCH_ATTR_CONTENT, false);
srv.addType(Tags.SERVICE_AUTH_RES);
srv.addURI(uri);
// add it to the XRD
xrd.addService(srv);
return xrd;
}
示例2: testCache
/*
****************************************************************************
* testCache()
****************************************************************************
*/
/**
*
*/
public void testCache()
{
Cache oCache = new Cache(1000);
assertTrue("Initial cache not empty", oCache.getNumNodes() == 0);
XRD oDesc = new XRD();
Service atAuthService = new Service();
atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
atAuthService.addType(Tags.SERVICE_AUTH_RES);
atAuthService.addURI("http://gcs.epok.net/xri/resolve?ns=at");
oDesc.addService(atAuthService);
XRD oDummy = new XRD();
Service dummyService = new Service();
dummyService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
dummyService.addType(Tags.SERVICE_AUTH_RES);
dummyService.addURI("http://www.example.com/xri/resolve?id=1");
oDummy.addService(dummyService);
GCSAuthority oAuth = new GCSAuthority("@");
oCache.stuff(oAuth, oDesc);
assertTrue("Initial cache incorrect", oCache.getNumNodes() == 1);
oCache.stuff(
(XRIAuthority) AuthorityPath.buildAuthorityPath("@!a!b!foo"), oDummy);
assertTrue("Cache size incorrect", oCache.getNumNodes() == 4);
oCache.stuff(
(XRIAuthority) AuthorityPath.buildAuthorityPath("@!a!c!moo"), oDummy);
assertTrue("Cache size incorrect", oCache.getNumNodes() == 6);
oCache.stuff(
(XRIAuthority) AuthorityPath.buildAuthorityPath("@!a!c!woo"), oDummy);
assertTrue("Cache size incorrect", oCache.getNumNodes() == 7);
Cache.CachedValue oVal =
oCache.find(
(XRIAuthority) AuthorityPath.buildAuthorityPath("@!a!c!woo"),
false);
assertTrue("Cached value not found", oVal != null);
oVal =
oCache.find(
(XRIAuthority) AuthorityPath.buildAuthorityPath("@!a!b!woo"),
false);
assertTrue("Cached value should not have been found", oVal == null);
oCache.dump();
}
示例3: run
/*
************************************************************************
* run()
************************************************************************
*/
/**
*
*/
public void run()
{
XRD oDummy = new XRD();
Service dummyService = new Service();
dummyService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
dummyService.addType(Tags.SERVICE_AUTH_RES);
dummyService.addURI("http://www.example.com/xri/resolve?id=1");
oDummy.addService(dummyService);
String[] oCases =
{ "@!a1!b2!c3!d4", "@!x1!y2!z3", "@!a1!b2!c3", "@!a1!b2", "@!a1!b2!m3", "@!a1!o2!p3", "@!a1!o2!q3", "@!a1!b2!c3!d4!e5", "@!x1!y2" };
Cache oCache = new Cache(1000);
for (int i = 0; i < 1000; i++)
{
int x = moRand.nextInt(oCases.length);
bool bStuff = moRand.nextBoolean();
XRIAuthority oAuth =
(XRIAuthority) AuthorityPath.buildAuthorityPath(oCases[x]);
if (bStuff)
{
oCache.stuff(oAuth, oDummy);
}
else
{
oCache.prune(oAuth);
}
oCache.find(oAuth, true);
}
}
示例4: testConcurrent
/*
****************************************************************************
* testConcurrent()
****************************************************************************
*/
/**
*
*/
public void testConcurrent()
{
Cache oCache = new Cache(1000);
oCache.prune((XRIAuthority) AuthorityPath.buildAuthorityPath("@"));
assertTrue("Initial cache not empty", oCache.getNumNodes() == 0);
XRD oDesc = new XRD();
Service atAuthService = new Service();
atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
atAuthService.addType(Tags.SERVICE_AUTH_RES);
atAuthService.addURI("http://gcs.epok.net/xri/resolve?ns=at");
oDesc.addService(atAuthService);
GCSAuthority oAuth = new GCSAuthority("@");
oCache.stuff(oAuth, oDesc);
assertTrue("Initial cache incorrect", oCache.getNumNodes() == 1);
oCache.setMaxSize(5);
Random oRand = new Random();
try
{
Thread[] oThreads = new StuffPruneThread[100];
for (int i = 0; i < oThreads.length; i++)
{
oThreads[i] = new StuffPruneThread(oRand);
}
for (int i = 0; i < oThreads.length; i++)
{
oThreads[i].start();
}
for (int i = 0; i < oThreads.length; i++)
{
oThreads[i].join();
}
}
catch (Exception e)
{
assertTrue("Unexpected exception" + e, false);
}
oCache.dump();
assertTrue(
"Max cache size not honored",
oCache.getNumNodes() <= oCache.getMaxSize());
Cache.CachedValue oVal =
oCache.find(
(XRIAuthority) AuthorityPath.buildAuthorityPath("@"), false);
assertTrue("Cached value for @ not found", oVal != null);
}
示例5: main
} // main()
/*
****************************************************************************
* process()
****************************************************************************
*/ /**
* Executes the xrilookup command as indicated by the input args. See
* outputUsage for the forms of invocation and details about the program
* arguments.
*
* @param sArgs - command line arguments (e.g., from main)
* @param sOutput - program output (e.g., for stdout)
*
* @return SUCCESS or FAILURE
*/
public int process(StringBuilder sOutput, String[] sArgs)
{
try
{
// re-initialize variables so this may be called more than once
sOutput.setLength(0);
msTargetXRI = null;
mbIsVerbose = false;
msRootEqualsURI = ROOT_DEF_EQ_URI;
msRootAtURI = ROOT_DEF_AT_URI;
msRootBangURI = ROOT_DEF_BANG_URI;
msProxyURI = null;
mbCheckRoots = true;
msRootFile = null;
try {
setTrustType(TRUST_TYPE);
}
catch (Exception e) {
e.printStackTrace();
}
// exit with message if no arguments passed on the command line
if (sArgs.length == 0)
{
outputPleaseTypeHelp(sOutput);
return FAILURE;
}
// this is the "help" form of invocation (usage 2)
if (sArgs[0].equalsIgnoreCase(CMD_HELP))
{
outputUsage(sOutput);
return SUCCESS;
}
// from here on, we're dealing with the "normal" form of invocation
// (usage 1).
// scan the args, setting member variables for options, rootURI,
// and resolve XRI
int iResult = scanArgs(sOutput, sArgs);
if (iResult == FAILURE)
{
return FAILURE;
}
// validate that the root uris are ok
if (mbCheckRoots)
{
iResult = validateRootURIs(sOutput);
if (iResult == FAILURE)
{
return FAILURE;
}
}
// create and configure a resolver
Resolver resolver = new Resolver();
// populate the root with whatever trustType the user requested
String trustParam = ";" + trustType.getParameterPair();
XRD eqRoot = new XRD();
Service eqAuthService = new Service();
eqAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + trustParam, SEPElement.MATCH_ATTR_CONTENT, Boolean.FALSE);
eqAuthService.addType(Tags.SERVICE_AUTH_RES);
eqAuthService.addURI(msRootEqualsURI);
eqRoot.addService(eqAuthService);
XRD atRoot = new XRD();
Service atAuthService = new Service();
atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + trustParam, SEPElement.MATCH_ATTR_CONTENT, Boolean.FALSE);
atAuthService.addType(Tags.SERVICE_AUTH_RES);
atAuthService.addURI(msRootAtURI);
atRoot.addService(atAuthService);
XRD bangRoot = new XRD();
Service bangAuthService = new Service();
bangAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + trustParam, SEPElement.MATCH_ATTR_CONTENT, Boolean.FALSE);
bangAuthService.addType(Tags.SERVICE_AUTH_RES);
bangAuthService.addURI(msRootBangURI);
bangRoot.addService(bangAuthService);
//.........这里部分代码省略.........
示例6: main
} // main()
/*
****************************************************************************
* process()
****************************************************************************
*/ /**
* Executes the xritracert command as indicated by the input args. See
* outputUsage for the forms of invocation and details about the program
* arguments.
*
* @param sArgs - command line arguments (e.g., from main)
* @param sOutput - program output (e.g., for stdout)
*
* @return SUCCESS or FAILURE
*/
public int process(StringBuilder sOutput, String[] sArgs)
{
try
{
// re-initialize variables so this may be called more than once
sOutput.setLength(0);
msTargetXRI = null;
mbIsVerbose = false;
mbDontOutputHeader = false;
msRootEqualsURI = ROOT_DEF_URI;
msRootAtURI = ROOT_DEF_URI;
// exit with message if no arguments passed on the command line
if (sArgs.length == 0)
{
outputPleaseTypeHelp(sOutput);
return FAILURE;
}
// this is the "help" form of invocation (usage 2)
if (sArgs[0].equalsIgnoreCase(CMD_HELP))
{
outputUsage(sOutput);
return SUCCESS;
}
// from here on, we're dealing with the "normal" form of invocation
// (usage 1).
// scan the args, setting member variables for options, rootURI,
// and resolve XRI
int iResult = scanArgs(sOutput, sArgs);
if (iResult == FAILURE)
{
return FAILURE;
}
// validate that the root uris are ok
iResult = validateRootURIs(sOutput);
if (iResult == FAILURE)
{
return FAILURE;
}
// create and configure a resolver
Resolver resolver = new Resolver();
XRD eqRoot = new XRD();
Service eqAuthService = new Service();
eqAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
eqAuthService.addType(Tags.SERVICE_AUTH_RES);
eqAuthService.addURI(msRootEqualsURI);
eqRoot.addService(eqAuthService);
XRD atRoot = new XRD();
Service atAuthService = new Service();
atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
atAuthService.addType(Tags.SERVICE_AUTH_RES);
atAuthService.addURI(msRootAtURI);
atRoot.addService(atAuthService);
resolver.setAuthority("=", eqRoot);
resolver.setAuthority("@", atRoot);
// invoke the tracert
tracert(sOutput, resolver);
}
catch (Throwable oThrowable)
{
outputException(sOutput, oThrowable);
return FAILURE;
}
return SUCCESS;
}