public static void Save(UUTDescription uut) { string uuid; if (uut != null) { string model = uut.Item.Identification.ModelName; string documentName = BuildAtmlFileName(model); uuid = uut.uuid; Document document = DocumentManager.GetDocument(uuid); if (document != null) { document.DocumentContent = Encoding.UTF8.GetBytes(uut.Serialize()); document.DataState = BASEBean.eDataState.DS_EDIT; document.name = documentName; DocumentManager.SaveDocument(document); } else { AssetIdentificationBean bean = new AssetIdentificationBean(); document = new Document(); document.name = documentName; document.DocumentContent = Encoding.UTF8.GetBytes(uut.Serialize()); document.DocumentType = dbDocument.DocumentType.UUT_DESCRIPTION; document.ContentType = "text/xml"; DocumentManager.SaveDocument(document); bean.assetNumber = model; bean.assetType = "Part"; bean.uuid = Guid.Parse(uuid); bean.DataState = BASEBean.eDataState.DS_ADD; bean.save(); } } }
public void Save() { string content = Serialize(); var document = new dbDocument(); var dao = new DocumentDAO(); bool documentExists = dao.hasDocument(uuid); //if( !documentExists ) // LogManager.Trace("Creating new Test Adapter Description with uuid of {0}", uuid); //else // LogManager.Trace("Saving Test Adapter Description with uuid of {0}", uuid); document.contentType = "text/xml"; document.documentDescription = "Test Adapter"; document.documentName = Identification.ModelName; document.documentVersion = version; document.documentSize = content.Length; document.documentTypeId = (int)dbDocument.DocumentType.TEST_ADAPTER_DESCRIPTION; document.documentContent = Encoding.UTF8.GetBytes(content); document.UUID = Guid.Parse(uuid); document.DataState = documentExists ? BASEBean.eDataState.DS_EDIT : BASEBean.eDataState.DS_ADD; document.save(); foreach (IdentificationNumber idNumber in Identification.IdentificationNumbers) { string type = Enum.GetName(typeof(IdentificationNumberType), idNumber.type); string number = idNumber.number; var asset = new AssetIdentificationBean(); asset.assetNumber = number; asset.assetType = type; asset.uuid = Guid.Parse(uuid); asset.DetermineDataState(); asset.save(); } }
/** * */ public string GetDocumentReference(string partNumber, string docType, string description, string assetType, string contentType) { string refUUID = ""; try { //Document is a Other type Asset. AssetIdentificationBean asset = DocumentManager.FindAsset(assetType, partNumber); if (asset != null) { refUUID = asset.uuid.ToString(); } else { refUUID = DocumentManager.CreateDocumentPlaceHolder(partNumber, assetType, contentType, docType, description); } } catch (Exception e) { LogManager.SourceError(ATMLReader.SOURCE, ErrorSavingDocument, e.Message); } return(refUUID); }
private static void CreateAsset(string referenceId, string combinedPartNumber) { AssetIdentificationBean asset; asset = new AssetIdentificationBean(); asset.uuid = Guid.Parse(referenceId); asset.assetType = "Part"; asset.assetNumber = combinedPartNumber; asset.DataState = BASEBean.eDataState.DS_ADD; asset.save(); }
public static string CreateDocumentPlaceHolder(string partNumber, string assetType, string contentType, string docType, string description) { string refId = null; var asset = new AssetIdentificationBean(); DocumentDAO dao = DataManager.getDocumentDAO(); try { dao.StartTransaction(); //Lookup Part Number for document string rootPartNumber = partNumber.Split('#')[0]; Document document = GetDocument(rootPartNumber, (int)Enum.Parse(typeof(dbDocument.DocumentType), docType)); if (document == null) { document = new Document(); document.uuid = Guid.NewGuid().ToString(); document.name = rootPartNumber; document.Item = ""; //Content document.DocumentContent = Encoding.UTF8.GetBytes(document.Item); document.ContentType = contentType ?? ""; document.Description = (description.Length > 255?description.Substring(0, 254):description) ?? ""; document.DocumentType = (dbDocument.DocumentType)Enum.Parse(typeof(dbDocument.DocumentType), docType); SaveDocument(document); } //Add reference id to asset lookup asset = new AssetIdentificationBean(); asset.uuid = Guid.Parse(document.uuid); asset.assetType = assetType; asset.assetNumber = partNumber; asset.DataState = BASEBean.eDataState.DS_ADD; asset.save(); refId = asset.uuid.ToString(); dao.CommitTransaction(); LogManager.Trace("A placeholder document for \"{0}\" has been created.", partNumber); } catch (Exception e) { dao.RollbackTransaction(); LogManager.Error(e, "An Error occurred creating a document for \"{0}\"", partNumber); } finally { dao.EndTransaction(); } return(refId); }
public static InstrumentDescription FindInstrument(string partNumber) { AssetIdentificationBean asset = DocumentManager.FindAsset("Part", partNumber); if (asset == null) { throw new Exception(string.Format("Failed to locate Asset Id \"{0}\"", partNumber)); } Document document = DocumentManager.GetDocument(asset.uuid); if (document == null) { throw new Exception(string.Format("Failed to locate Document Id \"{0}\"", asset.uuid)); } return(InstrumentDescription.Deserialize(Encoding.UTF8.GetString(document.DocumentContent))); }
public static void CreateProject() { var form = new ATMLProjectCreationForm(); //ObjectNameForm("Create Test Program Set Name"); //form.RegularExpression = @"^([A-Z]|[a-z]|[0-9]|_|-|\.|\s)+$"; if (DialogResult.OK == form.ShowDialog()) { UUTDescription uut = form.UutDescription; CreateProject(form.ProjectInfo); //UutManager.FindUUT() //--- Check if uut exists or not ---// var bean = new AssetIdentificationBean(); bean.assetType = "Part"; bean.assetNumber = uut.name; bean.uuid = Guid.Parse(uut.uuid); //DocumentManager.SaveDocument( new Document()); } }
/** * Determine the Reference UUID for the UUT Part Number provided. * @parameter partNumber the part number of the UUT * @parameter tpsName the name of the Test Program Set * @parameter ofpSwitchPin * @parameter swNo * @parameter testType * @parameter nomen * @parameter model * @parameter system * @parameter refDes * @parameter wuc * @parameter tpm * @parameter tm * @parameter tec * */ public string GetUUTReferenceId(string partNumber, string tpsName, string ofpSwitchPin, string swNo, string testType, string nomen, string model, string system, string refDes, string wuc, string tpm, string tm, string tec) { string refUUID = ""; try { //UUT is a Model Number type Asset. //TODO: Verify that this is correct: UUT - if no model then use part no if (string.IsNullOrWhiteSpace(model)) { model = partNumber; } AssetIdentificationBean asset = DocumentManager.FindAsset("Model", model); if (asset != null) { refUUID = asset.uuid.ToString(); } else { string prompt = string.Format("A UUT was not found for Model Number \"{0}\" - Would you like to create one?", model); if (DialogResult.Yes == MessageBox.Show(prompt, @"V E R I F Y", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { refUUID = UUTController.Instance.Create(partNumber, nomen, model); } } } catch (Exception e) { LogManager.SourceError(ATMLReader.SOURCE, "An error has occurred attempting to save the UUT information.\nError:{0}", e.Message); } return(refUUID); }
protected void SaveAssets(IAtmlObject atmlObject, ItemDescriptionIdentification identification, DocumentDAO dao, string uuid) { if (identification != null) { //----------------------------------------------------------------------------------// //--- Get existing assets for this entity and remove those assets already listed ---// //--- whatever is left over in the list can be deleted. These would be those ---// //--- assets that may have been deleted or renamed. ---// //----------------------------------------------------------------------------------// Dictionary <object, AssetIdentificationBean> existingAssets = dao.GetAssetsByUuid(uuid); var asset = new AssetIdentificationBean(); string modelNo = atmlObject.GetAtmlName(); if (!string.IsNullOrEmpty(modelNo)) { modelNo = modelNo.Trim(); } if (modelNo != null && existingAssets.ContainsKey(modelNo)) { asset.ID = existingAssets[atmlObject.GetAtmlName()].ID; existingAssets.Remove(modelNo); } asset.assetNumber = modelNo; asset.assetType = "Model"; asset.uuid = Guid.Parse(uuid); if (atmlObject.IsDeleted()) { asset.DataState = BASEBean.eDataState.DS_DELETE; } else { asset.DetermineDataState(); } asset.save(); if (identification.IdentificationNumbers != null) { foreach (IdentificationNumber idNumber in identification.IdentificationNumbers) { string type = Enum.GetName(typeof(IdentificationNumberType), idNumber.type); string number = idNumber.number; if (!string.IsNullOrEmpty(number)) { number = number.Trim(); } //-------------------------------------------------------------------------------------------------------------// //--- There is no need to save the asset if the model Number is duplicated as another identification number ---// //-------------------------------------------------------------------------------------------------------------// if (!number.Equals(modelNo)) { asset = new AssetIdentificationBean(); if (existingAssets.ContainsKey(number)) { asset.ID = existingAssets[number].ID; existingAssets.Remove(number); } asset.assetNumber = number; asset.assetType = type; asset.uuid = Guid.Parse(uuid); if (atmlObject.IsDeleted()) { asset.DataState = BASEBean.eDataState.DS_DELETE; } else { asset.DetermineDataState(); } try { asset.save(); } catch (Exception exception) { string msg = exception.Message; throw new Exception( string.Format("Failed adding the identifier \"{0}\" as a new asset. Error: {1}", idNumber, msg.Contains("duplicate") ? "The Identification Number is already assigned to another piece of equipment." : msg)); } } } } //----------------------------------------// //--- Remove Assets no longer attached ---// //----------------------------------------// foreach (AssetIdentificationBean assetBean in existingAssets.Values) { assetBean.DataState = BASEBean.eDataState.DS_DELETE; assetBean.save(); } } }
/** * */ 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 string InitializeTestStaion(string stationType, string station, string changeNo, string dateEntry, string fst) { string refNo = ""; bool usesRF = false; bool usesCNI = false; bool usesEO = false; bool usesHPDTS = false; bool usesSGMA = false; bool isHybrid = false; bool isRTCass = false; bool isECass = false; stationType = stationType.ToUpper(); station = station.ToUpper(); if (string.IsNullOrWhiteSpace(station)) { station = CASS; } if (string.IsNullOrWhiteSpace(stationType)) { stationType = station; } usesRF = stationType.Contains(RF); usesCNI = stationType.Contains(CNI); usesEO = stationType.Contains(EO); usesHPDTS = stationType.Contains(HPDTS); usesSGMA = stationType.Contains(SGMA); isHybrid = stationType.Contains(HYBRID); isRTCass = stationType.Contains(RTCASS); isECass = stationType.Contains(ECASS); if (!isRTCass && stationType.Contains(CASS)) { station = CASS; } else if (isRTCass) { station = RTCASS; } else if (isECass) { station = ECASS; } else if (isHybrid) { station = HYBRID; } if (usesRF) { station = station + "_" + RF; } if (usesCNI) { station = station + "_" + CNI; } if (usesEO) { station = station + "_" + EO; } if (usesHPDTS) { station = station + "_" + HPDTS; } if (usesSGMA) { station = station + "_" + SGMA; } const string assetType = "Model"; const string contentType = "text/xml"; string documentType = Enum.GetName(typeof(dbDocument.DocumentType), dbDocument.DocumentType.TEST_STATION_DESCRIPTION); AssetIdentificationBean asset = DocumentManager.FindAsset(assetType, station); if (asset != null) { refNo = asset.uuid.ToString(); } else { refNo = DocumentManager.CreateDocumentPlaceHolder ( station, //Part Number assetType, //Asset Type contentType, //Content Type documentType, //Document Type station + " 1671.6 Test Station Description" //Description ); var ts = new TestStationDescription11(); ts.Identification = new ItemDescriptionIdentification(); ts.name = station; ts.uuid = refNo; ts.Identification.ModelName = station; Document document = DocumentManager.GetDocument(refNo); document.DocumentContent = Encoding.UTF8.GetBytes(ts.Serialize()); DocumentManager.SaveDocument(document); } return(refNo); }
/** * Lookup the Instrument by the part number and test station in the asset table. */ public static String FindInstrumentReference(string partNumber, string stationId) { string referenceId = ""; try { IAtmlController <TestStationDescription11> controller = AtmlControllerFactory <TestStationDescription11> .Controller; TestStationDescription11 testStation = controller.Find(Guid.Parse(stationId)); if (testStation == null) { throw new Exception(string.Format(ErrorLocatingTestStation, stationId)); } string stationType = testStation.Identification.ModelName; string basePartNumber = partNumber.Split('#')[0]; string fullPartNumber = stationType + "." + basePartNumber; string combinedPartNumber = stationType + "." + partNumber; //--- has "#xxx" string instrumentName = fullPartNumber + ATMLContext.ATML_INSTRUMENT_FILENAME_SUFFIX; //--------------------------------------------------------------------------------------------------------// //--- TODO: Need to adjust this process //--- Strip the #xxx off //--- Prefix it with the station name //--- Check if instrument is in database - if not create a placeholder //--- Get instrument uuid for reference //--- Using the original part number (ie with #xxx) make sure its associated with the test station //--- This will provide quantities of an instrument via #xxx //--------------------------------------------------------------------------------------------------------// //-----------------------------------------// //--- Look for an asset in the database ---// //-----------------------------------------// AssetIdentificationBean asset = DocumentManager.FindAsset(AssetTypePart, combinedPartNumber); if (asset != null) { //-----------------------------// //--- Grab the reference id ---// //-----------------------------// referenceId = asset.uuid.ToString(); } else { //--- Lookup Document by Instrument Id ---// Document document = DocumentManager.GetDocumentByName(instrumentName); if (document == null) { //--- We should only prompt if the base part number is missing ---// referenceId = PromptUserToAddInstrument(basePartNumber, stationType, referenceId); } else { referenceId = document.uuid; CreateAsset(referenceId, combinedPartNumber); } } //-------------------------------------------------------------------------------------------------------// //--- Let see if the test station has a reference to the instrument instance, if no we need to add it ---// //-------------------------------------------------------------------------------------------------------// if (!AtmlControllerFactory <TestStationDescription11> .Controller.HasInstrumentReference(testStation, partNumber)) { //InstrumentDescription instrument = InstrumentController.FindInstrument(partNumber); AtmlControllerFactory <TestStationDescription11> .Controller.AddInstrumentReference(testStation as TestStationDescription11, partNumber, referenceId); } } catch (Exception e) { LogManager.SourceError(ATMLReader.SOURCE, ErrorSavingInstrument, partNumber, e.Message); } return(referenceId); }
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 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); }