Ejemplo n.º 1
0
        public static string CreateSerial(string license, string macAddress, string application, string module, SerialType sType, DateTime expiration, string pendrive)
        {
            string serial = string.Empty;

            concat(ref serial, ConvertString(application) + ConvertString(module));
            if (sType.HasFlag(SerialType.LICENSE_NAME))
            {
                concat(ref serial, ConvertString(license));
            }
            if (sType.HasFlag(SerialType.MAC_ADDRESS))
            {
                concat(ref serial, ConvertMacAddress(macAddress));
            }

            if (sType.HasFlag(SerialType.EXPIRATION_DATE))
            {
                concat(ref serial, ConvertToString((UInt64)(expiration.Year * 365 + expiration.Month * 31 + expiration.Day)));
            }

            if (sType.HasFlag(SerialType.PEN_DRIVE))
            {
                string letter = USBSerialNumber.GetDriveLetterFromName(pendrive);
                concat(ref serial, ConvertSerialNumber(USBSerialNumber.getSerialNumberFromDriveLetter(letter)));
            }

            // Checksum
            concat(ref serial, ConvertString(serial));
            return(serial);
        }
Ejemplo n.º 2
0
        private void tsmiLoadModule_Click(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();

            fd.CheckFileExists = true;
            fd.Filter          = "Config|*.config|All|*.*";
            if (fd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(fd.FileName);

            XmlNodeList xModules = xDoc.SelectNodes("modules/module");

            if (xDoc.SelectSingleNode("modules").Attributes["pendrive"] != null)
            {
                cbbPenDrive.Text = xDoc.SelectSingleNode("modules").Attributes["pendrive"].Value;
            }

            foreach (XmlNode xModule in xModules)
            {
                string    moduleCode = xModule.Attributes["code"].Value;
                NameSpace nSpace     = new NameSpace(xModule.Attributes["namespace"].Value);

                string moduleDir = Path.Combine(Path.GetDirectoryName(fd.FileName), nSpace.Folder);
                string menuFile  = Path.Combine(moduleDir, "menu.config");

                if (!File.Exists(menuFile))
                {
                    MessageBox.Show("Missing menu file");
                    return;
                }

                XmlDocument xDocMenu = new XmlDocument();
                xDocMenu.Load(menuFile);

                XmlNodeList xMod = xDocMenu.SelectNodes("menu/module");

                foreach (XmlNode xSignleMod in xMod)
                {
                    int row = DataGridView1.Rows.Add();
                    DataGridView1.Rows[row].Cells["colenable"].Value = xSignleMod.Attributes["enable"].Value == bool.TrueString;
                    SerialType sType = (SerialType)Enum.Parse(typeof(SerialType), xSignleMod.Attributes["serialtype"].Value);
                    DataGridView1.Rows[row].Cells["colLicenseType"].Value = sType;
                    DataGridView1.Rows[row].Cells["colApplication"].Value = moduleCode;
                    DataGridView1.Rows[row].Cells["colModuleName"].Value  = xSignleMod.Attributes["code"].Value;
                    if (sType.HasFlag(SerialType.EXPIRATION_DATE))
                    {
                        DataGridView1.Rows[row].Cells["colExpiration"].Value = xSignleMod.Attributes["expirationdate"].Value;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static bool CheckSerialType(SerialModule sm)
        {
            int pos = 1;

            string[] parts = sm.SerialNo.Split(new char[] { '-' });

            SerialType sType = (SerialType)Enum.Parse(typeof(SerialType), sm.SerialType);

            if (sType.HasFlag(SerialType.LICENSE_NAME))
            {
                if (parts[pos++] != ConvertString(SerialData.License))
                {
                    return(false);
                }
            }

            if (sType.HasFlag(SerialType.MAC_ADDRESS))
            {
                if (parts[pos++] != ConvertMacAddress(macAddres))
                {
                    return(false);
                }
            }

            if (sType.HasFlag(SerialType.EXPIRATION_DATE))
            {
                if (ConvertFromString(parts[pos++]) < (UInt64)(GlobalInfo.CurrentDate.Year * 365 + GlobalInfo.CurrentDate.Month * 31 + GlobalInfo.CurrentDate.Day))
                {
                    return(false);
                }
            }

            if (sType.HasFlag(SerialType.PEN_DRIVE))
            {
                string letter = USBSerialNumber.GetDriveLetterFromName(SerialData.PenDrive);
                if (letter == string.Empty || parts[pos++] != ConvertSerialNumber(USBSerialNumber.getSerialNumberFromDriveLetter(letter)))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
 private void btnCreate_Click(object sender, EventArgs e)
 {
     for (int t = 0; t < DataGridView1.Rows.Count; t++)
     {
         DateTime   expiration  = DateTime.Today;
         SerialType sType       = (SerialType)DataGridView1.Rows[t].Cells["colLicenseType"].Value;
         string     application = (string)DataGridView1.Rows[t].Cells["colApplication"].Value;
         string     module      = (string)DataGridView1.Rows[t].Cells["colModuleName"].Value;
         if (sType.HasFlag(SerialType.EXPIRATION_DATE))
         {
             expiration = (DateTime)DateTime.Parse(DataGridView1.Rows[t].Cells["colExpiration"].Value.ToString());
         }
         DataGridView1.Rows[t].Cells["colSerial"].Value = SerialManager.CreateSerial(txtLicense.Text, txtMac.Text, application, module, sType, expiration, cbbPenDrive.Text);
     }
 }
Ejemplo n.º 5
0
        private void tsmActivationSave_Click(object sender, EventArgs e)
        {
            SerialManager.Clear();
            SerialManager.SerialData.License  = txtLicense.Text;
            SerialManager.SerialData.PenDrive = cbbPenDrive.Text;

            for (int t = 0; t < DataGridView1.Rows.Count; t++)
            {
                DateTime   expiration  = DateTime.Today;
                bool       enable      = (bool)DataGridView1.Rows[t].Cells["colEnable"].Value;
                SerialType sType       = (SerialType)DataGridView1.Rows[t].Cells["colLicenseType"].Value;
                string     application = (string)DataGridView1.Rows[t].Cells["colApplication"].Value;
                string     module      = (string)DataGridView1.Rows[t].Cells["colModuleName"].Value;
                if (sType.HasFlag(SerialType.EXPIRATION_DATE))
                {
                    expiration = DateTime.Parse(DataGridView1.Rows[t].Cells["colExpiration"].Value.ToString());
                }
                string serial = DataGridView1.Rows[t].Cells["colSerial"].Value.ToString();
                SerialManager.AddModule(application, enable, module, sType, expiration, serial);
            }
            SerialManager.Save();
        }
Ejemplo n.º 6
0
        private void tsmSaveModule_Click(object sender, EventArgs e)
        {
            SaveFileDialog fd = new SaveFileDialog();

            fd.CheckFileExists = true;
            fd.Filter          = "Config|*.config|All|*.*";
            if (fd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(fd.FileName);

            XmlNodeList xModules = xDoc.SelectNodes("modules/module");

            if (!string.IsNullOrEmpty(cbbPenDrive.Text))
            {
                if (xDoc.SelectSingleNode("modules").Attributes["pendrive"] == null)
                {
                    XmlAttribute xAttr = xDoc.CreateAttribute("pendrive");
                    xDoc.SelectSingleNode("modules").Attributes.Append(xAttr);
                }
                xDoc.SelectSingleNode("modules").Attributes["pendrive"].Value = cbbPenDrive.Text;
            }

            foreach (XmlNode xModule in xModules)
            {
                string    moduleCode = xModule.Attributes["code"].Value;
                NameSpace nSpace     = new NameSpace(xModule.Attributes["namespace"].Value);

                string moduleDir = Path.Combine(Path.GetDirectoryName(fd.FileName), nSpace.Folder);
                string menuFile  = Path.Combine(moduleDir, "menu.config");

                if (!File.Exists(menuFile))
                {
                    MessageBox.Show("Missing menu file");
                    return;
                }

                XmlDocument xDocMenu = new XmlDocument();
                xDocMenu.Load(menuFile);

                XmlNodeList xMod = xDocMenu.SelectNodes("menu/module");

                foreach (XmlNode xSignleMod in xMod)
                {
                    if (xSignleMod.Attributes["enable"] == null)
                    {
                        XmlAttribute xAttr = xDocMenu.CreateAttribute("enable");
                        xSignleMod.Attributes.Append(xAttr);
                    }
                    xSignleMod.Attributes["enable"].Value = GetValue(moduleCode, xSignleMod.Attributes["code"].Value, "colenable");

                    if (xSignleMod.Attributes["serialtype"] == null)
                    {
                        XmlAttribute xAttr = xDocMenu.CreateAttribute("serialtype");
                        xSignleMod.Attributes.Append(xAttr);
                    }
                    xSignleMod.Attributes["serialtype"].Value = GetValue(moduleCode, xSignleMod.Attributes["code"].Value, "colLicenseType");

                    SerialType sType = (SerialType)Enum.Parse(typeof(SerialType), xSignleMod.Attributes["serialtype"].Value);

                    if (sType.HasFlag(SerialType.EXPIRATION_DATE))
                    {
                        if (xSignleMod.Attributes["expirationdate"] == null)
                        {
                            XmlAttribute xAttrDate = xDocMenu.CreateAttribute("expirationdate");
                            xSignleMod.Attributes.Append(xAttrDate);
                        }
                        xSignleMod.Attributes["expirationdate"].Value = GetValue(moduleCode, xSignleMod.Attributes["code"].Value, "colExpiration");
                    }
                }
                xDocMenu.Save(menuFile);
            }

            xDoc.Save(fd.FileName);
        }