public static Trace ( String message ) : void | ||
message | String | |
Résultat | void |
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 void SaveDocument(DocumentReference docRef) { bool newDocument = false; if (String.IsNullOrEmpty(docRef.uuid)) { docRef.uuid = Guid.NewGuid().ToString(); } //-------------------------------------------------// //--- We will save to the database at this time ---// //-------------------------------------------------// DocumentDAO documentDAO = DataManager.getDocumentDAO(); var document = new dbDocument(); if (documentDAO.hasDocument(docRef.uuid)) { document = documentDAO.openDatabaseDocument(docRef.uuid); document.DataState = BASEBean.eDataState.DS_EDIT; document.dateUpdated = DateTime.UtcNow; } else { document.DataState = BASEBean.eDataState.DS_ADD; document.dateAdded = DateTime.UtcNow; newDocument = true; } document.documentContent = docRef.DocumentContent; document.documentName = docRef.DocumentName; document.documentSize = docRef.DocumentContent.Length; document.contentType = docRef.ContentType; document.save(); LogManager.Trace("Referenced Document {0} has been {1}", document.documentName, newDocument ? "Added" : "Saved"); }
public static void SaveDocument(Document doc) { bool hasLocalTransaction = false; //------------------------------------------------------------// //--- Only save to the database if the content is not null ---// //------------------------------------------------------------// BASEBean.eDataState stateId; if (doc.DocumentContent != null) { if (String.IsNullOrEmpty(doc.uuid)) { doc.uuid = Guid.NewGuid().ToString(); } //-------------------------------------------------// //--- We will save to the database at this time ---// //-------------------------------------------------// DocumentDAO documentDAO = DataManager.getDocumentDAO(); try { if (!documentDAO.IsInTransaction) { documentDAO.StartTransaction(); hasLocalTransaction = true; } var document = new dbDocument(); bool hasDocumentByUuid = documentDAO.hasDocument(doc.uuid); bool hasDocumentByName = documentDAO.hasDocument(doc.name, (int)doc.DocumentType); if (hasDocumentByName != hasDocumentByUuid) { string msg = "There is an inconsistancy with the document uuid and the internal uuid for the device, please correct."; MessageBox.Show(msg, @"E R R O R"); throw new Exception(msg); } if (hasDocumentByUuid) { document = documentDAO.openDatabaseDocument(doc.uuid); stateId = document.DataState = (doc.DataState == BASEBean.eDataState.DS_DELETE ? BASEBean.eDataState.DS_DELETE : BASEBean.eDataState.DS_EDIT); document.dateUpdated = DateTime.UtcNow; } else { stateId = document.DataState = BASEBean.eDataState.DS_ADD; document.dateAdded = DateTime.UtcNow; } int assetsDeleted = 0; if (stateId == BASEBean.eDataState.DS_DELETE) { if (documentDAO.HasAssets(doc.uuid)) { assetsDeleted = documentDAO.DeleteAssets(doc.uuid); } } document.UUID = Guid.Parse(doc.uuid); document.documentDescription = doc.Description; document.documentTypeId = (int)doc.DocumentType; document.documentContent = doc.DocumentContent; document.documentName = doc.name; document.documentSize = doc.DocumentContent.Length; document.contentType = doc.ContentType; document.crc = doc.Crc32; document.save(); if (hasLocalTransaction) { documentDAO.CommitTransaction(); } LogManager.Trace("Document {0} has been {1}", document.documentName, stateId == BASEBean.eDataState.DS_ADD ? "Added" : stateId == BASEBean.eDataState.DS_DELETE ? "Deleted" : "Saved"); if (assetsDeleted > 0) { LogManager.Trace("Deleted {0} associated assets.", assetsDeleted); } if (document.DataState == BASEBean.eDataState.DS_ADD) { document.DataState = BASEBean.eDataState.DS_EDIT; } } catch (Exception e) { if (hasLocalTransaction) { documentDAO.RollbackTransaction(); LogManager.Error(e); } else { throw; } } } }