ATMLEquipmentLibrary.controls.EquipmentLibraryControl.ImportInstrumentDocument C# (CSharp) Method

ImportInstrumentDocument() private method

private ImportInstrumentDocument ( ) : void
return void
        private void ImportInstrumentDocument()
        {
            try
            {
                bool ok2Save = true;
                String xmlContent;
                //---------------------//
                //--- Open the file ---//
                //---------------------//
                if (FileManager.OpenXmlFile( out xmlContent ))
                {
                    var dataState = BASEBean.eDataState.DS_ADD;
                    var document = new Document();
                    InstrumentDescription instrumentDescription = null;
                    //---------------------------------------------------------------------------------------//
                    //--- Check that its a valid Instrument Description document by trying to Marshall it ---//
                    //---------------------------------------------------------------------------------------//
                    try
                    {
                        instrumentDescription = InstrumentDescription.Deserialize( xmlContent );
                    }
                    catch (Exception err)
                    {
                        throw new Exception( string.Format( Resources.Invalid_Instrument_Description_File___0_,
                                                            err.Message ) );
                    }

                    //------------------------------------------------------------------------------------------------//
                    //--- Next check to see if the uuid already exists - if so ask if the user wants to replace it ---//
                    //------------------------------------------------------------------------------------------------//
                    String uuid = instrumentDescription.uuid;
                    if (DocumentManager.HasDocument( uuid ))
                    {
                        ok2Save = false;
                        if (DialogResult.Yes ==
                            MessageBox.Show(
                                Resources
                                    .This_Instrument_already_exists__would_you_like_to_overwrite_the_existing_Instrument_Description_,
                                Resources.Q_U_E_S_T_I_O_N,
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question ))
                        {
                            document = DocumentManager.GetDocument( uuid );
                            dataState = BASEBean.eDataState.DS_EDIT;
                            ok2Save = true;
                        }
                    }

                    //-------------------------//
                    //--- Save the document ---//
                    //-------------------------//
                    if (ok2Save)
                    {
                        SaveInstrumentDescriptionDocument( instrumentDescription, document, dataState );
                        //-----------------------------------------//
                        //--- If Addin new then add to the list ---//
                        //-----------------------------------------//
                        if (dataState == BASEBean.eDataState.DS_ADD)
                        {
                            AddDocumentToInstrumentList( document );
                        }
                        else
                        {
                            //-------------------------------------------------------------------//
                            //--- otherwise, find the existing doc in the list and replace it ---//
                            //-------------------------------------------------------------------//
                            UpdateExistingDocumentInList( document, uuid );
                        }
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show( err.Message );
            }
        }