コード例 #1
0
ファイル: oai.cs プロジェクト: reeset/oai.cs
		//=========================================================
		// 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);
		}
コード例 #2
0
ファイル: oai.cs プロジェクト: reeset/oai.cs
		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;			
		}
コード例 #3
0
ファイル: oai.cs プロジェクト: reeset/oai.cs
		public ListIdentifier ListIdenifiers(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;			
		}
コード例 #4
0
ファイル: oai.cs プロジェクト: reeset/oai.cs
		public ListIdentifier ListIdenifiers(ResumptionToken objToken) 
		{
			return ListIdenifiers("", "", "", "", objToken);
		}
コード例 #5
0
ファイル: oai.cs プロジェクト: reeset/oai.cs
		public ListRecord ListRecords(string sPrefix, 
			string sset, 
			string sfrom, 
			string suntil, 
			ResumptionToken objToken, 
			ref Object objHandler) 
		{
            int fail = 0;
            Restart:
			System.IO.Stream objStream;
			ListRecord objList = new ListRecord();
			Record objRecord;
			ResumptionToken myToken;
			string tmp = "";
			System.Net.HttpWebRequest wr = null;
            System.Xml.XmlTextReader rd = null;

			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=ListRecords&metadataPrefix=" + sPrefix + sset + sfrom + suntil;

			} 
			else 
			{
				//This is where we handle the resumptionToken - McCown
				prequestURL = baseURL + "?verb=ListRecords&resumptionToken=" + objToken.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.Headers.Add("Host:" + System.Net.Dns.GetHostName());
                wr.UserAgent = cUserAgent + DateTime.Now.ToString();

                if (this.Timeout <= 0) { this.Timeout = 100000; }
                wr.Timeout = this.Timeout;

                System.Net.WebResponse response = wr.GetResponse();
                objStream = response.GetResponseStream();
                System.IO.StreamReader reader = new System.IO.StreamReader(objStream);
                prawXML = reader.ReadToEnd();
                //System.Windows.Forms.MessageBox.Show(prawXML);
                reader.Close();
                response.Close();
                rd = new System.Xml.XmlTextReader(prawXML, System.Xml.XmlNodeType.Document, null);
                rd.Normalization = true;
            }
            catch (System.Net.WebException ee)
            {
                int sleepval = 3000;
                
                fail++;
                //System.Windows.Forms.MessageBox.Show(tt.ToString());
                //System.Windows.Forms.MessageBox.Show(ee.ToString());
                if (ee.Status == System.Net.WebExceptionStatus.ProtocolError)
                {
                    var response = ee.Response as System.Net.HttpWebResponse;
                    if (response != null)
                    {
                        if ((int)response.StatusCode == 503)
                        {
                            string retryafter = response.Headers["Retry-After"];
                            if (retryafter != null && IsNumeric(retryafter) == true)
                            {
                                {
                                    sleepval = System.Convert.ToInt32(retryafter) * 1000;
                                }
                            }
                        }
                    }

                    if (fail <= 4)
                    {
                        //System.Windows.Forms.MessageBox.Show(sleepval.ToString());
                        System.Threading.Thread.Sleep(sleepval);
                        goto Restart;
                    }
                    else
                    {
                        wr.Abort();
                        error.errorName = ee.ToString();
                        error.errorDescription = ee.Message + "\n<br>Unable to connect to " + baseURL;
                        return null;
                    }
                }
            }
            catch (Exception e)
            {
               // System.Windows.Forms.MessageBox.Show("2");
                if (wr != null)
                {
                    wr.Abort();
                }
                error.errorName = e.ToString();
                error.errorDescription = e.Message + "\n<br>Unable to connect to " + baseURL;
                return null;
            }

            fail = 0;
			while (rd.Read()) 
			{
				if (rd.NodeType == System.Xml.XmlNodeType.Element) 
				{
					if (rd.Name == "responseDate")
					{
						presponseDate = rd.ReadString();
					}
					else if (rd.Name=="ListRecords") 
					{ 
						do 
						{
                            
							if (rd.Name=="record") 
							{
								tmp = ParseOAIContainer(ref rd, "record");
								objRecord = new Record(tmp,ref objHandler);
								objList.record.Add(objRecord);
								//return objRecord;
							} 
							else if (rd.Name=="resumptionToken") 
							{
								tmp=rd.ReadOuterXml();
								myToken = new ResumptionToken(tmp);
								objList.token = myToken;
							}
                            //else if (rd.Name.ToLower() == "OAI-PMH".ToLower())
                            //{
                            //    break;
                            //}
                            else if (rd.EOF == true)
                            {
                                error.errorName = "Empty ListRecords Request";
                                error.errorDescription = "No data was returned in the ListRecords Element.  This is likely an error.";
                                return null;
                            }
                            else rd.Read(); // Added the Read() and will never occur with the ReadInnerXml()

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

            
            return objList;
            

			
		}
コード例 #6
0
ファイル: oai.cs プロジェクト: reeset/oai.cs
		// 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);
		}
コード例 #7
0
ファイル: oai.cs プロジェクト: reeset/oai.cs
		public ListRecord ListRecords(ResumptionToken objToken) 
		{
			object objHandler = new object();
			objHandler = new OAI_DC();
			return ListRecords("", "", "", "", objToken, ref objHandler);
		}