Beispiel #1
0
        internal MarcDirectory(string mrcContent, int ldrLength, int dirLength, MarcLeader marcLeader)
        {
            var charList = mrcContent.ToCharArray().ToList().GetRange(ldrLength, dirLength);

            var i = 0;

            string GetNextField(int num)
            {
                var str = string.Join("", charList.GetRange(i, num));

                i += num;
                return(str);
            }

            while (i < charList.Count)
            {
                var entry = new DirFieldEntry();

                //  field tag (3):
                entry.Id = GetNextField(3);

                //  field length (4):
                entry.Length = GetNextField(4);

                //  field start position (5):
                entry.Start = GetNextField(5);

                // get field data ensuring that the length of each extracted field is it's UTF8 byte length not unicode char length. Failure to do this will result in subsequent fields having invalid data:
                var bytes = Encoding.UTF8.GetBytes(mrcContent).ToList().GetRange(int.Parse(marcLeader.BaseAddressOfData) + int.Parse(entry.Start), int.Parse(entry.Length)).ToArray();
                var str   = Encoding.UTF8.GetString(bytes);
                entry.DataChars = str.ToCharArray().ToList();

                DirEntryList.Add(entry);
            }
        }
Beispiel #2
0
        private MarcDirectory ParseDirectory(string mrcContent, MarcLeader mrcLdr)
        {
            const int ldrLength           = 24;
            const int dirTerminatorLength = 1;
            var       dirLength           = int.Parse(mrcLdr.BaseAddressOfData) - ldrLength - dirTerminatorLength;
            var       mrcDir = new MarcDirectory(mrcContent, ldrLength, dirLength, mrcLdr);

            v_RowsDirectory.AddRange(mrcDir.GetDirArray());
            return(mrcDir);
        }
Beispiel #3
0
        private MarcLeader ParseLeader(string recordContent)
        {
            var mrcLdr = new MarcLeader(recordContent);

            // Populate leader table:
            v_RowsLeader.AddRange(mrcLdr.GetLdrArray());
            // Populate fixed fields table:
            v_RowsProps.AddRange(mrcLdr.GetPropertyArray());
            return(mrcLdr);
        }
Beispiel #4
0
        private bool ParseControlFields(MarcLeader mrcLdr, MarcDirectory mrcDir)
        {
            var ctrlSupported   = new[] { "001", "003", "005", "006", "007", "008" };
            var fieldIdList     = mrcDir.DirEntryList.Select(x => x.Id).Where(x => x.StartsWith("00")).ToList();
            var ctrlUnsupported = fieldIdList.Except(ctrlSupported).ToList();

            if (ctrlUnsupported.Count > 0)
            {
                return(false);
            }

            // parse 001:
            var dirEntries001 = mrcDir.DirEntryList.SingleOrDefault(x => x.Id == "001")?.DataChars?.SkipLast(1)?.ToList();  // remove field terminator.

            if (dirEntries001 != null)
            {
                if (dirEntries001.Count != 13 || !dirEntries001.ToString().StartsWith("BIB-"))
                {
                    //throw new c_ParseException("Only predictivebib.org records supported.", c_StatusCode.InvalidCredentials);  // custom exception.
                }
                var mrc001 = new Marc001(dirEntries001);
                v_RowsControl.AddRange(mrc001.GetCtrlArray());
                //v_RowsControl.Add(new[] { "\u2009", "\u2009", "\u2009", "\u2009" });
            }

            // parse 003:
            var dirEntries003 = mrcDir.DirEntryList.SingleOrDefault(x => x.Id == "003")?.DataChars?.SkipLast(1)?.ToList();  // remove field terminator.

            if (dirEntries003 != null)
            {
                var mrc003 = new Marc003(dirEntries003);
                v_RowsControl.AddRange(mrc003.GetCtrlArray());
                //v_RowsControl.Add(new[] { "\u2009", "\u2009", "\u2009", "\u2009" });
            }

            // parse 005:
            var dirEntries005 = mrcDir.DirEntryList.SingleOrDefault(x => x.Id == "005")?.DataChars?.SkipLast(1)?.ToList();  // remove field terminator.

            if (dirEntries005 != null)
            {
                var mrc005 = new Marc005(dirEntries005);
                v_RowsControl.AddRange(mrc005.GetCtrlArray());
                //v_RowsControl.Add(new[] { "\u2009", "\u2009", "\u2009", "\u2009" });
            }

            // parse 006 (repeatable):
            foreach (var dirEntries in mrcDir.DirEntryList.Where(x => x.Id == "006"))
            {
                var dirEntries006 = dirEntries.DataChars?.SkipLast(1)?.ToList();  // remove field terminator.
                if (dirEntries006 != null)
                {
                    var mrc006 = new Marc006(dirEntries006);
                    v_RowsControl.AddRange(mrc006.Material.GetCtrlArray());
                    //v_RowsControl.Add(new[] { "\u2009", "\u2009", "\u2009", "\u2009" });
                }
            }

            // parse 007 (repeatable):
            foreach (var dirEntries in mrcDir.DirEntryList.Where(x => x.Id == "007"))
            {
                var dirEntries007 = dirEntries.DataChars?.SkipLast(1)?.ToList();  // remove field terminator.
                if (dirEntries007 != null)
                {
                    var mrc007 = new Marc007(dirEntries007);
                    v_RowsControl.AddRange(mrc007.Material.GetCtrlArray());
                    //v_RowsControl.Add(new[] { "\u2009", "\u2009", "\u2009", "\u2009" });
                }
            }

            // parse 008:
            var dirEntries008 = mrcDir.DirEntryList.SingleOrDefault(x => x.Id == "008")?.DataChars?.SkipLast(1)?.ToList();  // remove field terminator.

            if (dirEntries008 != null)
            {
                var mrc008 = new Marc008(mrcLdr.materialType, dirEntries008);
                v_RowsControl.AddRange(mrc008.GetCtrlArray());
                //v_RowsVarCtrl.Add(new[] { "\u2009", "\u2009", "\u2009", "\u2009" });
            }

            return(true);
        }