示例#1
0
        public List <StreamComment> NextCommentsPage(StreamItem streamItem)
        {
            PaginationRecord pg = commentsPager.Pg;

            pg.Page = "N";
            return(GetComments(streamItem, pg));
        }
示例#2
0
        public List <StreamComment> GetComments(StreamItem streamItem)
        {
            PaginationRecord pg = new PaginationRecord();

            pg.Page  = "F";
            pg.Limit = 10;
            return(GetComments(streamItem, pg));
        }
示例#3
0
        public void MarkTilesRead(StreamItem streamItem)
        {
            ObjectApi objectApi = new ObjectApi(session.GetApiClient());

            try
            {
                MarkAllTilesReadResult result = objectApi.MarkAllTilesRead(streamItem.Key);
                if (result.Hdr.Rc == 0)
                {
                }
                else
                {
                    throw new Exception("Error updating read info for contentKey " + streamItem.Key);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error updating read info for contentKey " + streamItem.Key, ex);
            }
        }
示例#4
0
        public List <StreamComment> GetComments(StreamItem streamItem, PaginationRecord pg)
        {
            CommentApi commentApi = new CommentApi(session.GetApiClient());

            try
            {
                CommentListV2OptionsRecord options = new CommentListV2OptionsRecord();
                options.SortDir       = "DESC";
                options.HighlightTag  = "mark";
                options.CreatorFilter = "all";
                options.ReadFilter    = "all";
                options.SortFilter    = "updateTime";

                AdditionalDataRecord additionalData = new AdditionalDataRecord();
                additionalData.SubType         = "general";
                additionalData.FirstLevelCount = true;

                GetCommentsResult getCommentsResult = commentApi.GetComments(streamItem.Key, options.ToJson(), pg.ToJson(), streamItem.CommentListKey, additionalData.ToJson());
                if (getCommentsResult.Hdr.Rc == 0)
                {
                    commentsPager = getCommentsResult.Pager;
                    List <StreamComment>   comments       = new List <StreamComment>();
                    List <CommentV2Record> commentRecords = getCommentsResult.Comments;
                    foreach (CommentV2Record commentRecord in commentRecords)
                    {
                        StreamComment comment = new StreamComment(commentRecord, streamItem.RecordType);
                        comments.Add(comment);
                    }

                    return(comments);
                }
                else
                {
                    throw new Exception("Error getting comments for contentKey " + streamItem.Key);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error getting comments for contentKey " + streamItem.Key, ex);
            }
        }
示例#5
0
        public void MarkCommentsRead(StreamItem streamItem)
        {
            CommentApi commentApi = new CommentApi(session.GetApiClient());

            try
            {
                MarkAllReadInput  input  = new MarkAllReadInput(streamItem.CommentListKey, streamItem.Key);
                MarkAllReadResult result = commentApi.MarkAllRead(input);
                if (result.Hdr.Rc == 0)
                {
                }
                else
                {
                    throw new Exception("Error marking as read info for contentKey " + streamItem.Key);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error updating read info for contentKey " + streamItem.Key, ex);
            }
        }
示例#6
0
 public StreamComment CreateComment(String text, StreamItem contentItem)
 {
     return(CreateComment(text, contentItem.Key, contentItem.RecordType, null, 0));
 }
示例#7
0
        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);
            }
        }