示例#1
0
        public string getImage(int commentId, IDBContext DBContext)
        {
            string imageBase64 = string.Empty;
            string path        = string.Empty;

            CORE.BLL.Service.SqlService.CommentSqlService CSService = new CORE.BLL.Service.SqlService.CommentSqlService(DBContext);
            path = CSService.GetFileFieldPath(commentId);

            if (!path.Equals(string.Empty))
            {
                Image image = Image.FromFile(path);
                using (Image thumbnail = image.GetThumbnailImage(50, 50, () => false, IntPtr.Zero))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        thumbnail.Save(memoryStream, ImageFormat.Png);
                        Byte[] bytes = new Byte[memoryStream.Length];
                        memoryStream.Position = 0;
                        memoryStream.Read(bytes, 0, (int)bytes.Length);
                        string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
                        imageBase64 = "data:image/png;base64," + base64String;
                    }
                }
            }


            return(imageBase64);
        }
        public List <CORE.DAL.Entities.Comment> GetCommentChilds(List <CORE.DAL.Entities.Comment> comments)
        {
            List <CORE.DAL.Entities.Comment> childs    = new List <CORE.DAL.Entities.Comment>();
            List <CORE.DAL.Entities.Comment> newChilds = new List <CORE.DAL.Entities.Comment>();

            using (IRSAPIClient proxy =
                       _helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
            {
                int workspaceId = _workspaceID;
                proxy.APIOptions.WorkspaceID = workspaceId;
                CORE.BLL.Service.RSAPIService.CommentRSAPIService cRSAPIService  = new CORE.BLL.Service.RSAPIService.CommentRSAPIService(proxy);
                CORE.BLL.Service.SqlService.CommentSqlService     commentService = new CORE.BLL.Service.SqlService.CommentSqlService(_helper.GetDBContext(workspaceId));
                foreach (CORE.DAL.Entities.Comment item in comments)
                {
                    childs = commentService.GetCommentsChild(item.ArtifactId);


                    if (!childs.Count().Equals(0))
                    {
                        foreach (CORE.DAL.Entities.Comment child in childs)
                        {
                            CORE.DAL.Entities.Comment comment = cRSAPIService.Get(child.ArtifactId);
                            newChilds.Add(comment);
                        }
                        item.CommentChilds = GetCommentChilds(newChilds);
                    }
                    else
                    {
                        item.CommentChilds = childs;
                    }
                }
            }
            return(comments);
        }
        public CORE.DAL.Entities.Comment GetCommentDataByRsapi(int commentAI)
        {
            CORE.DAL.Entities.Comment comment = new CORE.DAL.Entities.Comment();
            using (IRSAPIClient proxy = _helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
            {
                proxy.APIOptions.WorkspaceID = _workspaceID;
                CORE.BLL.Service.RSAPIService.CommentRSAPIService csrsapi = new CORE.BLL.Service.RSAPIService.CommentRSAPIService(proxy);
                CORE.BLL.Service.SqlService.CommentSqlService     cssql   = new RelativityAppCore.BLL.Service.SqlService.CommentSqlService(_helper.GetDBContext(_workspaceID));
                comment = csrsapi.Get(commentAI);
                comment.CommentChilds = cssql.GetCommentsChild(comment.ArtifactId);
                List <CORE.DAL.Entities.Comment> childs = new List <RelativityAppCore.DAL.Entities.Comment>();
                foreach (var c in comment.CommentChilds)
                {
                    childs.Add(csrsapi.Get(c.ArtifactId));
                }
                comment.CommentChilds = childs;
                comment.CommentChilds = GetCommentChilds(comment.CommentChilds.ToList());
            }

            return(comment);
        }
        public void drawCommentTree2(ref List <string> tree, List <Data.Entities.Comment> commentChilds)
        {
            if (commentChilds.Count.Equals(0))
            {
                tree.Add("<ul style='padding:0 0 0 20px'>|<li style='font-size:smaller;list-style:none;padding:0 0 0 0'>|-- Without Childs</li></ul>");
            }
            else
            {
                tree.Add("<ul  style='padding:0 0 0 20px'>|");

                foreach (Data.Entities.Comment coment in commentChilds)
                {
                    Service.SqlService.CommentSqlService commentService = new Service.SqlService.CommentSqlService(this.Helper.GetDBContext(this.Helper.GetActiveCaseID()));
                    coment.CommentChilds = commentService.GetCommentsChild(coment.ArtifactId);
                    tree.Add($"<li style='list-style:none;padding:0 0 0 0px'><a  target='_blank' href='http://192.168.0.148/Relativity/Case/Mask/View.aspx?AppID=1034680&ArtifactID={coment.ArtifactId}&ArtifactTypeID=1001041&SelectedTab=null'>|-- {coment.ArtifactId}</a></li>");

                    drawCommentTree2(ref tree, (coment.CommentChilds).ToList());
                }

                tree.Add("</ul>");
            }
        }
        public IEnumerable <CORE.DAL.Entities.Comment> GetReplysByObjectManager(int artifactId)
        {
            List <CORE.DAL.Entities.Comment> childs    = new List <CORE.DAL.Entities.Comment>();
            List <CORE.DAL.Entities.Comment> newChilds = new List <CORE.DAL.Entities.Comment>();

            using (IRSAPIClient proxy =
                       _helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
            {
                int workspaceId = _workspaceID;
                proxy.APIOptions.WorkspaceID = workspaceId;
                CORE.BLL.Service.RSAPIService.CommentRSAPIService cRSAPIService  = new CORE.BLL.Service.RSAPIService.CommentRSAPIService(proxy);
                CORE.BLL.Service.SqlService.CommentSqlService     commentService = new CORE.BLL.Service.SqlService.CommentSqlService(_helper.GetDBContext(workspaceId));
                childs = commentService.GetCommentsChild(artifactId);
                foreach (var child in childs)
                {
                    CORE.DAL.Entities.Comment comment = getDataReplyCommentByObjectManager(child.ArtifactId, workspaceId);
                    newChilds.Add(comment);
                }
            }

            return(newChilds);
        }
        public override kCura.EventHandler.Console GetConsole(PageEvent pageEvent)
        {
            int activeWorkspaceId = this.Helper.GetActiveCaseID();

            //Construct a console object to build the console appearing in the UI.
            kCura.EventHandler.Console returnConsole = new kCura.EventHandler.Console();
            returnConsole.Items = new List <IConsoleItem>();
            returnConsole.Title = CONSOLE_TITLE;
            string select = "<h3 style='color:#11599E'>Comments Tree</h3>";

            List <string> elements = new List <string>();

            elements.Add(select);
            using (kCura.Relativity.Client.IRSAPIClient client =
                       this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(Relativity.API.ExecutionIdentity.System))
            {
                client.APIOptions.WorkspaceID = this.Helper.GetActiveCaseID();
                Service.SqlService.CommentSqlService     commentService      = new Service.SqlService.CommentSqlService(this.Helper.GetDBContext(this.Helper.GetActiveCaseID()));
                Service.RSAPIService.CommentRSAPIService commentRSAPIService = new Service.RSAPIService.CommentRSAPIService(client);
                Data.Entities.Comment comment = commentRSAPIService.Get(this.ActiveArtifact.ArtifactID);
                comment.CommentChilds = commentService.GetCommentsChild(comment.ArtifactId);
                drawCommentTree2(ref elements, (comment.CommentChilds).ToList());
                returnConsole.HTMLBlocks = elements;
            }

            ConsoleHeader header = new ConsoleHeader("Console Application");

            //Construct the submit job button.
            ConsoleButton submitJobButton = new ConsoleButton();

            submitJobButton.Name           = INSERT_JOB_BUTTON_NAME;
            submitJobButton.DisplayText    = INSERT_JOB_DISPLAY_TEXT;
            submitJobButton.ToolTip        = INSERT_JOB_TOOL_TIP;
            submitJobButton.RaisesPostBack = true;
            submitJobButton.Enabled        = true;

            //Construct the delete job button
            ConsoleButton deleteJobButton = new ConsoleButton()
            {
                Name           = DELETE_JOB_BUTTON_NAME,
                DisplayText    = DELETE_JOB_DISPLAY_TEXT,
                ToolTip        = DELETE_JOB_TOOL_TIP,
                RaisesPostBack = true,
                Enabled        = true
            };

            //Button to see the comment data
            ConsoleButton seeCommentButton = new ConsoleButton()
            {
                Name           = "See Comment Data",
                DisplayText    = "Commen Data",
                ToolTip        = "Comment Data",
                RaisesPostBack = true,
                Enabled        = true
            };


            ConsoleSeparator separador = new ConsoleSeparator();


            //If a job is already in the queue, change the text and disable the button.
            if (pageEvent == PageEvent.PreRender)
            {
                SqlParameter commentArtifactId = new SqlParameter("@commentArtifacId", System.Data.SqlDbType.Int);
                commentArtifactId.Value = ActiveArtifact.ArtifactID;

                int jobCount = this.Helper.GetDBContext(activeWorkspaceId).ExecuteSqlStatementAsScalar <Int32>(JOB_EXISTS_QUERY, new SqlParameter[] { commentArtifactId });

                //Use the helper function to check if a job currently exists. Set Enabled to the opposite value.
                if (jobCount > 0)
                {
                    submitJobButton.Enabled = false;
                    deleteJobButton.Enabled = true;
                }
                else
                {
                    submitJobButton.Enabled = true;
                    deleteJobButton.Enabled = false;
                }

                //Get the base path to the application.
                String basePath = this.Application.ApplicationUrl.Substring(0, this.Application.ApplicationUrl.IndexOf("/Case/Mask/"));

                //Construct the path to the custom page with the current patient artifact id and current workspace.
                String patientProfilePageUrl = String.Format("{0}/CustomPages/{1}/Home/Index/?artifacId={2}", basePath, COMMENT_HISTORY_APPLICATION_GUID, ActiveArtifact.ArtifactID);

                //Create the JavaScript for the button and set the button property.
                String windowOpenJavaScript = String.Format("window.open('{0}', '', 'location=no,scrollbars=yes,menubar=no,toolbar=no,status=no,resizable=yes,width=300,height=400');", patientProfilePageUrl);
                seeCommentButton.OnClickEvent = windowOpenJavaScript;
            }


            //Add the buttons to the console.
            returnConsole.Items.Add(header);
            returnConsole.Items.Add(submitJobButton);
            returnConsole.Items.Add(deleteJobButton);
            returnConsole.Items.Add(seeCommentButton);
            returnConsole.Items.Add(separador);
            return(returnConsole);
        }
        public override Response Execute()
        {
            _logger = this.Helper.GetLoggerFactory().GetLogger().ForContext <PreSaveEventHandlerComment>();
            Response retVal = new Response();

            retVal.Success = true;
            retVal.Message = string.Empty;



            // Console.WriteLine(output);

            //string output = null;
            try
            {
                String comment = (String)this.ActiveArtifact.Fields[COMMENT_FIEL_GUID.ToString()].Value.Value;
                string user    = (String)this.ActiveArtifact.Fields[SYSTEM_CREATED_BY_FIELD.ToString()].Value.Value;



                if (!(ActiveArtifact.Fields[RELATED_COMMENT_FIELD.ToString()] == null))
                {
                    using (kCura.Relativity.Client.IRSAPIClient client =
                               this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(Relativity.API.ExecutionIdentity.System))
                    {
                        client.APIOptions.WorkspaceID = this.Helper.GetActiveCaseID();
                        Service.RSAPIService.CommentRSAPIService commentRSAPIService = new Service.RSAPIService.CommentRSAPIService(client);
                        Service.SqlService.CommentSqlService     commentSqlService   = new Service.SqlService.CommentSqlService(this.Helper.GetDBContext(Helper.GetActiveCaseID()));
                        int parentCommentId = (int)this.ActiveArtifact.Fields[RELATED_COMMENT_FIELD.ToString()].Value.Value;
                        Data.Entities.Comment parentComment = new Data.Entities.Comment(parentCommentId);
                        parentComment = commentRSAPIService.Get(parentCommentId);
                        List <Data.Entities.Comment> commentsChild = commentSqlService.GetCommentsChild(parentComment.ArtifactId);
                        parentComment.CommentChilds = commentsChild;
                        int user1 = parentComment.CreatedBy.ArtifactId;
                        int user2 = this.Helper.GetAuthenticationManager().UserInfo.ArtifactID;

                        if (commentsChild.Count.Equals(0))
                        {
                            if (user1.Equals(user2))
                            {
                                throw new StartConversation();
                            }
                        }
                    }
                }



                if (String.IsNullOrWhiteSpace(comment))
                {
                    _logger.LogError($"the comment field was not fill up ");
                    throw new FieldMissingException("Comment");
                }
                if (!ActiveArtifact.IsNew)
                {
                    using (kCura.Relativity.Client.IRSAPIClient client =
                               this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(ExecutionIdentity.System))
                    {
                        client.APIOptions.WorkspaceID = this.Helper.GetActiveCaseID();
                        Service.RSAPIService.CommentRSAPIService commentRSAPIService = new Service.RSAPIService.CommentRSAPIService(client);
                        Data.Entities.Comment currentComment = new Data.Entities.Comment(ActiveArtifact.ArtifactID);
                        currentComment = commentRSAPIService.Get(ActiveArtifact.ArtifactID);
                        int commentUserId = currentComment.CreatedBy.ArtifactId;
                        int currentUserId = this.Helper.GetAuthenticationManager().UserInfo.ArtifactID;

                        if (!commentUserId.Equals(currentUserId))
                        {
                            throw new DontEditAnotherComment();
                        }
                    }
                }


                Boolean          typeSelected = false;
                ChoiceCollection typeField    = (ChoiceCollection)this.ActiveArtifact.Fields[TYPE_FIELD_GUID.ToString()].Value.Value;

                foreach (Choice typeChoice in typeField)
                {
                    if (typeChoice.IsSelected)
                    {
                        typeSelected = true;
                        break;
                    }
                }

                if (!typeSelected)
                {
                    throw new FieldMissingException("Comment Type");
                }
            }
            catch (FieldMissingException fielMissingEx)
            {
                retVal.Success = false;
                retVal.Message = fielMissingEx.Message;
            }


            catch (Exception e)
            {
                retVal.Success = false;
                retVal.Message = e.Message;
            }
            return(retVal);
        }