コード例 #1
0
        private MARC_Record GetMarcRecord(String bNumber)
        {
            var    normalised = WellcomeLibraryIdentifiers.GetNormalisedBNumber(bNumber, false);
            var    identifier = WellcomeLibraryIdentifiers.GetShortBNumber(normalised).ToString(CultureInfo.InvariantCulture);
            string msg;
            var    endpoint = new Z3950_Endpoint(Z3950Name, Z3950Host, Z3950Port, Z3950DbName);

            return(MARC_Record_Z3950_Retriever.Get_Record_By_Primary_Identifier(identifier, endpoint, out msg));
        }
コード例 #2
0
        private void importButton_Button_Pressed(object sender, EventArgs e)
        {
            // Check the primary key is provided
            if (identifierTextBox.Text.Trim().Length == 0)
            {
                MessageBox.Show("Enter the primary identifier to import the Z39.50 records.    ", "Missing Primary Identifier", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Check the Z39.50 endpoint
            if (endpoint == null)
            {
                Z3950_Endpoint_Form endpointForm = new Z3950_Endpoint_Form();
                Hide();
                endpointForm.ShowDialog();
                Show();

                endpoint = endpointForm.Endpoint;
                if (endpoint == null)
                {
                    MessageBox.Show("Select a Z39.50 endpoint or enter information for a new or temporary endpoint.     ", "Missing Endpoint", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // Since this was a VALID entry, save this as the last Z39.50 endpoint used
            if ((endpoint.Name != NEW) && (endpoint.Name != TEMP))
            {
                MetaTemplate_UserSettings.Last_Z3950_Endpoint = endpoint.Name;
                MetaTemplate_UserSettings.Save();
            }

            string      identifier        = identifierTextBox.Text.Trim();
            string      out_message       = String.Empty;
            MARC_Record record_from_z3950 = MARC_Record_Z3950_Retriever.Get_Record_By_Primary_Identifier(identifier, endpoint, out out_message);

            if (record_from_z3950 == null)
            {
                if (out_message.Length > 0)
                {
                    MessageBox.Show(out_message, "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Unknown error occurred during request", "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                //MessageBox.Show("Found!!\n\n" + record_from_z3950.To_Machine_Readable_Record());
                Record = record_from_z3950;
            }
            Close();
        }
コード例 #3
0
        private static void demo4()
        {
            Console.WriteLine("Performing demo4 ( z39.50 )");

            try
            {
                // Create the Z39.50 endpoint
                Z3950_Endpoint endpoint = new Z3950_Endpoint("Moravian Library in Brno", "aleph.mzk.cz", 9991, "MZK01-UTF");

                // Retrieve the record by primary identifier
                string      out_message;
                MARC_Record record_from_z3950 = MARC_Record_Z3950_Retriever.Get_Record(/*7*/ 1063, "2610356038" /*"80-85609-28-2"*/, endpoint, out out_message,
                                                                                       Record_Character_Encoding.Unicode);
                //MARC_Record record_from_z3950 = MARC_Record_Z3950_Retriever.Get_Record_By_Primary_Identifier("4543338", endpoint, out out_message);

                // Display any error message encountered
                if (record_from_z3950 == null)
                {
                    if (out_message.Length > 0)
                    {
                        Console.WriteLine(out_message);
                    }
                    else
                    {
                        Console.WriteLine("Unknown error occurred during Z39.50 request");
                    }
                    return;
                }
                Console.WriteLine(record_from_z3950.Get_Data_Subfield(100, 'a'));
                Console.WriteLine(record_from_z3950);
                // Write as MARCXML
                record_from_z3950.Save_MARC_XML("C:\\Temp\\demo4.xml");
            }
            catch (Exception ee)
            {
                Console.WriteLine("EXCEPTION CAUGHT while performing Z39.50 demo. ( " + ee.Message + " )");
            }
        }
コード例 #4
0
        // Retrieves metadata from Z39.50 server
        private static IList <Metadata> RetrieveMetadataByZ39(IdentifierType identifierType, string value, bool isUnion)
        {
            string z39Server   = Settings.Z39ServerUrl;
            int    z39Port     = Settings.Z39Port;
            string z39Base     = Settings.Z39Base;
            string z39UserName = Settings.Z39UserName;
            string z39Password = Settings.Z39Password;
            Record_Character_Encoding z39Encoding = Settings.Z39Encoding;

            //Set union Z39.50
            if (isUnion)
            {
                z39Server   = Settings.Z39UnionServerUrl;
                z39Port     = Settings.Z39UnionPort;
                z39Base     = Settings.Z39UnionBase;
                z39Encoding = Settings.Z39UnionEncoding;
                z39UserName = null;
                z39Password = null;
            }

            int identifierFieldNumber;

            switch (identifierType)
            {
            case IdentifierType.BARCODE:
                identifierFieldNumber = Settings.Z39BarcodeField;
                break;

            case IdentifierType.CNB:
                if (isUnion)
                {
                    identifierFieldNumber = Settings.DEFAULT_NKP_CNB_FIELD;
                }
                else
                {
                    identifierFieldNumber = Settings.Z39CnbField;
                }
                break;

            case IdentifierType.EAN:
                identifierFieldNumber = Settings.Z39EanField;
                break;

            case IdentifierType.ISBN:
                identifierFieldNumber = Settings.Z39IsbnField;
                break;

            case IdentifierType.ISSN:
                identifierFieldNumber = Settings.Z39IssnField;
                break;

            case IdentifierType.ISMN:
                identifierFieldNumber = Settings.Z39IsmnField;
                break;

            case IdentifierType.OCLC:
                identifierFieldNumber = Settings.Z39OclcField;
                break;

            default:
                identifierFieldNumber = Settings.DEFAULT_FIELD;
                break;
            }

            //validate
            string errorText = "";

            if (string.IsNullOrEmpty(z39Server))
            {
                errorText += "Z39.50 Server URL; ";
            }
            if (z39Port <= 0)
            {
                errorText += "Z39.50 Sever Port; ";
            }
            if (string.IsNullOrEmpty(z39Base))
            {
                errorText += "Z39.50 Databáze; ";
            }
            if (identifierFieldNumber <= 0)
            {
                errorText += "Vyhledávací atribut";
            }

            if (!string.IsNullOrEmpty(errorText))
            {
                throw new ArgumentException("V nastaveních chybí následující údaje: " + errorText);
            }

            List <Metadata> metadataList = new List <Metadata>();
            string          errorMessage = "";

            try
            {
                Z3950_Endpoint endpoint;
                if (string.IsNullOrEmpty(z39UserName))
                {
                    endpoint = new Z3950_Endpoint("Z39.50",
                                                  z39Server, (uint)z39Port, z39Base);
                }
                else
                {
                    endpoint = new Z3950_Endpoint("Z39.50",
                                                  z39Server, (uint)z39Port, z39Base, z39UserName);
                    endpoint.Password = z39Password ?? "";
                }

                // Retrieve the record by primary identifier
                IEnumerable <MARC_Record> recordsFromZ3950 = MARC_Record_Z3950_Retriever.Get_Record(
                    identifierFieldNumber, '"' + value + '"', endpoint, out errorMessage, z39Encoding);

                MARCXML_Writer marcXmlWriter = new MARCXML_Writer(System.IO.Path.Combine(Settings.TemporaryFolder, "marcxml.xml"));

                if (recordsFromZ3950 != null)
                {
                    foreach (MARC_Record record in recordsFromZ3950)
                    {
                        Metadata metadata = new Metadata();
                        // Sysno
                        metadata.Sysno          = record.Control_Number;
                        metadata.FixedFields    = MarcGetFixedFields(record);
                        metadata.VariableFields = MarcGetVariableFields(record);

                        // Get identifiers list (ISBNs + 902a yearbooks)
                        List <MetadataIdentifier> Identifiers = getIdentifiersList(metadata);
                        metadata.Identifiers = Identifiers;

                        // Add to list
                        metadataList.Add(metadata);

                        // Write to MARC XML file
                        marcXmlWriter.AppendRecord(record);
                    }

                    // Finish MARC XML file
                    marcXmlWriter.Close();
                }
            }
            catch (Exception e)
            {
                throw new Z39Exception("Nastala chyba během stahování MARC záznamu pomocí Z39.50, nebo zápisu výsledného MARC záznamu na disk. Detailnější popis problému: " + e.Message);
            }

            // Display any error message encountered
            if (metadataList.Count == 0)
            {
                if (errorMessage.Length > 0)
                {
                    if (errorMessage.Contains("No matching record found in Z39.50 endpoint"))
                    {
                        errorMessage = "Nenalezen vhodný záznam.";
                    }

                    else if (errorMessage.Contains("Connection could not be made to"))
                    {
                        errorMessage = "Nebylo možné navázat spojení s " +
                                       errorMessage.Substring(errorMessage.LastIndexOf(' '));
                    }

                    throw new Z39Exception(errorMessage);
                }
                else
                {
                    throw new Z39Exception("Nastala neznámá chyba během Z39.50 dotazu");
                }
            }
            return(metadataList);
        }
コード例 #5
0
        // Retrieves metadata from Z39.50 server
        private void RetrieveMetadataByBarcodeZ39()
        {
            string z39Server   = Settings.Z39ServerUrl;
            int    z39Port     = Settings.Z39Port;
            string z39Base     = Settings.Z39Base;
            string z39UserName = Settings.Z39UserName;
            string z39Password = Settings.Z39Password;
            Record_Character_Encoding z39Encoding = Settings.Z39Encoding;
            int z39BarcodeField = Settings.Z39BarcodeField;

            //validate
            string errorText = "";

            if (string.IsNullOrEmpty(z39Server))
            {
                errorText += "Z39.50 Server URL; ";
            }
            if (z39Port <= 0)
            {
                errorText += "Z39.50 Sever Port; ";
            }
            if (string.IsNullOrEmpty(z39Base))
            {
                errorText += "Z39.50 Databáze; ";
            }
            if (z39BarcodeField <= 0)
            {
                errorText += "Vyhledávací atribut";
            }

            if (!string.IsNullOrEmpty(errorText))
            {
                throw new ArgumentException("V nastaveních chybí následující údaje: " + errorText);
            }

            string errorMessage = "";

            try
            {
                Z3950_Endpoint endpoint;
                if (string.IsNullOrEmpty(z39UserName))
                {
                    endpoint = new Z3950_Endpoint("Z39.50",
                                                  z39Server, (uint)z39Port, z39Base);
                }
                else
                {
                    endpoint = new Z3950_Endpoint("Z39.50",
                                                  z39Server, (uint)z39Port, z39Base, z39UserName);
                    endpoint.Password = z39Password ?? "";
                }

                // Retrieve the record by primary identifier
                MARC_Record record_from_z3950 = MARC_Record_Z3950_Retriever.Get_Record(
                    z39BarcodeField, this.barcode, endpoint, out errorMessage, z39Encoding);

                if (record_from_z3950 != null)
                {
                    Metadata metadata = new Metadata();
                    // Sysno
                    metadata.Sysno = record_from_z3950.Control_Number;
                    // Custom identifier
                    if (!string.IsNullOrWhiteSpace(metadata.Sysno))
                    {
                        metadata.Custom = Settings.Base + metadata.Sysno;
                    }
                    // Title
                    foreach (var field in Settings.MetadataTitleFields)
                    {
                        if (!record_from_z3950.has_Field(field.Key))
                        {
                            continue;
                        }
                        foreach (var subfield in field.Value)
                        {
                            metadata.Title += record_from_z3950.Get_Data_Subfield(field.Key, subfield).TrimEnd('/', ' ') + " ";
                        }
                    }
                    // Authors
                    string authors = "";
                    foreach (var field in Settings.MetadataAuthorFields)
                    {
                        if (!record_from_z3950.has_Field(field.Key))
                        {
                            continue;
                        }
                        List <MARC_Field> authorFields = record_from_z3950.Fields[field.Key];
                        foreach (var authorField in authorFields)
                        {
                            foreach (var subfield in field.Value)
                            {
                                MARC_Subfield authorSubfield = authorField.Subfields_By_Code(subfield).FirstOrDefault();
                                authors += authorSubfield == null ? "" : authorSubfield.Data;
                                authors += "@";
                            }
                            authors = authors.Trim() + "|";
                        }
                    }
                    metadata.Authors = ParseAuthors(authors, '@');
                    // Publish year
                    metadata.Year = GetZ39Subfields(record_from_z3950, Settings.MetadataPublishYearField.Item1,
                                                    Settings.MetadataPublishYearField.Item2);
                    // ISBN
                    metadata.ISBN = GetNormalizedISBN(GetZ39Subfields(record_from_z3950, Settings.MetadataIsbnField.Item1,
                                                                      Settings.MetadataIsbnField.Item2));
                    if (metadata.ISBN.Contains('|'))
                    {
                        Warnings.Add("Záznam obsahuje více než 1 ISBN, vyberte správné, jsou oddělena zvislou čárou.");
                    }
                    // ISSN
                    metadata.ISSN = GetNormalizedISSN(GetZ39Subfields(record_from_z3950, Settings.MetadataIssnField.Item1,
                                                                      Settings.MetadataIssnField.Item2));
                    if (metadata.ISSN.Contains('|'))
                    {
                        Warnings.Add("Záznam obsahuje více než 1 ISSN, vyberte správné, jsou oddělena zvislou čárou.");
                    }
                    // CNB
                    metadata.CNB = GetZ39Subfields(record_from_z3950, Settings.MetadataCnbField.Item1, Settings.MetadataCnbField.Item2);
                    if (metadata.CNB.Contains('|'))
                    {
                        Warnings.Add("Záznam obsahuje více než 1 ČNB, vyberte správné, jsou oddělena zvislou čárou.");
                    }
                    // OCLC
                    metadata.OCLC = GetZ39Subfields(record_from_z3950, Settings.MetadataOclcField.Item1, Settings.MetadataOclcField.Item2);
                    if (metadata.OCLC.Contains('|'))
                    {
                        Warnings.Add("Záznam obsahuje více než 1 OCLC, vyberte správné, jsou oddělena zvislou čárou.");
                    }
                    // EAN
                    string ean = "";
                    if (record_from_z3950.has_Field(Settings.MetadataEanField.Item1))
                    {
                        List <MARC_Field> eanFields = record_from_z3950.Fields[Settings.MetadataEanField.Item1];
                        foreach (var eanField in eanFields)
                        {
                            if (eanField.Indicator1 != Settings.MetadataEanField.Item3)
                            {
                                continue;
                            }
                            if (eanField.has_Subfield(Settings.MetadataEanField.Item2))
                            {
                                foreach (var eanSubfield in eanField.Subfields_By_Code(Settings.MetadataEanField.Item2))
                                {
                                    ean += eanSubfield.Data + "|";
                                }
                            }
                        }
                    }
                    ean = ean.TrimEnd('|');
                    if (!string.IsNullOrWhiteSpace(ean))
                    {
                        metadata.EAN = ean;
                        if (metadata.EAN.Contains('|'))
                        {
                            this.Warnings.Add("Záznam obsahuje více než 1 EAN, vyberte správné, jsou oddělena zvislou čárou");
                        }
                    }

                    metadata.FixedFields    = MarcGetFixedFields(record_from_z3950);
                    metadata.VariableFields = MarcGetVariableFields(record_from_z3950);

                    this.Metadata = metadata;
                }
            }
            catch (Exception)
            {
                throw new Z39Exception("Nastala neočekávaná chyba během Z39.50 dotazu.");
            }
            // Display any error message encountered
            if (this.Metadata == null)
            {
                if (errorMessage.Length > 0)
                {
                    if (errorMessage.Contains("No matching record found in Z39.50 endpoint"))
                    {
                        errorMessage = "Nenalezen vhodný záznam.";
                    }

                    else if (errorMessage.Contains("Connection could not be made to"))
                    {
                        errorMessage = "Nebylo možné navázat spojení s " +
                                       errorMessage.Substring(errorMessage.LastIndexOf(' '));
                    }

                    throw new Z39Exception(errorMessage);
                }
                else
                {
                    throw new Z39Exception("Nastala neznámá chyba během Z39.50 dotazu");
                }
            }
        }