public ShareLinkItem createBookmark(Uri link, String title, String description, List <String> spaceKeys, Bitmap icon) { try { LinkApi linkApi = new LinkApi(session.GetApiClient()); LinkV2Record linkRecord = new LinkV2Record(); linkRecord.Link = link.ToString(); linkRecord.Title = title; linkRecord.Text = description; linkRecord.Type = "document"; linkRecord.Subtype = "link"; CreateLinkInput createLinkInput = new CreateLinkInput(linkRecord); CreateLinkResult createLinkResult = linkApi.CreateLink(createLinkInput); if (createLinkResult.Hdr.Rc == 0) { LinkV2Record createdLink = createLinkResult.Link; if (spaceKeys != null) { SpaceApi spaceApi = new SpaceApi(session.GetApiClient()); ShareObjectInput shareInput = new ShareObjectInput(null, spaceKeys, null); ShareObjectResult shareResult = spaceApi.ShareObject(createdLink.Key, shareInput); if (shareResult.Hdr.Rc == 0) { GetLinkResult getLinkResult = linkApi.GetLink(createdLink.Key); if (getLinkResult.Hdr.Rc == 0) { createdLink = getLinkResult.Link; } else { throw new Exception("Vmoso error getting created link. Rc=" + getLinkResult.Hdr.Rc); } } else { throw new Exception("Vmoso error sharing link. Rc=" + shareResult.Hdr.Rc); } } ShareLinkItem item = new ShareLinkItem(createdLink.Title, createdLink.Text); item.Key = createdLink.Key; item.Link = new Uri(createdLink.Link); item.Record = createdLink; item.SetIcon(icon); List <ShareSpace> itemSpaces = new List <ShareSpace>(); foreach (DisplayRecord spaceDisplayRecord in createdLink.Destinations) { ShareSpace space = new ShareSpace(spaceDisplayRecord.Key, spaceDisplayRecord.DisplayName, null); itemSpaces.Add(space); } item.Spaces = itemSpaces; return(item); } else { throw new Exception("Vmoso error creating link. Rc=" + createLinkResult.Hdr.Rc); } } catch (Exception ex) { throw new Exception("Vmoso error creating link", ex); } }
public List <StreamItem> InvokeSearch(PaginationRecord pg) { try { StreamApi streamApi = new StreamApi(session.GetApiClient()); FormatRecord formatRecord = new FormatRecord(); formatRecord.ReturnCounts = true; formatRecord.ReturnRatings = true; formatRecord.ReturnSparc = true; formatRecord.ReturnAcl = true; StreamSearchResult result = streamApi.StreamSearch(options.ToJson(), pg.ToJson(), formatRecord.ToJson()); if (result.Hdr.Rc == 0) { pager = result.Pager; List <StreamItem> streamItems = new List <StreamItem>(); List <StreamRecordWrapper> recordWrappers = result.Stream; foreach (StreamRecordWrapper recordWrapper in recordWrappers) { StreamItem streamItem = new StreamItem(); streamItem.UnreadCount = (int)recordWrapper.BadgeCounts.TotalNewCount; streamItem.RecordType = recordWrapper.Recordtype; String recordJson = JsonConvert.SerializeObject(recordWrapper.Record); switch (streamItem.RecordType) { case RECORD_POSTV2: PostV2Record postRecord = JsonConvert.DeserializeObject <PostV2Record>(recordJson); streamItem.Key = postRecord.Key; streamItem.CommentListKey = postRecord.CommentlistKey; streamItem.Type = postRecord.Type; streamItem.SubType = postRecord.Subtype; streamItem.Name = postRecord.Title; streamItem.Record = postRecord; break; case RECORD_LINKV2: LinkV2Record linkRecord = JsonConvert.DeserializeObject <LinkV2Record>(recordJson); streamItem.Key = linkRecord.Key; streamItem.Type = linkRecord.Type; streamItem.SubType = linkRecord.Subtype; streamItem.Name = linkRecord.Title; streamItem.Record = linkRecord; break; case RECORD_TASK: TaskRecord taskRecord = JsonConvert.DeserializeObject <TaskRecord>(recordJson); streamItem.CommentListKey = taskRecord.CommentlistKey; streamItem.Key = taskRecord.Key; streamItem.Type = taskRecord.Type; streamItem.SubType = taskRecord.Subtype; streamItem.Name = taskRecord.Name; streamItem.Record = taskRecord; break; case RECORD_FILE: FileRecord fileRecord = JsonConvert.DeserializeObject <FileRecord>(recordJson); streamItem.Key = fileRecord.Key; streamItem.Type = fileRecord.Type; streamItem.SubType = fileRecord.Subtype; streamItem.Name = fileRecord.Name; streamItem.Record = fileRecord; break; default: Console.WriteLine(recordWrapper.Recordtype); break; } dynamic recordObject = JsonConvert.DeserializeObject(recordJson); dynamic destinations = recordObject.destinations; try { streamItem.SpacePath = destinations[0].fullPath + "/" + destinations[0].displayName; } catch (Exception ex) { } SparcActionRecord lastAction = recordWrapper.LastAction; if (lastAction != null) { Double timeUpdated = Convert.ToDouble(lastAction.Timestamp); DateTime timeStamp = UnixTimeStampToDateTime(timeUpdated); streamItem.TimeUpdated = timeStamp; List <StreamRecordWrapper> actors = lastAction.Actors; if (actors.Count > 0) { String actorRecordType = actors[0].Recordtype; String userRecordJson = JsonConvert.SerializeObject(actors[0].Record); switch (actorRecordType) { case USER_OBJECT_RECORD: UserObjectRecord userRecord = JsonConvert.DeserializeObject <UserObjectRecord>(userRecordJson); streamItem.LastUpdater = userRecord.DisplayName; streamItem.LastUpdaterFirstName = userRecord.FirstName; streamItem.LastUpdaterLastName = userRecord.LastName; streamItem.LastUpdaterIconKey = userRecord.IconSmall; break; } } String verb = ""; switch (lastAction.Verb) { case "create": verb = "Created"; break; case "update": verb = "Updated"; break; case "delete": verb = "Deleted"; break; case "rename": verb = "Renamed"; break; default: break; } switch (lastAction.Sparctype) { case "summary": switch (lastAction.Sparcsubtype) { case "all": streamItem.LastActionContent = verb + " a " + RECORDS[streamItem.RecordType]; break; default: break; } break; case "content": StreamRecordWrapper actionRecordWrapper = lastAction.Containers[0]; String actionRecordJson = JsonConvert.SerializeObject(actionRecordWrapper.Record); switch (lastAction.Sparcsubtype) { case "comment": CommentV2Record commentRecord = JsonConvert.DeserializeObject <CommentV2Record>(actionRecordJson); String textWithoutComments = Regex.Replace(commentRecord.Text, "<!--.*?-->", String.Empty, RegexOptions.Multiline); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(HttpUtility.HtmlDecode(textWithoutComments)); streamItem.LastActionContent = doc.DocumentNode.InnerText; break; default: break; } break; default: break; } String path = ""; if (PATHS.ContainsKey(streamItem.RecordType)) { path = PATHS[streamItem.RecordType]; } else { log.Error("URL for record type " + streamItem.RecordType + " not found"); } streamItem.Link = session.OriginalHost + "/" + path + "/" + streamItem.Key;; streamItems.Add(streamItem); } } return(streamItems); } else { throw new Exception("Error searching stream"); } } catch (Exception ex) { throw new Exception("Error searching stream", ex); } }