Пример #1
0
        public void TestOverdueTasks()
        {
            InitOrgStore();
            IndexOrgStore();
            var assignedUser = new User { Id = IlluminateDatabase.GenerateId<User>(), NameIdentifier = "nameidentifier", OrgKey = "OrgKey", EmailAddress = "*****@*****.**", DateOfBirth = new DateTime(1990, 1, 1), FirstName = "Test", LastName = "User", Config = new Config { Settings = new Dictionary<string, object>() } };
            var newtask = new Task
            {
                Id = IlluminateDatabase.GenerateId<Task>(),
                Type = new TaskType { Name = "test task" },
                DueDate = DateTime.Now.AddDays(-1),
                ConsolidatedCompletionDate = DateTime.Now,
                CreatedBy = Orguser.ToSimpleUser(),
                Title = "test task title",
                Description = "test task description",
                AssignedUsers = new List<SimpleUser> { assignedUser .ToSimpleUser()}
            };
            //store the task in the db
            using (var session = OrgStore.OpenSession())
            {
                session.Store(assignedUser);
                session.Store(newtask);
                
                
                session.SaveChanges();
                newtask.UpdateAssignees(session);
                while (OrgStore.DatabaseCommands.GetStatistics().StaleIndexes.Length != 0)
                {
                    Thread.Sleep(100);
                }

                var result = Task.GetNumberOverdueContextTasks(assignedUser.Id, null, session);
                Assert.AreEqual(1,result);

                //pretend user completes task

                newtask.CompletedDate = DateTime.Now;
                newtask.ConsolidatedCompletionDate = DateTime.Now;
                session.SaveChanges();
                while (OrgStore.DatabaseCommands.GetStatistics().StaleIndexes.Length != 0)
                {
                    Thread.Sleep(100);
                }

                result = Task.GetNumberOverdueContextTasks(assignedUser.Id, null, session);
                Assert.AreEqual(0, result);
            }

        }
