public void OnActivateCommand_Error() { var service = Substitute.For <ILicenseService>(); var ctx = Substitute.For <IApplicationContext>(); var model = new LicenseViewModel(service, ctx); var exception = new Exception("Exception"); var validation = new[] { new GeneralValidationFailure { Message = "Message", HowToResolve = "HowToResolve" } }; var licenseResult = new LicenseResult(null, exception, validation); service.RegisterAsync(Arg.Any <Guid>()).Returns(licenseResult); service.ValidateAsync(Arg.Any <bool>()).Returns(licenseResult); model.Initialize(); var key = new Guid("ae8cdf5f-26b3-4e2f-8e68-6ecc2e73720f"); model.RegisterKey = key.ToString(); model.ActivateCommand.Execute(null); service.Received().RegisterAsync(key); ctx.DidNotReceive().SetLicenseKeyAsync(Arg.Any <string>()); Assert.Equal(AppLicense.Demo, LicenseGlobals.Get()); Assert.Equal("|Message|HowToResolve|Exception|", model.ErrorMessage.Replace("\r\n", "|")); Assert.True(model.ShowError); Assert.False(model.IsBusy); }
public Task <LicenseResult> GetLicense(string enproductID) { //throw new NotImplementedException(); try { //code to call license server and get the details of product license var result = new LicenseResult() { Status = Domain.Enums.LicenseStatus.Active, ProductID = "", MyKey = "mysamplekeyvalue", ValidTill = DateTime.Now.AddDays(1), Error = "" }; return(Task.FromResult(result)); } catch (Exception ex) { var result = new LicenseResult() { Status = Domain.Enums.LicenseStatus.Unknown, ProductID = "", MyKey = "", ValidTill = DateTime.Now, Error = ex.Message }; return(Task.FromResult(result)); } }
async private void BtnEmailClicked(object sender, EventArgs e) { UpdateUI(true); LicenseService service = new LicenseService(ProgramVars.LicURL); LicenseRequest request = new LicenseRequest() { Method = "Request", ClientID = "", DeviceID = "", languageID = App.appSettings.languageID, ServerID = "", Email = tbEmail.Text }; try { LicenseResult result = await service.ExecuteAsync(request); if (result.statusCode != 0) { throw new Exception(result.status); } tbEmail.Text = ""; UpdateUI(false); licensePanel.IsVisible = true; emailPanel.IsVisible = false; await DisplayAlert(AppResources.Info, AppResources.LicenseRequested, AppResources.OK); } catch (Exception ex) { UpdateUI(false); await DisplayAlert(AppResources.Error, ex.Message, AppResources.OK); } }
private void verifyLicense() { try { LicenseResult lr = KeyGenerator.verifyKey(AssemblyInfo.AssemblyProduct); if (lr == LicenseResult.InvalidPC) { XtraMessageBox.Show("Esta licença está registrada para outro computador!\nContate o Suporte."); Environment.Exit(0); } else if (lr == LicenseResult.InvalidDate) { XtraMessageBox.Show("Esta licença está vencida!\nContate o Suporte."); Environment.Exit(0); } else if (lr == LicenseResult.Empty) { XtraMessageBox.Show("Software não está registrado, por favor contate o suporte!"); Environment.Exit(0); } else if (lr == LicenseResult.Error) { XtraMessageBox.Show("Ocorreu um erro ao verificar a licença do software\nContate o Suporte."); Environment.Exit(0); } } catch (Exception ex) { XtraMessageBox.Show(String.Format("Ocorreu um erro ao verificar a licença do software!" + "\nContate o Suporte.\n{0}\n\n{1}", ex.Message, ex.InnerException)); Environment.Exit(0); } }
public void OnActivateCommand_Ok() { var path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "data", "test.license.xml"); var service = Substitute.For <ILicenseService>(); var ctx = Substitute.For <IApplicationContext>(); var model = new LicenseViewModel(service, ctx); var license = License.Load(File.OpenRead(path)); var licenseResult = new LicenseResult(license, null, null); service.RegisterAsync(Arg.Any <Guid>()).Returns(licenseResult); service.ValidateAsync(Arg.Any <bool>()).Returns(licenseResult); var key = new Guid("D65321D5-B0F9-477D-828A-086F30E2BF89"); model.RegisterKey = key.ToString(); model.ActivateCommand.Execute(null); service.Received().RegisterAsync(key); service.Received().ValidateAsync(Arg.Any <bool>()); ctx.Received().SetLicenseKeyAsync(key.ToString()); Assert.Equal(AppLicense.Full, LicenseGlobals.Get()); Assert.False(model.IsBusy); }
public void InitializeTest_Invalid() { var service = Substitute.For <ILicenseService>(); var ctx = Substitute.For <IApplicationContext>(); var model = new LicenseViewModel(service, ctx); var appId = Guid.NewGuid().ToString(); var exception = new Exception("Exception"); var validation = new[] { new GeneralValidationFailure { Message = "Message", HowToResolve = "HowToResolve" } }; var validationResult = new LicenseResult(null, exception, validation); service.ValidateAsync(Arg.Any <bool>()).Returns(validationResult); ctx.GetValueOrDefault(LicenseGlobals.AppId, null).Returns(appId); model.Initialize(); Assert.Null(model.RegisterKey); Assert.Equal("|Message|HowToResolve|Exception|", model.ErrorMessage.Replace("\r\n", "|")); Assert.True(model.ShowError); Assert.Equal("Product Name - Demo", model.Description); Assert.Null(model.LicenseKey); Assert.False(model.ShowActivated); Assert.False(model.IsBusy); }
public void InitializeTest_Valid() { var path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "data", "test.license.xml"); var service = Substitute.For <ILicenseService>(); var ctx = Substitute.For <IApplicationContext>(); var model = new LicenseViewModel(service, ctx); var appId = Guid.NewGuid().ToString(); var license = License.Load(File.OpenRead(path)); var validationResult = new LicenseResult(license, null, null); service.ValidateAsync(Arg.Any <bool>()).Returns(validationResult); ctx.GetValueOrDefault(LicenseGlobals.AppId, null).Returns(appId); model.Initialize(); Assert.Null(model.RegisterKey); Assert.Null(model.ErrorMessage); Assert.False(model.ShowError); Assert.Equal("Product Name - Full", model.Description); Assert.Equal(license.Id.ToString(), model.LicenseKey); Assert.True(model.ShowActivated); Assert.False(model.IsBusy); }
public void Successful() { var license = License.Load("<license></license>"); var model = new LicenseResult(license, null, null); Assert.True(model.Successful); }
private void ShowLicenseError(LicenseResult result) { var sb = new StringBuilder(); foreach (var f in result.Failures) { sb.AppendLine(f.Code); // TODO: localize sb.AppendLine(f.Message); // TODO: localize sb.AppendLine(f.HowToResolve); // TODO: localize } if (result.Exception != null) { sb.AppendLine(result.Exception.Message); // TODO: generic failure instead } ErrorMessage = sb.Length > 0 ? sb.ToString() : null; }
public static LicenseResult GetRemoteLicense(string productString) { LicenseResult result = new LicenseResult(); try { string url = "https://encrypted.silmoon.com/apps/apis/config?appName=" + productString + "&configName=_license&outType=text/xml"; XmlDocument xml = new XmlDocument(); xml.Load(url); result.unlimited_state = xml["license"]["license_config_1"]["unlimited"]["state"].InnerText; result.unlimited_key = xml["license"]["license_config_1"]["unlimited"]["key"].InnerText; } catch (Exception ex) { result.Error = ex; } return(result); }
async private void BtnActivateClicked(object sender, EventArgs e) { UpdateUI(true); LicenseService service = new LicenseService(ProgramVars.LicURL); LicenseRequest request = new LicenseRequest() { Method = "Register", ClientID = tbLicenseKey.Text, DeviceID = App.appSettings.deviceID, languageID = App.appSettings.languageID, ServerID = "", Email = "" }; try { LicenseResult result = await service.ExecuteAsync(request); if (result.statusCode != 0) { throw new Exception(result.status); } App.appSettings.clientID = request.ClientID; App.appSettings.serverID = result.ServerID; App.appSettings.installationID = result.InstallationID; App.appSettings.isDemo = result.IsDemo; App.appSettings.serviceURL = result.URLs[0]; App.appSettings.imageURL = result.URLs[2]; ProgramVars.URL = App.appSettings.serviceURL; ProgramVars.ImageHandlerUrl = App.appSettings.imageURL; UpdateUI(false); await App.SaveAllPropertiesAsync(); await App.Current.MainPage.Navigation.PopAsync(true); } catch (Exception ex) { UpdateUI(false); tbLicenseKey.Text = ""; await DisplayAlert(AppResources.Error, ex.Message, AppResources.OK); } }
public LicenseResult VerifyLicense() { Random rnd = new Random(); Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); LicenseResult licenseResult = new LicenseResult(); if (_user.Length < 3 || _pass.Length < 3) { licenseResult.Valid = false; licenseResult.Error = "ERR101"; } int randInt = rnd.Next(124, 18724); string randIntHash = GetMd5Hash("S!k@l" + (randInt + 1563).ToString(CultureInfo.InvariantCulture)); string htmlResult = new System.Net.WebClient().DownloadString("http://www.chocobotxiv.com/forum/licensing/action.php?user="******"&pass="******"&action=1&session=" + randInt + "&version=" + fvi.FileMajorPart + "." + fvi.FileMinorPart); bool result = htmlResult == randIntHash; if (result) { //IniParser ini = new IniParser(@"chocobot.ini"); IniParserLegacy.IniFile ini = new IniParserLegacy.IniFile(System.Windows.Forms.Application.StartupPath + "\\chocobot.ini"); ini.IniWriteValue("Credentials", "UserName", _user); ini.IniWriteValue("Credentials", "Password", _pass); //ini.SaveSettings(); } else { licenseResult.Error = htmlResult.Trim(); } licenseResult.Valid = result; return(licenseResult); }
public LicenseResult VerifyLicense() { Random rnd = new Random(); Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); LicenseResult licenseResult = new LicenseResult(); if (_user.Length < 3 || _pass.Length < 3) { licenseResult.Valid = false; licenseResult.Error = "ERR101"; } int randInt = rnd.Next(124, 18724); string randIntHash = GetMd5Hash("S!k@l" + (randInt + 1563).ToString(CultureInfo.InvariantCulture)); string htmlResult = new System.Net.WebClient().DownloadString("http://www.chocobotxiv.com/forum/licensing/action.php?user="******"&pass="******"&action=1&session=" + randInt + "&version=" + fvi.FileMajorPart + "." + fvi.FileMinorPart); bool result = htmlResult == randIntHash; if(result) { //IniParser ini = new IniParser(@"chocobot.ini"); IniParserLegacy.IniFile ini = new IniParserLegacy.IniFile(System.Windows.Forms.Application.StartupPath + "\\chocobot.ini"); ini.IniWriteValue("Credentials", "UserName", _user); ini.IniWriteValue("Credentials", "Password", _pass); //ini.SaveSettings(); } else { licenseResult.Error = htmlResult.Trim(); } licenseResult.Valid = result; return licenseResult; }
public void Close(LicenseResult result) { DialogResult = result; }
public void OnLicenseResult(LicenseResultType result) { LicenseResult?.Invoke(this, result); }
async private void BtnLoginClicked(object sender, EventArgs e) { //0. Check if network available // if (Connectivity.NetworkAccess != NetworkAccess.Internet) { await DisplayAlert(AppResources.Warning, AppResources.NoNetwork, AppResources.OK); return; } await SetWaitStatus(true); // 1. Check license // LicenseService service = new LicenseService(ProgramVars.LicURL); LicenseRequest request = new LicenseRequest() { Method = "Validate", ClientID = App.appSettings.clientID, DeviceID = App.appSettings.deviceID, languageID = App.appSettings.languageID, ServerID = App.appSettings.serverID }; try { LicenseResult result = await service.ExecuteAsync(request); if (result.statusCode != 0) { App.appSettings.serverID = result.ServerID; await App.SaveAllPropertiesAsync(); throw new Exception(result.status); } // Check if license is about to expire // int nrDaysValid = result.ExpirationDate.Subtract(DateTime.Now).Days; if (nrDaysValid < 30) { await DisplayAlert(AppResources.Warning, $"License is about to expire in {nrDaysValid} days. Renew license !!!", AppResources.OK); } // App.appSettings.serverID = result.ServerID; App.appSettings.installationID = result.InstallationID; App.appSettings.isDemo = result.IsDemo; App.appSettings.serviceURL = result.URLs[0]; App.appSettings.imageURL = result.URLs[2]; ProgramVars.URL = App.appSettings.serviceURL; ProgramVars.ImageHandlerUrl = App.appSettings.imageURL; //await App.SaveAllPropertiesAsync(); await SetWaitStatus(false); } catch (Exception ex) { await SetWaitStatus(false); await DisplayAlert(AppResources.Error, ex.Message, AppResources.OK); //lbDemo.IsVisible = true; //lbDemo.Text = $"Error:{ex.Message}"; return; } // 2. Goto login page // await App.Current.MainPage.Navigation.PushAsync(new LoginPage(), true); }
public void NotSuccessful() { var model = new LicenseResult(null, new Exception(), null); Assert.False(model.Successful); }