Beispiel #1
0
        public IEnumerable <File> GetFiles(ProjectEntity entity)
        {
            if (entity == null)
            {
                return(new List <File>());
            }

            if (!ProjectSecurity.CanReadFiles(entity.Project))
            {
                return(new List <File>());
            }

            using (var tagdao = FilesIntegration.GetTagDao())
                using (var filedao = FilesIntegration.GetFileDao())
                {
                    var ids   = tagdao.GetTags(entity.GetType().Name + entity.ID, TagType.System).Where(t => t.EntryType == FileEntryType.File).Select(t => t.EntryId).ToArray();
                    var files = 0 < ids.Length ? filedao.GetFiles(ids) : new List <File>();

                    var rootId = FileEngine.GetRoot(entity.Project.ID);

                    //delete tags when file moved from project folder
                    files.Where(file => !file.RootFolderId.Equals(rootId)).ToList()
                    .ForEach(file =>
                    {
                        DetachFile(entity, file.ID);
                        files.Remove(file);
                    });

                    files.ForEach(r => r.Access = FileEngine.GetFileShare(r, entity.Project.ID));
                    return(files);
                }
        }
        public void AttachFile(ProjectEntity entity, object fileId, bool notify)
        {
            if (!ProjectSecurity.CanReadFiles(entity.Project))
            {
                return;
            }

            File file;

            using (var dao = FilesIntegration.GetTagDao())
            {
                dao.SaveTags(new Tag(entity.GetType().Name + entity.ID, TagType.System, Guid.Empty)
                {
                    EntryType = FileEntryType.File, EntryId = fileId
                });
                file = FileEngine.GetFile(fileId, 0);
                FileEngine.GenerateImageThumb(file);
            }

            if (notify && !Factory.DisableNotifications)
            {
                var senders = GetSubscribers(entity);
                NotifyClient.Instance.SendNewFile(senders, entity, file.Title);
            }
        }
Beispiel #3
0
        //Test to add the project
        public void ShouldAddProject()
        {
            var projectId     = _projectList.Count() + 1;
            var projectDetail = new ProjectEntity
            {
                ProjectId       = projectId,
                ProjectName     = "New Project for Testing",
                ProjectPriority = 6,
                ProjectStatus   = "Y",
                DateReqd        = "Y",
                StartDate       = new DateTime(2018, 10, 5),
                EndDate         = new DateTime(2018, 12, 7),
                ManagerId       = 3,
                AddDate         = DateTime.Now
            };

            _mockRepository.AddProject(projectDetail);

            ProjectEntity addedProject = _mockRepository.GetProject(projectId);

            Assert.IsTrue(_projectList.Count() == 6);
            Assert.IsNotNull(addedProject);
            Assert.AreSame(addedProject.GetType(), typeof(ProjectEntity));
            Assert.AreEqual(addedProject.ProjectId, projectId);
            Assert.IsTrue(projectDetail.ProjectName == addedProject.ProjectName);
            Assert.IsTrue(projectDetail.ManagerId == addedProject.ManagerId);
        }
Beispiel #4
0
        public void SendNewComment(ProjectEntity entity, Comment comment)
        {
            INotifyAction action;

            if (entity.GetType() == typeof(Issue))
            {
                action = NotifyConstants.Event_NewCommentForIssue;
            }
            else if (entity.GetType() == typeof(Message))
            {
                action = NotifyConstants.Event_NewCommentForMessage;
            }
            else if (entity.GetType() == typeof(Milestone))
            {
                action = NotifyConstants.Event_NewCommentForMilestone;
            }
            else if (entity.GetType() == typeof(Task))
            {
                action = NotifyConstants.Event_NewCommentForTask;
            }
            else
            {
                return;
            }

            var interceptor = new InitiatorInterceptor(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), ""));

            try
            {
                client.AddInterceptor(interceptor);
                client.SendNoticeAsync(
                    action,
                    entity.NotifyId,
                    null,
                    new TagValue(NotifyConstants.Tag_ProjectID, entity.Project.ID),
                    new TagValue(NotifyConstants.Tag_ProjectTitle, entity.Project.Title),
                    new TagValue(NotifyConstants.Tag_EntityTitle, entity.Title),
                    new TagValue(NotifyConstants.Tag_EntityID, entity.ID),
                    new TagValue(NotifyConstants.Tag_AdditionalData, comment.Content),
                    GetReplyToEntityTag(entity, comment));
            }
            finally
            {
                client.RemoveInterceptor(interceptor.Name);
            }
        }