Пример #2
0
        public static HIGEntry Capture(IDocumentStore store, User user, HIGCaptureViewModel model)
        {
            using (var orgSession = store.OpenSession())
            {
                var simpleUser = user.ToSimpleUser();
            
                var hv = new HIGEntry
                {
                    CaptureDate = DateTime.Now,
                    ConsolidatedCompletionDate = DateTime.Now,
                    Subject = simpleUser,
                    Value = model.HIGValue,
                    Message = model.HIGMessage,
                    Id = IlluminateDatabase.GenerateId<HIGEntry>(),
                    LastInDay = true
                };

                if (user.LatestHig != null && user.LatestHig.CaptureDate.Date == DateTime.UtcNow.Date) //same day
                {
                    //previous hig should be not latest in day. 
                    var lasthig = orgSession.Load<HIGEntry>(user.LatestHig.Id);
                    lasthig.LastInDay = false; 
                }

                //set users latest hig. 
                user.LatestHig = hv;

                if (hv.Value < 0)
                {
                    //alert! Alert!

                    var notify = new Notification
                    {
                        About = simpleUser,
                        Body =
                            String.Format(
                                "{0} added a new negative HIG on {1}. Perhaps you should investigate",
                                user.Name, hv.CaptureDate),
                        SendDate = DateTime.Now,
                        Title = string.Format("HIG Alert for {0}", user.Name),
                        From = EmailRecipient.GetIlluminateRecipient(),
                        NotificationRecipients = new[]
                                                                          {
                                                                              new NotificationRecipient
                                                                                  {

                                                                                      NotificationDeliveryTypes =
                                                                                          NotificationDeliveryTypes
                                                                                              .Toast |
                                                                                          NotificationDeliveryTypes
                                                                                              .Email |
                                                                                              NotificationDeliveryTypes.Sms
                                                                                              ,
                                                                                      
                                                                                      Users = user.Relationships
                                                                                      .Where(r => r.RelationshipName == Role.BuiltInRole.LineManager.ToString() )

                                                                                  }
                                                                          },
                    };
                    orgSession.Store(notify);
                }


                orgSession.Store(user);
                orgSession.Store(hv);
                orgSession.SaveChanges();

                return hv; 
            }
        }
        private void GenerateUsers()
        {
            if(_numUsers>_firstNames.Length)
                throw new ArgumentException(string.Format("Can only create up to {0} users",_firstNames.Length));
            var users = new List<IUser>(_numUsers);
            var rand = new Random();
            for (var count = 0; count < _numUsers; count++)
            {
                var user = new User
                {
                    FirstName = _firstNames[count],
                    LastName = _lastNames[count],
                    CreatedDate = DateTime.Now,
                    DateOfBirth = DateTime.Now.AddYears(GetAge()),
                    EmailAddress = GetEmail(_firstNames[count],_lastNames[count]),
                    Id = IlluminateDatabase.GenerateId<User>(),
                    OrgKey = _orgKey,
                    PersonnelNumber = _rand.Next(1000,10000).ToString(),
                    MobilePhoneNumber = "44756783568",
                    Roles =
                        new List<Role>
                                           {
                                               Role.GetRole(Role.BuiltInRole.Manager),
                                           },
                    Position = _positions[count],
                    
                    Avatar = new Avatar{PublicID = _avatarImages[count],Tags = new []{_orgKey}},


                };
                user.LatestHig= new HIGEntry
                {
                    CaptureDate = DateTime.Now,
                    ConsolidatedCompletionDate = DateTime.Now,
                    Subject = user.ToSimpleUser(),
                    Value =  rand.Next(-2,2),
                    Id = IlluminateDatabase.GenerateId<HIGEntry>(),
                    LastInDay = true
                };
                users.Add(user);
            }

            var ownerUser = new User
            {
                FirstName = _ownerFirstName,
                LastName = _ownerLastName,
                CreatedDate = DateTime.Now,
                DateOfBirth = DateTime.Now.AddYears(GetAge()),
                EmailAddress = _ownerEmail,
                Id = IlluminateDatabase.GenerateId<User>(),
                OrgKey = _orgKey,
                PersonnelNumber = _rand.Next(1000, 10000).ToString(),
                MobilePhoneNumber = "44756783568",
                Roles =
                    new List<Role>
                                           {
                                               Role.GetRole(Role.BuiltInRole.Manager),
                                               Role.GetRole(Role.BuiltInRole.Administrator),
                                               Role.GetRole(Role.BuiltInRole.Analytics),
                                           },
                Position = "Owner",
                RewardPointsLeft = 100000

            };
            foreach (var user in users)
            {
                user.AddManager(ownerUser);
            }
            users.Add(ownerUser);
            _users = users;
            var authUsers = new List<IAuthUser> {ownerUser.ToAuthUser()};
            _authUsers = authUsers;
        }
        public virtual void EmailActivation(AuthUser au, User ou, IDocumentStore orgStore)
        {

            //check not already activated. Work this out from 
            if (String.IsNullOrEmpty(au.ActivationCode))
            {
                throw new Exception("User is already activated");
            }

            var activationurl = String.Format("{0}://{1}/{2}", Request.Url.Scheme, ConfigurationManager.AppSettings["ActivationUrl"], au.ActivationCode);

            var notification = new Notification
                                   {
                                       Title = "New Administrator account for Illuminate",
                                       Body = Email.GetActivationEmailBody(ou, activationurl,au.ActivationCode,""),
                                       Id = IlluminateDatabase.GenerateId<Notification>(),
                                       NotificationRecipients = new[]
                                                                    {
                                                                        new NotificationRecipient
                                                                            {
                                                                                Users = new[] {ou.ToSimpleUser()},
                                                                                NotificationDeliveryTypes =
                                                                                    NotificationDeliveryTypes.Email
                                                                            }
                                                                    },
                                       SendDate = DateTime.Now
                                   };

            using (var session = orgStore.OpenSession())
            {
                session.Store(notification);
                session.SaveChanges();
            }
            
        }