/**
*
*/
public string LookupReferenceByPartNumber(string partNumber, string className)
{
string refUUID = "";
DocumentDAO dao = DataManager.getDocumentDAO();
AssetIdentificationBean asset = dao.FindAsset(AssetTypePart, partNumber);
if (asset == null)
{
string uuid = Guid.NewGuid().ToString();
var id = new ItemDescriptionIdentification();
var idNo = new ManufacturerIdentificationNumber();
idNo.type = IdentificationNumberType.Part;
idNo.number = partNumber;
id.IdentificationNumbers = new List<IdentificationNumber>();
id.IdentificationNumbers.Add(idNo);
id.ModelName = partNumber;
string test1 = idNo.Serialize();
string test2 = id.Serialize();
LogManager.SourceError(ATMLReader.SOURCE, "Failed to locate asset for part number: {0} ", partNumber);
Type _type = Type.GetType(className + ",ATMLModelLibrary");
if (_type == null)
LogManager.SourceError(ATMLReader.SOURCE, "Invalid Class Name: {0}", className);
else
{
object obj = Activator.CreateInstance(_type);
PropertyInfo pi = _type.GetProperty("uuid");
if (pi == null)
LogManager.SourceError(ATMLReader.SOURCE, "Class Name: {0} does not support the uuid property.", className);
else
{
pi.SetValue(obj, uuid, null);
}
PropertyInfo piId = _type.GetProperty("Identification");
if (piId == null)
{
//check to see if there is an Item property and if the Item property is an ItemDescription type
piId = _type.GetProperty("Item");
if (piId != null)
piId = piId.GetType().GetProperty("Identification");
if (piId == null)
LogManager.SourceError(ATMLReader.SOURCE, "Class Name: {0} does not support the Identification property.", className);
else
{
piId.SetValue(obj, id, null);
}
}
else
{
piId.SetValue(obj, id, null);
}
MethodInfo mi = _type.GetMethod("Save");
if (mi == null)
LogManager.SourceError(ATMLReader.SOURCE, "Class Name: {0} does not support a save() method.", className);
else
{
mi.Invoke(obj, null);
refUUID = uuid;
LogManager.SourceInfo(ATMLReader.SOURCE, "*** A Part Document has been created for part number: {0}.", partNumber);
}
}
}
else
{
refUUID = asset.uuid.ToString();
}
return refUUID;
}