Beispiel #5
0
        public void SendNewFile(List <IRecipient> recipients, ProjectEntity entity, string fileTitle)
        {
            INotifyAction action;

            if (entity.GetType() == typeof(Message))
            {
                action = NotifyConstants.Event_NewFileForDiscussion;
            }
            else if (entity.GetType() == typeof(Task))
            {
                action = NotifyConstants.Event_NewFileForTask;
            }
            else
            {
                return;
            }

            var interceptor = new InitiatorInterceptor(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), ""));

            try
            {
                client.AddInterceptor(interceptor);
                client.SendNoticeToAsync(
                    action,
                    entity.NotifyId,
                    recipients.ToArray(),
                    true,
                    new TagValue(NotifyConstants.Tag_ProjectID, entity.Project.ID),
                    new TagValue(NotifyConstants.Tag_ProjectTitle, entity.Project.Title),
                    new TagValue(NotifyConstants.Tag_EntityTitle, entity.Title),
                    new TagValue(NotifyConstants.Tag_EntityID, entity.ID),
                    new TagValue(NotifyConstants.Tag_AdditionalData, fileTitle));
            }
            finally
            {
                client.RemoveInterceptor(interceptor.Name);
            }
        }
Beispiel #6
0
        public void DetachFile(ProjectEntity entity, object fileId)
        {
            if (!ProjectSecurity.CanReadFiles(entity.Project))
            {
                return;
            }

            using (var dao = FilesIntegration.GetTagDao())
            {
                dao.RemoveTags(new Tag(entity.GetType().Name + entity.ID, TagType.System, Guid.Empty)
                {
                    EntryType = FileEntryType.File, EntryId = fileId
                });
            }
        }
Beispiel #7
0
 /// <summary>
 /// While using a target file as storage, determines the fingerprint for the given
 /// <see cref="ProjectEntity"/>.
 /// </summary>
 /// <param name="entity">The <see cref="ProjectEntity"/> to generate a hashcode for.</param>
 /// <param name="filePath">The filepath to use as temporary storage.</param>
 /// <returns>The binary hashcode for <paramref name="entity"/>.</returns>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="entity"/> is <c>null</c>.</exception>
 /// <exception cref="QuotaExceededException">Thrown when <paramref name="entity"/>
 /// contains more than <see cref="int.MaxValue"/> unique object instances.</exception>
 /// <exception cref="UnauthorizedAccessException">The caller does not have the
 /// required permissions or <paramref name="filePath"/> is read-only.</exception>
 /// <exception cref="IOException">An I/O exception occurred while creating the file
 /// at <paramref name="filePath"/>.</exception>
 private static byte[] ComputeHash(ProjectEntity entity, string filePath)
 {
     using (HashAlgorithm hashingAlgorithm = MD5.Create())
         using (FileStream stream = File.Create(filePath))
             using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(stream))
             {
                 var serializer = new DataContractSerializer(entity.GetType(),
                                                             Enumerable.Empty <Type>(),
                                                             int.MaxValue, false, true, null);
                 serializer.WriteObject(writer, entity);
                 writer.Flush();
                 stream.Seek(0, SeekOrigin.Begin);
                 return(hashingAlgorithm.ComputeHash(stream));
             }
 }
Beispiel #8
0
        public List <File> GetEntityFiles(ProjectEntity entity)
        {
            if (entity == null)
            {
                return(new List <File>());
            }

            using (var tagdao = FilesIntegration.GetTagDao())
                using (var filedao = FilesIntegration.GetFileDao())
                {
                    var ids   = tagdao.GetTags(entity.GetType().Name + entity.ID, TagType.System).Where(t => t.EntryType == FileEntryType.File).Select(t => t.EntryId).ToArray();
                    var files = 0 < ids.Length ? filedao.GetFiles(ids) : new List <File>();
                    files.ForEach(r => r.Access = GetFileShare(r, entity.Project.ID));
                    SetThumbUrls(files);
                    return(files);
                }
        }
Beispiel #9
0
        public void Add_Project()
        {
            var projectId = _projects.Count() + 1;
            var project   = new ProjectEntity
            {
                ProjectId        = projectId,
                ProjectName      = "Enhancement project",
                StartDate        = "01/01/2019",
                EndDate          = "01/31/2019",
                Priority         = 15,
                ProjectManagerId = 1234567
            };

            _mockRepository.AddProject(project);
            Assert.IsTrue(_projects.Count() == 4);
            ProjectEntity testProject = GetProjectById(projectId);

            Assert.IsNotNull(testProject);
            Assert.AreSame(testProject.GetType(), typeof(ProjectEntity));
            Assert.AreEqual(project.ProjectName, testProject.ProjectName);
            Assert.AreEqual(project.StartDate, testProject.StartDate);
            Assert.AreEqual(project.Priority, testProject.Priority);
            Assert.AreEqual(project.ProjectManagerId, testProject.ProjectManagerId);
        }
