private void SaveMilestones(IEnumerable <IMilestone> milestones)
        {
            var projectEngine   = _engineFactory.GetProjectEngine();
            var mileStoneEngine = _engineFactory.GetMilestoneEngine();

            foreach (var milestone in milestones.Where(x => _withClosed || !x.Completed))
            {
                try
                {
                    var newMilestone = new Milestone
                    {
                        Title    = ReplaceLineSeparator(milestone.Title),
                        DeadLine = milestone.Deadline,
                        Status   = milestone.Completed ? MilestoneStatus.Closed : MilestoneStatus.Open,
                        Project  = projectEngine.GetByID(FindProject(milestone.ProjectID)),
                        IsKey    = false,
                        IsNotify = false
                    };
                    newMilestone = mileStoneEngine.SaveOrUpdate(newMilestone, false, true);
                    _newMilestonesID.Add(new MilestoneIDWrapper {
                        InBasecamp = milestone.ID, InProjects = newMilestone.ID
                    });
                }
                catch (Exception e)
                {
                    Status.LogError(string.Format(ImportResource.FailedToSaveMilestone, milestone.Title), e);
                    LogError(string.Format("milestone '{0}' failed", milestone.Title), e);
                    _newMilestonesID.RemoveAll(x => x.InBasecamp == milestone.ID);
                }
            }
        }
 public MilestoneWrapper(Milestone milestone)
 {
     Id = milestone.ID;
     ProjectOwner = new SimpleProjectWrapper(milestone.Project);
     Title = milestone.Title;
     Description = milestone.Description;
     Created = (ApiDateTime)milestone.CreateOn;
     CreatedBy = EmployeeWraper.Get(milestone.CreateBy);
     Updated = (ApiDateTime)milestone.LastModifiedOn;
     if (milestone.CreateBy != milestone.LastModifiedBy)
     {
         UpdatedBy = EmployeeWraper.Get(milestone.LastModifiedBy);
     }
     if (!milestone.Responsible.Equals(Guid.Empty))
     {
         Responsible = EmployeeWraper.Get(milestone.Responsible);
     }
     Status = (int)milestone.Status;
     Deadline = new ApiDateTime(milestone.DeadLine, TimeZoneInfo.Local);
     IsKey = milestone.IsKey;
     IsNotify = milestone.IsNotify;
     CanEdit = ProjectSecurity.CanEdit(milestone);
     CanDelete = ProjectSecurity.CanDelete(milestone);
     ActiveTaskCount = milestone.ActiveTaskCount;
     ClosedTaskCount = milestone.ClosedTaskCount;
 }
        public static bool CanGoToFeed(Milestone milestone, Guid userId)
        {
            if (milestone == null) return false;
            if (!CanGoToFeed(milestone.Project, userId)) return false;

            return milestone.Responsible == userId ||
                   GetTeamSecurityForParticipants(milestone.Project, userId, ProjectTeamSecurity.Milestone);
        }
 public override Milestone Save(Milestone milestone)
 {
     if (milestone != null)
     {
         ResetCache(milestone.ID);
     }
     return base.Save(milestone);
 }
        public static void Milestone(Milestone milestone, String actionText, int actionType, int businessValue)
        {
            //DropProjectActivitiesCache(milestone.Project);

            UserActivityPublisher.Publish<TimeLinePublisher>(new TimeLineUserActivity(actionText, actionType, businessValue)
            {
                ContentID = String.Empty,
                ContainerID = milestone.Project.ID.ToString(),
                Title = milestone.Title,
                URL = String.Concat(VirtualPathUtility.ToAbsolute(ConfigurationManager.BaseVirtualPath + "milestones.aspx"), String.Format("?prjID={0}&id={1}", milestone.Project.ID, milestone.ID)),
                AdditionalData = String.Format(AdditionalDataPattern, EntityType.Milestone, String.Empty, milestone.Project.Title),
                SecurityId = string.Format(SecurityDataPattern, EntityType.Milestone, milestone.ID, milestone.Project.ID)
            });
        }
        public static void Task(Task task, Milestone milestone, String actionText, int actionType, int businessValue, bool withPreview)
        {
            //DropProjectActivitiesCache(task.Project);

            UserActivityPublisher.Publish<TimeLinePublisher>(new TimeLineUserActivity(actionText, actionType, businessValue)
            {

                ContentID = (milestone != null) ? milestone.ToString() : String.Empty,
                ContainerID = task.Project.ID.ToString(),
                Title = task.Title,
                URL = String.Concat(VirtualPathUtility.ToAbsolute(ConfigurationManager.BaseVirtualPath + "tasks.aspx").Replace("api/", ""), String.Format("?prjID={0}&id={1}", task.Project.ID, task.ID)),
                AdditionalData = String.Format(AdditionalDataPattern, EntityType.Task, (milestone != null) ? milestone.Title : String.Empty, task.Project.Title),
                SecurityId = string.Format(SecurityDataPattern, EntityType.Task, task.ID, task.Project.ID),
                HtmlPreview = withPreview ? task.Description.HtmlEncode() : null
            });
        }
