예제 #1
0
        private void buttonDecrypt_Click(object sender, EventArgs e)
        {
            textBoxResult.Text = "";
            byte[] myData = System.Text.Encoding.Unicode.GetBytes(textBoxSourceText.Text);
            Variables.myStatus = Variables.myHasp.Decrypt(myData);

            if (Variables.myStatus == HaspStatus.StatusOk)
            {
                textBoxResult.Text = System.Text.Encoding.Unicode.GetString(myData);
            }
            else
            {
                textBoxResult.Text = MultiLanguage.ErrorMessageReplacer(language.Key, "Error: ") + Variables.myStatus.ToString();
            }
        }
예제 #2
0
        public FormSettings()
        {
            InitializeComponent();
            ;
            foreach (var el in FormMain.alpPackSourceXdocument.Root.Elements("AvailableLanguages"))
            {
                foreach (var el2 in el.Elements("language"))
                {
                    comboBoxSelectLanguage.Items.Add(el2.Value);
                }
            }

            foreach (var el3 in Variables.vendorCode)
            {
                comboBoxBatchCode.Items.Add(el3.Key.Key);
            }

            comboBoxBatchCode.SelectedIndex = comboBoxBatchCode.FindString(Properties.Settings.Default.CurrentBatchCode);

            toolTipTextBoxAddNewBatchCode.SetToolTip(textBoxAddNewBatchCode, MultiLanguage.ErrorMessageReplacer(FormMain.language.Key, "Format for input: ") + Variables.formatForInputToolTip);
        }
예제 #3
0
        public FormMain()
        {
            InitializeComponent();

            alp = new MultiLanguage(System.IO.File.Exists(Variables.baseDir + "\\AllLanguageInOnePack.alp") ? Variables.baseDir + "\\AllLanguageInOnePack.alp" : "");
            alpPackSourceXdocument = alp.LoadAlp(System.IO.File.Exists(Variables.baseDir + "\\AllLanguageInOnePack.alp") ? Variables.baseDir + "\\AllLanguageInOnePack.alp" : "");

            language = MultiLanguage.ResetLanguage(alpPackSourceXdocument);

            if (Properties.Settings.Default.BatchCodes != null && !String.IsNullOrEmpty(Properties.Settings.Default.BatchCodes.ToString()))
            {
                foreach (var el in Properties.Settings.Default.BatchCodes.Root.Elements("vendor"))
                {
                    if (el.Descendants().FirstOrDefault(p => p.Name == "batchCode").Value == "DEMOMA")
                    {
                        break;
                    }

                    Variables.vendorCode.Add(new KeyValuePair <string, string>(el.Descendants().FirstOrDefault(p => p.Name == "batchCode").Value, el.Descendants().FirstOrDefault(p => p.Name == "vendorId").Value), el.Descendants().FirstOrDefault(p => p.Name == "vendorCode").Value);
                }
            }

            SettingsWindow = new FormSettings();
        }
예제 #4
0
        private void buttonAddNewBatchCode_Click(object sender, EventArgs e)
        {
            if (Regex.IsMatch(textBoxAddNewBatchCode.Text, Variables.regExForValidatingNewBatchCode))
            {
                var    tmpBatchCodeData = textBoxAddNewBatchCode.Text.Split("-:".ToCharArray(), 3);
                string tmpBatchCode     = tmpBatchCodeData[0];
                string tmpVendorId      = tmpBatchCodeData[1];
                string tmpVendorCode    = tmpBatchCodeData[2];

                if (tmpBatchCode != "" && tmpVendorId != "" && tmpVendorCode != "" && Variables.vendorCode.ContainsKey(new KeyValuePair <string, string>(tmpBatchCode, tmpVendorId)) == false)
                {
                    Variables.vendorCode.Add(new KeyValuePair <string, string>(tmpBatchCode, tmpVendorId), tmpVendorCode);
                }

                comboBoxBatchCode.Items.Add(tmpBatchCode);

                var tmpXElement = new XElement("vendor");
                tmpXElement.Add(new XElement("batchCode", tmpBatchCode));
                tmpXElement.Add(new XElement("vendorId", tmpVendorId));
                tmpXElement.Add(new XElement("vendorCode", tmpVendorCode));
                Properties.Settings.Default.BatchCodes.Root.Add(tmpXElement);
                Properties.Settings.Default.Save();

                textBoxAddNewBatchCode.Text = "";
            }
            else
            {
                MessageBox.Show(MultiLanguage.ErrorMessageReplacer(FormMain.language.Key, @"Incorrect new Batch code! Maybe incorrect format of input string. Please check your data, you should using this format: ") + Variables.formatForInputToolTip + "(Regex: " + Variables.regExForValidatingNewBatchCode + ")", MultiLanguage.ErrorMessageReplacer(FormMain.language.Key, "Incorrect Vendor Data!"));
            }
        }
