本文整理汇总了C#中Cache.CreateAuthenticatedView方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.CreateAuthenticatedView方法的具体用法?C# Cache.CreateAuthenticatedView怎么用?C# Cache.CreateAuthenticatedView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache.CreateAuthenticatedView方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: runWithUserReader
void runWithUserReader(Cache cache)
{
Console.WriteLine();
Console.WriteLine("------------------------------------------------------------");
Console.WriteLine("Logging in as reader1. Has access to reads but not writes. ");
Console.WriteLine("------------------------------------------------------------");
//user "reader1" 's credential
Properties<string, object> credentials = Properties<string, object>.Create<string, object>();
//user = "reader1" has permission to do get ops only
credentials.Insert("security-username", "reader1");
credentials.Insert("security-password", "reader1");
// Create user cache by passing credentials
IRegionService userCache2 = cache.CreateAuthenticatedView(credentials);
// Create region using usercache
IRegion<string, string> userRegion2 = userCache2.GetRegion<string, string>("exampleRegion");
bool exceptiongot = false;
string res = userRegion2["key-1"];
Console.WriteLine("get successful");
try
{
//"reader1" trying to do put operation on region, it should get NotAuthorized exception
Console.WriteLine();
Console.WriteLine("attempting put. Should fail.");
userRegion2["key-1"] = "key-1";
}
catch (NotAuthorizedException ex)
{
Console.WriteLine("Got expected UnAuthorizedException: {0}", ex.Message);
exceptiongot = true;
}
if (exceptiongot == false)
{
Console.WriteLine("Example FAILED: Did not get expected NotAuthorizedException");
}
else
{
Console.WriteLine("User reader1 got expected exception while doing put operation.");
}
//close the user cache
userCache2.Close();
}
示例2: runWithUserRoot
void runWithUserRoot(Cache cache)
{
Console.WriteLine("------------------------------------------------------------");
Console.WriteLine("Logging in as root. Should have access to reads and writes ");
Console.WriteLine("------------------------------------------------------------");
//user "root" 's credential
Properties<string, object> credentials = Properties<string, object>.Create<string, object>();
//user = "root" has permission to do put/get both
credentials.Insert("security-username", "root");
credentials.Insert("security-password", "root");
// Create user cache by passing credentials
IRegionService userCache1 = cache.CreateAuthenticatedView(credentials);
Console.WriteLine("Created the Region Programmatically. 2");
// Create region using usercache
IRegion<string, string> userRegion1 = userCache1.GetRegion<string, string>("exampleRegion");
//doing operation on behalf of user "root"
userRegion1["key-1"] = "val-1";
string result = userRegion1["key-1"];
// commented 1/2015 for Morgan Stanley since they do not use functions
//to execute function on server
/*
Execution<object> exc = FunctionService<object>.OnServer(userCache1);
bool getResult = true;
ArrayList args1 = new ArrayList();
args1.Add("key-1");
try
{
IResultCollector<object> rc = exc.WithArgs<ArrayList>(args1).Execute(
getFuncIName, getResult);
ICollection<object> executeFunctionResult = rc.GetResult();
Console.WriteLine("on one server: result count= {0}.", executeFunctionResult.Count);
List<object> resultList1 = new List<object>();
foreach (List<object> item in executeFunctionResult)
{
foreach (object subitem in item)
{
resultList1.Add(subitem);
}
}
for (int i = 0; i < resultList1.Count; i++)
{
Console.WriteLine("on one server:get:result[{0}]={1}.", i, (string)resultList1[i]);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
*
* */
//to execute Query
// Get the QueryService from the Cache.
QueryService<string, string> qrySvc = userCache1.GetQueryService<string, string>();
Console.WriteLine("Got the QueryService from the user Cache");
// Execute a Query which returns a ResultSet.
Query<string> qry = qrySvc.NewQuery("SELECT DISTINCT * FROM /exampleRegion");
ISelectResults<string> results = qry.Execute();
Console.WriteLine("ResultSet Query returned {0} rows", results.Size);
userCache1.Close();
Console.WriteLine("User root done put/get ops successfully");
}