Пример #1
0
        public System.Xml.XmlDocument GetORCIDRecordPublic(BO.ORCID.Person orcidPerson, string loggedInInternalUsername)
        {
            BO.ORCID.REFPermission refPermission = new BLL.ORCID.REFPermission().Get((int)BO.ORCID.REFPermission.REFPermissions.read_public);

            // Make sure we have either created the ORCID or the user has provided the ORCID.
            if (orcidPerson.ORCIDIsNull)
            {
                throw new ProfilesRNSDLL.DevelopmentBase.BO.ExceptionSafeToDisplay("Cannot return the ORCID record, the ORCID identifier has not been recorded.");
            }

            try
            {
                string ORCIDCreateProfileURL = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL + "/" + orcidPerson.ORCID + "/";

                var httpWebRequest = WebRequest.Create(ORCIDCreateProfileURL);
                httpWebRequest.ContentType = "application/vdn.orcid+xml";
                httpWebRequest.Method      = System.Net.WebRequestMethods.Http.Get;

                //string authToken = BLL.ORCID.OAuth.SetToken(refPermission.PermissionScope, loggedInInternalUsername);

                //httpWebRequest.Headers.Add("client_id", ProfilesRNSDLL.BO.ORCID.Config.ClientID);
                //httpWebRequest.Headers.Add("client_secret", ProfilesRNSDLL.BO.ORCID.Config.ClientSecret);
                //httpWebRequest.Headers.Add("scope", SCOPE_READ_PUBLIC);
                //httpWebRequest.Headers.Add("grant_type", "client_credentials");

                string token = BLL.ORCID.OAuth.GetClientToken(refPermission.PermissionScope, loggedInInternalUsername);
                httpWebRequest.Headers.Add("Authorization", " Bearer " + token);
                httpWebRequest.Headers.Add("Scope", refPermission.PermissionScope);

                using (WebResponse response = httpWebRequest.GetResponse())
                {
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        string result = reader.ReadToEnd();
                        System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
                        xml.LoadXml(result);
                        return(xml);
                    }
                }
                // curl -H 'Content-Type: application/vdn.orcid+xml' -H 'Authorization: Bearer f6d49570-c048-45a9-951f-a81ebb1fa543' -X GET 'http://api.sandbox-1.orcid.org/v1.0.23/0000-0003-1495-7122/orcid-profile' -L -i
            }
            catch (Exception ex)
            {
                throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while connecting to ORCID.  Unable to retrieve token information to save.");
            }
        }
