public void GenerateProxy(StringBuilder sb, string controlID)
{
sb.Append(this.Attribute.Alias.IsEmpty() ? this.Name : this.Attribute.Alias);
sb.Append(":function(");
foreach (ParameterInfo parameterInfo in this.Params)
{
sb.Append(parameterInfo.Name);
sb.Append(",");
}
sb.Append("config");
sb.Append("){");
sb.Append("Ext.net.DirectMethod.request(\"");
sb.Append(this.Name);
sb.Append("\",Ext.applyIf(config || {}, {");
int index = 0;
bool needComma = false;
if (this.Params.Length>0)
{
sb.Append("params:{");
foreach (ParameterInfo parameterInfo in this.Params)
{
sb.Append(parameterInfo.Name);
sb.Append(":");
sb.AppendFormat(parameterInfo.Name);
index++;
if (index < this.Params.Length)
{
sb.Append(",");
}
}
sb.Append("}");
needComma = true;
}
if (this.Method.IsStatic)
{
sb.Append(needComma ? "," : "");
sb.Append("specifier:\"static\"");
needComma = true;
}
if (controlID.IsNotEmpty())
{
sb.Append(needComma ? "," : "");
sb.AppendFormat("control:\"{0}\"", controlID);
needComma = true;
}
if (this.Attribute.Method == HttpMethod.GET)
{
sb.Append(needComma ? "," : "");
sb.Append("method:\"GET\"");
needComma = true;
}
if (this.Attribute.ShowMask)
{
sb.Append(needComma ? "," : "");
sb.Append("eventMask:{showMask:true");
if (this.Attribute.Msg.IsNotEmpty())
{
sb.Append(",msg:").Append(JSON.Serialize(this.Attribute.Msg));
}
if (this.Attribute.MsgCls.IsNotEmpty())
{
sb.Append(",msgCls:").Append(JSON.Serialize(this.Attribute.MsgCls));
}
if (this.Attribute.CustomTarget.IsNotEmpty())
{
this.Attribute.Target = MaskTarget.CustomTarget;
}
if (this.Attribute.Target != MaskTarget.Page)
{
sb.Append(",target:").Append(JSON.Serialize(this.Attribute.Target.ToString().ToLower()));
}
if (this.Attribute.Target == MaskTarget.CustomTarget && this.Attribute.CustomTarget.IsNotEmpty())
{
ResourceManager sm = null;
if (HttpContext.Current != null)
{
sm = ResourceManager.GetInstance(HttpContext.Current);
}
string script = TokenUtils.ReplaceRawToken((sm != null) ? TokenUtils.ParseTokens(this.Attribute.CustomTarget, sm) : TokenUtils.ParseAndNormalize(this.Attribute.CustomTarget));
sb.Append(",customTarget:").Append(script);
//sb.Append(",customTarget:").Append(JSON.Serialize(this.Attribute.CustomTarget));
}
sb.Append("}");
needComma = true;
}
if (this.Attribute.Type == DirectEventType.Load)
{
sb.Append(needComma ? "," : "");
sb.Append("type:\"load\"");
needComma = true;
}
if (this.Attribute.ViewStateMode != ViewStateMode.Inherit)
{
sb.Append(needComma ? "," : "");
sb.AppendFormat("viewStateMode:\"{0}\"", this.Attribute.ViewStateMode.ToString().ToLowerInvariant());
needComma = true;
}
if (this.Attribute.RethrowException)
{
sb.Append(needComma ? "," : "");
sb.AppendFormat("rethrowException:{0}", this.Attribute.RethrowException.ToString().ToLowerInvariant());
needComma = true;
}
if (this.Attribute.Timeout != 30000)
{
sb.Append(needComma ? "," : "");
sb.AppendFormat("timeout:{0}", this.Attribute.Timeout);
needComma = true;
}
if (this.Attribute.DisableCaching.HasValue)
{
sb.Append(needComma ? "," : "");
sb.AppendFormat("disableCaching:{0}", this.Attribute.DisableCaching.Value.ToString().ToLowerInvariant());
needComma = true;
}
if (this.Attribute.DisableCachingParam != "_dc")
{
sb.Append(needComma ? "," : "");
sb.AppendFormat("disableCachingParam:{0}", this.Attribute.DisableCachingParam);
needComma = true;
}
if (this.Attribute.SuccessFn.IsNotEmpty())
{
sb.Append(needComma ? "," : "");
sb.AppendFormat("success:{0}", this.Attribute.SuccessFn);
needComma = true;
}
if (this.Attribute.CompleteFn.IsNotEmpty())
{
sb.Append(needComma ? "," : "");
sb.AppendFormat("complete:{0}", this.Attribute.CompleteFn);
needComma = true;
}
if (this.Attribute.FailureFn.IsNotEmpty())
{
sb.Append(needComma ? "," : "");
sb.AppendFormat("failure:{0}", this.Attribute.FailureFn);
}
sb.Append("}));}");
}
}