Example #7
0
 public void SendMilestoneDeadline(Guid userID, Milestone milestone)
 {
     var recipient = ToRecipient(userID);
     if (recipient != null)
     {
         client.SendNoticeToAsync(
             NotifyConstants.Event_MilestoneDeadline,
             milestone.NotifyId,
             new[] { recipient },
             GetDefaultSenders(recipient),
             null,
             new TagValue(NotifyConstants.Tag_ProjectID, milestone.Project.ID),
             new TagValue(NotifyConstants.Tag_ProjectTitle, milestone.Project.Title),
             new TagValue(NotifyConstants.Tag_EntityTitle, milestone.Title),
             new TagValue(NotifyConstants.Tag_EntityID, milestone.ID),
             ReplyToTagProvider.Comment("project.milestone", milestone.ID.ToString()));
     }
 }
Example #8
0
 public void SendAboutMilestoneClosing(List<IRecipient> recipients, Milestone milestone)
 {
     client.BeginSingleRecipientEvent("milestone closed");
     var interceptor = new InitiatorInterceptor(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), ""));
     client.AddInterceptor(interceptor);
     try
     {
         client.SendNoticeToAsync(
             NotifyConstants.Event_MilestoneClosed,
             milestone.NotifyId,
             recipients.ToArray(),
             GetDefaultSenders(recipients.FirstOrDefault()),
             null,
             new TagValue(NotifyConstants.Tag_ProjectID, milestone.Project.ID),
             new TagValue(NotifyConstants.Tag_ProjectTitle, milestone.Project.Title),
             new TagValue(NotifyConstants.Tag_EntityTitle, milestone.Title),
             new TagValue(NotifyConstants.Tag_EntityID, milestone.ID),
             new TagValue(NotifyConstants.Tag_AdditionalData, HttpUtility.HtmlEncode(milestone.Description)),
             ReplyToTagProvider.Comment("project.milestone", milestone.ID.ToString()));
     }
     finally
     {
         client.RemoveInterceptor(interceptor.Name);
         client.EndSingleRecipientEvent("milestone closed");
     }
 }