예제 #5
0
        private void buttonLoginLogout_Click(object sender, EventArgs e)
        {
            if (Variables.myStatus != HaspStatus.StatusOk)
            {
                if (Variables.connectToSpecifyKeyId == true && !String.IsNullOrEmpty(Variables.specifyKeyId))
                {
                    Variables.myStatus = Variables.myHasp.Login(Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()], Variables.scopeForSpecificKeyId.Replace("{KEY_ID}", Variables.specifyKeyId));
                }
                else
                {
                    Variables.myStatus = Variables.myHasp.Login(Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()], Variables.scopeForLocal);

                    if (Variables.myStatus != HaspStatus.StatusOk)
                    {
                        Variables.myStatus = Variables.myHasp.Login(Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()]);
                    }
                }

                if (Variables.myStatus == HaspStatus.StatusOk)
                {
                    buttonLoginLogout.Text = MultiLanguage.ErrorMessageReplacer(language.Key, "Logout");
                    keyInfo                   = XDocument.Parse(MyGlobalMethods.GetSessionInfo("<haspformat format=\"keyinfo\"/>"));
                    productInfo               = XDocument.Parse(MyGlobalMethods.GetSessionInfo(Variables.formatForGetProductId));
                    featureInfo               = XDocument.Parse(MyGlobalMethods.GetSessionInfo(Variables.formatForGetFeatureId));
                    parentKeyId               = keyInfo.Descendants().FirstOrDefault(p => p.Name.LocalName == "haspid").Value;
                    productId                 = productInfo.Descendants().FirstOrDefault(p => p.Name.LocalName == "id").Value;
                    productName               = productInfo.Descendants().FirstOrDefault(p => p.Name.LocalName == "name").Value;
                    featureId                 = featureInfo.Descendants().FirstOrDefault(f => f.Name.LocalName == "id").Value;
                    featureName               = featureInfo.Descendants().FirstOrDefault(f => f.Name.LocalName == "name").Value;
                    linkLabelKeyInfo.Text     = parentKeyId;
                    linkLabelLicenseInfo.Text = productName + " -> " + featureName + " (FID: " + featureId + ")";
                    labelLoginStatusCode.Text = Variables.myStatus.ToString();

                    if (keyInfo.Descendants().Where(p => p.Name.LocalName == "address").Count() > 0)
                    {
                        labelNumberOfDaysForDetach.Enabled = true;
                        numericUpDownDaysForDetach.Enabled = true;
                        buttonDetach.Enabled       = true;
                        buttonCancelDetach.Enabled = false;
                    }
                    else
                    {
                        labelNumberOfDaysForDetach.Enabled = false;
                        numericUpDownDaysForDetach.Enabled = false;
                        buttonDetach.Enabled       = false;
                        buttonCancelDetach.Enabled = true;
                    }

                    labelIntro.Text                      = MultiLanguage.ErrorMessageReplacer(language.Key, "Login successfully!");
                    labelIntro.ForeColor                 = Color.Green;
                    pictureBoxLike.Visible               = true;
                    pictureBoxDislike.Visible            = false;
                    panelMain.Enabled                    = true;
                    labelLoginStatus.Enabled             = true;
                    labelLoginStatusCode.Enabled         = true;
                    labelCurrentLicense.Enabled          = true;
                    linkLabelLicenseInfo.Enabled         = true;
                    labelKeyInfo.Enabled                 = true;
                    linkLabelKeyInfo.Enabled             = true;
                    buttonCheckAvailableLicenses.Enabled = false;
                    sForm.labelLanguage.Enabled          = false;
                    sForm.comboBoxSelectLanguage.Enabled = false;
                    sForm.labelSelectBatchCode.Enabled   = false;
                    sForm.comboBoxBatchCode.Enabled      = false;
                    sForm.labelAddNewBatchCode.Enabled   = false;
                    sForm.textBoxAddNewBatchCode.Enabled = false;
                    sForm.buttonAddNewBatchCode.Enabled  = false;
                    sForm.buttonDeleteBatchCode.Enabled  = false;
                    sForm.labelFeatureIdForUsing.Enabled = false;
                    sForm.numericUpDownFeatureId.Enabled = false;
                }
                else
                {
                    labelLoginStatusCode.Text = Variables.myStatus.ToString();
                    labelIntro.Text           = MultiLanguage.ErrorMessageReplacer(language.Key, "Please login first!");
                    labelIntro.ForeColor      = Color.Black;
                    panelMain.Enabled         = false;
                    pictureBoxLike.Visible    = false;
                    pictureBoxDislike.Visible = true;
                }
            }
            else
            {
                Variables.myStatus                   = Variables.myHasp.Logout();
                Variables.myStatus                   = HaspStatus.AlreadyLoggedOut;
                buttonLoginLogout.Text               = MultiLanguage.ErrorMessageReplacer(language.Key, "Login");
                labelIntro.Text                      = MultiLanguage.ErrorMessageReplacer(language.Key, "Please login first!");
                linkLabelLicenseInfo.Text            = "...";
                linkLabelKeyInfo.Text                = "...";
                labelLoginStatusCode.Text            = "...";
                textBoxSourceText.Text               = "";
                textBoxResult.Text                   = "";
                labelIntro.ForeColor                 = Color.Black;
                panelMain.Enabled                    = false;
                pictureBoxLike.Visible               = false;
                pictureBoxDislike.Visible            = false;
                labelNumberOfDaysForDetach.Enabled   = false;
                numericUpDownDaysForDetach.Value     = 0;
                numericUpDownDaysForDetach.Enabled   = true;
                buttonDetach.Enabled                 = false;
                buttonCancelDetach.Enabled           = false;
                labelLoginStatus.Enabled             = false;
                labelLoginStatusCode.Enabled         = false;
                labelCurrentLicense.Enabled          = false;
                linkLabelLicenseInfo.Enabled         = false;
                labelKeyInfo.Enabled                 = false;
                linkLabelKeyInfo.Enabled             = false;
                buttonCheckAvailableLicenses.Enabled = true;
                sForm.labelLanguage.Enabled          = true;
                sForm.comboBoxSelectLanguage.Enabled = true;
                sForm.labelSelectBatchCode.Enabled   = true;
                sForm.comboBoxBatchCode.Enabled      = true;
                sForm.labelAddNewBatchCode.Enabled   = true;
                sForm.textBoxAddNewBatchCode.Enabled = true;
                sForm.buttonAddNewBatchCode.Enabled  = !String.IsNullOrEmpty(sForm.textBoxAddNewBatchCode.Text) ? true : false;
                sForm.buttonDeleteBatchCode.Enabled  = (sForm.comboBoxBatchCode.SelectedItem.ToString() != "DEMOMA") ? true : false;
                sForm.labelFeatureIdForUsing.Enabled = true;
                sForm.numericUpDownFeatureId.Enabled = true;
            }
        }
