Exemple #1
0
 public static IJavascriptType FromString(string value)
 {
     if (string.IsNullOrEmpty(value))
     {
         return(new JsString());
     }
     if (value[0] == '[' && value[value.Length - 1] == ']')
     {
         JsArray a = new JsArray();
         a.SetValueString(value);
         return(a);
     }
     else
     {
         int pos = value.IndexOf('!');
         if (pos <= 0)
         {
             return(new JsString(value));
         }
         string st = value.Substring(0, pos);
         Type   t  = XmlUtil.GetKnownType(st);
         if (t == null)
         {
             return(new JsString(value));
         }
         IJavascriptType js = (IJavascriptType)Activator.CreateInstance(t);
         js.SetValueString(value.Substring(pos + 1));
         return(js);
     }
 }
Exemple #2
0
        public void CreateActionJavaScript(string methodName, StringCollection code, StringCollection parameters, string returnReceiver)
        {
            IJavascriptType ijt = this.ObjectInstance as IJavascriptType;

            if (ijt == null)
            {
                Type t = this.ObjectInstance as Type;
                if (t != null)
                {
                    if (t.GetInterface("IJavascriptType") != null)
                    {
                        ijt = Activator.CreateInstance(t) as IJavascriptType;
                    }
                }
            }
            if (ijt != null)
            {
                string m = ijt.GetJavascriptMethodRef(this.GetJavaScriptReferenceCode(code), methodName, code, parameters);
                if (!string.IsNullOrEmpty(m))
                {
                    if (string.IsNullOrEmpty(returnReceiver))
                    {
                        code.Add(string.Format(CultureInfo.InvariantCulture, "{0};\r\n", m));
                    }
                    else
                    {
                        code.Add(string.Format(CultureInfo.InvariantCulture, "{0}={1};\r\n", returnReceiver, m));
                    }
                    return;
                }
            }
            WebPageCompilerUtility.CreateActionJavaScript(this.GetJavaScriptReferenceCode(code), methodName, code, parameters, returnReceiver);
        }
Exemple #3
0
 public void SetValueString(string value)
 {
     if (string.IsNullOrEmpty(value))
     {
         _value = null;
     }
     else
     {
         if (value[0] == '[' && value[value.Length - 1] == ']')
         {
             string s = value.Substring(1);
             s = s.Substring(0, s.Length - 1);
             string[] ss = s.Split(',');
             _value = new IJavascriptType[ss.Length];
             for (int i = 0; i < ss.Length; i++)
             {
                 _value[i] = WebClientData.FromString(ss[i]);
                 JsString jss = _value[i] as JsString;
                 if (jss != null)
                 {
                     jss.SetValueString(jss.GetValueString().Replace(COMMACODE, ","));
                 }
             }
         }
         else
         {
             IJavascriptType js = WebClientData.FromString(value);
             _value    = new IJavascriptType[1];
             _value[0] = js;
         }
     }
 }
        public bool IsNullOrDefaultValue()
        {
            if (_value == null)
            {
                return(true);
            }
            IJavascriptType js = _value as IJavascriptType;

            if (js != null)
            {
                return(js.IsDefaultValue());
            }
            if (VPLUtil.IsNumber(_type))
            {
                try
                {
                    double d = Convert.ToDouble(_value);
                    return(d != 0);
                }
                catch
                {
                    return(true);
                }
            }
            if (typeof(bool).Equals(_type))
            {
                try
                {
                    bool b = Convert.ToBoolean(_value);
                    if (b)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                catch
                {
                    return(true);
                }
            }
            if (typeof(DateTime).Equals(_type))
            {
                try
                {
                    DateTime dt = Convert.ToDateTime(_value);
                    return(dt > DateTime.MinValue);
                }
                catch
                {
                    return(true);
                }
            }
            return(false);
        }
 public PropertyDescriptorClientVariable(string name, IJavascriptType type, WebClientValueCollection owner)
     : base(name, new Attribute[] {
     new WebClientMemberAttribute(), new BindableAttribute(true)
 })
 {
     _owner = owner;
     _type  = type;
     _name  = name;
 }
Exemple #6
0
        public object Clone()
        {
            JsArray obj = new JsArray();

            if (_value != null)
            {
                IJavascriptType[] jss = new IJavascriptType[_value.Length];
                for (int i = 0; i < _value.Length; i++)
                {
                    jss[i] = _value[i].Clone() as IJavascriptType;
                }
                obj._value = jss;
            }
            return(obj);
        }
 //return default non-null value
 public string CreateJavaScript(StringCollection sb)
 {
     if (typeof(string).Equals(ClassType))
     {
         return("''");
     }
     if (GlobalFunctionAttribute.IsGlobalFunctionType(ClassType))
     {
         return(string.Empty);
     }
     if (ClassType.GetInterface("IJavascriptType") != null)
     {
         IJavascriptType js = Activator.CreateInstance(ClassType) as IJavascriptType;
         return(js.CreateDefaultObject());
     }
     return(ClassType.Name);
 }
        public string GetJsCode()
        {
            if (VPLUtil.IsNumber(_type))
            {
                if (_value == null)
                {
                    return("0");
                }
                return(_value.ToString());
            }
            if (typeof(bool).Equals(_type))
            {
                bool b = Convert.ToBoolean(_value);
                if (b)
                {
                    return("true");
                }
                else
                {
                    return("false");
                }
            }
            if (typeof(DateTime).Equals(_type))
            {
                if (_value == null)
                {
                    return("'1900-01-01'");
                }
                DateTime dt = Convert.ToDateTime(_value);
                return(string.Format(CultureInfo.InvariantCulture, "'{0}'", dt.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture)));
            }
            IJavascriptType js = _value as IJavascriptType;

            if (js != null)
            {
                return(js.GetValueJsCode());
            }
            if (_value == null)
            {
                return("''");
            }
            string s = _value.ToString();

            return(string.Format(CultureInfo.InvariantCulture, "'{0}'", s.Replace("'", "\\'")));
        }
