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 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(); } } }
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); }
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 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); }