using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using GZTW.AyaNova.BLL; namespace AyaNova { public partial class GlobalFetchKey : Form { public GlobalFetchKey() { InitializeComponent(); } private void GlobalFetchKey_Load(object sender, EventArgs e) { Icon = Resource1.AyaNova5; } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } private void btnOK_Click(object sender, EventArgs e) { string sEmail = edEmail.Text; string sFetchCode = edFetchCode.Text; if (string.IsNullOrWhiteSpace(sEmail)) { MessageBox.Show("Email address is required\r\nEnter it exactly as it appears in the license email we sent you."); return; } if (string.IsNullOrWhiteSpace(sFetchCode)) { MessageBox.Show("Fetch Code is required\r\nEnter it exactly as it appears in the license email we sent you."); return; } string sUrl = "https://rockfish.ayanova.com/fetch/" + sFetchCode + "/" + sEmail; //string sUrl = "https://rockfish.gztechworks.com/fetch/" + sFetchCode + "/" + sEmail; //TODO: maybe alt url in case?? or fuck it wont' matter with v8 coming anyway //case 3875 System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)3072; using (System.Net.WebClient client = new System.Net.WebClient()) { try { Cursor.Current = Cursors.WaitCursor; string s = client.DownloadString(sUrl); //case 1172 string sKeyType = "AyaNovaLiteLicenseKey"; if (s.Contains("AyaNovaLicenseKey"))//modified to take out <> for case 3122 { sKeyType = "AyaNovaLicenseKey"; } bool containsXML = s.Contains(""); bool containsJSON = s.Contains("[KEY"); if (!containsXML && !containsJSON) { Util.PromptWithIconOKOnlyFromLocaleKey("Key.Error.NotFound", MessageBoxIcon.Error); return; } //Key sanity checks bool isRequestedTrial = false; int newScheduleableUsers = 0; if (containsJSON) { string keyNoWS = System.Text.RegularExpressions.Regex.Replace(AyaBizUtils.ExtractString(s, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1").ToLowerInvariant(); if (keyNoWS.Contains("\"RequestedTrial\":\"True\"".ToLowerInvariant())) { isRequestedTrial = true; } newScheduleableUsers = int.Parse(AyaBizUtils.ExtractString(keyNoWS, ",\"TotalScheduleableUsers\":\"".ToLowerInvariant(), "\",")); } else { //xml key isRequestedTrial = s.Contains("RequestedTrial>true"); newScheduleableUsers = int.Parse(AyaBizUtils.ExtractString(s, "", "")); } if (AyaBizUtils.RequestedTrial && isRequestedTrial) { MessageBox.Show( "This requested trial license can not be used because this database already contains a requested trial license\r\n" , "", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } //Don't allow them to enter a lite key into a db that is currently not a standalone firebird //otherwise they could permanently lock themselves out of the db (until we fixed it of course) if (sKeyType == "AyaNovaLiteLicenseKey" && !AyaBizUtils.AyaNovaConnectionSetting.SingleUserConnection) { MessageBox.Show( "This AyaNova Lite license can not be used because the current database is not a single user stand alone FireBird database.\r\n" + "AyaNova Lite can not be used with a Firebird server or Microsoft SQL server.\r\n", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } //case 2084 //warn if less users in new key than in current license if (!AyaBizUtils.Trial) { if (AyaBizUtils.ScheduleableUsers > newScheduleableUsers) { //case 3199 if (MessageBox.Show("WARNING: The Key you are about to apply is for less scheduleable resource licenses than your database is presently licensed for.\r\n\r\nPlease cancel and resolve; or select OK to apply", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK) { return; } } } if (!AyaBizUtils.Insert(s)) { Util.PromptWithIconOKOnlyFromLocaleKey("Key.Error.NotValid", MessageBoxIcon.Error); Application.Exit(); } else { //edNotes.Text = AyaBizUtils.View(); Util.PromptWithIconOKOnlyFromLocaleKey("Key.Label.Saved", MessageBoxIcon.Information); Application.Exit(); } } catch (System.Net.WebException wex) { string s= wex.Message; if (s.Contains("404")) { MessageBox.Show("No license was found for the Fetch address and Fetch code provided.\r\n\r\n" + "This can happen if either address or code was entered incorrectly or \r\n" + "this can also happen if the key has already been fetched.\r\n\r\n" + "Check your entry and try again or contact us at support@ayanova.com", "License not found"); } else { CopyableMessageBox m = new CopyableMessageBox("An unexpected network error occurred, please contact support@ayanova.com with these details:\r\n"+wex.Message); m.BringToFront(); m.ShowDialog(); m.Dispose(); } } catch (Exception ex) { CopyableMessageBox m = new CopyableMessageBox("An unexpected error occurred, please contact support@ayanova.com with these details:\r\n" + ex.Message); m.BringToFront(); m.ShowDialog(); m.Dispose(); } } } }//eoc }