Example #1
0
        public static void checkLicenseFile()
        {
            System.Resources.ResourceManager rm = null;
            rm = new System.Resources.ResourceManager("QuestionannaireApp.Localization", Assembly.GetExecutingAssembly());
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Properties.Settings.Default.culture);

            using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
            {
                try
                {
                    using (IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream("license.lic", System.IO.FileMode.Open, isolatedStorageFile))
                    {
                        using (System.IO.StreamReader sr = new System.IO.StreamReader(isolatedStorageFileStream))
                        {
                            var activated = LicenseCheck.isActivated(sr.ReadLine());
                            if (!activated)
                            {
                                MessageBox.Show(rm.GetString("activationExpired"), rm.GetString("activation"), MessageBoxButtons.OK);
                                Properties.Settings.Default.block = true;
                            }
                            else
                            {
                                Properties.Settings.Default.block = false;
                            }
                        }
                    }
                }

                catch
                {
                    if (CheckForInternetConnection() == true && !isolatedStorageFile.FileExists("license.lic"))
                    {
                        License license = new License();
                        license.ShowDialog();
                    }
                    else if (CheckForInternetConnection() == false && !isolatedStorageFile.FileExists("license.lic"))
                    {
                        Properties.Settings.Default.block = true;
                    }
                    else
                    {
                        Properties.Settings.Default.block = false;
                    }
                }
            }
        }