Exemplo n.º 1
0
        public string DoSearch(string url, oclc_api_classify.Class_Type ctype, bool bsummary, out string[] subjects)
        {
            LastError = "";

            string sreturn = helpers.MakeOpenHTTPRequest(url, SetProxy, "GET"); // helpers.MakeHTTPRequest(url, SetProxy);

            //process results
            return ProcessClassify(sreturn, ctype, bsummary, out subjects);
        }
Exemplo n.º 2
0
        private string ProcessClassify(string s, oclc_api_classify.Class_Type ctype, bool bsummary, out string[] subjects)
        {
            LastError = "";

            subjects = null;
            System.Xml.XmlDocument objXML = new System.Xml.XmlDocument();
            System.Xml.XmlNamespaceManager oMan = new System.Xml.XmlNamespaceManager(objXML.NameTable);
            oMan.AddNamespace("oclc", "http://classify.oclc.org");
            try
            {

                objXML.LoadXml(s);

                //First check to see if this is is a record with multiple works
                System.Xml.XmlNodeList test_nodes = objXML.SelectNodes("//oclc:works/oclc:work", oMan);

                //System.Windows.Forms.MessageBox.Show(test_nodes.Count.ToString());
                if (test_nodes != null && test_nodes.Count > 0)
                {
                    try
                    {
                        string url = "http://classify.oclc.org/classify2/Classify?swid=" + test_nodes[0].Attributes["swid"].InnerText + "&summary=" + bsummary.ToString();
                        string txml = helpers.MakeOpenHTTPRequest(url, SetProxy, "GET"); // helpers.MakeHTTPRequest(url, SetProxy);

                        if (txml != "")
                        {
                            objXML.LoadXml(txml);
                        }
                        else
                        {
                            return "";
                        }
                    }
                    catch
                    {
                        return "";
                    }
                }

            }
            catch (System.Exception ee)
            {
                //System.Windows.Forms.MessageBox.Show(ee.ToString());
                LastError = s;
            }

            System.Xml.XmlNodeList objList;

            try
            {
                System.Collections.ArrayList tsubject = new System.Collections.ArrayList();
                //look to see if subjects are present
                objList = objXML.SelectNodes("//oclc:fast/oclc:headings/oclc:heading", oMan);
                if (objList != null)
                {
                    foreach (System.Xml.XmlNode objN in objList)
                    {
                        if (objN.Attributes["ident"] != null)
                        {
                            tsubject.Add(objN.Attributes["ident"].InnerText);
                        }
                    }
                    subjects = new string[tsubject.Count];
                    tsubject.CopyTo(subjects);
                }

                if (ctype == Class_Type.dd)
                {
                    objList = objXML.SelectNodes("//oclc:ddc/oclc:mostPopular", oMan);
                    if (objList != null)
                    {
                        foreach (System.Xml.XmlNode objN in objList)
                        {

                            if (objN.Attributes["nsfa"] != null)
                            {
                                return objN.Attributes["nsfa"].InnerText;
                                break;
                            }
                        }
                    }
                }
                else
                {

                    objList = objXML.SelectNodes("//oclc:lcc/oclc:mostPopular", oMan);
                    if (objList != null)
                    {
                        foreach (System.Xml.XmlNode objN in objList)
                        {
                            if (objN.Attributes["nsfa"] != null)
                            {
                                return objN.Attributes["nsfa"].InnerText;
                                break;
                            }
                        }
                    }
                    else
                    {
                        //System.Windows.Forms.MessageBox.Show("miss");
                    }
                }
                return "";
            }
            catch (Exception e)
            {
                LastError = e.ToString();
                return "";
            }
        }