Inheritance: ATMLDataAccessLibrary.db.beans.DocumentBean
コード例 #1
0
        public DocumentLibrarySelectionForm( List<string> selectedDocumentIds, dbDocument.DocumentType documentType )
        {
            InitializeComponent();

            cmbDocumentType.DataSource = Enum.GetNames(typeof(dbDocument.DocumentType));
            DocumentType = documentType;
            cmbDocumentType.SelectedIndex = cmbDocumentType.FindStringExact(Enum.GetName(typeof(dbDocument.DocumentType), documentType));

            Closing += DocumentLibrarySelectionForm_Closing;
            Load += DocumentLibrarySelectionForm_Load;
            documentLibraryListControl.DoubleClick += documentLibraryListControl_DoubleClick;
            documentLibraryListControl.Items.Clear();
            documentLibraryListControl.DefaultDocumentType = documentType;
            List<Document> documents = DocumentManager.GetDocumentsByType( (int) documentType );
            foreach (Document document in documents)
            {
                //--------------------------------------------------------------------------------------//
                //--- Only add to the Library List if the document is not already selected in a list ---//
                //--------------------------------------------------------------------------------------//
                //INFO: This may not work because an instrument may have multiple instances
                //if (selectedDocumentIds.Find( s => s == document.uuid ) == null)
                    documentLibraryListControl.AddListViewObject( document );
            }
        }
コード例 #2
0
ファイル: Common.cs プロジェクト: UtrsSoftware/ATMLWorkBench
 public Document(dbDocument document)
 {
     if (document != null)
     {
         ContentType = document.contentType;
         name = document.documentName;
         DocumentContent = document.documentContent;
         if (document.documentTypeId != null) DocumentType = (dbDocument.DocumentType) document.documentTypeId;
         Description = document.documentDescription;
         uuid = document.UUID.ToString();
         version = document.documentVersion;
         if (document.contentType != null && document.contentType.Contains("text"))
         {
             Item = Encoding.UTF8.GetString(document.documentContent);
             ItemElementName = DocumentItemChoiceType.Text;
         }
         else
         {
             var document_uri = (string) ATMLContext.GetProperty("environment.document-location");
             Item = document_uri + "?id=" + uuid;
             ItemElementName = DocumentItemChoiceType.URL;
         }
     }
 }
コード例 #3
0
        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;
                    }
                }
            }
        }
コード例 #4
0
        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" );
        }
コード例 #5
0
 public static bool IsEditableDocumentType( dbDocument.DocumentType documentType )
 {
     bool editable = false;
     var bean = CacheManager.GetDocumentTypeCache().getItem( "" + (int) documentType ) as LuDocumentTypeBean;
     if (bean != null && bean.objectEditable != null)
         editable = bean.objectEditable.Value;
     return editable;
 }
コード例 #6
0
 private static Document GetDocument(dbDocument document, string xml)
 {
     var doc = new Document();
     doc.uuid = document.UUID.ToString();
     doc.name = document.documentName;
     doc.version = document.documentVersion;
     doc.DocumentContent = Encoding.UTF8.GetBytes(xml);
     doc.ContentType = DocumentManager.GetContentType(".xml");
     return doc;
 }
コード例 #7
0
 private void btnImportCapabilityDocument_Click(object sender, EventArgs e)
 {
     String xml;
     String fileName;
     DocumentDAO dao = DataManager.getDocumentDAO();
     if (FileManager.OpenXmlFile(out xml, out fileName))
     {
         Capabilities1 capabilities = Capabilities1.Deserialize(xml);
         String uuid = capabilities.uuid;
         String name = capabilities.name;
         String version = capabilities.version;
         var document = new dbDocument();
         bool isNew = !dao.hasDocument(uuid);
         _documentReference.DocumentContent = Encoding.UTF8.GetBytes(xml);
         _documentReference.DocumentType = dbDocument.DocumentType.CAPABILITY_LIBRARY;
         _documentReference.DocumentName = document.documentName;
         _documentReference.ContentType = document.contentType;
         if (capabilityListControl.InstrumentDescription != null
             && !capabilityListControl.InstrumentDescription.HasDoument(document.UUID.ToString()))
         {
             Document doc = GetDocument(document, xml);
             capabilityListControl.InstrumentDescription.AddDocument(doc);
         }
         else if (capabilityListControl.TestAdapterDescription != null
                  && !capabilityListControl.TestAdapterDescription.HasDoument(document.UUID.ToString()))
         {
             Document doc = GetDocument(document, xml);
             capabilityListControl.TestAdapterDescription.AddDocument(doc);
         }
         else if (capabilityListControl.TestStationDescription != null
                  && !capabilityListControl.TestStationDescription.HasDoument(document.UUID.ToString()))
         {
             Document doc = GetDocument(document, xml);
             capabilityListControl.TestStationDescription.AddDocument(doc);
         }
     }
 }
コード例 #8
0
 public DocumentForm( dbDocument.DocumentType documentType )
     : this()
 {
     SelectDocumentType( documentType );
 }
コード例 #9
0
 private void SelectDocumentType( dbDocument.DocumentType documentType )
 {
     foreach (DocumentType type in cmbDocumentType.Items)
     {
         if (type.typeId == (int) documentType)
             cmbDocumentType.SelectedItem = type;
     }
 }
コード例 #10
0
 /**
  * Call this method to save the document data to the database.
  */
 private static void SaveInstrumentDescriptionDocument( InstrumentDescription instrumentDescription,
     Document document,
     BASEBean.eDataState dataState)
 {
     var dbDocument = new dbDocument();
     String xml = instrumentDescription.Serialize();
     document.DocumentContent = dbDocument.documentContent = Encoding.UTF8.GetBytes( xml );
     dbDocument.documentSize = xml.Length;
     document.ContentType = dbDocument.contentType = ATMLContext.CONTEXT_TYPE_XML;
     dbDocument.DataState = dataState;
     if (dataState == BASEBean.eDataState.DS_ADD)
         dbDocument.dateAdded = DateTime.UtcNow;
     else if (dataState == BASEBean.eDataState.DS_EDIT)
         dbDocument.dateUpdated = DateTime.UtcNow;
     document.Description = dbDocument.documentDescription = instrumentDescription.Description;
     dbDocument.documentTypeId = (int) dbDocument.DocumentType.INSTRUMENT_DESCRIPTION;
     document.DocumentType = dbDocument.DocumentType.INSTRUMENT_DESCRIPTION;
     document.version = dbDocument.documentVersion = instrumentDescription.version;
     document.name = dbDocument.documentName = instrumentDescription.Identification.ModelName;
     dbDocument.UUID = Guid.Parse( instrumentDescription.uuid );
     document.uuid = instrumentDescription.uuid;
     dbDocument.save();
 }
コード例 #11
0
        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();
            }
        }