|
3#
楼主 |
发表于 2007-8-18 15:12:05
|
只看该作者
private void buildExpiration()
{
if(m_expiration.equalsIgnoreCase("unlimited"))
{
return;
}
StringTokenizer st = new StringTokenizer(m_expiration, "/");
m_month = Integer.parseInt(st.nextToken());
m_date = Integer.parseInt(st.nextToken());
m_year = Integer.parseInt(st.nextToken());
m_expirationTime = new GregorianCalendar(m_year, m_month - 1, m_date, 23, 59, 59);
if(m_startdate != null)
{
st = new StringTokenizer(m_startdate, "/");
int month = Integer.parseInt(st.nextToken());
int date = Integer.parseInt(st.nextToken());
int year = Integer.parseInt(st.nextToken());
m_startTime = new GregorianCalendar(year, month - 1, date, 0, 0, 1);
}
}
public boolean isExpired()
{
if(m_expiration.equalsIgnoreCase("unlimited"))
{
return false;
}
GregorianCalendar now = new GregorianCalendar();
if(now.after(m_expirationTime))
{
return true;
}
if(m_startTime != null)
{
return m_startTime.after(now);
} else
{
return false;
}
}
public String getEdition()
{
return m_edition;
}
private int getMaxAllocations(EnLicenseType licType)
{
int licTypeValue = licType.asInt();
switch(licTypeValue)
{
case 1: // '\001'
return m_defects;
case 2: // '\002'
return m_tests;
case 3: // '\003'
return m_reqs;
case 13: // '\r'
return m_components;
}
throw new CTdException("Max allocation for license type '" + licType.getName() + "' could not be retieved");
}
public boolean isLicenseTypeEnabled(EnLicenseType licType)
{
if(isExpired())
{
return false;
}
switch(licType.asInt())
{
case 1: // '\001'
case 2: // '\002'
case 3: // '\003'
case 13: // '\r'
int maxLicenseAllocations = 0;
try
{
maxLicenseAllocations = getMaxAllocations(licType);
}
catch(CTdException e)
{
return false;
}
if(maxLicenseAllocations == EnLicenseStatus.UNLIMITED.asInt())
{
return true;
}
return maxLicenseAllocations > 0;
case 12: // '\f'
return m_dashboard;
case 10: // '\n'
return m_advanced_reports;
case 9: // '\t'
return m_version_control;
case 4: // '\004'
case 5: // '\005'
case 6: // '\006'
case 7: // '\007'
case 8: // '\b'
case 11: // '\013'
default:
return false;
}
}
public EnLicenseStatus canAllocateLicense(EnLicenseType licType, int currentLicenseUsage)
{
if(isExpired())
{
return EnLicenseStatus.KEY_EXPIRED;
}
switch(licType.asInt())
{
case 1: // '\001'
case 2: // '\002'
case 3: // '\003'
case 13: // '\r'
int maxLicenseAllocations = 0;
try
{
maxLicenseAllocations = getMaxAllocations(licType);
}
catch(CTdException e)
{
return EnLicenseStatus.DENIED;
}
if(maxLicenseAllocations == EnLicenseStatus.UNLIMITED.asInt())
{
return EnLicenseStatus.APPROVED;
}
if(currentLicenseUsage >= (int)((float)maxLicenseAllocations * m_tolerance))
{
return EnLicenseStatus.DENIED;
}
if(currentLicenseUsage >= maxLicenseAllocations)
{
return EnLicenseStatus.OVERFLOW_ALERT;
} else
{
return EnLicenseStatus.APPROVED;
}
case 12: // '\f'
return m_dashboard ? EnLicenseStatus.APPROVED : EnLicenseStatus.DENIED;
case 4: // '\004'
case 5: // '\005'
case 6: // '\006'
case 7: // '\007'
case 8: // '\b'
case 9: // '\t'
case 10: // '\n'
case 11: // '\013'
default:
return EnLicenseStatus.DENIED;
}
}
public IFileRec getLicenseStatus(Map used)
{
StringBuffer expTime = null;
expTime = new StringBuffer();
IFileRec resultFrec = new CFileRec();
if(m_expiration.equalsIgnoreCase("Unlimited"))
{
expTime.append("Unlimited");
} else
{
expTime.append(m_month).append("/").append(m_date).append("/").append(m_year);
long daysToExpiration = (m_expirationTime.getTime().getTime() - System.currentTimeMillis()) / 0x5265c00L;
resultFrec.addItem("DaysToExpiration", daysToExpiration);
}
resultFrec.addItem("ExpirationDate", expTime.toString());
int usedLicenses = 0;
if(used.containsKey(EnLicenseType.BUG))
{
usedLicenses = ((Integer)used.get(EnLicenseType.BUG)).intValue();
} else
{
usedLicenses = 0;
}
saveLicStatus(EnLicenseType.BUG.getName(), EnLicenseType.BUG.getStatusCaption(), EnLicenseType.BUG, usedLicenses, resultFrec);
if(used.containsKey(EnLicenseType.LAB))
{
usedLicenses = ((Integer)used.get(EnLicenseType.LAB)).intValue();
} else
{
usedLicenses = 0;
}
saveLicStatus(EnLicenseType.LAB.getName(), EnLicenseType.LAB.getStatusCaption(), EnLicenseType.LAB, usedLicenses, resultFrec);
if(used.containsKey(EnLicenseType.REQUIREMENT))
{
usedLicenses = ((Integer)used.get(EnLicenseType.REQUIREMENT)).intValue();
} else
{
usedLicenses = 0;
}
saveLicStatus(EnLicenseType.REQUIREMENT.getName(), EnLicenseType.REQUIREMENT.getStatusCaption(), EnLicenseType.REQUIREMENT, usedLicenses, resultFrec);
if(used.containsKey(EnLicenseType.COMPONENTS))
{
usedLicenses = ((Integer)used.get(EnLicenseType.COMPONENTS)).intValue();
} else
{
usedLicenses = 0;
}
saveLicStatus(EnLicenseType.COMPONENTS.getName(), EnLicenseType.COMPONENTS.getStatusCaption(), EnLicenseType.COMPONENTS, usedLicenses, resultFrec);
resultFrec.addItem("Tolerance", Math.round((m_tolerance - 1.0F) * 100F));
resultFrec.addItem(EnLicenseType.VC.getStatusCaption(), CTdGeneralFunctions.booleanToStr(m_version_control));
resultFrec.addItem(EnLicenseType.ADVANCEDREPORTS.getStatusCaption(), CTdGeneralFunctions.booleanToStr(m_advanced_reports));
resultFrec.addItem(EnLicenseType.DASHBOARD.getStatusCaption(), CTdGeneralFunctions.booleanToStr(m_dashboard));
return resultFrec;
}
private void saveLicStatus(String name, String caption, EnLicenseType licType, int used, IFileRec outFrec)
{
IFileRec licStat = null;
licStat = new CFileRec();
licStat.addItem("inuse", used);
licStat.addItem("max", getMaxAllocations(licType));
licStat.addItem("name", caption);
outFrec.addItem(name, licStat.toString());
}
} |
|