Reputation: 377
I loaded the latest version of Acuminator and now I am getting Warnings and Errors on code that was always working.
I am getting a PX1094 warning that I need a PXHidden or PXCacheName on some local DACs inside a graph. Existing code:
[Serializable]
public partial class EDGetOrderFilter : IBqlTable
{
#region ReviewType
}
[Serializable]
public partial class EDIGetOrder : PX.Data.IBqlTable
{
#region Selected
// Fields from Exception table
#region ExceptID
#region intID
#region ExceptReason
#region ImportDate
}
The DACs are currently decorated with Serializable but why do I need to add the PXCacheName attribute also? I am assuming I just need:
[PXCacheName ("EDGetOrderFilter")]
[PXCacheName ("EDIGetOrder")]
What does the new attribute do for me?
I am also getting a PX1050 error while throwing an exception with a literal
if (cntr == 0)
throw new PXException("No active Partner Data entries!");
I followed the link to the documentation and it is showing to setup Localizable strings. I have never done this and I hesitant to change working code. Could someone explain to me why the changes are required?
The code from the documentation:
[PXLocalizable]
public static class Messages
{
public const string SpecialText = "Hardcoded String";
public const string SpecialTextToFormat = "Hardcoded String To Format {0}";
}
public string PXLocalizerAll()
{
string localizedString;
object parameter = new object();
localizedString = PXLocalizer.Localize(Messages.SpecialText);
localizedString = PXLocalizer.Localize(Messages.SpecialText, typeof(MyMessages).FullName);
localizedString = PXLocalizer.LocalizeFormat(Messages.SpecialTextToFormat, parameter);
return localizedString;
}
public class LocalizationExceptions
{
public void ExceptionsLocalization()
{
throw new PXArgumentException(nameof(ExceptionsLocalization), Messages.SpecialText);
}
}
public class DetailNonLocalizableBypassedException : PXException
{
public object ItemToBypass { get; }
public DetailNonLocalizableBypassedException(object itemToBypass)
: base(Messages.SpecialText)
{
ItemToBypass = itemToBypass;
}
}
I have never used the localization logic and am unfamiliar with it. I want to write the code correctly but I need to understand what the changes do.
Upvotes: 1
Views: 365
Reputation: 8278
I loaded the latest version of Acuminator and now I am getting Warnings and Errors on code that was always working.
The purpose of the Acuminator tool is to enforce a set of standards when building a solution using Acumatica Framework. It isn't meant to validate a solution as working and the automated nature of the tool means it might occasionally suggest something that looks unnecessary or sub-optimal. Overall the trade-off should bring higher code quality and uniformity.
Could someone explain to me why the changes are required?
The immediate concern is that the changes are required to pass Acuminator validation. Passing Acuminator validation would apply if you are developing an ISV Solution and seeking Acumatica ISV Solution Certification.
The DACs are currently decorated with Serializable but why do I need to add the PXCacheName attribute also?
More metadata is better than less. Various mechanism in the system will fetch the Cache name and surface it on the UI. Perhaps it might be used to generate more meaningful or less technical error messages. It can also be used by more features in the future.
I followed the link to the documentation and it is showing to setup Localizable strings. I have never done this and I hesitant to change working code.
I think you might be able to skip the full localization setup. Acuminator is likely looking for two things:
throw new PXException("No literal constants");
This can be fixed by putting the constants in a Message class:
throw new PXException(Messages.NamedConstant);
There should be minimal plumbing so a user could expand translations by way of configuration. Using one of the PXMessages.Localize methods will accomplish that:
PXMessages.LocalizeNoPrefix(Messages.NamedConstant);
I haven't tested it but I believe those two changes (example below) will satisfy Acuminator constraints and shouldn't create undesirable side-effects in your code base:
throw new PXException(PXMessages.LocalizeNoPrefix(Messages.NamedConstant));
Upvotes: 1