/// <summary>
 /// Initializes a new instance of the <see cref="ShowPersonMatchedFilesControl"/> class.
 /// </summary>
 /// <param name="person">The person.</param>
 public ShowPersonMatchedFilesControl(PersonExtended person)
 {
     _person = person;
     InitializeComponent();
     txtTitle.Text = $"Listing matched files for {person.Person.Name}";
     Loaded       += ShowPersonMatchedFilesControl_Loaded;
 }
        /// <summary>
        /// Gets trained faces from the API.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="guidList">The unique identifier list.</param>
        /// <returns></returns>
        private async Task GetFacesFromServerAsync(PersonExtended person, ConcurrentBag <Guid> guidList)
        {
            var  tasks = new List <Task>();
            Guid guid;

            while (guidList.TryTake(out guid))
            {
                tasks.Add(Task.Factory.StartNew((object inParams) =>
                {
                    var prm = (Tuple <PersonExtended, Guid>)inParams;
                    try
                    {
                        var face = _faceServiceClient.GetPersonFaceInLargePersonGroupAsync(SelectedGroup.Group.LargePersonGroupId, prm.Item1.Person.PersonId, prm.Item2).Result;

                        this.Dispatcher.Invoke(
                            new Action <ObservableCollection <Models.Face>, string, PersistedFace>(UIHelper.UpdateFace),
                            prm.Item1.Faces,
                            face.UserData,
                            face);
                    }
                    catch (FaceAPIException e)
                    {
                        // if operation conflict, retry.
                        if (e.ErrorCode.Equals("ConcurrentOperationConflict"))
                        {
                            guidList.Add(guid);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.InnerException != null && ex.InnerException.Message.Contains("not found"))
                        {
                            return;
                        }

                        guidList.Add(guid);
                        this.Dispatcher.Invoke(() =>
                        {
                            MainWindow.Log($"Service request limit exceeded (20/min) - Re-trying in 2 seconds");
                            Task.Delay(2000).Wait();
                        });
                    }
                }, new Tuple <PersonExtended, Guid>(person, guid)));

                if (tasks.Count >= _maxConcurrentProcesses || guidList.IsEmpty)
                {
                    await Task.WhenAll(tasks);

                    tasks.Clear();
                }
            }

            await Task.WhenAll(tasks);

            tasks.Clear();

            return;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the people for selected group.
        /// </summary>
        /// <returns></returns>
        private async Task GetPeopleForSelectedGroup()
        {
            if (SelectedGroup == null)
            {
                return;
            }

            MainWindow.Log("Loading group persons...");
            SelectedGroup.GroupPersons.Clear();

            Microsoft.ProjectOxford.Face.Contract.Person[] peops = null;

            while (true)
            {
                try
                {
                    // ListPersonsInLargePersonGroupAsync also has skip/take overrides
                    peops = await _faceServiceClient.ListPersonsInLargePersonGroupAsync(SelectedGroup.Group.LargePersonGroupId);

                    break;
                }
                catch (Exception e)
                {
                    MainWindow.Log($"API rate limit exceeded, retrying");
                    await Task.Delay(1000);
                }
            }

            if (peops == null)
            {
                MainWindow.Log($"failed to get Persons in group");
                return;
            }

            foreach (var p in peops)
            {
                var person = new PersonExtended {
                    Person = p
                };
                person.PersonFilesDbCount = _db.GetFileCountForPersonId(p.PersonId);
                this.Dispatcher.Invoke(() =>
                {
                    SelectedGroup.GroupPersons.Add(person);
                });

                // Initially loading just one, to save on API calls
                var guidList = new ConcurrentBag <Guid>(person.Person.PersistedFaceIds.Take(1));

                await GetFacesFromServerAsync(person, guidList);
            }

            MainWindow.Log("Finished loading group persons");
            CheckPeopleInDatabase();
        }
Ejemplo n.º 4
0
 public virtual Task SendTemplateEmail(Dictionary <string, string> substituions,
                                       string subject,
                                       EmailTemplate emailTemplate,
                                       PersonExtended from,
                                       PersonExtended to)
 {
     return(SendTemplateEmail(substituions,
                              subject,
                              emailTemplate,
                              from.Email,
                              from.PreferredName,
                              to.Email,
                              to.PreferredName));
 }
Ejemplo n.º 5
0
 public async Task NotifyHr(LeaveRequest leaveRequest,
                            PersonWithStaff requestedBy,
                            PersonExtended supervisor,
                            LeaveUsage leaveUsage)
 {
     if (!ShouldNotifyHr(leaveRequest, leaveUsage))
     {
         return;
     }
     var substitutions = BuildSubstitutions(leaveRequest, requestedBy, supervisor, supervisor, leaveUsage);
     await _emailService.SendTemplateEmail(substitutions,
                                           $"{PersonFullName(requestedBy)} has requested leave",
                                           EmailTemplate.NotifyHrLeaveRequest,
                                           requestedBy,
                                           _personRepository.GetStaffNotifyHr());
 }
Ejemplo n.º 6
0
        public PersonExtended GetPersonByName(string userName)
        {
            Person person = this.personsManager.GetByName(userName);

            if (person == null)
            {
                person = this.GetUserInfo(userName);
            }

            var personExtended = new PersonExtended(person)
            {
                AnswerUnits = this.GetAllUnits(),
                AnswerTypes = this.GetAllAnswerTypes()
            };

            return(personExtended);
        }
Ejemplo n.º 7
0
        public void TestMethod()
        {
            const string name    = "John";
            const string surname = "Doe";
            const string address = "Person address";

            var johnExtended = new PersonExtended();

            var delta = new Delta <PersonExtended>();

            delta.Add(x => x.Name, name);
            delta.Add(x => x.Surname, surname);
            delta.Add(x => x.Address, address);
            delta.Patch(johnExtended);

            Assert.AreEqual(name, johnExtended.Name);
            Assert.AreEqual(surname, johnExtended.Surname);
            Assert.AreEqual(address, johnExtended.Address);
        }
Ejemplo n.º 8
0
        public ActionResult Find(string url)
        {
            try
            {
                this.Logger.Debug($"Controller: hit find: {url}");

                string userName = this.siteHelper.GetUserName(url);
                if (string.IsNullOrWhiteSpace(userName))
                {
                    return(this.Json($"{url}: Error: Missing username", JsonRequestBehavior.AllowGet));
                }

                PersonExtended personExtended = this.siteHelper.GetPersonByName(userName);
                return(this.PartialView("_Find", personExtended));
            }
            catch (Exception ex)
            {
                return(this.Json($"{url}: Error: {ex.Message}", JsonRequestBehavior.AllowGet));
            }
        }