예제 #6
0
 private void linkLabelKeyInfo_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     MessageBox.Show(MyGlobalMethods.GetSessionInfo("<haspformat format=\"keyinfo\"/>"), MultiLanguage.ErrorMessageReplacer(language.Key, "Key Info"));
 }
예제 #7
0
        private void buttonCancelDetach_Click(object sender, EventArgs e)
        {
            if (Variables.useUrl)
            {
                string myCancelDetachStatus = MyGlobalMethods.CancelDetachViaUrl(productId);

                if (myCancelDetachStatus == HttpStatusCode.OK.ToString())
                {
                    buttonLoginLogout.PerformClick();

                    MessageBox.Show(MultiLanguage.ErrorMessageReplacer(language.Key, "Current status of the opperation is: {0} \nPlease, re-login in application, for using CLOUD license.").Replace("{0}", myCancelDetachStatus), MultiLanguage.ErrorMessageReplacer(language.Key, "Successfully Canceled Detaching license!"));
                }
                else
                {
                    //handle error
                    MessageBox.Show(MultiLanguage.ErrorMessageReplacer(language.Key, "Status request: {0} \nSomething goes wrong... Please, try again later!").Replace("{0}", myCancelDetachStatus), MultiLanguage.ErrorMessageReplacer(language.Key, "Cancel Detaching error!"));
                }
            }
            else
            {
                string myCancelDetachStatus = MyGlobalMethods.CancelDetachViaLicensingApi(parentKeyId);

                if (myCancelDetachStatus == HaspStatus.StatusOk.ToString())
                {
                    buttonLoginLogout.PerformClick();

                    MessageBox.Show(MultiLanguage.ErrorMessageReplacer(language.Key, "Current status of the opperation is: {0} \nPlease, re-login in application, for using CLOUD license.").Replace("{0}", myCancelDetachStatus), MultiLanguage.ErrorMessageReplacer(language.Key, "Successfully Canceled Detaching license!"));
                }
                else
                {
                    //handle error
                    MessageBox.Show(myCancelDetachStatus, MultiLanguage.ErrorMessageReplacer(language.Key, "Cancel Detaching error!"));
                }
            }
        }
