Example #1
0
        public StreamComment UpdateComment(String text, StreamComment comment)
        {
            try
            {
                CommentApi      commentApi    = new CommentApi(session.GetApiClient());
                CommentV2Record commentRecord = comment.Record;
                commentRecord.Text = text;

                UpdateCommentInput  updateCommentInput  = new UpdateCommentInput(comment.ContentKey, commentRecord);
                UpdateCommentResult updateCommentResult = commentApi.UpdateComment(updateCommentInput);
                if (updateCommentResult.Hdr.Rc == 0)
                {
                    CommentV2Record updatedCommentRecord = updateCommentResult.Comment;
                    StreamComment   updatedComment       = new StreamComment(updatedCommentRecord, comment.ContentRecordType);
                    return(updatedComment);
                }
                else
                {
                    throw new Exception("Error creating comment. Rc=" + updateCommentResult.Hdr.Rc);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error creating comment", ex);
            }
        }
Example #2
0
        public StreamComment(CommentV2Record commentRecord, String parentRecordType)
        {
            this.Record            = commentRecord;
            this.ContentRecordType = parentRecordType;
            this.ContentKey        = commentRecord.ContentKey;
            this.CommentId         = (int)commentRecord.CommentID;
            this.CommentCId        = (int)commentRecord.CommentCID;
            this.CommentPId        = (int)commentRecord.CommentPID;
            this.CommentListKey    = commentRecord.CommentListKey;
            if (commentRecord.SubCommentCount != null)
            {
                this.SubCommentCount = (int)commentRecord.SubCommentCount;
            }
            this.Text  = commentRecord.Text;
            this.Owner = commentRecord.Creator.DisplayName;
            String capitals = "";

            string[] words = this.Owner.Split(' ');
            int      count = 0;

            foreach (string word in words)
            {
                capitals += word.Substring(0, 1);
                count++;
                if (count == 2)
                {
                    break;
                }
            }
            this.OwnerCapitals = capitals;
            this.OwnerKey      = commentRecord.Creator.Key;
            this.OwnerIconKey  = commentRecord.Creator.IconSmall;
            Double timeUpdated = Convert.ToDouble(commentRecord.Timeupdated);

            this.TimeUpdated = UnixTimeStampToDateTime(timeUpdated);
        }
Example #3
0
        private StreamComment CreateComment(String text, String contentKey, String contentRecordType, String commentListKey, int principalCommentId)
        {
            try
            {
                CommentApi      commentApi    = new CommentApi(session.GetApiClient());
                CommentV2Record commentRecord = new CommentV2Record();
                commentRecord.ContentKey = contentKey;

                if (principalCommentId > 0)
                {
                    commentRecord.CommentPID = principalCommentId;
                }
                if (commentListKey != null)
                {
                    commentRecord.CommentListKey = commentListKey;
                }

                commentRecord.Text = text;

                CreateCommentInput  createCommentInput  = new CreateCommentInput(contentKey, commentRecord);
                CreateCommentResult createCommentResult = commentApi.CreateComment(createCommentInput);
                if (createCommentResult.Hdr.Rc == 0)
                {
                    CommentV2Record createdComment = createCommentResult.Comment;
                    StreamComment   comment        = new StreamComment(createdComment, contentRecordType);
                    return(comment);
                }
                else
                {
                    throw new Exception("Error creating comment. Rc=" + createCommentResult.Hdr.Rc);
                }
            } catch (Exception ex)
            {
                throw new Exception("Error creating comment", ex);
            }
        }
Example #4
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);
            }
        }