This commit is contained in:
346
keys/Generator/MsgGen.cs
Normal file
346
keys/Generator/MsgGen.cs
Normal file
@@ -0,0 +1,346 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace GroundZero.KeyCodes
|
||||
{
|
||||
class MsgGen
|
||||
{
|
||||
|
||||
/*
|
||||
*
|
||||
* - Trial greeting message
|
||||
Lite and Full separate
|
||||
[FirstName] - requesters first name, need to auto capitalize first letter
|
||||
|
||||
- Key message
|
||||
[LicenseExpiryDate] (Now plus 7 days)
|
||||
[LicenseDescription] (textual description of info for body of message see code)
|
||||
[LicenseKey] (actual key)
|
||||
|
||||
New key message
|
||||
Lite
|
||||
Full
|
||||
Add on key message
|
||||
Lite
|
||||
Full
|
||||
|
||||
Licensed trial key message
|
||||
Lite
|
||||
Full
|
||||
|
||||
|
||||
*/
|
||||
public static string TrialGreetingMessage(bool bLite, string sName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(sName))
|
||||
{
|
||||
// convert to char array of the string
|
||||
char[] letters = sName.ToCharArray();
|
||||
// upper case the first char
|
||||
letters[0] = char.ToUpper(letters[0]);
|
||||
// return the array made of the new char array
|
||||
sName = new string(letters);
|
||||
}
|
||||
|
||||
if (!bLite)
|
||||
{
|
||||
return File.ReadAllText(FileName(MessageType.TrialGreetingFull)).Replace("[FirstName]", sName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return File.ReadAllText(FileName(MessageType.TrialGreetingLite)).Replace("[FirstName]", sName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static string TrialKeyMessage(bool bLite, string sRegTo, bool XMLFormat)
|
||||
{
|
||||
KeyGen kg = new KeyGen();
|
||||
|
||||
kg.Lite = bLite;
|
||||
//case 2094 moved to plugins
|
||||
//kg.FeatureMBIInterface = !bLite;
|
||||
//kg.FeatureWebInterface = !bLite;
|
||||
|
||||
kg.Expires = DateTime.Now.AddDays(31);
|
||||
|
||||
kg.Plugins = new DataTable();
|
||||
kg.Plugins.Columns.Add("Plugin");
|
||||
//kg.Plugins.Columns.Add("Version");
|
||||
kg.Plugins.Columns.Add("SubscriptionExpires");
|
||||
|
||||
|
||||
#region Add trial plugins
|
||||
DataRow dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "QBI - QuickBooks interface";
|
||||
//dr["Version"] = "7";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
|
||||
dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "QBOI - QuickBooks Online interface";
|
||||
//dr["Version"] = "7";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
|
||||
dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "PTI - US Sage 50/Peachtree interface";
|
||||
//dr["Version"] = "7";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
|
||||
if (!kg.Lite)
|
||||
{
|
||||
dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "QuickNotification";
|
||||
//dr["Version"] = "Licensed";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
}
|
||||
|
||||
dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "ExportToXls";
|
||||
//dr["Version"] = "Licensed";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
|
||||
dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "OutlookSchedule";
|
||||
//dr["Version"] = "Licensed";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
|
||||
dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "AyaNovaOLI";
|
||||
//dr["Version"] = "Licensed";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
|
||||
dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "ImportExportCSVDuplicate";
|
||||
//dr["Version"] = "Licensed";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
|
||||
if (!kg.Lite)
|
||||
{
|
||||
dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "WBI - Web browser interface";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
|
||||
dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "MBI - Minimal browser interface";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
|
||||
|
||||
dr = kg.Plugins.NewRow();
|
||||
dr["Plugin"] = "RI - Responsive Interface";
|
||||
dr["SubscriptionExpires"] = kg.Expires.ToString();
|
||||
kg.Plugins.Rows.Add(dr);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
kg.RegisteredTo = sRegTo;
|
||||
kg.RequestedTrial = true;
|
||||
|
||||
if (kg.Lite)
|
||||
kg.ScheduleableUsers = 1;
|
||||
else
|
||||
kg.ScheduleableUsers = 5;
|
||||
|
||||
kg.SelectedLicenseType = "Web requested trial";
|
||||
kg.WillExpire = true;
|
||||
|
||||
|
||||
return FormatMessage(kg, XMLFormat);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static string FormatMessage(KeyGen kg, bool XMLFormat)
|
||||
{
|
||||
string sMessage = "";
|
||||
|
||||
if (kg.SelectedLicenseType == "New")
|
||||
{
|
||||
if (kg.Lite)
|
||||
{
|
||||
sMessage = File.ReadAllText(FileName(MessageType.KeyNewLite));
|
||||
}
|
||||
else
|
||||
{
|
||||
sMessage = File.ReadAllText(FileName(MessageType.KeyNewFull));
|
||||
}
|
||||
}
|
||||
else if (kg.SelectedLicenseType == "Add on")
|
||||
{
|
||||
if (kg.Lite)
|
||||
{
|
||||
sMessage = File.ReadAllText(FileName(MessageType.KeyAddOnLite));
|
||||
}
|
||||
else
|
||||
{
|
||||
sMessage = File.ReadAllText(FileName(MessageType.KeyAddOnFull));
|
||||
}
|
||||
}
|
||||
else//licensed trial
|
||||
{
|
||||
if (kg.Lite)
|
||||
{
|
||||
sMessage = File.ReadAllText(FileName(MessageType.KeyTrialLite));
|
||||
}
|
||||
else
|
||||
{
|
||||
sMessage = File.ReadAllText(FileName(MessageType.KeyTrialFull));
|
||||
}
|
||||
}
|
||||
|
||||
//token substitutions
|
||||
sMessage = sMessage.Replace("[LicenseExpiryDate]", kg.InstallableUntil.ToLongDateString());
|
||||
sMessage = sMessage.Replace("[LicenseDescription]", LicenseInfo(kg));
|
||||
sMessage = sMessage.Replace("[LicenseKey]", kg.Generate(XMLFormat));
|
||||
|
||||
return sMessage;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Extra info to display about key at top of key message
|
||||
/// </summary>
|
||||
/// <param name="kg"></param>
|
||||
/// <returns></returns>
|
||||
public static string LicenseInfo(KeyGen kg)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("LICENSE DETAILS\r\n");
|
||||
sb.Append("This key must be installed before: ");
|
||||
sb.Append(kg.InstallableUntil.ToLongDateString());
|
||||
sb.Append("\r\n");
|
||||
|
||||
//if (kg.SelectedLicenseType == "Web requested trial")
|
||||
//{
|
||||
// sb.Append("*** This temporary license key has been provided for limited evaluation purposes only *** \r\n");
|
||||
// sb.Append("This license will expire and AyaNova usage will be restricted after: " + kg.Expires.ToLongDateString() + "\r\n\r\n");
|
||||
//}
|
||||
|
||||
if (kg.LockOut)
|
||||
{
|
||||
sb.Append("*** This temporary license key is provided for evaluation use only pending payment ***\r\n");
|
||||
sb.Append("This license will expire and AyaNova usage will be restricted after: " + kg.Expires.ToLongDateString() + "\r\n");
|
||||
sb.Append("\r\n");
|
||||
sb.Append("A permanent license key will be sent to you when payment \r\n" +
|
||||
"has been received and processed. There will be no extensions or \r\n" +
|
||||
"exceptions. Please send in payment early enough to allow for \r\n" +
|
||||
"mail and processing time to ensure uninterrupted use of AyaNova" + (kg.Lite ? " Lite" : "") + ". \r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
sb.Append("Registered to: ");
|
||||
sb.Append(kg.RegisteredTo);
|
||||
sb.Append("\r\n");
|
||||
|
||||
|
||||
sb.Append("Scheduleable resources: ");
|
||||
switch (kg.ScheduleableUsers)
|
||||
{
|
||||
case 1:
|
||||
sb.AppendLine("1");
|
||||
break;
|
||||
case 5:
|
||||
sb.AppendLine("Up to 5");
|
||||
break;
|
||||
case 10:
|
||||
sb.AppendLine("Up to 10");
|
||||
break;
|
||||
case 20:
|
||||
sb.AppendLine("Up to 20");
|
||||
break;
|
||||
case 50:
|
||||
sb.AppendLine("Up to 50");
|
||||
break;
|
||||
case 999:
|
||||
sb.AppendLine("Up to 999");
|
||||
break;
|
||||
}
|
||||
|
||||
sb.AppendLine("Support and updates until: " + kg.Expires.ToLongDateString() + "\r\n");
|
||||
|
||||
if (kg.Plugins.Rows.Count > 0)
|
||||
{
|
||||
sb.Append("\r\n");
|
||||
sb.Append("Plugins:\r\n");
|
||||
foreach (DataRow dr in kg.Plugins.Rows)
|
||||
{
|
||||
sb.Append("\t");
|
||||
sb.Append(dr["Plugin"].ToString());
|
||||
sb.Append(" support and updates until: ");
|
||||
DateTime dtx = DateTime.Parse(dr["SubscriptionExpires"].ToString());
|
||||
sb.Append(dtx.ToLongDateString());
|
||||
sb.Append("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
#region MessageType enum
|
||||
|
||||
|
||||
static string FileName(MessageType mtype)
|
||||
{
|
||||
switch (mtype)
|
||||
{
|
||||
case MessageType.TrialGreetingFull:
|
||||
return "TrialGreetingFull.txt";
|
||||
case MessageType.TrialGreetingLite:
|
||||
return "TrialGreetingLite.txt";
|
||||
case MessageType.KeyNewFull:
|
||||
return "KeyNewFull.txt";
|
||||
case MessageType.KeyNewLite:
|
||||
return "KeyNewLite.txt";
|
||||
case MessageType.KeyAddOnFull:
|
||||
return "KeyAddOnFull.txt";
|
||||
case MessageType.KeyAddOnLite:
|
||||
return "KeyAddOnLite.txt";
|
||||
case MessageType.KeyTrialFull:
|
||||
return "KeyTrialFull.txt";
|
||||
case MessageType.KeyTrialLite:
|
||||
return "KeyTrialLite.txt";
|
||||
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
#endregion MessageTypeEnum
|
||||
|
||||
|
||||
}//end of class
|
||||
public enum MessageType
|
||||
{
|
||||
None,
|
||||
TrialGreetingLite,
|
||||
TrialGreetingFull,
|
||||
KeyNewFull,
|
||||
KeyNewLite,
|
||||
KeyAddOnFull,
|
||||
KeyAddOnLite,
|
||||
KeyTrialFull,
|
||||
KeyTrialLite
|
||||
|
||||
}
|
||||
}//end of namespace
|
||||
Reference in New Issue
Block a user