private ReplaceRawToken ( string script ) : string | ||
script | string | |
Résultat | string |
public static string ParseTokens(string script, Control seed) { if (script == null) { return(null); } if (script.ToString().StartsWith("<!token>")) { return(script.ToString().Substring(8)); } if (seed == null) { seed = TokenUtils.Page; } bool isRaw = ( TokenUtils.IsAlertToken(script) || TokenUtils.IsRawToken(script) || TokenUtils.IsSelectToken(script)); script = TokenUtils.ReplaceIDTokens(script, seed); script = TokenUtils.ReplaceSelectTokens(script); script = TokenUtils.ReplaceAlertToken(script); script = TokenUtils.ReplaceRawToken(script); script = TokenUtils.ReplaceFunctionToken(script); return((isRaw || TokenUtils.IsFunction(script)) ? "<raw>".ConcatWith(script) : script); }
public virtual string ToString(bool camelNames) { //this.EnsureDataBind(); ParameterMode mode = this.Mode; string name = camelNames ? this.Name.ToLowerCamelCase() : this.Name; if (this.Params.Count > 0) { return(this.ToStringInnerParams(name)); } else { string script = TokenUtils.ParseTokens(this.Value, this.Owner); if (TokenUtils.IsRawToken(script)) { mode = ParameterMode.Raw; script = TokenUtils.ReplaceRawToken(script); } return(JSON.Serialize(name).ConcatWith(":", this.Encode ? "Ext.encode(" : "", mode == ParameterMode.Raw ? script : JSON.Serialize(script), this.Encode ? ")" : "")); } }
public virtual string ToScript() { if (this.Fn.IsNotEmpty()) { return(this.NamePrefix + this.Fn); } string handler = TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(this.Handler, this.Owner)); if (this.Args != null && this.Args.Length > 0) { if (this.FormatHandler) { return(this.NamePrefix + "function(".ConcatWith(this.Args.Join(","), "){", handler.FormatWith(this.Args), "}")); } else { return(this.NamePrefix + "function(".ConcatWith(this.Args.Join(","), "){", handler, "}")); } } else { return(this.NamePrefix + "function(){".ConcatWith(handler).ConcatWith("}")); } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer) { if (value is string) { if (Value_RE.Match(value.ToString()).Success) { writer.WriteRawValue(value.ToString()); } else { string prms; switch (this.Name) { case "before": prms = "el,type,action,extraParams,o"; break; case "complete": prms = "success,response,result,el,type,action,extraParams,o"; break; default: prms = "response,result,el,type,action,extraParams,o"; break; } value = TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(value.ToString(), this.OwnerControl)); writer.WriteRawValue(new JFunction((string)value, prms).ToScript()); } } }
public virtual string ValueToString() { ParameterMode mode = this.Mode; if (this.Params.Count > 0) { return(this.ToStringInnerParams(null)); } string script = TokenUtils.ParseTokens(this.Value, this.Owner); if (TokenUtils.IsRawToken(script)) { mode = ParameterMode.Raw; script = TokenUtils.ReplaceRawToken(script); } else if (mode == ParameterMode.Auto) { KeyValuePair <string, ParameterMode> result = this.GetAutoValue(script); mode = result.Value; script = result.Key; } return((this.Encode ? "Ext.encode(" : "").ConcatWith( mode == ParameterMode.Raw ? script : JSON.Serialize(script), this.Encode ? ")" : "")); }
private void WriteValue(string name, object value) { if (value is string) { value = TokenUtils.ParseTokens(value.ToString(), this.owner); string temp = value.ToString(); if (temp.StartsWith("<string>")) { int count = 8; string rawMarker = TokenUtils.Settings.RawMarker; if (temp.StartsWith("<string>" + rawMarker)) { count += rawMarker.Length; } this.writer.WritePropertyName(name); this.writer.WriteValue(temp.Substring(count)); return; } if (TokenUtils.IsRawToken(temp)) { this.WriteRawValue(name, TokenUtils.ReplaceRawToken(temp)); return; } } this.writer.WritePropertyName(name); if (value is Unit) { Unit unit = (Unit)value; if (unit.Type == UnitType.Pixel) { this.writer.WriteValue(Convert.ToInt32(((Unit)value).Value)); } else if (unit.Type == UnitType.Percentage) { this.writer.WriteValue(unit.Value.ToString() + "%"); } } else if (value is Enum) { this.writer.WriteValue(value.ToString()); } else if (value is IScriptable) { this.writer.WriteValue(((IScriptable)value).ToScript()); } else { this.writer.WriteValue(value); } }
protected override void OnPreRender(EventArgs e) { if (!this.DesignMode) { this.Controls.Add(new LiteralControl(TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(this.ScriptBlock, this)))); } base.OnPreRender(e); }
public static string NormalizeRawToken(string script) { if (TokenUtils.IsRawToken(script)) { return(TokenUtils.ReplaceRawToken(script)); } return(JSON.Serialize(script, JSON.ScriptConvertersInternal)); }
public virtual void Filter(string field, string value, bool anyMatch, bool caseSensitive) { if (TokenUtils.IsRawToken(value)) { value = TokenUtils.ReplaceRawToken(value); } this.Call("filter", field, value, anyMatch, caseSensitive); }
protected virtual string ParseTarget(string target) { string parsedTarget = TokenUtils.ParseTokens(target, this); if (TokenUtils.IsRawToken(parsedTarget)) { return(TokenUtils.ReplaceRawToken(parsedTarget)); } return("\"".ConcatWith(parsedTarget, "\"")); }
public virtual void AddScript(string script) { if (script.IsNotEmpty() && !this.IsParentDeferredRender && this.Visible) { if (this.AlreadyRendered && this.HasResourceManager) { this.ResourceManager.RegisterOnReadyScript(ResourceManager.ScriptOrderNumber, TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(script, this))); } else { this.ProxyScripts.Add(ResourceManager.ScriptOrderNumber, TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(script, this))); } } }
protected override void SetModelAdditionalValue(KeyValuePair <string, object> value) { base.SetModelAdditionalValue(value); if (!value.Key.StartsWith("__ext.net.")) { if (value.Value != null && value.Value is string && TokenUtils.IsRawToken(value.Value.ToString())) { this.CustomConfig.Add(new ConfigItem(value.Key, TokenUtils.ReplaceRawToken(value.Value.ToString()), ParameterMode.Raw)); } else { this.CustomConfig.Add(new ConfigItem(value.Key, JSON.Serialize(value.Value), ParameterMode.Raw)); } } }
private void WriteRawValue(string name, object value, bool parseTokens) { this.writer.WritePropertyName(name); if (value is string) { value = TokenUtils.ParseTokens(value.ToString(), this.owner); } else { if (value is IScriptable) { value = ((IScriptable)value).ToScript(); } } string temp = value.ToString(); this.writer.WriteRawValue(TokenUtils.IsRawToken(temp) ? TokenUtils.ReplaceRawToken(temp) : temp); }
public static string ParseTokens(string script, bool addRawMarker, Control seed) { TokenSettings settings = TokenUtils.Settings; if (script == null) { return(null); } if (script.ToString().StartsWith("<!token>")) { return(script.ToString().Substring(8)); } if (settings.Disable || (settings.DisableDuringDirectEvent && X.IsAjaxRequest)) { return(script); } if (seed == null) { seed = TokenUtils.Page; } bool isRaw = ( TokenUtils.IsAlertToken(script) || TokenUtils.IsRawToken(script) || TokenUtils.IsSelectToken(script)); script = TokenUtils.ReplaceIDTokens(script, seed); script = TokenUtils.ReplaceSelectTokens(script); script = TokenUtils.ReplaceAlertToken(script); script = TokenUtils.ReplaceRawToken(script); script = TokenUtils.ReplaceFunctionToken(script); return((addRawMarker && (isRaw || TokenUtils.IsFunction(script))) ? TokenUtils.Settings.RawMarker.ConcatWith(script) : script); }
public virtual string ValueToString() { //this.EnsureDataBind(); ParameterMode mode = this.Mode; if (this.Params.Count > 0) { return(this.ToStringInnerParams(null)); } else { string script = TokenUtils.ParseTokens(this.Value, this.Owner); if (TokenUtils.IsRawToken(script)) { mode = ParameterMode.Raw; script = TokenUtils.ReplaceRawToken(script); } return((this.Encode ? "Ext.encode(" : "").ConcatWith( mode == ParameterMode.Raw ? script : JSON.Serialize(script), this.Encode ? ")" : "")); } }
public virtual string ToConfigString() { if (this.Format != RendererFormat.None) { if (this.FormatArgs != null && this.FormatArgs.Length > 0) { return(new JFunction("return Ext.util.Format.".ConcatWith( this.Format.ToString().ToLowerCamelCase(), "(value,", this.FormatArgs.Join(), ");"), "value").ToScript()); } if (this.Handler.IsEmpty()) { return("Ext.util.Format.".ConcatWith(this.Format.ToString().ToLowerCamelCase())); } } if (this.Handler.IsNotEmpty()) { string temp = TokenUtils.ParseTokens(this.Handler, this.Owner); if (TokenUtils.IsRawToken(temp)) { return(TokenUtils.ReplaceRawToken(temp)); } return(new JFunction( temp, this.Args) .ToScript()); } return(TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(this.Fn))); }
public virtual void AddScript(string script) { if (this.IsProxy || this.AlreadyRendered) { if (HttpContext.Current == null) { ResourceManager.AddInstanceScript(script); return; } ResourceManager rm = ResourceManager.GetInstance(HttpContext.Current); if (HttpContext.Current.CurrentHandler is Page && rm != null) { rm.AddScript(script); } else { ResourceManager.AddInstanceScript(script); } return; } if (script.IsNotEmpty() && !this.IsParentDeferredRender && this.Visible) { if (this.AlreadyRendered && this.HasResourceManager) { this.ResourceManager.RegisterOnReadyScript(ResourceManager.ScriptOrderNumber, TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(script, this))); } else { this.ProxyScripts.Add(ResourceManager.ScriptOrderNumber, TokenUtils.ReplaceRawToken(TokenUtils.ParseTokens(script, this))); } } }
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("}));}"); }
public static string ReplaceIDTokens(string script, Control seed) { script = TokenUtils.ReplaceDirectMethods(script, seed); Control control = null; string[] parts = null; foreach (Match match in ID_Pattern_RE.Matches(script)) { parts = match.Value.Between("{", "}").Split('.'); control = ControlUtils.FindControl(seed, parts[0]); if (control != null) { if (parts.Length == 2) { PropertyInfo prop = control.GetType().GetProperty(parts[1]); if (prop != null) { object value = prop.GetValue(control, null); if (value == null) { value = ReflectionUtils.GetDefaultValue(prop); } if (value is string) { string val = TokenUtils.ParseTokens(value.ToString(), control); if (TokenUtils.IsRawToken(val)) { val = JSON.Serialize(TokenUtils.ReplaceRawToken(val)).Chop(); } else { val = JSON.Serialize(val); } script = script.Replace(match.Value, val); } else { script = script.Replace(match.Value, JSON.Serialize(value)); } } } else { if (control is Observable || control is UserControl) { script = script.Replace(match.Value, control.ClientID); } else { script = script.Replace(match.Value, "Ext.get(\"" + control.ClientID + "\")"); } } } else { script = script.Replace(match.Value, "Ext.get(\"" + parts[0] + "\")"); } } return(script); }