Ejemplo n.º 1
0
        //============================================================================*
        // OnGetKeyClicked()
        //============================================================================*

        protected void OnGetKeyClicked(Object sender, EventArgs e)
        {
            bool fValidKey = true;

            string strName  = NameTextBox.Value.Trim();
            string strEmail = EmailTextBox.Value.Trim();

            string strKey = cRWRegistry.CreateKey(strName, strEmail, VersionTextBox.Value);

            if (string.IsNullOrEmpty(strKey))
            {
                KeyLabel.Text = "Invalid Parms!";
            }
            else
            {
                KeyLabel.Text = strKey;

                if (cRWRegistry.ValidateKey(strKey, NameTextBox.Value, EmailTextBox.Value, VersionTextBox.Value))
                {
                    ValidatedLabel.Text = " (Validated)";
                }
                else
                {
                    ValidatedLabel.Text = " (NOT VALID!!)";

                    fValidKey = false;
                }
            }

            if (fValidKey)
            {
                cRWLicenseCommands RWLicenseCommands = new cRWLicenseCommands();

                m_RWLicenseList = null;

                cKeyCommand.eErrorCodes eErrorCode = RWLicenseCommands.GetLicenseList(NameTextBox.Value, EmailTextBox.Value, strKey, out m_RWLicenseList);

                if (eErrorCode == cKeyCommand.eErrorCodes.None)
                {
                    LicenseCountLabel.Text = String.Format("{0:G0} current licenses", m_RWLicenseList.Count);

                    if (m_RWLicenseList.Count > 0)
                    {
                        AdditionalLicenseCheckBox.Checked = true;
                    }

                    m_fGetKey = true;
                }
                else
                {
                    LicenseCountLabel.Text = String.Format("Error {0} encountered during GetLicenseList() operation.", cKeyCommand.ErrorString(eErrorCode));
                }
            }

            UpdateButtons();
        }
Ejemplo n.º 2
0
        //============================================================================*
        // OnAddClicked()
        //============================================================================*

        protected void OnAddClicked(Object sender, EventArgs e)
        {
            cRWLicenseCommands RWLicenseCommands = new cRWLicenseCommands();

            string strKey = KeyLabel.Text;

            cKeyCommand.eErrorCodes eErrorCode = RWLicenseCommands.AddLicense(NameTextBox.Value, EmailTextBox.Value, strKey);

            if (eErrorCode == cKeyCommand.eErrorCodes.None)
            {
                LicenseCountLabel.Text = "License Added Successfully!";

                m_fAddKey = true;

                m_RWLicenseList = null;

                eErrorCode = RWLicenseCommands.GetLicenseList(NameTextBox.Value, EmailTextBox.Value, strKey, out m_RWLicenseList);

                if (eErrorCode == cKeyCommand.eErrorCodes.None)
                {
                    LicenseCountLabel.Text = String.Format("{0:G0} current licenses", m_RWLicenseList.Count);

                    AdditionalLicenseCheckBox.Checked = m_RWLicenseList.Count > 1;
                }
                else
                {
                    LicenseCountLabel.Text = String.Format("Error {0} encountered during GetLicenseList() operation.", cKeyCommand.ErrorString(eErrorCode));
                }
            }
            else
            {
                LicenseCountLabel.Text = String.Format("Error {0} Adding License!", eErrorCode);
            }

            if (m_RWLicenseList.Count > 1)
            {
                AdditionalLicenseCheckBox.Checked = true;
            }

            UpdateButtons();
        }
