Beispiel #1
0
        /// <summary>
        /// Removes the converter.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="t">The t.</param>
        internal static void RemoveConverter(AjaxSettings settings, Type t)
        {
            Type        key;
            bool        removed = false;
            IEnumerator m       = settings.SerializableConverters.Keys.GetEnumerator();

            while (!removed && m.MoveNext())
            {
                key = (Type)m.Current;
                if (settings.SerializableConverters[key].GetType() == t)
                {
                    settings.SerializableConverters.Remove(key);
                    removed = true;
                }
            }

            removed = false;
            m       = settings.DeserializableConverters.Keys.GetEnumerator();

            while (!removed && m.MoveNext())
            {
                key = (Type)m.Current;
                if (settings.DeserializableConverters[key].GetType() == t)
                {
                    settings.DeserializableConverters.Remove(key);
                    removed = true;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds the default converter.
        /// </summary>
        /// <param name="settings">The settings.</param>
        internal static void AddDefaultConverter(AjaxSettings settings)
        {
            #region Default Converters

            AddConverter(settings, new StringConverter());
            AddConverter(settings, new PrimitiveConverter());
            AddConverter(settings, new GuidConverter());
            AddConverter(settings, new ExceptionConverter());
            AddConverter(settings, new EnumConverter());
            AddConverter(settings, new DecimalConverter());

            AddConverter(settings, new NameValueCollectionConverter());

            AddConverter(settings, new DateTimeConverter());

            AddConverter(settings, new DataSetConverter());
            AddConverter(settings, new DataTableConverter());
            AddConverter(settings, new DataViewConverter());

            AddConverter(settings, new IJavaScriptObjectConverter());

            AddConverter(settings, new IDictionaryConverter());
            AddConverter(settings, new IListConverter());
            AddConverter(settings, new IEnumerableConverter());

            AddConverter(settings, new DataRowConverter());
            AddConverter(settings, new HtmlControlConverter());

            #endregion
        }
Beispiel #3
0
        /// <summary>
        /// Adds the converter.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="converter">The converter.</param>
        /// <param name="replace">if set to <c>true</c> [replace].</param>
        internal static void AddConverter(AjaxSettings settings, JavaScriptConverter converter, bool replace)
        {
            Type t;

            for (int i = 0; i < converter.SerializableTypes.Length; i++)
            {
                t = converter.SerializableTypes[i];

                if (settings.SerializableConverters.ContainsKey(t))
                {
                    if (replace)
                    {
                        settings.SerializableConverters[t] = converter;
                    }
                    continue;
                }

                settings.SerializableConverters.Add(t, converter);
            }

            for (int i = 0; i < converter.DeserializableTypes.Length; i++)
            {
                t = converter.DeserializableTypes[i];

                if (settings.DeserializableConverters.ContainsKey(t))
                {
                    if (replace)
                    {
                        settings.DeserializableConverters[t] = converter;
                    }
                    continue;
                }

                settings.DeserializableConverters.Add(t, converter);
            }
        }
        /// <summary>
        /// Creates a configuration section handler.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="configContext">Configuration context object.</param>
        /// <param name="section"></param>
        /// <returns>The created section handler object.</returns>
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            AjaxSettings settings = new AjaxSettings();

            Utility.AddDefaultConverter(settings);

            foreach (XmlNode n in section.ChildNodes)
            {
#if (!JSONLIB)
                if (n.Name == "urlClassMappings")
                {
                    settings.UseAssemblyQualifiedName = n.SelectSingleNode("@useAssemblyQualifiedName[.='true']") != null;

                    XmlNode ns, url;

                    foreach (XmlNode e in n.SelectNodes("add"))
                    {
                        ns  = e.SelectSingleNode("@type");
                        url = e.SelectSingleNode("@path");
#if (NET20)
                        if (ns == null || String.IsNullOrEmpty(ns.InnerText) || url == null || String.IsNullOrEmpty(url.InnerText))
#else
                        if (ns == null || ns.InnerText.Length == 0 || url == null || url.InnerText.Length == 0)
#endif
                        { continue; }

                        if (settings.UrlClassMappings.Contains(url.InnerText))
                        {
                            throw new Exception("Duplicate namespace mapping '" + url.InnerText + "'.");
                        }

                        settings.UrlClassMappings.Add(url.InnerText, ns.InnerText);
                    }
                }
                else if (n.Name == "security")
                {
                    if (n.SelectSingleNode("@provider") != null)
                    {
                        string securityProviderType = n.SelectSingleNode("@provider").InnerText;

                        AjaxSecurity sec = new AjaxSecurity(securityProviderType);

                        if (sec.Init())
                        {
                            settings.Security = sec;
                        }
                    }
                    if (n.SelectSingleNode("@token") != null)
                    {
                        // settings.TokenEnabled = n.SelectSingleNode("@enabled") != null && n.SelectSingleNode("@enabled").InnerText == "true";
                        settings.TokenSitePassword = n.SelectSingleNode("@token") != null?n.SelectSingleNode("@token").InnerText : settings.TokenSitePassword;
                    }
                }
                else if (n.Name == "typeJavaScriptGenerator")
                {
                    if (n.SelectSingleNode("@type") != null)
                    {
                        settings.TypeJavaScriptGenerator = n.SelectSingleNode("@type").InnerText;
                    }
                }
                else if (n.Name == "debug")
                {
                    if (n.SelectSingleNode("@enabled") != null && n.SelectSingleNode("@enabled").InnerText == "true")
                    {
                        settings.DebugEnabled = true;
                    }
                }
                else
#endif
                if (n.Name == "jsonConverters")
                {
                    if (n.SelectSingleNode("@includeTypeProperty") != null && n.SelectSingleNode("@includeTypeProperty").InnerText == "true")
                    {
                        settings.IncludeTypeProperty = true;
                    }
                    if (n.SelectSingleNode("@useSimpleObjectNaming") != null && n.SelectSingleNode("@useSimpleObjectNaming").InnerText == "true")
                    {
                        settings.UseSimpleObjectNaming = true;
                    }

                    XmlNodeList jsonConverters = n.SelectNodes("add");

                    foreach (XmlNode j in jsonConverters)
                    {
                        XmlNode t = j.SelectSingleNode("@type");

                        if (t == null)
                        {
                            continue;
                        }

                        Type type = Type.GetType(t.InnerText);

                        if (type == null)
                        {
                            // throw new ArgumentException("Could not find type " + t.InnerText + ".");
                            continue;
                        }

                        if (!typeof(JavaScriptConverter).IsAssignableFrom(type))
                        {
                            // throw new ArgumentException("Type " + t.InnerText + " does not inherit from JavaScriptObjectConverter.");
                            continue;
                        }

                        StringDictionary d = new StringDictionary();
                        foreach (XmlAttribute a in j.Attributes)
                        {
                            if (d.ContainsKey(a.Name))
                            {
                                continue;
                            }
                            d.Add(a.Name, a.Value);
                        }

                        JavaScriptConverter c = (JavaScriptConverter)Activator.CreateInstance(type);
                        c.Initialize(d);

                        Utility.AddConverter(settings, c, true);
                    }


                    jsonConverters = n.SelectNodes("remove");

                    foreach (XmlNode j in jsonConverters)
                    {
                        XmlNode t = j.SelectSingleNode("@type");

                        if (t == null)
                        {
                            continue;
                        }

                        Type type = Type.GetType(t.InnerText);

                        if (type == null)
                        {
                            // throw new ArgumentException("Could not find type " + t.InnerText + ".");
                            continue;
                        }

                        Utility.RemoveConverter(settings, type);
                    }
                }
            }

            return(settings);
        }
Beispiel #5
0
 /// <summary>
 /// Adds the converter.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="converter">The converter.</param>
 internal static void AddConverter(AjaxSettings settings, JavaScriptConverter converter)
 {
     AddConverter(settings, converter, false);
 }