public string Create(string partNumber, string nomen, string model) { string refUUID = null; DocumentDAO dao = DataManager.getDocumentDAO(); try { dao.StartTransaction(); AssetIdentificationBean asset; var description = new UUTDescription(); ItemDescription item = new HardwareUUT(); var identificationNumber = new ManufacturerIdentificationNumber(); identificationNumber.number = partNumber; identificationNumber.manufacturerName = "[Unknown]"; identificationNumber.type = IdentificationNumberType.Part; description.name = nomen; description.uuid = Guid.NewGuid().ToString(); item.Identification = new ItemDescriptionIdentification(); item.Identification.ModelName = model; item.Identification.IdentificationNumbers = new List <IdentificationNumber>(); item.Identification.IdentificationNumbers.Add(identificationNumber); description.Item = item; refUUID = description.uuid; //------------------------------------------------------------------------------------// //--- Add document to document database ---// //--- The UUT is a Model Number Asset so we will use a model name for the filename ---// //--- We will also use the ATML Standard number (1671.3) for part of the file name ---// //------------------------------------------------------------------------------------// string docName = string.Format("{0}{1}", FileUtils.MakeGoodFileName(model), ATMLContext.ATML_UUT_FILENAME_SUFFIX); var document = new Document(); document.Description = description.name; document.uuid = refUUID; document.name = docName; document.Item = description.Serialize(); document.DocumentContent = Encoding.UTF8.GetBytes(document.Item); document.ContentType = ATMLContext.CONTEXT_TYPE_XML; document.DocumentType = dbDocument.DocumentType.UUT_DESCRIPTION; Save(document); //----------------------------------------// //--- Add reference id to asset lookup ---// //----------------------------------------// asset = new AssetIdentificationBean(); asset.uuid = Guid.Parse(refUUID); asset.assetType = "Model"; asset.assetNumber = model; asset.DataState = BASEBean.eDataState.DS_ADD; asset.save(); //Add uut document to atml directory - use part number as file name + 1671.3 //TODO: Replace with an event //ProjectManager.SaveATMLDocument( docName, FileManager.AtmlFileType.AtmlTypeUut, document.DocumentContent,true ); dao.CommitTransaction(); } catch (Exception e) { dao.RollbackTransaction(); throw e; } finally { dao.EndTransaction(); } return(refUUID); }
/** * */ 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); }
public static InstrumentDescription CreateInstrument(string partNumber, string stationType) { InstrumentDescription description = null; DocumentDAO dao = DataManager.getDocumentDAO(); try { AssetIdentificationBean stationAsset = DocumentManager.FindAsset("Model", stationType); if (stationAsset == null) { throw new Exception(string.Format("Failed to locate the \"{0}\" Test Station", stationType)); } TestStationDescription11 testStation = TestStationController.Instance.Find(stationAsset.uuid); if (testStation == null) { throw new Exception(string.Format("Failed to locate the \"{0}\" Test Station", stationType)); } //---------------------------------------------------------------// //--- String off any numeric instance count (suffix in #xxxx) ---// //---------------------------------------------------------------// string fullPartNumber = partNumber.Split('#')[0]; //--------------------------------// //--- Prepend the station name ---// //--------------------------------// fullPartNumber = stationType + "." + fullPartNumber; dao.StartTransaction(); AssetIdentificationBean asset; description = new InstrumentDescription(); var identificationNumber = new ManufacturerIdentificationNumber(); identificationNumber.number = fullPartNumber; identificationNumber.manufacturerName = "[Unknown]"; identificationNumber.type = IdentificationNumberType.Part; description.name = fullPartNumber; description.uuid = Guid.NewGuid().ToString(); description.Identification = new ItemDescriptionIdentification(); description.Identification.ModelName = partNumber; description.Identification.IdentificationNumbers = new List <IdentificationNumber>(); description.Identification.IdentificationNumbers.Add(identificationNumber); //Add document to document database //The UUT is a Model Number Asset so we will use a model name for the filename //We will also use the ATML Standard number (1671.3) for part of the file name string docName = string.Format("{0}.1671.2.xml", FileUtils.MakeGoodFileName(fullPartNumber)); var document = new Document(); document.Description = description.name; document.uuid = description.uuid; document.name = docName; document.Item = description.Serialize(); document.DocumentContent = Encoding.UTF8.GetBytes(document.Item); document.ContentType = "text/xml"; document.DocumentType = dbDocument.DocumentType.INSTRUMENT_DESCRIPTION; PersistanceController.Save(document); //Add reference id to asset lookup asset = new AssetIdentificationBean(); asset.uuid = Guid.Parse(description.uuid); asset.assetType = "Part"; asset.assetNumber = fullPartNumber; asset.DataState = BASEBean.eDataState.DS_ADD; asset.save(); //Add instrument document to atml directory - use part number as file name + 1671.2 //TODO: Think about this: ProjectManager.SaveATMLDocument(docName, ProjectManager.AtmlTypeInstrument, document.DocumentContent); //----------------------------------------------// //--- Add the instrument to the test station ---// //----------------------------------------------// TestStationController.Instance.AddInstrumentReference(testStation, partNumber, document.uuid);//, //document.DocumentContent ); dao.CommitTransaction(); } catch (Exception e) { dao.RollbackTransaction(); throw e; } finally { dao.EndTransaction(); } return(description); }