Пример #1
0
        public ListIdentifier ListIdentifiers(string sPrefix,
            string sset,
            string sfrom,
            string suntil,
            ResumptionToken objToken)
        {
            System.IO.Stream objStream;
            ListIdentifier objList = new ListIdentifier();
            Identifiers objRecord;
            ResumptionToken myToken;
            string tmp = "";
            System.Net.HttpWebRequest wr;
            System.Xml.XmlTextReader rd;

            if (sPrefix.Length == 0)
            {
                sPrefix = "oai_dc";
            }

            if (objToken == null)
            {
                if (sset.Length != 0)
                {
                    sset = "&set=" + sset;
                }
                if (sfrom.Length != 0)
                {
                    sfrom = "&from=" + sfrom;
                }
                if (suntil.Length != 0)
                {
                    suntil = "&until=" + suntil;
                }

                prequestURL = baseURL + "?verb=ListIdentifiers&metadataPrefix=" + sPrefix + sset + sfrom + suntil;

            }
            else
            {
                prequestURL = baseURL + "?verb=ListIdentifiers&resumptionToken=" + objToken.resumptionToken;
                //This is where we handle the resumptionToken
            }
            //======================================================
            // If you wanted to support additional metadata formats,
            // you would just need to have additional handlers.
            //======================================================
            //Console.Write(sURL);
            try
            {
                wr = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(prequestURL);
                wr.UserAgent = cUserAgent;
                System.Net.WebResponse response = wr.GetResponse();
                objStream = response.GetResponseStream();
                System.IO.StreamReader reader = new System.IO.StreamReader(objStream);
                prawXML = reader.ReadToEnd();
                reader.Close();
                rd = new System.Xml.XmlTextReader(prawXML, System.Xml.XmlNodeType.Document, null);
            }
            catch (Exception e)
            {
                error.errorName = "badConnection";
                error.errorDescription = e.Message + "<br>Unable to connect to " + baseURL;
                return null;
            }

            while (rd.Read())
            {
                if (rd.NodeType == System.Xml.XmlNodeType.Element)
                {
                    if (rd.Name == "responseDate")
                    {
                        presponseDate = rd.ReadString();
                    }
                    else if (rd.Name == "ListIdentifiers")
                    {
                        do
                        {
                            if (rd.Name == "header")
                            {
                                tmp = rd.ReadOuterXml();
                                //tmp += ParseOAIContainer(ref rd, "header", true);
                                //Console.WriteLine("In the Function: " + tmp);
                                objRecord = new Identifiers(tmp);
                                objList.record.Add(objRecord);
                                //return objRecord;
                            }
                            else if (rd.Name == "resumptionToken")
                            {
                                tmp = rd.ReadOuterXml();
                                myToken = new ResumptionToken(tmp);
                                objList.token = myToken;
                            }
                            else rd.Read(); // Added the Read() and will never occur with the ReadInnerXml()

                        } while (rd.Name != "ListIdentifiers"); // loop
                    }
                    else if (rd.Name == "error")
                    {
                        error.errorName = rd.GetAttribute("code");
                        error.errorDescription = rd.ReadString();
                        rd.Close();
                        return null;
                    }
                }
            }

            rd.Close();
            return objList;
        }
Пример #2
0
 public ListIdentifier ListIdentifiers(ResumptionToken objToken)
 {
     return ListIdentifiers("", "", "", "", objToken);
 }
Пример #3
0
        public ListSet ListSets(ResumptionToken objToken, ref Object objHandler)
        {
            System.IO.Stream objStream;
            OAI_LIST objRecord;
            ListSet objList = new ListSet();
            ResumptionToken myToken;
            string tmp = "";
            System.Net.HttpWebRequest wr;
            System.Xml.XmlTextReader rd;

            if (objToken == null)
            {
                prequestURL = baseURL + "?verb=ListSets";
            }
            else
            {
                prequestURL = baseURL + "?verb=ListSets&resumptionToken=" + objToken.resumptionToken;
                //This is where we handle the resumptionToken
            }
            //======================================================
            // If you wanted to support additional metadata formats,
            // you would just need to have additional handlers.
            //======================================================

            try
            {
                wr = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(prequestURL);
                wr.UserAgent = cUserAgent;
                System.Net.WebResponse response = wr.GetResponse();
                objStream = response.GetResponseStream();
                System.IO.StreamReader reader = new System.IO.StreamReader(objStream);
                prawXML = reader.ReadToEnd();
                reader.Close();
                rd = new System.Xml.XmlTextReader(prawXML, System.Xml.XmlNodeType.Document, null);
            }
            catch (Exception e)
            {
                error.errorName = e.ToString();
                error.errorDescription = e.Message + "\n<br>Unable to connect to " + baseURL;
                return null;
            }

            while (rd.Read())
            {
                if (rd.NodeType == System.Xml.XmlNodeType.Element)
                {
                    if (rd.Name == "responseDate")
                    {
                        presponseDate = rd.ReadString();
                    }
                    else if (rd.Name == "ListSets")
                    {
                        //while (rd.Read())
                        do
                        {
                            if (rd.Name == "set")
                            {
                                objRecord = new OAI_LIST(rd.ReadInnerXml(), ref objHandler);
                                objList.listset.Add(objRecord);
                                //return objRecord;
                            }
                            else if (rd.Name == "resumptionToken")
                            {
                                tmp = rd.ReadOuterXml();
                                myToken = new ResumptionToken(tmp);
                                objList.token = myToken;
                            }
                            else rd.Read(); // Added the Read() and will never occur with the ReadInnerXml()

                        } while (rd.Name != "ListSets"); // loop
                    }
                    else if (rd.Name == "error")
                    {
                        error.errorName = rd.GetAttribute("code");
                        error.errorDescription = rd.ReadString();
                        return null;
                    }
                }
            }

            rd.Close();
            return objList;
        }
Пример #4
0
 //=========================================================
 // Sub/Function: ListSets
 // Description: Returns a list of collections currently
 // available for harvesting from this oai server.
 //==========================================================
 public ListSet ListSets(ResumptionToken objToken)
 {
     object objHandler = new object();
     objHandler = new OAI_DC();
     return ListSets(objToken, ref objHandler);
 }
Пример #5
0
 // McCown
 public ListRecord ListRecords(string sPrefix, string sset, string sfrom, string suntil, ResumptionToken objToken)
 {
     object objHandler = new object();
     objHandler = new OAI_DC();
     return ListRecords(sPrefix, sset, sfrom, suntil, objToken, ref objHandler);
 }
Пример #6
0
 public ListRecord ListRecords(ResumptionToken objToken)
 {
     object objHandler = new object();
     objHandler = new OAI_DC();
     return ListRecords("", "", "", "", objToken, ref objHandler);
 }