Exemplo n.º 1
0
        public static string Export(Model.IHardware v_hardware)
        {
            string t_maclist = "";
            string t_cpulist = "";

            foreach (string t_mac in v_hardware.MAC)
            {
                t_maclist += "." + t_mac;
            }
            if (t_maclist.Length > 0)
            {
                t_maclist = t_maclist.Substring(1);
            }

            foreach (string t_cpu in v_hardware.CPU)
            {
                t_cpulist += "." + t_cpu;
            }
            if (t_cpulist.Length > 0)
            {
                t_cpulist = t_cpulist.Substring(1);
            }

            return(t_maclist + ":" + t_cpulist);
        }
Exemplo n.º 2
0
        private Model.IHardware ParseHardware(string v_source)
        {
            Model.IHardware t_target = null;
            try
            {
                t_target = Hardware.Import(v_source);
            }
            catch { }

            return(t_target);
        }
Exemplo n.º 3
0
        protected override void OnActivateLicense(string v_activation_id)
        {
            string[] t_fields;

            string   v_subkey;
            string   v_name;
            string   t_usage_info;
            DateTime?t_install_time  = null;
            DateTime?t_update_time   = null;
            DateTime?t_activate_time = null;

            Model.IHardware t_install_hardware  = null;
            Model.IHardware t_activate_hardware = null;
            string          t_license_id;
            string          t_activate_license_id;

            this.m_mailgo.Track.Debug("Start activating license");

            this.GetUsageInfoKeys(out v_subkey, out v_name);
            this.GetValue(out t_usage_info, Registry.LocalMachine, v_subkey, v_name);

            t_usage_info = this.DecryptUsageInfo(t_usage_info);
            this.GetUsageInfo(out t_install_time, out t_update_time, out t_activate_time, out t_install_hardware, out t_activate_hardware, out t_license_id, t_usage_info);

            try
            {
                string t_raw_activation_id = this.DecryptActivationId(v_activation_id);
                t_fields              = t_raw_activation_id.Split(new char[] { '|' });
                t_activate_hardware   = Hardware.Import(t_fields[0]);
                t_activate_license_id = t_fields[1];
            }
            catch (Exception e)
            {
                this.m_mailgo.Track.Error(e);
                throw new Model.XBadActivationID();
            }
            if (!Hardware.IsSame(t_install_hardware, t_activate_hardware))
            {
                throw new Model.XBadActivationID();
            }
            if (t_activate_license_id != t_license_id)
            {
                throw new Model.XBadActivationID();
            }
            t_update_time   = DateTime.Now;
            t_activate_time = DateTime.Now;
            this.GetUsageInfo(out t_usage_info, t_install_time, t_update_time, t_activate_time, t_install_hardware, t_activate_hardware, t_license_id);
            this.SetValue(Registry.CurrentUser, v_subkey, v_name, this.EncryptUsageInfo(t_usage_info));

            this.m_mailgo.Track.Debug("Finish activating license");
        }
Exemplo n.º 4
0
        private void HardwareWF_Load(object sender, EventArgs e)
        {
            Model.IHardware t_hardware = this.m_license.ReadHardware();

            foreach (string t_mac in t_hardware.MAC)
            {
                this.txtMAC.Text += t_mac + Environment.NewLine;
            }

            foreach (string t_cpu in t_hardware.CPU)
            {
                this.txtCPU.Text += t_cpu + Environment.NewLine;
            }
        }