예제 #8
0
        private void buttonDetach_Click(object sender, EventArgs e)
        {
            var myId = MyGlobalMethods.GetInfo(Variables.scopeForLocal, Variables.formatForGetId);

            string info          = null;
            int    detachingTime = (Convert.ToInt32(numericUpDownDaysForDetach.Value) * 24 * 60 * 60);

            HaspStatus myDetachStatus = Hasp.Transfer(Variables.actionForDetach.Replace("{PRODUCT_ID}", productId).Replace("{NUMBER_OF_SECONDS}", detachingTime.ToString()), Variables.scopeForSpecificKeyId.Replace("{KEY_ID}", parentKeyId), Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()], myId, ref info);

            if (myDetachStatus == HaspStatus.StatusOk)
            {
                // hasp_update
                string     ack            = null;
                HaspStatus myUpdateStatus = Hasp.Update(info, ref ack);

                if (myUpdateStatus == HaspStatus.StatusOk)
                {
                    //handle success
                    var tmpAvaliablesKeys = XDocument.Parse(MyGlobalMethods.GetInfo(Variables.scopeForLocal, Variables.formatForGetAvailableLicenses));
                    foreach (var el in tmpAvaliablesKeys.Root.Elements("hasp"))
                    {
                        foreach (var el2 in el.Elements("feature"))
                        {
                            if (el2.Attribute("id").Value == Variables.myFeature.FeatureId.ToString())
                            {
                                childKeyId = el.Attribute("id").Value;
                                break;
                            }
                        }

                        if (String.IsNullOrEmpty(childKeyId))
                        {
                            break;
                        }
                    }

                    MessageBox.Show(MultiLanguage.ErrorMessageReplacer(language.Key, "Current status of the opperation is: {0} \nPlease, re-login in application, for using LOCALLY license.").Replace("{0}", myUpdateStatus.ToString()), MultiLanguage.ErrorMessageReplacer(language.Key, "Successfully Detached!"));
                }
                else
                {
                    //handle error
                    MessageBox.Show(myUpdateStatus.ToString(), MultiLanguage.ErrorMessageReplacer(language.Key, "Detaching apply update error!"));
                }
            }
            else
            {
                if (myDetachStatus == HaspStatus.InvalidDuration)
                {
                    try
                    {
                        var tmpAvaliablesKeys = XDocument.Parse(MyGlobalMethods.GetInfo(Variables.scopeForLocal, Variables.formatForGetAvailableLicenses));
                        foreach (var el in tmpAvaliablesKeys.Root.Elements("hasp"))
                        {
                            foreach (var el2 in el.Elements("feature"))
                            {
                                if (el2.Attribute("id").Value == Variables.myFeature.FeatureId.ToString())
                                {
                                    childKeyId = el.Attribute("id").Value;
                                    break;
                                }
                            }

                            if (String.IsNullOrEmpty(childKeyId))
                            {
                                break;
                            }
                        }

                        string myCancelDetachStatus = Variables.useUrl ? MyGlobalMethods.CancelDetachViaUrl(productId, childKeyId) : MyGlobalMethods.CancelDetachViaLicensingApi(childKeyId);

                        if (myCancelDetachStatus == HttpStatusCode.OK.ToString() || myCancelDetachStatus == HaspStatus.StatusOk.ToString())
                        {
                            myDetachStatus = Hasp.Transfer(Variables.actionForDetach.Replace("{PRODUCT_ID}", productId).Replace("{NUMBER_OF_SECONDS}", detachingTime.ToString()), Variables.scopeForSpecificKeyId.Replace("{KEY_ID}", parentKeyId), Variables.vendorCode[Variables.vendorCode.Keys.Where(k => k.Key == Variables.currentBatchCode).FirstOrDefault()], myId, ref info);

                            if (myDetachStatus == HaspStatus.StatusOk)
                            {
                                // hasp_update
                                string     ack            = null;
                                HaspStatus myUpdateStatus = Hasp.Update(info, ref ack);

                                if (myUpdateStatus == HaspStatus.StatusOk)
                                {
                                    //handle success
                                    MessageBox.Show(MultiLanguage.ErrorMessageReplacer(language.Key, "Current status of the opperation is: {0} \nPlease, re-login in application, for using LOCALLY license.").Replace("{0}", myUpdateStatus.ToString()), MultiLanguage.ErrorMessageReplacer(language.Key, "Successfully Detached!"));
                                }
                                else
                                {
                                    //handle error
                                    MessageBox.Show(myUpdateStatus.ToString(), MultiLanguage.ErrorMessageReplacer(language.Key, "Detaching apply update error!"));
                                }
                            }
                            else
                            {
                                //handle error
                                MessageBox.Show(myDetachStatus.ToString(), MultiLanguage.ErrorMessageReplacer(language.Key, "Re-Detaching error!"));
                            }
                        }
                        else
                        {
                            //handle error
                            MessageBox.Show(MultiLanguage.ErrorMessageReplacer(language.Key, "Status request: {0} \nSomething goes wrong... Please, try again later!").Replace("{0}", myCancelDetachStatus), MultiLanguage.ErrorMessageReplacer(language.Key, "Cancel Detaching error (In Re-Detach)!"));
                        }
                    }
                    catch
                    {
                        // do nothing...
                        MessageBox.Show(myDetachStatus.ToString(), MultiLanguage.ErrorMessageReplacer(language.Key, "Detaching error!"));
                    }
                }
                else
                {
                    //handle error
                    MessageBox.Show(myDetachStatus.ToString(), MultiLanguage.ErrorMessageReplacer(language.Key, "Detaching error!"));
                }
            }
        }