Beispiel #10
0
        public void SendNewComment(ProjectEntity entity, Comment comment)
        {
            INotifyAction action;
            if (entity.GetType() == typeof(Issue)) action = NotifyConstants.Event_NewCommentForIssue;
            else if (entity.GetType() == typeof(Message)) action = NotifyConstants.Event_NewCommentForMessage;
            else if (entity.GetType() == typeof(Milestone)) action = NotifyConstants.Event_NewCommentForMilestone;
            else if (entity.GetType() == typeof(Task)) action = NotifyConstants.Event_NewCommentForTask;
            else return;

            var interceptor = new InitiatorInterceptor(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), ""));
            try
            {
                client.AddInterceptor(interceptor);
                client.SendNoticeAsync(
                    action,
                    entity.NotifyId,
                    null,
                    new TagValue(NotifyConstants.Tag_ProjectID, entity.Project.ID),
                    new TagValue(NotifyConstants.Tag_ProjectTitle, entity.Project.Title),
                    new TagValue(NotifyConstants.Tag_EntityTitle, entity.Title),
                    new TagValue(NotifyConstants.Tag_EntityID, entity.ID),
                    new TagValue(NotifyConstants.Tag_AdditionalData, comment.Content),
                    GetReplyToEntityTag(entity, comment));
            }
            finally
            {
                client.RemoveInterceptor(interceptor.Name);
            }
        }
        public void DetachFile(ProjectEntity entity, object fileId)
        {
            if (!ProjectSecurity.CanReadFiles(entity.Project)) return;

            using (var dao = FilesIntegration.GetTagDao())
            {
                dao.RemoveTags(new Tag(entity.GetType().Name + entity.ID, TagType.System, Guid.Empty) { EntryType = FileEntryType.File, EntryId = fileId });
            }
        }
        public void AttachFile(ProjectEntity entity, object fileId, bool notify)
        {
            if (!ProjectSecurity.CanReadFiles(entity.Project)) return;

            File file;

            using (var dao = FilesIntegration.GetTagDao())
            {
                dao.SaveTags(new Tag(entity.GetType().Name + entity.ID, TagType.System, Guid.Empty) { EntryType = FileEntryType.File, EntryId = fileId });
                file = FileEngine.GetFile(fileId, 0);
            }

            if (notify && !Factory.DisableNotifications)
            {
                var senders = GetSubscribers(entity);
                NotifyClient.Instance.SendNewFile(senders, entity, file.Title);
            }
        }
        public IEnumerable<File> GetFiles(ProjectEntity entity)
        {
            if (entity == null) return new List<File>();

            if (!ProjectSecurity.CanReadFiles(entity.Project)) return new List<File>();

            using (var tagdao = FilesIntegration.GetTagDao())
            using (var filedao = FilesIntegration.GetFileDao())
            {
                var ids = tagdao.GetTags(entity.GetType().Name + entity.ID, TagType.System).Where(t => t.EntryType == FileEntryType.File).Select(t => t.EntryId).ToArray();
                var files = 0 < ids.Length ? filedao.GetFiles(ids) : new List<File>();

                var rootId = FileEngine.GetRoot(entity.Project.ID);

                //delete tags when file moved from project folder
                files.Where(file => !file.RootFolderId.Equals(rootId)).ToList()
                    .ForEach(file =>
                    {
                        DetachFile(entity, file.ID);
                        files.Remove(file);
                    });

                files.ForEach(r => r.Access = FileEngine.GetFileShare(r, entity.Project.ID));
                return files;
            }
        }
        public void SendNewFile(List<IRecipient> recipients, ProjectEntity entity, string fileTitle)
        {
            INotifyAction action;
            if (entity.GetType() == typeof(Message)) action = NotifyConstants.Event_NewFileForDiscussion;
            else if (entity.GetType() == typeof(Task)) action = NotifyConstants.Event_NewFileForTask;
            else return;

            var interceptor = new InitiatorInterceptor(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), ""));
            try
            {
                client.AddInterceptor(interceptor);
                client.SendNoticeToAsync(
                    action,
                    entity.NotifyId,
                    recipients.ToArray(), 
                    true,
                    new TagValue(NotifyConstants.Tag_ProjectID, entity.Project.ID),
                    new TagValue(NotifyConstants.Tag_ProjectTitle, entity.Project.Title),
                    new TagValue(NotifyConstants.Tag_EntityTitle, entity.Title),
                    new TagValue(NotifyConstants.Tag_EntityID, entity.ID),
                    new TagValue(NotifyConstants.Tag_AdditionalData, fileTitle));
            }
            finally
            {
                client.RemoveInterceptor(interceptor.Name);
            }
        }
Beispiel #15
0
        public List<File> GetEntityFiles(ProjectEntity entity)
        {
            if (entity == null) return new List<File>();

            using (var tagdao = FilesIntegration.GetTagDao())
            using (var filedao = FilesIntegration.GetFileDao())
            {
                var ids = tagdao.GetTags(entity.GetType().Name + entity.ID, TagType.System).Where(t => t.EntryType == FileEntryType.File).Select(t => t.EntryId).ToArray();
                var files = 0 < ids.Length ? filedao.GetFiles(ids) : new List<File>();
                files.ForEach(r => r.Access = GetFileShare(r, entity.Project.ID));
                SetThumbUrls(files);
                return files;
            }
        }