Exemplo n.º 5
0
        public static bool IsSame(Model.IHardware v_source, Model.IHardware v_target)
        {
            if (v_source == null || v_target == null)
            {
                return(false);
            }

            /* 10:40 AM 2008/05/19 Kawane-san wanted not to check the MACAddress any more so I comment these code.
             * if (v_source.MAC.Count != v_target.MAC.Count) return false;
             *
             *
             * foreach (string t_src in v_source.MAC)
             * {
             *  if (v_target.MAC.IndexOf(t_src) < 0) return false;
             * }
             *
             * foreach (string t_tag in v_target.MAC)
             * {
             *  if (v_source.MAC.IndexOf(t_tag) < 0) return false;
             * }
             *
             */

            if (v_source.CPU.Count != v_target.CPU.Count)
            {
                return(false);
            }

            foreach (string t_src in v_source.CPU)
            {
                if (v_target.CPU.IndexOf(t_src) < 0)
                {
                    return(false);
                }
            }

            foreach (string t_tag in v_target.CPU)
            {
                if (v_source.CPU.IndexOf(t_tag) < 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        private void GetUsageInfo(out DateTime?v_install_time, out DateTime?v_update_time, out DateTime?v_activate_time, out Model.IHardware v_install_hardware, out Model.IHardware v_activate_hardware, out string v_raw_license_id, string v_source)
        {
            v_install_time      = null;
            v_update_time       = null;
            v_activate_time     = null;
            v_install_hardware  = null;
            v_activate_hardware = null;
            v_raw_license_id    = null;

            string[] t_fields = v_source.Split(new char[] { '|' });

            if (t_fields.Length < 6)
            {
                return;
            }

            v_install_time      = ParseDateTime(t_fields[0]);
            v_update_time       = ParseDateTime(t_fields[1]);
            v_activate_time     = ParseDateTime(t_fields[2]);
            v_install_hardware  = ParseHardware(t_fields[3]);
            v_activate_hardware = ParseHardware(t_fields[4]);

            v_raw_license_id = "";
            for (int t_idx = 5; t_idx < t_fields.Length; t_idx++)
            {
                v_raw_license_id += "|" + t_fields[t_idx];
            }
            if (v_raw_license_id.Length > 0)
            {
                v_raw_license_id = v_raw_license_id.Substring(1);
            }
        }
Exemplo n.º 7
0
        private void GetUsageInfo(out string v_target, DateTime?v_install_time, DateTime?v_update_time, DateTime?v_activate_time, Model.IHardware v_install_hardware, Model.IHardware v_activate_hardware, string v_raw_license_id)
        {
            const string c_format = "fffssmmHHddMMyyyy";

            v_target  = (v_install_time.HasValue ? v_install_time.Value.ToString(c_format) : "");
            v_target += "|" + (v_update_time.HasValue ? v_update_time.Value.ToString(c_format) : "");
            v_target += "|" + (v_activate_time.HasValue ? v_activate_time.Value.ToString(c_format) : "");
            v_target += "|" + (v_install_hardware != null ? Hardware.Export(v_install_hardware) : "");
            v_target += "|" + (v_activate_hardware != null ? Hardware.Export(v_activate_hardware) : "");
            v_target += "|" + v_raw_license_id;
        }
Exemplo n.º 8
0
        protected override void OnCheckLicense(out bool v_installed, out bool v_evaluted, out bool v_activated, out bool v_expired, out DateTime?v_expired_date, out string v_license_id)
        {
            v_installed    = true;
            v_evaluted     = true;
            v_activated    = false;
            v_expired      = true;
            v_expired_date = null;
            v_license_id   = null;

            string   v_subkey;
            string   v_name;
            string   t_usage_info;
            DateTime?t_install_time  = null;
            DateTime?t_update_time   = null;
            DateTime?t_activate_time = null;

            Model.IHardware t_install_hardware  = null;
            Model.IHardware t_activate_hardware = null;
            string          t_raw_license_id;
            char            t_version_type;
            string          t_activate_period_str;
            int             t_activate_period;
            string          t_guid;

            this.m_mailgo.Track.Debug("Start checking license");

            this.GetUsageInfoKeys(out v_subkey, out v_name);
            this.GetValue(out t_usage_info, Registry.LocalMachine, v_subkey, v_name);

            if (t_usage_info == null)
            {
                v_installed = false;
                return;
            }

            try
            {
                t_usage_info = this.DecryptUsageInfo(t_usage_info);
            }
            catch (Exception ex)
            {
                this.m_mailgo.Track.Error(ex);
                return;
            }

            this.GetUsageInfo(out t_install_time, out t_update_time, out t_activate_time, out t_install_hardware, out t_activate_hardware, out t_raw_license_id, t_usage_info);

            DateTime t_now = DateTime.Now;

            this.m_mailgo.Track.Debug("Current time : " + t_now.ToString());

            this.m_mailgo.Track.Debug("Check install time, update time, install hardware has value");

            if (!t_install_time.HasValue)
            {
                return;
            }
            if (!t_update_time.HasValue)
            {
                return;
            }
            if (t_install_hardware == null)
            {
                this.m_mailgo.Track.Debug("Can not get install_hardware!");
                return;
            }

            this.m_mailgo.Track.Debug("Install time : " + t_install_time.Value.ToString());
            this.m_mailgo.Track.Debug("Update time : " + t_update_time.Value.ToString());

            if (DateTime.Compare(t_now, t_install_time.Value) <= 0)
            {
                return;
            }
            //if (DateTime.Compare(t_now, t_update_time.Value) <= 0) return;

            this.m_mailgo.Track.Debug("Current time is valid");

            Model.IHardware t_current_hardware = ((Model.ILicensePG) this).ReadHardware();

            #region Log hardware info

            this.m_mailgo.Track.Debug("Install_hardware:");
            this.m_mailgo.Track.Debug("MAC count: " + t_install_hardware.MAC.Count.ToString() + " Item list: ");
            foreach (string MACItem in t_install_hardware.MAC)
            {
                this.m_mailgo.Track.Debug(MACItem);
            }
            this.m_mailgo.Track.Debug("CPU count: " + t_install_hardware.CPU.Count.ToString() + " Item list: ");
            foreach (string CPUItem in t_install_hardware.CPU)
            {
                this.m_mailgo.Track.Debug(CPUItem);
            }
            this.m_mailgo.Track.Debug("-----------------------------------------------------");
            this.m_mailgo.Track.Debug("Current hardware:");
            this.m_mailgo.Track.Debug("MAC count: " + t_current_hardware.MAC.Count.ToString() + " Item list: ");
            foreach (string MACItem in t_install_hardware.MAC)
            {
                this.m_mailgo.Track.Debug(MACItem);
            }
            this.m_mailgo.Track.Debug("CPU count: " + t_current_hardware.CPU.Count.ToString() + " Item list: ");
            foreach (string CPUItem in t_install_hardware.CPU)
            {
                this.m_mailgo.Track.Debug(CPUItem);
            }

            #endregion

            if (!Hardware.IsSame(t_install_hardware, t_current_hardware))
            {
                this.m_mailgo.Track.Debug("Install_Hardware is not the same with current hardware");
                return;
            }

            this.m_mailgo.Track.Debug("Current hardware is valid");

            try
            {
                this.GetLicenseId(out t_version_type, out t_activate_period_str, out t_guid, t_raw_license_id);
                t_activate_period = int.Parse(t_activate_period_str);
                this.GetVersionType(out v_evaluted, t_version_type);
            }
            catch (Exception ex)
            {
                this.m_mailgo.Track.Error(ex);
                return;
            }

            this.m_mailgo.Track.Debug("License ID is valid");

            if (t_activate_time.HasValue && t_activate_hardware != null)
            {
                if (Hardware.IsSame(t_install_hardware, t_activate_hardware))
                {
                    this.m_mailgo.Track.Debug("install_time: " + t_install_time.Value.ToString());
                    this.m_mailgo.Track.Debug("activate_time: " + t_activate_time.Value.ToString());
                    this.m_mailgo.Track.Debug("activate period: " + t_activate_period_str);
                    if (DateTime.Compare(t_install_time.Value, t_activate_time.Value) < 0)
                    {
                        v_activated = true;
                    }
                }
                else
                {
                    this.m_mailgo.Track.Debug("install_hardware and activate_hardware is not the same!");
                }
            }

            if (!v_activated)
            {
                t_activate_time     = null;
                t_activate_hardware = null;
                if (DateTime.Compare(t_now, t_update_time.Value) <= 0)
                {
                    return;
                }
            }

            v_expired_date = t_install_time.Value.AddDays(t_activate_period);
            this.m_mailgo.Track.Debug("expired_date: " + v_expired_date.Value.ToString());
            v_expired = (DateTime.Compare(t_now, v_expired_date.Value) >= 0);

            t_update_time = t_now;
            v_license_id  = this.EncryptLicenseId(t_raw_license_id);

            this.GetUsageInfo(out t_usage_info, t_install_time, t_update_time, t_activate_time, t_install_hardware, t_activate_hardware, t_raw_license_id);
            this.m_mailgo.Track.Debug("Finish checking license11");
            this.SetValue(Registry.CurrentUser, v_subkey, v_name, this.EncryptUsageInfo(t_usage_info));
            this.m_mailgo.Track.Debug("Finish checking license");
        }
Exemplo n.º 9
0
 private void DisplayHardware(Model.IHardware v_hardware)
 {
     this.txtMacList.Text = string.Join(Environment.NewLine, v_hardware.MAC.ToArray());
     this.txtCpuList.Text = string.Join(Environment.NewLine, v_hardware.CPU.ToArray());
 }