public SearchProviders.CdbLucene.SearchReply Transition(Model.Document document) { JArray jray; JObject jobj; string id, type; decimal score; SearchProviders.CdbLucene.SearchReply cdbSearchReply; SearchProviders.CdbLucene.ResourceResult cdbResourceResult; SearchProviders.CdbLucene.VersionResult cdbVersionResult; string verifyString; if (!VerifyDocumentIntegrity(document, out verifyString)) { Logger.Storage.Error("The document is not properly formatted. It is missing the property '" + verifyString + "'."); throw new FormattingException("The argument document does not have the necessary property '" + verifyString + "'."); } try { cdbSearchReply = new SearchProviders.CdbLucene.SearchReply() { ETag = document["etag"].Value <string>(), FetchDuration = document["fetch_duration"].Value <int>(), Limit = document["limit"].Value <int>(), Q = document["q"].Value <string>(), SearchDuration = document["search_duration"].Value <int>(), Skip = document["skip"].Value <int>(), TotalRows = document["total_rows"].Value <int>() }; // Optional if (document["analyzer"] != null) { cdbSearchReply.Analyzer = document["analyzer"].Value <string>(); } if (document["plan"] != null) { cdbSearchReply.Plan = document["plan"].Value <string>(); } jray = (JArray)document["rows"]; for (int i = 0; i < jray.Count; i++) { jobj = (JObject)jray[i]; id = jobj["id"].Value <string>(); score = jobj["score"].Value <decimal>(); jobj = (JObject)jobj["fields"]; type = jobj["type"].Value <string>(); if (type == "resource") { string abc = jobj["tags"].Value <string>(); string[] tagsArray = jobj["tags"].Value <string>().Split(','); string[] rightsArray = jobj["usagerights"].Value <string>().Split(','); List <string> tags = new List <string>(); List <Security.UsageRight> usageRights = new List <Security.UsageRight>(); for (int j = 0; j < tagsArray.Length; j++) { tagsArray[j] = tagsArray[j].Trim(); if (tagsArray[j].Length > 0) { tags.Add(tagsArray[j]); } } for (int j = 0; j < rightsArray.Length; j++) { rightsArray[j] = rightsArray[j].Trim(); if (rightsArray[j].Length > 0) { string key = rightsArray[j].Substring(0, rightsArray[j].IndexOf(':')); string value = rightsArray[j].Substring(rightsArray[j].IndexOf(':') + 1); usageRights.Add(new Security.UsageRight(key, (Security.Authorization.ResourcePermissionType) int.Parse(value))); } } cdbResourceResult = new SearchProviders.CdbLucene.ResourceResult(id, score, jobj["created"].Value <DateTime>(), jobj["creator"].Value <string>(), jobj["modified"].Value <DateTime>(), jobj["modifier"].Value <string>(), jobj["checkedoutat"].Value <DateTime?>(), jobj["checkedoutto"].Value <string>(), jobj["lastcommit"].Value <DateTime>(), jobj["lastcommitter"].Value <string>(), jobj["title"].Value <string>(), tags, usageRights); cdbSearchReply.Results.Add(cdbResourceResult); } else if (type == "version") { cdbVersionResult = new SearchProviders.CdbLucene.VersionResult(id, score, jobj["created"].Value <DateTime>(), jobj["creator"].Value <string>(), jobj["modified"].Value <DateTime>(), jobj["modifier"].Value <string>(), jobj["md5"].Value <string>(), jobj["extension"].Value <string>()); cdbSearchReply.Results.Add(cdbVersionResult); } else { throw new UnsupportedException("The received type of document is not supported."); } } } catch (Exception e) { Logger.Storage.Error("An exception occurred while attempting to parse the document.", e); throw; } return(cdbSearchReply); }
public SearchProviders.CdbLucene.SearchReply Transition(Model.Document document) { JArray jray; JObject jobj; string id, type; decimal score; SearchProviders.CdbLucene.SearchReply cdbSearchReply; SearchProviders.CdbLucene.ResourceResult cdbResourceResult; SearchProviders.CdbLucene.VersionResult cdbVersionResult; string verifyString; if (!VerifyDocumentIntegrity(document, out verifyString)) { Logger.Storage.Error("The document is not properly formatted. It is missing the property '" + verifyString + "'."); throw new FormattingException("The argument document does not have the necessary property '" + verifyString + "'."); } try { cdbSearchReply = new SearchProviders.CdbLucene.SearchReply() { ETag = document["etag"].Value<string>(), FetchDuration = document["fetch_duration"].Value<int>(), Limit = document["limit"].Value<int>(), Q = document["q"].Value<string>(), SearchDuration = document["search_duration"].Value<int>(), Skip = document["skip"].Value<int>(), TotalRows = document["total_rows"].Value<int>() }; // Optional if (document["analyzer"] != null) cdbSearchReply.Analyzer = document["analyzer"].Value<string>(); if (document["plan"] != null) cdbSearchReply.Plan = document["plan"].Value<string>(); jray = (JArray)document["rows"]; for (int i = 0; i < jray.Count; i++) { jobj = (JObject)jray[i]; id = jobj["id"].Value<string>(); score = jobj["score"].Value<decimal>(); jobj = (JObject)jobj["fields"]; type = jobj["type"].Value<string>(); if (type == "resource") { string abc = jobj["tags"].Value<string>(); string[] tagsArray = jobj["tags"].Value<string>().Split(','); string[] rightsArray = jobj["usagerights"].Value<string>().Split(','); List<string> tags = new List<string>(); List<Security.UsageRight> usageRights = new List<Security.UsageRight>(); for (int j=0; j < tagsArray.Length; j++) { tagsArray[j] = tagsArray[j].Trim(); if (tagsArray[j].Length > 0) tags.Add(tagsArray[j]); } for (int j=0; j < rightsArray.Length; j++) { rightsArray[j] = rightsArray[j].Trim(); if (rightsArray[j].Length > 0) { string key = rightsArray[j].Substring(0, rightsArray[j].IndexOf(':')); string value = rightsArray[j].Substring(rightsArray[j].IndexOf(':') + 1); usageRights.Add(new Security.UsageRight(key, (Security.Authorization.ResourcePermissionType)int.Parse(value))); } } cdbResourceResult = new SearchProviders.CdbLucene.ResourceResult(id, score, jobj["created"].Value<DateTime>(), jobj["creator"].Value<string>(), jobj["modified"].Value<DateTime>(), jobj["modifier"].Value<string>(), jobj["checkedoutat"].Value<DateTime?>(), jobj["checkedoutto"].Value<string>(), jobj["lastcommit"].Value<DateTime>(), jobj["lastcommitter"].Value<string>(), jobj["title"].Value<string>(), tags, usageRights); cdbSearchReply.Results.Add(cdbResourceResult); } else if (type == "version") { cdbVersionResult = new SearchProviders.CdbLucene.VersionResult(id, score,jobj["created"].Value<DateTime>(), jobj["creator"].Value<string>(), jobj["modified"].Value<DateTime>(), jobj["modifier"].Value<string>(), jobj["md5"].Value<string>(), jobj["extension"].Value<string>()); cdbSearchReply.Results.Add(cdbVersionResult); } else throw new UnsupportedException("The received type of document is not supported."); } } catch(Exception e) { Logger.Storage.Error("An exception occurred while attempting to parse the document.", e); throw; } return cdbSearchReply; }