Example #1
0
        public void ProcessRequest(HttpContext context)
        {
            string pi = context.Request["pi"] ?? "1", ps = context.Request["ps"] ?? "10";
            int    pageIndex = int.Parse(pi), pageSize = int.Parse(ps);

            context.Response.ContentType = "text/plain";
            string   type       = context.Request["type"];
            Bib1Attr SearchType = Bib1Attr.Title;

            if (type == "1")
            {
                SearchType = Bib1Attr.Author;
            }
            else if (type == "2")
            {
                SearchType = Bib1Attr.ISBN;
            }
            string kw     = context.Request["kw"] ?? "java";
            var    server = new Server("server1");
            int    count  = 0;
            var    tt     = server.GetRecordsMarc(SearchType, kw, pageSize, pageIndex, out count).Select(obj =>
            {
                return(new {
                    Title = obj.Get_Data_Subfield(200, 'a'),
                    Author = obj.Get_Data_Subfield(200, 'f'),
                    ISBN = obj.Get_Data_Subfield(10, 'a'),
                    Year = obj.Get_Data_Subfield(210, 'a')
                });
            });

            context.Response.Write(JsonConvert.SerializeObject(new { list = tt, count = count }));
        }
Example #2
0
 public IEnumerable <MarcRecord> GetRecordsMarc(Bib1Attr attr, string key, int pageSize, int pageIndex, out int count)
 {
     return(_getRecord(attr, key, pageSize, pageIndex, out count)
            .Select(obj =>
     {
         return new MarcRecord(obj.Content);
     }));
 }
Example #3
0
        public ICollection <MarcRecord> GetRecords(Server endpoint, Bib1Attr attr, string key)
        {
            var marcRecords = new Collection <MarcRecord>();

            try
            {
                var parser = new ExchangeFormatParser();

                var connection = new Connection(endpoint.Uri, Convert.ToInt32(endpoint.Port))
                {
                    DatabaseName = endpoint.DatabaseName
                };

                if (!string.IsNullOrEmpty(endpoint.Username))
                {
                    connection.Username = endpoint.Username;
                }

                if (!string.IsNullOrEmpty(endpoint.Password))
                {
                    connection.Password = endpoint.Password;
                }

                connection.Syntax = RecordSyntax.UsMarc;
                var query = new PrefixQuery(Prefix + attr.GetAttributes() + key);

                var records = connection.Search(query);

                if (records.Count == 0)
                {
                    return(marcRecords);
                }

                foreach (IRecord rec in records)
                {
                    var ms = new MemoryStream(rec.Content);

                    try
                    {
                        var marcrec = parser.Parse(ms);
                        marcRecords.Add(marcrec);
                        parser.Close();
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.Message);
                Logger.Error(ex);
            }

            return(marcRecords);
        }
Example #4
0
        private IEnumerable <Record> _getRecord(Bib1Attr attr, string key, int pageSize, int pageIndex, out int count)
        {
            IEnumerable <Record> result = new List <Record>();

            count = 0;
            try
            {
                var connection = new Connection(this.Uri, Convert.ToInt32(this.Port))
                {
                    DatabaseName = this.DatabaseName
                };
                if (!string.IsNullOrEmpty(Username))
                {
                    connection.Username = Username;
                }

                if (!string.IsNullOrEmpty(Password))
                {
                    connection.Password = Password;
                }

                connection.Syntax = RecordSyntax.UsMarc;

                var query = new PrefixQuery(Prefix + attr.GetAttributes() + key);

                ResultSet records = connection.Search(query);
                count = (int)records.Size;
                if (records.Size > 0)
                {
                    int skip = (pageIndex - 1) * pageSize;
                    if (skip + pageSize > records.Size)
                    {
                        skip = (int)records.Size - pageSize;
                    }
                    result = records.Skip(skip).Take(pageSize);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(result);
        }
Example #5
0
 public static string GetAttributes(this Bib1Attr attr)
 {
     return($"@attr 1={(int)attr} ");
 }
Example #6
0
 public IEnumerable <string> GetRecordsJson(Bib1Attr attr, string key, int pageSize, int pageIndex, out int count)
 {
     return(_getRecord(attr, key, pageSize, pageIndex, out count).Select(obj => obj.JsonResult));
 }
Example #7
0
 public SearchQuery(Server server, Bib1Attr attr, string query)
     : this(new[] { server }, attr, query)
 {
 }
Example #8
0
 public SearchQuery(IEnumerable <Server> servers, Bib1Attr attr, string query)
 {
     _servers  = servers;
     _bib1Attr = attr;
     _query    = $"\"{query}\"";
 }
Example #9
0
        public async Task <IDictionary <Server, IEnumerable <string> > > Search(string query, Bib1Attr attr)
        {
            var search = new SearchQuery(Servers, attr, query);
            var found  = await search.Search();

            var result = new Dictionary <Server, IEnumerable <string> >();

            foreach (var pair in found)
            {
                var xmlRecord = new Collection <string>();
                foreach (var marcRecord in pair.Value)
                {
                    xmlRecord.Add(marcRecord.ToMarcXml());
                }
                result.Add(pair.Key, xmlRecord);
            }

            return(result);
        }