internal ContractHandler AddContract(string ContractName, ExtendType extend)
        {
            XmlHelper req = new XmlHelper("<Request/>");

            req.AddElement(".", "ContractName", ContractName);

            req.AddElement(".", "Definition");
            XmlElement authElement = req.AddElement("Definition", "Authentication");

            if (extend == ExtendType.open)
            {
                XmlElement e = req.AddElement("Definition/Authentication", "Public");
                e.SetAttribute("Enabled", "true");
            }
            else
            {
                if (extend != ExtendType.none && extend != ExtendType.open)
                {
                    authElement.SetAttribute("Extends", extend.ToString());
                }
            }

            Parent.SendRequest("UDSManagerService.CreateContract", new Envelope(req));

            ContractHandler contract = ContractHandler.CreateNew(ContractName, extend);

            JoinProject(contract);
            return(contract);
        }
        internal void ImportContract(XmlElement xmlElement)
        {
            string          tableName = xmlElement.GetAttribute("Name");
            ContractHandler contract  = this.GetProjectContract(tableName);

            XmlHelper h = new XmlHelper(xmlElement);

            Parent.SendRequest("UDSManagerService.ImportContract", new Envelope(new XmlHelper(xmlElement)));

            if (contract != null)
            {
                return;
            }

            this.JoinProject(ContractHandler.CreateNew(tableName, ExtendType.none));
        }
        internal void ImportContracts(XmlElement xmlElement, bool import)
        {
            XmlHelper h = new XmlHelper(xmlElement);
            List <ContractHandler> jp = new List <ContractHandler>();
            List <ContractHandler> lp = new List <ContractHandler>();

            foreach (XmlElement contractElement in h.GetElements("Contract"))
            {
                string          contractName = contractElement.GetAttribute("Name");
                ContractHandler contract     = this.GetProjectContract(contractName);

                if (contract == null)
                {
                    jp.Add(ContractHandler.CreateNew(contractName, ExtendType.none));
                }
            }

            foreach (ContractHandler contract in this.Contracts)
            {
                bool contains = false;
                foreach (XmlElement contractElement in h.GetElements("Contract"))
                {
                    string contractName = contractElement.GetAttribute("Name");
                    if (contract.Name.ToLower() == contractName.ToLower())
                    {
                        contains = true;
                        break;
                    }
                }

                if (!contains && import)
                {
                    lp.Add(contract);
                }
            }

            Parent.SendRequest("UDSManagerService.ImportContracts", new Envelope(h));

            this.ModifyProjects(jp, lp);

            XmlElement pref = MainForm.CurrentProject.Preference;
            XmlHelper  ph   = new XmlHelper(pref);

            foreach (XmlElement e in h.GetElements("Property"))
            {
                string     attr   = e.GetAttribute("Name");
                XmlElement target = null;
                foreach (XmlElement p in ph.GetElements("Property"))
                {
                    string name = p.GetAttribute("Name");
                    if (attr != name)
                    {
                        continue;
                    }

                    target = p;
                }
                if (target != null)
                {
                    pref.RemoveChild(target);
                }

                e.SetAttribute("Source", "Import");
                ph.AddElement(".", e);
            }
            //Console.WriteLine(ph.XmlString);
            MainForm.CurrentProject.UpdateProjectPreference(pref);
        }