Пример #2
0
        public System.Xml.XmlDocument GetORCIDRecordLimited(BO.ORCID.Person orcidPerson, string loggedInInternalUsername)
        {
            BO.ORCID.REFPermission refPermission = new BLL.ORCID.REFPermission().Get((int)BO.ORCID.REFPermission.REFPermissions.orcid_profile_read_limited);

            // Make sure we have either created the ORCID or the user has provided the ORCID.
            if (orcidPerson.ORCIDIsNull)
            {
                throw new ProfilesRNSDLL.DevelopmentBase.BO.ExceptionSafeToDisplay("Cannot return the ORCID record, the ORCID identifier has not been recorded.");
            }

            // Make sure the users has granted the permission to read the profile.
            BO.ORCID.PersonToken personToken = new BLL.ORCID.PersonToken().GetByPersonIDAndPermissionID(orcidPerson.PersonID, (int)BO.ORCID.REFPermission.REFPermissions.orcid_profile_read_limited);
            if (personToken.Exists && !personToken.IsExpired)
            {
                try
                {
                    string ORCIDCreateProfileURL = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL_WITH_VERSION + "/" + orcidPerson.ORCID + "/" + refPermission.MethodAndRequest;

                    var httpWebRequest = WebRequest.Create(ORCIDCreateProfileURL);
                    httpWebRequest.ContentType = "application/vdn.orcid+xml";
                    httpWebRequest.Method      = System.Net.WebRequestMethods.Http.Get;

                    httpWebRequest.Headers.Add("Authorization", " Bearer " + personToken.AccessToken);

                    using (WebResponse response = httpWebRequest.GetResponse())
                    {
                        using (var reader = new StreamReader(response.GetResponseStream()))
                        {
                            string result = reader.ReadToEnd();
                            System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
                            xml.LoadXml(result);
                            return(xml);
                        }
                    }
                    // curl -H 'Content-Type: application/vdn.orcid+xml' -H 'Authorization: Bearer f6d49570-c048-45a9-951f-a81ebb1fa543' -X GET 'http://api.sandbox-1.orcid.org/v1.0.23/0000-0003-1495-7122/orcid-profile' -L -i
                }
                catch (Exception ex)
                {
                    throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while connecting to ORCID.  Unable to retrieve token information to save.");
                }
            }
            else
            {
                throw new ProfilesRNSDLL.DevelopmentBase.BO.ExceptionSafeToDisplay("Cannot return the ORCID record, permission has not been granted to read the record.");
            }
        }
        public System.Xml.XmlDocument GetORCIDRecordPublic(BO.ORCID.Person orcidPerson, string loggedInInternalUsername)
        {
            BO.ORCID.REFPermission refPermission = new BLL.ORCID.REFPermission().Get((int)BO.ORCID.REFPermission.REFPermissions.read_public);

            // Make sure we have either created the ORCID or the user has provided the ORCID.
            if (orcidPerson.ORCIDIsNull)
            {
                throw new ProfilesRNSDLL.DevelopmentBase.BO.ExceptionSafeToDisplay("Cannot return the ORCID record, the ORCID identifier has not been recorded.");
            }

            try
            {
                string ORCIDCreateProfileURL = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL + "/" + orcidPerson.ORCID + "/";

                var httpWebRequest = WebRequest.Create(ORCIDCreateProfileURL);
                httpWebRequest.ContentType = "application/vdn.orcid+xml";
                httpWebRequest.Method = System.Net.WebRequestMethods.Http.Get;

                //string authToken = BLL.ORCID.OAuth.SetToken(refPermission.PermissionScope, loggedInInternalUsername);

                //httpWebRequest.Headers.Add("client_id", ProfilesRNSDLL.BO.ORCID.Config.ClientID);
                //httpWebRequest.Headers.Add("client_secret", ProfilesRNSDLL.BO.ORCID.Config.ClientSecret);
                //httpWebRequest.Headers.Add("scope", SCOPE_READ_PUBLIC);
                //httpWebRequest.Headers.Add("grant_type", "client_credentials");

                string token = BLL.ORCID.OAuth.GetClientToken(refPermission.PermissionScope, loggedInInternalUsername);
                httpWebRequest.Headers.Add("Authorization", " Bearer " + token);
                httpWebRequest.Headers.Add("Scope", refPermission.PermissionScope);

                using (WebResponse response = httpWebRequest.GetResponse())
                {
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        string result = reader.ReadToEnd();
                        System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
                        xml.LoadXml(result);
                        return xml;
                    }
                }
                // curl -H 'Content-Type: application/vdn.orcid+xml' -H 'Authorization: Bearer f6d49570-c048-45a9-951f-a81ebb1fa543' -X GET 'http://api.sandbox-1.orcid.org/v1.0.23/0000-0003-1495-7122/orcid-profile' -L -i
            }
            catch (Exception ex)
            {
                throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while connecting to ORCID.  Unable to retrieve token information to save.");
            }
        }
        public System.Xml.XmlDocument GetORCIDRecordLimited(BO.ORCID.Person orcidPerson, string loggedInInternalUsername)
        {
            BO.ORCID.REFPermission refPermission = new BLL.ORCID.REFPermission().Get((int)BO.ORCID.REFPermission.REFPermissions.orcid_profile_read_limited);

            // Make sure we have either created the ORCID or the user has provided the ORCID.
            if (orcidPerson.ORCIDIsNull)
            {
                throw new ProfilesRNSDLL.DevelopmentBase.BO.ExceptionSafeToDisplay("Cannot return the ORCID record, the ORCID identifier has not been recorded.");
            }

            // Make sure the users has granted the permission to read the profile.
            BO.ORCID.PersonToken personToken = new BLL.ORCID.PersonToken().GetByPersonIDAndPermissionID(orcidPerson.PersonID, (int)BO.ORCID.REFPermission.REFPermissions.orcid_profile_read_limited);
            if (personToken.Exists && !personToken.IsExpired)
            {
                try
                {
                    string ORCIDCreateProfileURL = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL_WITH_VERSION + "/" + orcidPerson.ORCID + "/" + refPermission.MethodAndRequest;

                    var httpWebRequest = WebRequest.Create(ORCIDCreateProfileURL);
                    httpWebRequest.ContentType = "application/vdn.orcid+xml";
                    httpWebRequest.Method = System.Net.WebRequestMethods.Http.Get;

                    httpWebRequest.Headers.Add("Authorization", " Bearer " + personToken.AccessToken);

                    using (WebResponse response = httpWebRequest.GetResponse())
                    {
                        using (var reader = new StreamReader(response.GetResponseStream()))
                        {
                            string result = reader.ReadToEnd();
                            System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
                            xml.LoadXml(result);
                            return xml;
                        }
                    }
                    // curl -H 'Content-Type: application/vdn.orcid+xml' -H 'Authorization: Bearer f6d49570-c048-45a9-951f-a81ebb1fa543' -X GET 'http://api.sandbox-1.orcid.org/v1.0.23/0000-0003-1495-7122/orcid-profile' -L -i
                }
                catch (Exception ex)
                {
                    throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while connecting to ORCID.  Unable to retrieve token information to save.");
                }
            }
            else
            {
                throw new ProfilesRNSDLL.DevelopmentBase.BO.ExceptionSafeToDisplay("Cannot return the ORCID record, permission has not been granted to read the record.");
            }
        }