本文整理汇总了C#中MindTouch.Dream.XUri.With方法的典型用法代码示例。如果您正苦于以下问题:C# XUri.With方法的具体用法?C# XUri.With怎么用?C# XUri.With使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MindTouch.Dream.XUri
的用法示例。
在下文中一共展示了XUri.With方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Meter
public XDoc Meter(
[DekiExtParam("meter width")] int width,
[DekiExtParam("meter height")] int height,
[DekiExtParam("meter position (between 0 and 100)")] int value,
[DekiExtParam("meter label (default: none)", true)] string label,
[DekiExtParam("meter colors (e.g. [ \"ff0000\", \"00ff00\", \"0000ff\" ]; default: nil)", true)] ArrayList colors
) {
XUri uri = new XUri("http://chart.apis.google.com/chart")
.With("chs", string.Format("{0}x{1}", width, height))
.With("cht", "gom")
.With("chd", "t:" + Math.Max(0, Math.Min(value, 100)));
if(!string.IsNullOrEmpty(label)) {
uri = uri.With("chl", label);
}
if(colors != null) {
uri = uri.With("chco", string.Join(",", AsStrings(colors)));
}
return new XDoc("html").Start("body").Start("img").Attr("src", uri).End().End();
}
示例2: BarChart
public XDoc BarChart(
[DekiExtParam("chart width")] int width,
[DekiExtParam("chart height")] int height,
[DekiExtParam("chart values (e.g. [ 1, 2, 3 ] for single series, or [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] for multi-series)")] ArrayList values,
[DekiExtParam("chart legends (e.g. [ \"first\", \"secong\", \"third\" ]; default: nil)", true)] ArrayList legends,
[DekiExtParam("chart colors (e.g. [ \"ff0000\", \"00ff00\", \"0000ff\" ]; default: nil)", true)] ArrayList colors,
[DekiExtParam("draw bars vertically (default: true)", true)] bool? vertical,
[DekiExtParam("draw bars stacked (default: false)", true)] bool? stacked,
[DekiExtParam("chart x-axis labels (e.g. [ \"first\", \"second\", \"third\" ]; default: [ 1, 2, 3, ... ])", true)] ArrayList xaxis,
[DekiExtParam("chart y-axis labels (e.g. [ 0, 50, 100 ]; default: [ 0, max/2, max ])", true)] ArrayList yaxis
) {
int count;
double max;
XUri uri = new XUri("http://chart.apis.google.com/chart")
.With("chs", string.Format("{0}x{1}", width, height))
.With("cht", vertical.GetValueOrDefault(true) ? (stacked.GetValueOrDefault(false) ? "bvs" : "bvg") : (stacked.GetValueOrDefault(false) ? "bhs" : "bhg"))
.With("chd", MakeChartData(values, stacked ?? false, out count, out max));
// check if we need to create a default X-axis
if(xaxis == null) {
xaxis = new ArrayList(count);
for(int i = 1; i <= count; ++i) {
xaxis.Add(i.ToString());
}
}
// check if we need to create a default Y-axis
if(yaxis == null) {
yaxis = new ArrayList(3);
yaxis.Add("0");
yaxis.Add((max / 2).ToString("#,##0.##"));
yaxis.Add(max.ToString("#,##0.##"));
}
// create axis labels
if((xaxis.Count > 0 ) && (yaxis.Count > 0)) {
uri = uri.With("chxt", "x,y").With("chxl", string.Format("0:|{0}|1:|{1}", string.Join("|", AsStrings(xaxis)), string.Join("|", AsStrings(yaxis))));
} else if(xaxis.Count > 0) {
uri = uri.With("chxt", "x").With("chxl", string.Format("0:|{0}", string.Join("|", AsStrings(xaxis))));
} else if(yaxis.Count > 0) {
uri = uri.With("chxt", "y").With("chxl", string.Format("0:|{0}", string.Join("|", AsStrings(yaxis))));
}
if(legends != null) {
uri = uri.With("chdl", string.Join("|", AsStrings(legends)));
}
if(colors != null) {
uri = uri.With("chco", string.Join(",", AsStrings(colors)));
}
return new XDoc("html").Start("body").Start("img").Attr("src", uri).End().End();
}
示例3: PieChart
public XDoc PieChart(
[DekiExtParam("chart width")] int width,
[DekiExtParam("chart height")] int height,
[DekiExtParam("chart values (e.g. [ 1, 2, 3 ])")] ArrayList values,
[DekiExtParam("chart labels (e.g. [ \"first\", \"secong\", \"third\" ]; default: nil)", true)] ArrayList labels,
[DekiExtParam("chart colors (e.g. [ \"ff0000\", \"00ff00\", \"0000ff\" ]; default: nil)", true)] ArrayList colors,
[DekiExtParam("draw 3D chart (default: true)", true)] bool? threeD
) {
int count;
double max;
XUri uri = new XUri("http://chart.apis.google.com/chart")
.With("chs", string.Format("{0}x{1}", width, height))
.With("cht", threeD.GetValueOrDefault(true) ? "p3" : "p")
.With("chd", MakeChartData(values, false, out count, out max));
if(labels != null) {
uri = uri.With("chl", string.Join("|", AsStrings(labels)));
}
if(colors != null) {
uri = uri.With("chco", string.Join(",", AsStrings(colors)));
}
return new XDoc("html").Start("body").Start("img").Attr("src", uri).End().End();
}
示例4: BuildS3Uri
private XUri BuildS3Uri(string verb, XUri uri, TimeSpan expireTime) {
var expireTimeSeconds = ((long)(new TimeSpan(DateTime.UtcNow.Add(expireTime).Subtract(DateTimeUtil.Epoch).Ticks).TotalSeconds)).ToString();
var result = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", verb, string.Empty, string.Empty, expireTimeSeconds, uri.Path);
var hmac = new HMACSHA1(Encoding.UTF8.GetBytes(_privateKey));
var signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(result)));
return uri.With("AWSAccessKeyId", _publicKey).With("Signature", signature).With("Expires", expireTimeSeconds);
}
示例5: LineChart
public XDoc LineChart(
[DekiExtParam("chart width")] int width,
[DekiExtParam("chart height")] int height,
[DekiExtParam("chart values (e.g. [ 1, 2, 3 ])")] ArrayList values,
[DekiExtParam("chart legends (e.g. [ \"first\", \"secong\", \"third\" ]; default: nil)", true)] ArrayList legends,
[DekiExtParam("chart colors (e.g. [ \"ff0000\", \"00ff00\", \"0000ff\" ]; default: nil)", true)] ArrayList colors,
[DekiExtParam("chart x-axis labels (e.g. [ \"first\", \"second\", \"third\" ]; default: [ 1, 2, 3, ... ])", true)] ArrayList xaxis,
[DekiExtParam("chart y-axis labels (e.g. [ 0, 50, 100 ]; default: [ 0, max/2, max ])", true)] ArrayList yaxis
) {
int count;
double max;
XUri uri = new XUri("http://chart.apis.google.com/chart")
.With("chs", string.Format("{0}x{1}", width, height))
.With("cht", "lc")
.With("chd", MakeChartData(values, false, out count, out max));
// check if we need to create a default X-axis
if(xaxis == null) {
xaxis = new ArrayList(count);
for(int i = 1; i <= count; ++i) {
xaxis.Add(i.ToString());
}
}
// check if we need to create a default Y-axis
if(yaxis == null) {
yaxis = new ArrayList(3);
yaxis.Add("0");
yaxis.Add((max / 2).ToString("#,##0.##"));
yaxis.Add(max.ToString("#,##0.##"));
}
// create axis labels
if((xaxis != null) && (yaxis != null)) {
uri = uri.With("chxt", "x,y").With("chxl", string.Format("0:|{0}|1:|{1}", string.Join("|", AsStrings(xaxis)), string.Join("|", AsStrings(yaxis))));
} else if(xaxis != null) {
uri = uri.With("chxt", "x").With("chxl", string.Format("0:|{0}", string.Join("|", AsStrings(xaxis))));
} else if(yaxis != null) {
uri = uri.With("chxt", "y").With("chxl", string.Format("0:|{0}", string.Join("|", AsStrings(yaxis))));
}
if(legends != null) {
uri = uri.With("chdl", string.Join("|", AsStrings(legends)));
}
if(colors != null) {
uri = uri.With("chco", string.Join(",", AsStrings(colors)));
}
return new XDoc("html").Start("body").Start("img").Attr("src", uri).End().End();
}
示例6: GetUserXml
public static XDoc GetUserXml(UserBE user, string relation, bool showPrivateInfo) {
XDoc userXml = new XDoc(string.IsNullOrEmpty(relation) ? "user" : "user." + relation);
userXml.Attr("id", user.ID);
userXml.Attr("href", DekiContext.Current.ApiUri.At("users", user.ID.ToString()));
userXml.Elem("nick", user.Name);
userXml.Elem("username", user.Name);
userXml.Elem("fullname", user.RealName ?? String.Empty);
// check if we can add the email address
if(showPrivateInfo) {
userXml.Elem("email", user.Email);
} else {
userXml.Start("email").Attr("hidden", true).End();
}
// add gravatar
if(!IsAnonymous(user) && !string.IsNullOrEmpty(user.Email)) {
DekiContext context = DekiContext.CurrentOrNull;
XUri gravatar = new XUri("http://www.gravatar.com/avatar");
string hash = string.Empty;
if(context != null) {
DekiInstance deki = context.Instance;
string secure = context.Instance.GravatarSalt ?? string.Empty;
if(!secure.EqualsInvariantIgnoreCase("hidden")) {
hash = StringUtil.ComputeHashString(secure + (user.Email ?? string.Empty).Trim().ToLowerInvariant(), System.Text.Encoding.UTF8);
}
// add size, if any
string size = deki.GravatarSize;
if(size != null) {
gravatar = gravatar.With("s", size);
}
// add rating, if any
string rating = deki.GravatarRating;
if(rating != null) {
gravatar = gravatar.With("r", rating);
}
// add default icon, if any
string def = deki.GravatarDefault;
if(def != null) {
gravatar = gravatar.With("d", def);
}
}
if(!string.IsNullOrEmpty(hash)) {
userXml.Elem("hash.email", hash);
userXml.Elem("uri.gravatar", gravatar.At(hash + ".png"));
} else {
userXml.Elem("hash.email", string.Empty);
userXml.Elem("uri.gravatar", gravatar.At("no-email.png"));
}
}
return userXml;
}
示例7: lock
//--- Interface Methods ---
int IPlugEndpoint.GetScoreWithNormalizedUri(XUri uri, out XUri normalized)
{
int result;
XUri prefix;
lock(_aliases) {
_aliases.TryGetValue(uri, out prefix, out result);
}
// check if we found a match
if(prefix != null) {
normalized = uri.ChangePrefix(prefix, _localMachineUri);
// if 'dream.in.uri' is not set, set it
if((normalized.GetParam(DreamInParam.URI, null) == null) && !prefix.Scheme.EqualsInvariant("local")) {
normalized = normalized.With(DreamInParam.URI, prefix.ToString());
}
} else {
normalized = null;
}
return (result > 0) ? result + Plug.BASE_ENDPOINT_SCORE : 0;
}
示例8: BuildS3Uri
private XUri BuildS3Uri(string verb, XUri uri, TimeSpan expireTime) {
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
string expireTimeSeconds = expireTimeSeconds = ((long)(new TimeSpan(DateTime.UtcNow.Add(expireTime).Subtract(epoch).Ticks).TotalSeconds)).ToString();
string result = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", verb, string.Empty, string.Empty, expireTimeSeconds, uri.Path);
HMACSHA1 hmac = new HMACSHA1(Encoding.UTF8.GetBytes(_private_key));
string signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(result)));
XUri ret = uri.With("AWSAccessKeyId", _public_key).With("Signature", signature).With("Expires", expireTimeSeconds);
return ret;
}
示例9: FetchResult
//--- Methods ---
private Yield FetchResult(string name, XUri input, Hashtable args, Result<XDoc> response) {
// build uri
XUri uri = new XUri("http://www.dapper.net/RunDapp?v=1").With("dappName", name);
if(input != null) {
uri = uri.With("applyToUrl", input.ToString());
}
if(args != null) {
foreach(DictionaryEntry entry in args) {
uri = uri.With(VARIABLE_PREFIX + SysUtil.ChangeType<string>(entry.Key), SysUtil.ChangeType<string>(entry.Value));
}
}
// check if we have a cached result
XDoc result;
string key = uri.ToString();
lock(_cache) {
if(_cache.TryGetValue(key, out result)) {
response.Return(result);
yield break;
}
}
// fetch result
Result<DreamMessage> res;
yield return res = Plug.New(uri).GetAsync();
if(!res.Value.IsSuccessful) {
throw new DreamInternalErrorException(string.Format("Unable to process Dapp: ", input));
}
if(!res.Value.HasDocument) {
throw new DreamInternalErrorException(string.Format("Dapp response is not XML: ", input));
}
// add result to cache and start a clean-up timer
lock(_cache) {
_cache[key] = res.Value.ToDocument();
}
TaskTimer.New(TimeSpan.FromSeconds(CACHE_TTL), RemoveCachedEntry, key, TaskEnv.None);
response.Return(res.Value.ToDocument());
yield break;
}
示例10: MakeUserObject
internal Hashtable MakeUserObject(UserBE user) {
// initialize gravatar link
DekiInstance deki = DekiContext.Current.Instance;
XUri gravatar = new XUri("http://www.gravatar.com/avatar");
// add size, if any
string size = deki.GravatarSize;
if(size != null) {
gravatar = gravatar.With("s", size);
}
// add rating, if any
string rating = deki.GravatarRating;
if(rating != null) {
gravatar = gravatar.With("r", rating);
}
// add default icon, if any
string def = deki.GravatarDefault;
if(def != null) {
gravatar = gravatar.With("d", def);
}
// initialize user object
Hashtable result = new Hashtable(StringComparer.OrdinalIgnoreCase);
string hash = string.Empty;
if(user != null) {
var env = DreamContext.Current.GetState<DekiScriptEnv>();
string secure = deki.GravatarSalt ?? string.Empty;
if(!secure.EqualsInvariantIgnoreCase("hidden") && !string.IsNullOrEmpty(user.Email)) {
hash = StringUtil.ComputeHashString(secure + (user.Email ?? string.Empty).Trim().ToLowerInvariant(), Encoding.UTF8);
}
PageBE homePage = UserBL.GetHomePage(user);
result.Add("id", user.ID);
result.Add("name", user.Name);
result.Add("fullname", !string.IsNullOrEmpty(user.RealName) ? user.RealName : null);
result.Add("uri", Utils.AsPublicUiUri(homePage.Title));
result.Add("api", Utils.AsPublicApiUri("users", user.ID).ToString());
result.Add("homepage", PropertyAt("$page", homePage.ID, true));
result.Add("anonymous", UserBL.IsAnonymous(user));
result.Add("admin", PermissionsBL.IsUserAllowed(user, Permissions.ADMIN));
result.Add("feed", Utils.AsPublicApiUri("users", user.ID).At("feed").ToString());
result.Add("authtoken", (!env.IsSafeMode && DekiContext.Current.User.ID == user.ID) ? DekiContext.Current.AuthToken : null);
result.Add("properties", PropertyAt("$userprops", user.ID));
result.Add("comments", PropertyAt("$usercomments", user.ID));
result.Add("timezone", DekiScriptLibrary.RenderTimeZone(DekiScriptLibrary.ParseTimeZone(user.Timezone)));
result.Add("language", DekiScriptExpression.Constant(string.IsNullOrEmpty(user.Language) ? null : user.Language));
result.Add("metrics", PropertyAt("$usermetrics", user.ID));
if(Utils.ShowPrivateUserInfo(user)) {
result.Add("email", user.Email);
}
result.Add("groups", PropertyAt("$usergroups", user.ID));
} else {
result.Add("id", 0);
result.Add("name", null);
result.Add("fullname", null);
result.Add("uri", null);
result.Add("api", null);
result.Add("homepage", null);
result.Add("anonymous", true);
result.Add("admin", false);
result.Add("feed", null);
result.Add("authtoken", null);
result.Add("properties", new Hashtable(StringComparer.OrdinalIgnoreCase));
result.Add("comments", new ArrayList());
result.Add("timezone", "GMT");
result.Add("language", DekiScriptNil.Value);
result.Add("metrics", new Hashtable(StringComparer.OrdinalIgnoreCase));
result.Add("groups", new Hashtable(StringComparer.OrdinalIgnoreCase));
}
// set the emailhash and gravatar values
if(!string.IsNullOrEmpty(hash)) {
result.Add("emailhash", hash);
result.Add("gravatar", gravatar.At(hash + ".png"));
} else {
result.Add("emailhash", string.Empty);
result.Add("gravatar", gravatar.At("no-email.png"));
}
return result;
}