Example #9
0
 public void SendAboutResponsibleByMilestone(Milestone milestone)
 {
     var recipient = ToRecipient(milestone.Responsible);
     if (recipient != null)
     {
         client.SendNoticeToAsync(
             NotifyConstants.Event_ResponsibleForMilestone,
             milestone.NotifyId,
             new[] { recipient },
             GetDefaultSenders(recipient),
             null,
             new TagValue(NotifyConstants.Tag_ProjectID, milestone.Project.ID),
             new TagValue(NotifyConstants.Tag_ProjectTitle, milestone.Project.Title),
             new TagValue(NotifyConstants.Tag_EntityTitle, milestone.Title),
             new TagValue(NotifyConstants.Tag_EntityID, milestone.ID),
             new TagValue(NotifyConstants.Tag_AdditionalData, new Hashtable { { "MilestoneDescription", HttpUtility.HtmlEncode(milestone.Description) } }),
             ReplyToTagProvider.Comment("project.milestone", milestone.ID.ToString()));
     }
 }
        public MilestoneWrapper AddProjectMilestone(int id, string title, ApiDateTime deadline, bool isKey, bool isNotify, string description, Guid responsible, bool notifyResponsible)
        {
            if (title == null) throw new ArgumentNullException("title");
            if (deadline == DateTime.MinValue) throw new ArgumentNullException("deadline");
            var project = EngineFactory.GetProjectEngine().GetByID(id).NotFoundIfNull();

            ProjectSecurity.DemandCreateMilestone(project);

            var milestone = new Milestone
            {
                Description = description ?? "",
                Project = project,
                Title = title.Trim(),
                DeadLine = deadline,
                IsKey = isKey,
                Status = MilestoneStatus.Open,
                IsNotify = isNotify,
                Responsible = responsible
            };
            EngineFactory.GetMilestoneEngine().SaveOrUpdate(milestone, notifyResponsible);
            return new MilestoneWrapper(milestone);
        }
 public SimpleMilestoneWrapper(Milestone milestone)
 {
     Id = milestone.ID;
     Title = milestone.Title;
     Deadline = (ApiDateTime)milestone.DeadLine;
 }
        public static bool CanRead(Milestone milestone, Guid userId)
        {
            if (milestone == null || !CanRead(milestone.Project, userId)) return false;
            if (milestone.Responsible == userId) return true;

            return CanReadMilestones(milestone.Project, userId);
        }
 public Milestone SaveOrUpdate(Milestone milestone)
 {
     return SaveOrUpdate(milestone, false, false);
 }
 private Feed ToFeed(Milestone milestone)
 {
     var itemUrl = "/products/projects/milestones.aspx#project=" + milestone.Project.ID;
     var projectUrl = "/products/projects/tasks.aspx?prjID=" + milestone.Project.ID;
     return new Feed(milestone.CreateBy, milestone.CreateOn)
         {
             Item = item,
             ItemId = milestone.ID.ToString(CultureInfo.InvariantCulture),
             ItemUrl = CommonLinkUtility.ToAbsolute(itemUrl),
             Product = Product,
             Module = Name,
             Title = milestone.Title,
             Description = Helper.GetHtmlDescription(HttpUtility.HtmlEncode(milestone.Description)),
             ExtraLocation = milestone.Project.Title,
             ExtraLocationUrl = CommonLinkUtility.ToAbsolute(projectUrl),
             AdditionalInfo = Helper.GetUser(milestone.Responsible).DisplayName,
             AdditionalInfo2 = milestone.DeadLine.ToString("MM.dd.yyyy"),
             Keywords = string.Format("{0} {1}", milestone.Title, milestone.Description),
             HasPreview = false,
             CanComment = false,
             GroupId = GetGroupId(item, milestone.CreateBy, milestone.Project.ID.ToString(CultureInfo.InvariantCulture))
         };
 }
 public static void DemandDelete(Milestone milestone)
 {
     if (!CanDelete(milestone)) throw CreateSecurityException();
 }
 public static void DemandEdit(Milestone milestone)
 {
     if (!CanEdit(milestone)) throw CreateSecurityException();
 }
 public static void DemandRead(Milestone milestone)
 {
     if (!CanRead(milestone != null ? milestone.Project : null)) throw CreateSecurityException();
 }
        public static bool CanDelete(Milestone milestone)
        {
            if (!Can(milestone)) return false;
            if (IsProjectManager(milestone.Project)) return true;

            return IsInTeam(milestone.Project) && milestone.CreateBy == CurrentUserId;
        }
        public static bool CanEdit(Milestone milestone)
        {
            if (!Can(milestone)) return false;
            if (milestone.Project.Status == ProjectStatus.Closed) return false;
            if (IsProjectManager(milestone.Project)) return true;
            if (!CanRead(milestone)) return false;

            return IsInTeam(milestone.Project) &&
                   (milestone.CreateBy == CurrentUserId ||
                    milestone.Responsible == CurrentUserId);
        }
 public static bool CanRead(Milestone milestone)
 {
     return CanRead(milestone, CurrentUserId);
 }