Exemple #9
0
        public void CreateActionJavaScript(string methodName, StringCollection code, StringCollection parameters, string returnReceiver)
        {
            if (ClassType != null && _type.BaseClassType.GetInterface("IJavascriptType") != null)
            {
                IJavascriptType js = Activator.CreateInstance(_type.BaseClassType) as IJavascriptType;
                string          v  = js.GetJavascriptMethodRef(this.CodeName, methodName, code, parameters);

                if (string.IsNullOrEmpty(returnReceiver))
                {
                }
                else
                {
                    code.Add(returnReceiver);
                    code.Add("=");
                }
                code.Add(v);
                code.Add(";\r\n");
            }
            else if (this.BaseClassType.IsArray)
            {
                if (string.CompareOrdinal(methodName, "Set") == 0)
                {
                    code.Add(CodeName);
                    code.Add("[");
                    code.Add(parameters[0]);
                    code.Add("]=");
                    code.Add(parameters[1]);
                    code.Add(";\r\n");
                }
                else if (string.CompareOrdinal(methodName, "Get") == 0)
                {
                    if (!string.IsNullOrEmpty(returnReceiver))
                    {
                        code.Add(string.Format(CultureInfo.InvariantCulture,
                                               "{0}={1}[{2}];\r\n", returnReceiver, this.GetJavaScriptReferenceCode(code), parameters[0]));
                    }
                }
            }
            else
            {
                WebPageCompilerUtility.CreateActionJavaScript(this.CodeName, methodName, code, parameters, returnReceiver);
            }
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            string nm = textBox1.Text.Trim();

            if (string.IsNullOrEmpty(nm))
            {
                MessageBox.Show(this, "Name cannot be empty", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (string.CompareOrdinal(nm, "tag") == 0)
            {
                MessageBox.Show(this, "Name is in use", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                bool bExists = false;
                if (_names != null)
                {
                    if (string.CompareOrdinal(_defName, nm) != 0)
                    {
                        bExists = _names.Contains(nm);
                    }
                }
                if (bExists)
                {
                    MessageBox.Show(this, "Name is in use", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    Type t;
                    if (listBox1.SelectedIndex >= 0)
                    {
                        t = _types[listBox1.Items[listBox1.SelectedIndex] as string];
                    }
                    else
                    {
                        t = typeof(JsString);
                    }
                    ReturnName        = nm;
                    ReturnType        = Activator.CreateInstance(t) as IJavascriptType;
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
Exemple #11
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            string nm = textBox1.Text.Trim();

            if (string.IsNullOrEmpty(nm))
            {
                MessageBox.Show(this, "Name cannot be empty", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                bool bExists = false;
                if (_owner != null)
                {
                    if (!(_defVal != null && string.Compare(_defVal.Name, nm, StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        bExists = (_owner[nm] != null);
                    }
                }
                if (bExists)
                {
                    MessageBox.Show(this, "Name is in use", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    Return      = new SessionVariable();
                    Return.Name = nm;
                    Type t;
                    if (listBox1.SelectedIndex >= 0)
                    {
                        t = _types[listBox1.Items[listBox1.SelectedIndex] as string];
                    }
                    else
                    {
                        t = typeof(JsString);
                    }
                    Return.Value      = Activator.CreateInstance(t) as IJavascriptType;
                    ReturnName        = nm;
                    ReturnType        = Return.Value;
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
 public override void CreateJavaScript(StringCollection sb, StringCollection parameters, string returnReceiver)
 {
     if (_returnReceiver != null)
     {
         if (_returnReceiver.BaseClassType.GetInterface("IJavascriptType") != null)
         {
             IJavascriptType js = Activator.CreateInstance(_returnReceiver.BaseClassType) as IJavascriptType;
             string          v  = js.GetJavascriptMethodRef(_returnReceiver.CodeName, ".ctor", sb, parameters);
             sb.Add(_returnReceiver.CodeName);
             sb.Add("=");
             sb.Add(v);
             sb.Add(";\r\n");
             return;
         }
     }
     if (_mif != null && _returnReceiver != null)
     {
         if (_mif.ReflectedType != null && _mif.ReflectedType.IsArray)
         {
             sb.Add(_returnReceiver.CodeName);
             sb.Add("=new Array();\r\n");
             if (parameters != null && parameters.Count > 0)
             {
                 string idx = string.Format(CultureInfo.InvariantCulture, "i{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                 sb.Add("for(var ");
                 sb.Add(idx);
                 sb.Add("=0;");
                 sb.Add(idx);
                 sb.Add("<");
                 sb.Add(parameters[0]);
                 sb.Add(";");
                 sb.Add(idx);
                 sb.Add("++) {\r\n");
                 sb.Add(_returnReceiver.CodeName);
                 sb.Add(".push(null);\r\n");
                 sb.Add("}\r\n");
             }
         }
     }
 }
 public SessionVariable()
 {
     _value = new JsString();
 }
        public static string ObjectCreateJavaScriptCode(object v)
        {
            if (v == null || v == System.DBNull.Value)
            {
                return("null");
            }
            IJavascriptType ijt = v as IJavascriptType;

            if (ijt != null)
            {
                return(ijt.GetValueJsCode());
            }
            Type t = v.GetType();

            if (typeof(WebMouseButton).Equals(t))
            {
                WebMouseButton wmb = (WebMouseButton)v;
                switch (wmb)
                {
                case WebMouseButton.Left:
                    return("JsonDataBinding.mouseButtonLeft()");

                case WebMouseButton.Middle:
                    return("4");

                default:
                    return("2");
                }
            }
            if (typeof(Cursor).Equals(t))
            {
                Cursor cr = (Cursor)v;
                return(string.Format(CultureInfo.InvariantCulture, "'{0}'", GetJavascriptCursorValue(cr, true)));
            }
            if (typeof(EnumWebCursor).Equals(t))
            {
                return(string.Format(CultureInfo.InvariantCulture, "'{0}'", v.ToString().Replace("_", "-")));
            }
            if (t.IsEnum)
            {
                if (JavaScriptEnumAttribute.IsJavaScriptEnum(t))
                {
                    return(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", t.FullName, Enum.GetName(t, v)));
                }
                else
                {
                    return(string.Format(CultureInfo.InvariantCulture, "'{0}'", v));
                }
            }
            if (typeof(string).Equals(t))
            {
                string s = v as string;
                if (s.Length == 0)
                {
                    return("''");
                }
                s = s.Replace("\r", "\\r").Replace("\n", "\\n").Replace("'", "\\'");
                return(string.Format(CultureInfo.InvariantCulture, "'{0}'", s));
            }
            if (typeof(bool).Equals(t))
            {
                bool c = Convert.ToBoolean(v);
                if (c)
                {
                    return("true");
                }
                else
                {
                    return("false");
                }
            }
            if (typeof(Color).Equals(t))
            {
                Color c = (Color)v;
                return(string.Format(CultureInfo.InvariantCulture, "'{0}'", GetColorString(c)));
            }
            if (typeof(Font).Equals(t))
            {
                Font ft = (Font)v;
                return(string.Format(CultureInfo.InvariantCulture, "'{0}'", GetFontStyleString(ft)));
            }
            if (typeof(Cursor).Equals(t))
            {
                return(string.Format(CultureInfo.InvariantCulture, "'{0}'", GetJavascriptCursorValue((Cursor)v, true)));
            }
            if (VPLUtil.IsNumber(t))
            {
                return(v.ToString());
            }
            if (t.IsArray)
            {
                Array         a  = v as Array;
                StringBuilder sb = new StringBuilder("[");
                if (a.Length > 0)
                {
                    sb.Append(ObjectCreateJavaScriptCode(a.GetValue(0)));
                    for (int i = 1; i < a.Length; i++)
                    {
                        sb.Append(",");
                        sb.Append(ObjectCreateJavaScriptCode(a.GetValue(i)));
                    }
                }
                sb.Append("]");
                return(sb.ToString());
            }
            return(string.Format(CultureInfo.InvariantCulture, "'{0}'", v));
        }
Exemple #15
0
 public WebClientValue(string name, IJavascriptType v)
 {
     _name  = name;
     _value = v;
 }
Exemple #16
0
 public WebClientValue(KeyValuePair <string, IJavascriptType> v)
 {
     _name  = v.Key;
     _value = v.Value;
 }