Ejemplo n.º 3
0
        //============================================================================*
        // GetLicenseList()
        //============================================================================*

        public cKeyCommand.eErrorCodes GetLicenseList(string strName, string strEmail, string strKey, out cRWLicenseList RWLicenseList)
        {
            RWLicenseList = new cRWLicenseList();

            string strCommand = sm_strURL + String.Format("?Command=GetLicenses&Name={0}&Email={1}&Key={2}", strName, strEmail, strKey);

            string strResponse = "GetLicenses:";

            //----------------------------------------------------------------------------*
            // Initialize the Request
            //----------------------------------------------------------------------------*

            WebRequest Request = WebRequest.Create(strCommand);

            HttpWebResponse Response  = null;
            Stream          KeyStream = null;
            StreamReader    KeyReader = null;

            cKeyCommand.eErrorCodes eErrorCode = cKeyCommand.eErrorCodes.None;

            try
            {
                //----------------------------------------------------------------------------*
                // Send the request
                //----------------------------------------------------------------------------*

                Response = (HttpWebResponse)Request.GetResponse();

                //----------------------------------------------------------------------------*
                // Get the response
                //----------------------------------------------------------------------------*

                KeyStream = Response.GetResponseStream();

                KeyReader = new StreamReader(KeyStream);

                //----------------------------------------------------------------------------*
                // Check each line of the response for the command string
                //----------------------------------------------------------------------------*

                bool fResponseFound = false;

                while (!fResponseFound && !KeyReader.EndOfStream)
                {
                    string strLine = KeyReader.ReadLine();

                    //----------------------------------------------------------------------------*
                    // If response is found, record the error code
                    //----------------------------------------------------------------------------*

                    if (strLine.Length > strResponse.Length && strLine.Substring(0, strResponse.Length) == strResponse)
                    {
                        fResponseFound = true;

                        int nError = 0;

                        int.TryParse(strLine.Substring(strResponse.Length + 1), out nError);

                        eErrorCode = (cKeyCommand.eErrorCodes)nError;

                        break;
                    }
                }

                if (!fResponseFound)
                {
                    eErrorCode = cKeyCommand.eErrorCodes.InvalidResponse;
                }

                //----------------------------------------------------------------------------*
                // Get the list of licenses
                //----------------------------------------------------------------------------*

                if (eErrorCode == cKeyCommand.eErrorCodes.None)
                {
                    cRWLicense RWLicense = null;

                    while (!KeyReader.EndOfStream)
                    {
                        string strLine = KeyReader.ReadLine();

                        //----------------------------------------------------------------------------*
                        // If a license start is found, create a new license
                        //----------------------------------------------------------------------------*

                        if (strLine.Length > "License:".Length && strLine.Substring(0, "License:".Length) == "License:")
                        {
                            if (RWLicense != null)
                            {
                                RWLicenseList.Add(RWLicense);
                            }

                            RWLicense = new cRWLicense();

                            continue;
                        }

                        //----------------------------------------------------------------------------*
                        // If a license name is found, add it to the current license
                        //----------------------------------------------------------------------------*

                        if (strLine.Length > "Name:".Length && strLine.Substring(0, "Name:".Length) == "Name:")
                        {
                            if (RWLicense != null)
                            {
                                RWLicense.Name = strLine.Substring("Name:".Length + 1, strLine.IndexOf("<br />") - "Name:".Length - 1);
                            }

                            continue;
                        }

                        //----------------------------------------------------------------------------*
                        // If a license email is found, add it to the current license
                        //----------------------------------------------------------------------------*

                        if (strLine.Length > "Email:".Length && strLine.Substring(0, "Email:".Length) == "Email:")
                        {
                            if (RWLicense != null)
                            {
                                RWLicense.Email = strLine.Substring("Email:".Length + 1, strLine.IndexOf("<br />") - "Email:".Length - 1);
                            }

                            continue;
                        }

                        //----------------------------------------------------------------------------*
                        // If a license key is found, add it to the current license
                        //----------------------------------------------------------------------------*

                        if (strLine.Length > "Key:".Length && strLine.Substring(0, "Key:".Length) == "Key:")
                        {
                            if (RWLicense != null)
                            {
                                RWLicense.Key = strLine.Substring("Key:".Length + 1, strLine.IndexOf("<br />") - "Key:".Length - 1);
                            }

                            continue;
                        }

                        //----------------------------------------------------------------------------*
                        // If a license computer name is found, add it to the current license
                        //----------------------------------------------------------------------------*

                        if (strLine.Length > "Computer Name:".Length && strLine.Substring(0, "Computer Name:".Length) == "Computer Name:")
                        {
                            if (RWLicense != null)
                            {
                                RWLicense.ComputerName = strLine.Substring("Computer Name:".Length + 1, strLine.IndexOf("<br />") - "Computer Name:".Length - 1);
                            }

                            continue;
                        }

                        //----------------------------------------------------------------------------*
                        // If a license NIC is found, add it to the current license
                        //----------------------------------------------------------------------------*

                        if (strLine.Length > "NIC:".Length && strLine.Substring(0, "NIC:".Length) == "NIC:")
                        {
                            if (RWLicense != null)
                            {
                                RWLicense.NIC = strLine.Substring("NIC:".Length + 1, strLine.IndexOf("<br />") - "NIC:".Length - 1);
                            }

                            continue;
                        }
                    }

                    if (RWLicense != null)
                    {
                        RWLicenseList.Add(RWLicense);
                    }
                }
            }

            //----------------------------------------------------------------------------*
            // If there's an error sending or receiving, just continue
            //----------------------------------------------------------------------------*

            catch
            {
            }

            //----------------------------------------------------------------------------*
            // Clean up and exit
            //----------------------------------------------------------------------------*

            finally
            {
/*				if (KeyReader != null)
 *                                      KeyReader.Close();
 *
 *                              if (KeyStream != null)
 *                                      KeyStream.Close();
 *
 *                              if (Response != null)
 *                                      Response.Close();
 */         }

            return(eErrorCode);
        }