Example #21
0
 public void SendAboutMilestoneCreating(List<IRecipient> recipients, Milestone milestone)
 {
     client.SendNoticeToAsync(
         NotifyConstants.Event_MilestoneCreated,
         milestone.NotifyId,
         recipients.ToArray(),
         GetDefaultSenders(recipients.FirstOrDefault()),
         null,
         new TagValue(NotifyConstants.Tag_ProjectID, milestone.Project.ID),
         new TagValue(NotifyConstants.Tag_ProjectTitle, milestone.Project.Title),
         new TagValue(NotifyConstants.Tag_EntityTitle, milestone.Title),
         new TagValue(NotifyConstants.Tag_EntityID, milestone.ID),
         new TagValue(NotifyConstants.Tag_AdditionalData, new Hashtable { { "MilestoneDescription", HttpUtility.HtmlEncode(milestone.Description) } }),
         ReplyToTagProvider.Comment("project.milestone", milestone.ID.ToString())
         );
 }
        private void NotifyMilestone(Milestone milestone, bool notifyResponsible, bool isNew, Guid oldResponsible)
        {
            //Don't send anything if notifications are disabled
            if (_engineFactory.DisableNotifications) return;

            if (isNew && milestone.Project.Responsible != SecurityContext.CurrentAccount.ID && !milestone.Project.Responsible.Equals(milestone.Responsible))
            {
                NotifyClient.Instance.SendAboutMilestoneCreating(new List<Guid> { milestone.Project.Responsible }, milestone);
            }

            if (notifyResponsible && milestone.Responsible != SecurityContext.CurrentAccount.ID)
            {
                if (isNew || !oldResponsible.Equals(milestone.Responsible))
                    NotifyClient.Instance.SendAboutResponsibleByMilestone(milestone);
                else
                    NotifyClient.Instance.SendAboutMilestoneEditing(milestone);
            }
        }
        public Milestone SaveOrUpdate(Milestone milestone, bool notifyResponsible, bool import)
        {
            if (milestone == null) throw new ArgumentNullException("milestone");
            if (milestone.Project == null) throw new Exception("milestone.project is null");
            if (milestone.Responsible.Equals(Guid.Empty)) throw new Exception("milestone.responsible is empty");

            // check guest responsible
            if (ProjectSecurity.IsVisitor(milestone.Responsible))
            {
                ProjectSecurity.CreateGuestSecurityException();
            }

            milestone.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            milestone.LastModifiedOn = TenantUtil.DateTimeNow();

            var isNew = milestone.ID == default(int);//Task is new
            var oldResponsible = Guid.Empty;

            if (isNew)
            {
                if (milestone.CreateBy == default(Guid)) milestone.CreateBy = SecurityContext.CurrentAccount.ID;
                if (milestone.CreateOn == default(DateTime)) milestone.CreateOn = TenantUtil.DateTimeNow();

                ProjectSecurity.DemandCreateMilestone(milestone.Project);
                milestone = _milestoneDao.Save(milestone);
            }
            else
            {
                var oldMilestone = _milestoneDao.GetById(new[] {milestone.ID}).FirstOrDefault();

                if (oldMilestone == null) throw new ArgumentNullException("milestone");

                oldResponsible = oldMilestone.Responsible;

                ProjectSecurity.DemandEdit(milestone);
                milestone = _milestoneDao.Save(milestone);

            }


            if (!milestone.Responsible.Equals(Guid.Empty))
                NotifyMilestone(milestone, notifyResponsible, isNew, oldResponsible);

            return milestone;
        }
 private static bool CanRead(Milestone m)
 {
     return ProjectSecurity.CanRead(m);
 }
 public static void Task(Task task, Milestone milestone, String actionText, int actionType, int businessValue)
 {
     Task(task, milestone, actionText, actionType, businessValue, false);
 }
 public Milestone SaveOrUpdate(Milestone milestone, bool notifyResponsible)
 {
     return SaveOrUpdate(milestone, notifyResponsible, false);
 }
 public static bool CanGoToFeed(Milestone milestone, Guid userId)
 {
     if (milestone == null || !IsProjectsEnabled(userId))
     {
         return false;
     }
     if (!IsInTeam(milestone.Project, userId, false) && !IsFollow(milestone.Project, userId))
     {
         return false;
     }
     return milestone.Responsible == userId || GetTeamSecurityForParticipants(milestone.Project, userId, ProjectTeamSecurity.Milestone);
 }
        public Milestone ChangeStatus(Milestone milestone, MilestoneStatus newStatus)
        {
            ProjectSecurity.DemandEdit(milestone);

            if (milestone == null) throw new ArgumentNullException("milestone");
            if (milestone.Project == null) throw new Exception("Project can be null.");
            if (milestone.Status == newStatus) return milestone;
            if (milestone.ActiveTaskCount != 0 && newStatus == MilestoneStatus.Closed) throw new Exception("Can not close a milestone with open tasks");

            milestone.Status = newStatus;
            milestone.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            milestone.LastModifiedOn = TenantUtil.DateTimeNow();
            milestone.StatusChangedOn = TenantUtil.DateTimeNow();

            var senders = new HashSet<Guid> { milestone.Project.Responsible, milestone.CreateBy, milestone.Responsible };

            if (newStatus == MilestoneStatus.Closed && !_engineFactory.DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutMilestoneClosing(senders, milestone);
            }

            if (newStatus == MilestoneStatus.Open && !_engineFactory.DisableNotifications && senders.Count != 0)
            {
                NotifyClient.Instance.SendAboutMilestoneResumed(senders, milestone);
            }

            return _milestoneDao.Save(milestone);
        }
        public virtual Milestone Save(Milestone milestone)
        {
            using (var db = new DbManager(DatabaseId))
            {
                if (milestone.DeadLine.Kind != DateTimeKind.Local)
                    milestone.DeadLine = TenantUtil.DateTimeFromUtc(milestone.DeadLine);

                var insert = Insert(MilestonesTable)
                    .InColumnValue("id", milestone.ID)
                    .InColumnValue("project_id", milestone.Project != null ? milestone.Project.ID : 0)
                    .InColumnValue("title", milestone.Title)
                    .InColumnValue("create_by", milestone.CreateBy.ToString())
                    .InColumnValue("create_on", TenantUtil.DateTimeToUtc(milestone.CreateOn))
                    .InColumnValue("last_modified_by", milestone.LastModifiedBy.ToString())
                    .InColumnValue("last_modified_on", TenantUtil.DateTimeToUtc(milestone.LastModifiedOn))
                    .InColumnValue("deadline", milestone.DeadLine)
                    .InColumnValue("status", milestone.Status)
                    .InColumnValue("is_notify", milestone.IsNotify)
                    .InColumnValue("is_key", milestone.IsKey)
                    .InColumnValue("description", milestone.Description)
                    .InColumnValue("status_changed", milestone.StatusChangedOn)
                    .InColumnValue("responsible_id", milestone.Responsible.ToString())
                    .Identity(1, 0, true);
                milestone.ID = db.ExecuteScalar<int>(insert);
                return milestone;
            }
        }
        public void Delete(Milestone milestone)
        {
            if (milestone == null) throw new ArgumentNullException("milestone");

            ProjectSecurity.DemandEdit(milestone);
            _milestoneDao.Delete(milestone.ID);

            var users = new HashSet<Guid> { milestone.Project.Responsible, milestone.Responsible };

            NotifyClient.Instance.SendAboutMilestoneDeleting(users, milestone);
        }
 private void SaveMilestones(IMilestone[] milestones)
 {
     var projectEngine = _engineFactory.GetProjectEngine();
     var mileStoneEngine = _engineFactory.GetMilestoneEngine();
     foreach (var milestone in milestones.Where(x => _withClosed ? true : !x.Completed))
     {
         try
         {
             Milestone newMilestone = new Milestone()
             {
                 Title = ReplaceLineSeparator(milestone.Title),
                 DeadLine = milestone.Deadline,
                 Status = milestone.Completed ? MilestoneStatus.Closed : MilestoneStatus.Open,
                 Project = projectEngine.GetByID(FindProject(milestone.ProjectID)),
                 IsKey = false,
                 IsNotify = false
             };
             newMilestone = mileStoneEngine.SaveOrUpdate(newMilestone, false, true);
             NewMilestonesID.Add(new MilestoneIDWrapper() { inBasecamp = milestone.ID, inProjects = newMilestone.ID });
         }
         catch (Exception e)
         {
             Status.LogError(string.Format(SettingsResource.FailedToSaveMilestone, milestone.Title), e);
             LogError(string.Format("milestone '{0}' failed", milestone.Title), e);
             NewMilestonesID.RemoveAll(x => x.inBasecamp == milestone.ID);
         }
     }
 }