public string GetIdentifier(MerritQueryData queryData, RepositoryModel repositoryModel) { throw new NotImplementedException(); }
/// <summary> /// Helper method to get the identifier from merrit. /// </summary> /// <param name="postFileData"></param> /// <param name="authorization"></param> /// <returns></returns> protected string GetIdentifier(PublishMessage postFileData, string authorization, string identifierUrl, Citation citation) { Check.IsNotNull(postFileData, "postFileData"); Check.IsNotNull(authorization, "authorization"); Check.IsNotNull(identifierUrl, "identifierUrl"); var file = this.GetFileByFileId(postFileData.FileId); MerritQueryData queryData = new MerritQueryData(); queryData.KeyValuePair = new List<DKeyValuePair<string, string>>() { new DKeyValuePair<string, string> { Key = "Profile", Value = "oneshare_ark_only" }, new DKeyValuePair<string, string> { Key = "Who", Value = citation.Publisher }, new DKeyValuePair<string, string> { Key = "What", Value = citation.Title}, new DKeyValuePair<string, string> { Key = "When", Value = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture) } }.ToArray(); RepositoryModel repositoryModel = new RepositoryModel() { Authorization = authorization, RepositoryLink = identifierUrl, RepositoryName = MerritConstants.OneShare }; return this.RepositoryAdapter.GetIdentifier(queryData, repositoryModel); }
public string GetIdentifier(MerritQueryData queryData, RepositoryModel repositoryModel) { HttpWebRequest httpRequest = null; HttpWebResponse httpResponse = null; Stream dataStream = null; StreamReader reader = null; string restResponse; string requestBody = GetIdentifierRequestBody(queryData); if (queryData != null && repositoryModel != null) { IgnoreBadCertificates(); httpRequest = (HttpWebRequest)HttpWebRequest.Create(repositoryModel.RepositoryLink); httpRequest.ContentType = "multipart/form-data; boundary=" + MerritConstants.Boundary; httpRequest.Method = "POST"; byte[] buffer = Encoding.UTF8.GetBytes(requestBody); httpRequest.ContentLength = buffer.Length; httpRequest.Headers.Add("Authorization", "Basic " + repositoryModel.Authorization); try { dataStream = httpRequest.GetRequestStream(); dataStream.Write(buffer, 0, buffer.Length); httpResponse = (HttpWebResponse)httpRequest.GetResponse(); } catch (WebException webException) { dataStream.Dispose(); httpResponse = (HttpWebResponse)webException.Response; if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) { return "false|" + "The username or password you entered is incorrect."; } else if (httpResponse.StatusCode == HttpStatusCode.NotFound) { return "false|" + "Issue with the repository configuration, Contact administrator."; } return "false|" + webException.Message; } } if (httpResponse.StatusCode != HttpStatusCode.OK && httpResponse.StatusCode != HttpStatusCode.Unauthorized && httpResponse.StatusCode != HttpStatusCode.NotFound) { return "false|Network Exception"; } dataStream = httpResponse.GetResponseStream(); reader = new StreamReader(dataStream); restResponse = reader.ReadToEnd(); reader.Close(); httpResponse.Close(); if (!restResponse.Contains("ark:")) { return "false|" + "Issue with the repository configuration, Contact administrator."; } // Get Identifier from the response. return string.Concat("true|", restResponse.Substring(restResponse.IndexOf("ark:", StringComparison.Ordinal)).Trim()); }
protected static RepositoryModel GetRepositoryModel(DM.Repository repository, string authorization) { Check.IsNotNull(repository, "repository"); Check.IsNotNull(authorization, "authorization"); RepositoryModel repositoryModel = new RepositoryModel(); repositoryModel.Authorization = authorization; repositoryModel.RepositoryName = MerritConstants.OneShare; repositoryModel.SelectedRepository = repository; repositoryModel.RepositoryLink = repository.HttpPostUriTemplate; return repositoryModel; }