public void Remove(AvtActivation act)
 {
     Remove(act.RegistrationCode, act.Host);
 }
 public void AddActivation(AvtActivation act)
 {
     AddActivation(act.RegistrationCode, act.Host, act.ActivationCode, act.ProductKey, act.BaseProductCode, act.BaseProductVersion);
 }
 public AvtActivation Clone()
 {
     AvtActivation act = new AvtActivation();
     act.ActivationCode = ActivationCode;
     act.RegistrationCode = RegistrationCode;
     act.Host = Host;
     act.ProductKey = ProductKey;
     act.BaseProductVersion = BaseProductVersion;
     act.BaseProductCode = BaseProductCode;
     return act;
 }
        public Dictionary<string, AvtActivation> GetActivations()
        {
            SqlConnection conn = new SqlConnection(_conStr);
            SqlDataAdapter a = new SqlDataAdapter("select * from " + _dbo + _qualifier + _table, conn);
            DataSet s = new DataSet(); a.Fill(s);

            Dictionary<string, AvtActivation> activations = new Dictionary<string, AvtActivation>();
            foreach (DataRow dr in s.Tables[0].Rows) {
                AvtActivation act = new AvtActivation();
                act.Host = dr["Host"].ToString();
                act.RegistrationCode = dr["RegistrationCode"].ToString();
                act.ActivationCode = dr["ActivationCode"].ToString();
                act.ProductKey = dr["ProductKey"].ToString();
                act.BaseProductVersion = dr["BaseProductVersion"].ToString();
                act.BaseProductCode = dr["BaseProductCode"].ToString();
                //Console.WriteLine(dr[0].ToString());
                activations[act.Host] = act;
            }

            return activations;
        }
        public AvtActivation Activate(string regCode, string productCode, string version, string host, string productKey)
        {
            AvtRegistrationCode r = new AvtRegistrationCode(regCode);

            // remove www
            if (host.IndexOf("www.") == 0 || host.IndexOf("http://www.") == 0 || host.IndexOf("https://www.") == 0) host = host.Substring(host.IndexOf("www.") + 4);

            // for domain license, also remove dev. and staging. (we grant these free)
            if (r.VariantCode == "DOM") {
                if (host.IndexOf("dev.") == 0 || host.IndexOf("http://dev.") == 0 || host.IndexOf("https://dev.") == 0) host = host.Substring(host.IndexOf("dev.") + 4);
                if (host.IndexOf("staging.") == 0 || host.IndexOf("http://staging.") == 0 || host.IndexOf("https://staging.") == 0) host = host.Substring(host.IndexOf("staging.") + 8);
            }

            Dictionary<string, string> data = new Dictionary<string, string>();
            Dictionary<string, string> prvData = new Dictionary<string, string>();
            data["product"] = productCode; // this is not encrypted because we need to extract the private key on the server side
            prvData["regcode"] = regCode;
            prvData["version"] = version;
            prvData["hostname"] = host;

            XmlDocument xmlAct = new XmlDocument();
            try {
                xmlAct.LoadXml(SendData(_regCoreSrv + "?cmd=activate", productKey, data, prvData));
            } catch (Exception e) {
                throw new Exception("An error occured (" + e.Message + ")");
            }

            if (xmlAct["error"] != null) {
                throw new Exception(xmlAct["error"].InnerText);
            }

            AvtActivation act = new AvtActivation();
            act.RegistrationCode = regCode;
            act.Host = xmlAct.FirstChild["host"].InnerText;
            act.ActivationCode = xmlAct.FirstChild["activation_code"].InnerText;
            act.ProductKey = xmlAct.FirstChild["product_key"].InnerText;
            act.BaseProductCode = r.ProductCode;
            act.BaseProductVersion = xmlAct.FirstChild["version"].InnerText;

            if (!act.IsValid(productCode, version)) {
                throw new Exception("Invalid activation");
            }

            // add activation
            _src.AddActivation(act);
            _initActivations[act.Host] = act;
            _validActivations[act.Host] = act;

            return act;
        }