private List <AHAItem> InvokeSearch(SearchStreamOptionsRecord options, PaginationRecord pg) { try { log.Debug("Search options: " + options.ToJson()); log.Debug("Search page: " + pg.ToJson()); this.options = options; ObjectApi objectApi = new ObjectApi(session.GetApiClient()); log.Debug("Calling SearchObjects API"); SearchObjectsResult result = objectApi.SearchObjects(options.ToJson(), pg.ToJson()); if (result.Hdr.Rc == 0) { pager = result.Pager; List <AHAItem> items = new List <AHAItem>(); List <Record> records = result.Records; log.Debug(records.Count + " records returned"); foreach (var record in records) { String jsonString = record.Json; log.Debug("Record: " + jsonString); log.Debug("Creating AHA item"); AHAItem item = itemFromJson(jsonString); log.Debug("AHAItem: " + JsonConvert.SerializeObject(item)); if (item.Type.Equals(FILE_TYPE)) { log.Debug("Getting additional info for file"); FileApi fileApi = new FileApi(session.GetApiClient()); ViewFileResult viewFileResult = fileApi.ViewFile(item.Key); if (viewFileResult.Hdr.Rc == 0) { FileRecord fileRecord = viewFileResult.File; item.LastUpdater = fileRecord.LastUpdater.DisplayName; item.Version = fileRecord.UiVersion; log.Debug("Last updater: " + item.LastUpdater); log.Debug("Version: " + item.Version); } else { log.Error("Vmoso error getting additional info for file. Rc=" + viewFileResult.Hdr.Rc); } } items.Add(item); } return(items); } else { throw new Exception("Vmoso error searching objects. Rc=" + result.Hdr.Rc); } } catch (Exception ex) { throw new Exception("Error searching objects from Vmoso", ex); } }
public AHAItem itemFromJson(String jsonString) { dynamic dynObj = JsonConvert.DeserializeObject(jsonString); String key = dynObj.key; String name = dynObj.name; String type = dynObj.type; String subtype = dynObj.subtype; String symbol = getSymbolFromTypes(type, subtype); String iconKey = dynObj.iconSmall; String richLink = dynObj.rich_link; //String link = "<a href=\"" + session.OriginalHost + getHref(richLink) + "\">@" + name + "</a>"; String path = ""; if (PATHS.ContainsKey(type)) { path = PATHS[type]; } else { log.Error("URL for type " + type + " not found"); } String link = session.OriginalHost + "/" + path + "/" + key; AHAItem item = new AHAItem(symbol, key, name, type, subtype, iconKey, link); if (type.Equals(FILE_TYPE)) { String fileExtension = getFileExtension(name); item.FileType = fileExtension; } String timeUpdatedString = dynObj.timeupdated; Double timeUpdated = Double.Parse(timeUpdatedString); DateTime timeStamp = UnixTimeStampToDateTime(timeUpdated); item.TimeUpdated = timeStamp; item.Json = jsonString; return(item); }