Esempio n. 1
0
        public override string ToString()
        {
            string toReturn = base.ToString();

            toReturn = toReturn + " " + LicenceKey.ToString() + " " + SizeInMB.ToString();
            return(toReturn);
        }
Esempio n. 2
0
        public long GenerateLicence()
        {
            var licenceKey = new LicenceKey();

            _dataAccess.ExecuteNonQuery($"INSERT INTO licences(licenceKey) VALUES('{licenceKey.Key}');");
            ActualiseCache();
            return(_localCache.Where(x => x.Key == licenceKey.Key).Select(x => x.Id).SingleOrDefault());
        }
Esempio n. 3
0
        public int GetVersionFromLicenceKey()
        {
            int        version = 0;
            LicenceKey license = new LicenceKey();

            license = ReadLicenceKey(license, @"C:\ProgramData\SystemAndersson\AnderssonProduktion\", "LicenceKey.xml");

            if (license.Key != Guid.Empty)
            {
                Guid ProgGuid = license.Key;
                switch (ProgGuid.ToString())
                {
                case "330cea46-b763-437f-9760-6c93a17a5a19":     //20
                {
                    version = 1;
                    break;
                }

                case "f96f6d17-f572-40e0-82a0-e7e35300f359":     //40
                {
                    version = 2;
                    break;
                }

                case "bdfd5f09-5de7-440e-a7f8-faaf4606550b":     //60
                {
                    version = 3;
                    break;
                }

                case "cb391dec-5579-4e7c-9853-f2f595490dc0":    //60i
                {
                    version = 3;
                    break;
                }

                case "e324962c-ae9c-4bdd-9651-e204dd9540ca":    //20i
                {
                    version = 1;
                    break;
                }

                case "c7b501bb-2966-4550-a7b1-9e1d61f39e46":    //40i
                {
                    version = 2;
                    break;
                }
                }
            }
            return(version);
        }
Esempio n. 4
0
        private void AddUserForm_Load(object sender, EventArgs e)
        {
            if (!isAdd)
            {
                tbCompany.Text             = user.Company;
                tbDeviceName.Text          = user.Name;
                tbInformation.Text         = user.Information;
                tbUserName.Text            = user.UserName;
                cbTypeDevice.SelectedIndex = user.TypePC;
                mtbPhone.Text = user.Phone;

                LicenceKey key = db.LicenceKeys.Where(x => x.Active == true && x.UserId == user.UserId).FirstOrDefault();
                mtbLicenceKey.Text = key.Key;
            }
        }
        public IDictionary <string, object> GetContextClaims(string aspectName)
        {
            try
            {
                string key = WebRequestContext.Localization.GetConfigValue("51degrees.licenseKey");
                if (!string.IsNullOrEmpty(key))
                {
                    Log.Info("Found 51 Degrees licence key.");

                    // add key to dynamic licences so the update thread can handle updating
                    LicenceKey.AddKey(key);
                    if (PerformUpdateRequest(key))
                    {
                        Log.Info("51 Degrees DataSet is out of date so requesting latest one with supplied licence key.");
                        HttpContext.Current.Items[key.GetHashCode()] = true;
                        ThreadPool.QueueUserWorkItem(_ =>
                        {
                            LicenceKey.Activate(key);
                        });
                    }
                }
                else
                {
                    // no big deal if no license key
                    Log.Warn("51degrees.licenseKey key has not been populated.");
                }
            }
            catch (Exception ex)
            {
                Log.Error("An error occured when attempted to access the 51degrees.licenseKey configuration setting.", ex);
                if (WebProvider.ActiveProvider != null)
                {
                    Log.Info(string.Format("Current 51 Degrees DataSet name: '{0}'", WebProvider.ActiveProvider.DataSet.Name));
                }
            }

            // grab all the properties from the data set and map to context claims
            Dictionary <string, object> claims = new Dictionary <string, object>();

            foreach (IAspectMap x in _properties)
            {
                object v = x.Value;
                Log.Debug(string.Format("Context claim property {0}.{1} = {2}", x.Aspect, x.Name, v != null ? v.ToString() : "<NULL>"));
                claims.Add(string.Format("{0}.{1}", x.Aspect, x.Name), v);
            }

            return(claims);
        }
Esempio n. 6
0
 public static LicenceKey ReadLicenceKey(LicenceKey settings, string path, string filename)
 {
     //string filename = "StartUpSettings.xml";
     try
     {
         XmlSerializer x      = new XmlSerializer(typeof(LicenceKey));
         StreamReader  reader = new StreamReader(path + filename);
         settings = (LicenceKey)x.Deserialize(reader);
         reader.Dispose();
         return(settings);
     }
     catch
     {
         return(settings);
     }
 }
Esempio n. 7
0
        private void ActualiseCache()
        {
            _localCache.Clear();
            var reader = _dataAccess.ExecuteReader("SELECT id, licenceKey, isUsed FROM licences;");

            if (reader.HasRows)
            {
                reader.Read();
                var licenceKey = new LicenceKey(reader.GetInt64(0), reader.GetString(1), reader.GetBoolean(2));
                if (!_localCache.Contains(licenceKey))
                {
                    _localCache.Add(licenceKey);
                }
                while (reader.Read())
                {
                    licenceKey = new LicenceKey(reader.GetInt64(0), reader.GetString(1), reader.GetBoolean(2));
                    if (!_localCache.Contains(licenceKey))
                    {
                        _localCache.Add(licenceKey);
                    }
                }
            }
            reader.Close();
        }
Esempio n. 8
0
        private async void StartButton_Click(Object sender, EventArgs e)
        {
            async Task invalidMessage(String message)
            {
                String text = StartButton.Text;

                StartButton.BackColor          = Color.LightPink;
                StartButton.ForeColor          = Color.Black;
                StartButton.Font               = new Font(StartButton.Font, FontStyle.Bold);
                StartButton.Text               = message;
                StartButton.Enabled            = false;
                LanguageImagedComboBox.Enabled = false;
                await Task.Delay(1500).ConfigureAwait(true);

                StartButton.BackColor          = DefaultBackColor;
                StartButton.ForeColor          = DefaultForeColor;
                StartButton.Font               = new Font(StartButton.Font, FontStyle.Regular);
                StartButton.Text               = text;
                StartButton.Enabled            = true;
                LanguageImagedComboBox.Enabled = true;
            }

            if (LicenceID.Text.Length == 0)
            {
                LicenceID.Focus();
                await invalidMessage(localization.IDLabel).ConfigureAwait(true);

                return;
            }
            if (!LicenceKey.MaskFull)
            {
                LicenceKey.Focus();
                String key       = new Regex("[^0-9A-Z- ']").Replace(LicenceKey.Text, String.Empty).TrimEnd(' ', '-');
                Int32  selStart  = key.TakeWhile(c => c == ' ' || c == '-').Count();
                Int32  keyLength = key.Length - selStart;
                LicenceKey.SelectionStart  = selStart;
                LicenceKey.SelectionLength = keyLength;
                await invalidMessage(localization.KeyLabel).ConfigureAwait(true);

                return;
            }


            Licence licence = new Licence(LicenceID.Text, LicenceKey.Text);

            if (!licence.IsValid())
            {
                LicenceID.Focus();
                await invalidMessage(localization.InvalidKeyID).ConfigureAwait(true);

                return;
            }
            String languageCode = CountryData.EnglishNameByIso2.FirstOrDefault(x => x.Value == LanguageImagedComboBox.Text).Key.ToLower();

            if (!NotSaveSettingsCheckBox.Checked)
            {
                Registry.Registry.SetRegistry(new RegistrySettings(LicenceID.Text, LicenceKey.Text, languageCode, ScreenImagedComboBox.SelectedIndex,
                                                                   IsDisguiseRuler.Checked, NotSaveSettingsCheckBox.Checked, NotDisplayAnymoreCheckBox.Checked));
            }
            else
            {
                Registry.Registry.RemoveRegistry();
            }

            try
            {
                Hide();
                MainForm ruler = new MainForm(licence, Monitors.GetMonitors()[ScreenImagedComboBox.SelectedIndex],
                                              languageCode,
                                              IsDisguiseRuler.Checked);
                ruler.Closed += (s, args) => Close();
                ruler.Show();
                Dispose();
            }
            catch (ObjectDisposedException)
            {
                Close();
                Application.Exit();
            }
            catch (Exception ex)
            {
                throw new Exception(
                          $"{localization.OccurredError}\n" +
                          $"{ex.Source}\n" +
                          $"{ex.Message}\n" +
                          $"{ex.HResult}\n" +
                          $"{ex.StackTrace}");
            }
        }
Esempio n. 9
0
        private bool SaveChange()
        {
            if (tbDeviceName.TextLength == 0)
            {
                MessageBox.Show("Введите название устройства (для оботражения)");
                return(false);
            }
            if (cbTypeDevice.Text == "")
            {
                MessageBox.Show("Виберете тип устройства!");
                return(false);
            }
            if (mtbLicenceKey.Text.Contains(' ') && MessageBox.Show("Для пользователя не сгенерирован ключ активации, сохранить без ключа?", "", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return(false);
            }

            user.Name     = tbDeviceName.Text;
            user.UserName = tbUserName.Text;
            user.DateReg  = DateTime.Now;
            if (parentGroup != null)
            {
                if (parentGroup.Tag != null)
                {
                    user.Group = db.UserGroups.Where(x => x.UsersGroupId == ((UsersGroup)parentGroup.Tag).UsersGroupId).First();
                }
            }
            user.Information = tbInformation.Text;
            user.TypePC      = cbTypeDevice.SelectedIndex;
            user.Phone       = mtbPhone.Text;
            user.Company     = tbCompany.Text;

            if (isAdd)
            {
                db.Users.Add(user);
                db.SaveChanges();
                isAdd = false;
            }
            else
            {
                if (user != null)
                {
                    db.Users.Attach(user);
                    db.Entry(db.Users.Find(user.UserId)).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    MessageBox.Show("Ошибка редактирования пользователя!");
                    return(false);
                }
            }

            if (!mtbLicenceKey.Text.Contains(' '))
            {
                LicenceKey licenseKey = new LicenceKey()
                {
                    Active     = true,
                    DateExp    = dtpDateTo.Value,
                    Key        = mtbLicenceKey.Text,
                    User       = user,
                    DateCreate = DateTime.Now,
                    UnicId     = null
                };
                db.LicenceKeys.Add(licenseKey);
                db.SaveChanges();
                lbNoSave.Visible = false;
                btApply.Enabled  = false;
            }
            //else
            //    MessageBox.Show("Ошибка редактирования ключа!");
            return(true);
        }