Example #1
0
        public static Type SelectTypeVersion(Form caller, string typeString)
        {
            DlgChangeTypeVersion dlg = new DlgChangeTypeVersion();

            dlg.SetTypeText(typeString);
            if (dlg.ShowDialog(caller) == DialogResult.OK)
            {
                return(dlg.ReturnType);
            }
            return(null);
        }
        private void processclass(ComponentID c, int idx)
        {
            bool   bOK = false;
            string msg = string.Empty;

            if (File.Exists(c.ComponentFile))
            {
                XmlDocument xml = new XmlDocument();
                xml.Load(c.ComponentFile);
                if (xml.DocumentElement != null)
                {
                    bOK = true;
                    XmlNodeList typeNodes = xml.DocumentElement.SelectNodes("Types/Item");
                    if (typeNodes != null && typeNodes.Count > 0)
                    {
                        bool          bModified = false;
                        StringBuilder sb        = new StringBuilder();
                        foreach (XmlNode nd in typeNodes)
                        {
                            string stype = XmlUtil.GetAttribute(nd, "fullTypeName");
                            if (!string.IsNullOrEmpty(stype))
                            {
                                bool b = false;
                                Type t;
                                try
                                {
                                    t = Type.GetType(stype);
                                    if (t != null)
                                    {
                                        b = true;
                                    }
                                }
                                catch
                                {
                                }
                                if (!b)
                                {
                                    int k = stype.IndexOf("Version=", StringComparison.Ordinal);
                                    if (k > 0)
                                    {
                                        string stype2 = stype.Substring(0, k).Trim();
                                        if (stype2.EndsWith(","))
                                        {
                                            stype2 = stype2.Substring(0, stype2.Length - 1);
                                        }
                                        if (!string.IsNullOrEmpty(stype2))
                                        {
                                            try
                                            {
                                                t = Type.GetType(stype2);
                                                if (t != null)
                                                {
                                                    b         = true;
                                                    bModified = true;
                                                    XmlUtil.SetAttribute(nd, "fullTypeName", t.AssemblyQualifiedName);
                                                }
                                            }
                                            catch
                                            {
                                            }
                                            if (!b)
                                            {
                                                k = stype2.IndexOf(',');
                                                if (k > 0)
                                                {
                                                    stype2 = stype2.Substring(0, k).Trim();
                                                    try
                                                    {
                                                        t = Type.GetType(stype2);
                                                        if (t != null)
                                                        {
                                                            b         = true;
                                                            bModified = true;
                                                            XmlUtil.SetAttribute(nd, "fullTypeName", t.AssemblyQualifiedName);
                                                        }
                                                    }
                                                    catch
                                                    {
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (!b)
                                {
                                    string so;
                                    XmlUtil.DisableTypePathAdjust = true;
                                    t = XmlUtil.GetLibTypeAttribute(nd, out so);
                                    if (t != null)
                                    {
                                        b = true;
                                    }
                                    XmlUtil.DisableTypePathAdjust = false;
                                }
                                if (!b)
                                {
                                    int k = stype.IndexOf("Version=", StringComparison.Ordinal);
                                    if (k > 0)
                                    {
                                        if (stype.IndexOf(',', k) > 0)
                                        {
                                            this.Invoke((MethodInvoker)(delegate()
                                            {
                                                t = DlgChangeTypeVersion.SelectTypeVersion(this, stype);
                                                if (t != null)
                                                {
                                                    b = true;
                                                    bModified = true;
                                                    XmlUtil.SetAttribute(nd, "fullTypeName", t.AssemblyQualifiedName);
                                                }
                                            }));
                                        }
                                    }
                                }
                                if (!b)
                                {
                                    bOK = false;
                                    sb.Append(stype);
                                    sb.Append("\r\n");
                                }
                            }
                        }
                        if (!bOK)
                        {
                            msg = string.Format(CultureInfo.InvariantCulture, "Following classes cannot be loaded:\r\n{0}", sb.ToString());
                        }
                        else if (bModified)
                        {
                            xml.Save(c.ComponentFile);
                        }
                    }
                }
                else
                {
                    msg = string.Format(CultureInfo.InvariantCulture, "Invalid class file:{0}", c.ComponentFile);
                }
            }
            else
            {
                msg = string.Format(CultureInfo.InvariantCulture, "File not found:{0}", c.ComponentFile);
            }
            if (bOK)
            {
                this.Invoke((MethodInvoker)(delegate()
                {
                    _tbl.Rows[idx][0] = Resource1._ok.ToBitmap();
                    _tbl.Rows[idx][2] = "OK";
                    _tbl.Rows[idx][3] = "";
                }));
            }
            else
            {
                this.Invoke((MethodInvoker)(delegate()
                {
                    _tbl.Rows[idx][0] = Resource1._cancel.ToBitmap();
                    _tbl.Rows[idx][2] = "Error";
                    _tbl.Rows[idx][3] = msg;
                }));
            }
        }