Пример #1
0
        public void getLockcode()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;

            _machineLockCode = GetMachineLockCode();
            String appname = Encrypt(_appname, _keyBytes);

            _licFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                                        "\\Autodesk\\", MakeValidFileName(appname));

            //read and find if license type is online or offline.
            int returnVal = isOfflineLic();

            LockCode lockDlg = new LockCode();

            //add  time, so that string looks different each time
            String timenow = DateTime.Now.ToString(_timeFormat, CultureInfo.InvariantCulture);

            if (returnVal == ONLINE) //online
            {
                lockDlg.codeTxt.Text = Encrypt(_licVersion.ToString() + STR_SEP +
                                               timenow + STR_SEP +
                                               _machineLockCode + STR_SEP +
                                               _appname + STR_SEP +
                                               STR_ONLINE, _LicBytes);
            }
            else
            {
                lockDlg.codeTxt.Text = Encrypt(_licVersion.ToString() + STR_SEP +
                                               timenow + STR_SEP +
                                               _machineLockCode + STR_SEP +
                                               _appname + STR_SEP +
                                               STR_OFFLINE, _LicBytes);
            }

            lockDlg.bUpdateLic = false;

            //show the dialog
            Application.ShowModalDialog(lockDlg);
        }
Пример #2
0
        public void updatelicense() // This method can have any name
        {
            //we will have

            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;

            LockCode lockDlg = new LockCode();

            lockDlg.codeTxt.Text = "";
            lockDlg.bUpdateLic   = true;
            System.Windows.Forms.DialogResult results = Application.ShowModalDialog(lockDlg);

            if (results != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }


            _machineLockCode = GetMachineLockCode();
            String appname = Encrypt(_appname, _keyBytes);

            _licFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                                        "\\Autodesk\\", MakeValidFileName(appname));

            //Decrypt using lic bytes...
            String license = Decrypt(lockDlg.codeTxt.Text, _LicBytes);

            String[] stringSeparators = new String[] { STR_SEP };
            String[] result           = license.Split(stringSeparators, StringSplitOptions.None);

            if (result.Length != 5)
            {
                return;
            }

            //version
            String version = result[0];

            //app name
            String name = result[1];

            //machine code
            String macCode = result[2];

            //expire date
            String strDays = result[3];

            //type of Lic
            String licType = result[4];

            //check machine is same
            if (!macCode.Equals(_machineLockCode))
            {
                ed.WriteMessage("error, not the same machine");
                return;
            }

            //check if the app name is same
            if (!name.Equals(_appname))
            {
                ed.WriteMessage("error, not the same app");
                return;
            }


            //update the license
            String sLastRunTimeStamp = DateTime.Now.ToString(_timeFormat, CultureInfo.InvariantCulture);
            String onLineTimeStamp   = DateTime.Now.ToString(_timeFormat, CultureInfo.InvariantCulture);

            DateTime dbExpireDate = DateTime.Now;

            if (licType.Equals(STR_ONLINE))
            {
                String sExpiryTimeStamp = DateTime.Now.AddDays(_days).ToString(_timeFormat, CultureInfo.InvariantCulture);
                Write2LicFile(_licFilePath, _appID, _machineLockCode, sExpiryTimeStamp, sLastRunTimeStamp, sLastRunTimeStamp, STR_ONLINE);
            }
            else
            {
                Write2LicFile(_licFilePath, _appID, _machineLockCode, strDays, sLastRunTimeStamp, sLastRunTimeStamp, STR_OFFLINE);
            }
        }