public IList <FeedingSourceDTO> GetFeedingSourceDTOs(bool canViewAndSearchAll, bool includeRestricted, string uploadedByUserId) { FeedingSourceDTO output = null; FeedingSource feedingSourceAlias = null; AdminUser uploadedByAlias = null; AdminUser approvedByAlias = null; AdminUser rejectedByAlias = null; Source sourceAlias = null; PersonSource personSourceAlias = null; EventSource eventSourceAlias = null; UnitSource unitSourceAlias = null; OperationSource operationSourceAlias = null; var q = Session.QueryOver <FeedingSource>(() => feedingSourceAlias) .JoinAlias(() => feedingSourceAlias.UploadedBy, () => uploadedByAlias, JoinType.LeftOuterJoin) .JoinAlias(() => feedingSourceAlias.ApprovedBy, () => approvedByAlias, JoinType.LeftOuterJoin) .JoinAlias(() => feedingSourceAlias.RejectedBy, () => rejectedByAlias, JoinType.LeftOuterJoin) .JoinAlias(() => feedingSourceAlias.Source, () => sourceAlias, JoinType.LeftOuterJoin) .JoinAlias(() => sourceAlias.PersonSources, () => personSourceAlias, JoinType.LeftOuterJoin) .JoinAlias(() => sourceAlias.EventSources, () => eventSourceAlias, JoinType.LeftOuterJoin) .JoinAlias(() => sourceAlias.UnitSources, () => unitSourceAlias, JoinType.LeftOuterJoin) .JoinAlias(() => sourceAlias.OperationSources, () => operationSourceAlias, JoinType.LeftOuterJoin) .SelectList(list => list .Select(Projections.Group(() => feedingSourceAlias.Id)).WithAlias(() => output.Id) .Select(Projections.Group(() => feedingSourceAlias.Name)).WithAlias(() => output.Name) .Select(Projections.Group(() => feedingSourceAlias.Restricted)).WithAlias(() => output.Restricted) .Select(Projections.Group(() => feedingSourceAlias.FileModifiedDateTime)).WithAlias(() => output.FileModifiedDateTime) .Select(Projections.Group(() => uploadedByAlias.UserName)).WithAlias(() => output.UploadedBy) .Select(Projections.Group(() => feedingSourceAlias.UploadDate)).WithAlias(() => output.UploadDate) .Select(Projections.Group(() => approvedByAlias.UserName)).WithAlias(() => output.ApprovedBy) .Select(Projections.Group(() => feedingSourceAlias.ApprovedDate)).WithAlias(() => output.ApproveDate) .Select(Projections.Group(() => rejectedByAlias.UserName)).WithAlias(() => output.RejectedBy) .Select(Projections.Group(() => feedingSourceAlias.RejectedDate)).WithAlias(() => output.RejectedDate) .Select(Projections.Group(() => feedingSourceAlias.RejectedReason)).WithAlias(() => output.RejectedReason) .Select(Projections.Group(() => feedingSourceAlias.UploadNotes)).WithAlias(() => output.UploadNotes) .Select(Projections.Group(() => feedingSourceAlias.Source.Id)).WithAlias(() => output.SourceID) .Select(Projections.Group(() => feedingSourceAlias.IsReadOnly)).WithAlias(() => output.IsReadOnly) .Select(Projections.Group(() => feedingSourceAlias.IsPublic)).WithAlias(() => output.IsPublic) .Select(Projections.Count(() => personSourceAlias.Person.Id)).WithAlias(() => output.PersonSourceCount) .Select(Projections.Count(() => eventSourceAlias.Event.Id)).WithAlias(() => output.EventSourceCount) .Select(Projections.Count(() => unitSourceAlias.Unit.Id)).WithAlias(() => output.UnitSourceCount) .Select(Projections.Count(() => operationSourceAlias.Operation.Id)).WithAlias(() => output.OperationSourceCount) ); if (canViewAndSearchAll) { if (!includeRestricted) { q = q.Where(() => feedingSourceAlias.Restricted == false); } } else { // user can access sources they uploaded as well as sources marked public q = q.Where(() => uploadedByAlias.UserID == uploadedByUserId || feedingSourceAlias.IsPublic); } return(q.TransformUsing(Transformers.AliasToBean <FeedingSourceDTO>()) .List <FeedingSourceDTO>()); }
public ActionResult Person(int sourceId, int targetId) { Source source = this.sourceTasks.GetSource(sourceId); if (source != null) { Profiling2.Domain.Prf.Persons.Person person = this.personTasks.GetPerson(targetId); if (person != null) { PersonSourceViewModel vm = new PersonSourceViewModel(); vm.SourceId = source.Id; vm.PersonId = person.Id; vm.PopulateDropDowns(this.sourceTasks.GetReliabilities()); ViewBag.Person = person; ViewBag.Source = source; PersonSource ps = source.GetPersonSource(person); if (ps != null) { // Person is already attached to Source vm.Id = ps.Id; vm.Commentary = ps.Commentary; vm.Notes = ps.Notes; } return(View(vm)); } } return(new HttpNotFoundResult()); }
public JsonNetResult Edit(PersonSourceViewModel vm) { if (ModelState.IsValid) { PersonSource ps = this.sourceAttachmentTasks.GetPersonSource(vm.Id.Value); if (ps != null) { if (vm.ReliabilityId.HasValue) { ps.Reliability = this.sourceTasks.GetReliability(vm.ReliabilityId.Value); } ps.Commentary = vm.Commentary; ps.Notes = vm.Notes; ps = this.sourceAttachmentTasks.SavePersonSource(ps); return(JsonNet(string.Empty)); } else { Response.StatusCode = (int)HttpStatusCode.NotFound; return(JsonNet("Person source not found.")); } } else { return(JsonNet(this.GetErrorsForJson())); } }
public void Expected_Not_Matched_PropertyCount() { var source = new PersonSource() { Name = "Junil, Um" }; var target = new PersonTarget2(); var mapping = new ReflectionMapping(source, target, new ReflectionMappingOption() { ThrowIfNotMatched = true }); }
public IList <PersonSourceDTO> GetPersonSourceDTOs(int personId) { PersonSourceDTO dto = null; PersonSource psAlias = null; Source sAlias = null; Person pAlias = null; Reliability rAlias = null; return(Session.QueryOver <PersonSource>(() => psAlias) .JoinAlias(() => psAlias.Source, () => sAlias) .JoinAlias(() => psAlias.Person, () => pAlias) .JoinAlias(() => psAlias.Reliability, () => rAlias) .Where(() => pAlias.Id == personId) .And(() => !psAlias.Archive) .SelectList(list => list .Select(() => psAlias.Id).WithAlias(() => dto.Id) .Select(() => psAlias.Commentary).WithAlias(() => dto.Commentary) .Select(() => psAlias.Notes).WithAlias(() => dto.Notes) .Select(() => sAlias.Id).WithAlias(() => dto.SourceId) .Select(() => sAlias.SourceName).WithAlias(() => dto.SourceName) .Select(() => sAlias.IsRestricted).WithAlias(() => dto.SourceIsRestricted) .Select(() => pAlias.Id).WithAlias(() => dto.PersonId) .Select(() => rAlias.Id).WithAlias(() => dto.ReliabilityId) .Select(() => rAlias.ReliabilityName).WithAlias(() => dto.ReliabilityName) ) .TransformUsing(Transformers.AliasToBean <PersonSourceDTO>()) .List <PersonSourceDTO>()); }
static void Main(string[] args) { PeopleRepository allPeople = null; PeopleRepository offLimitsPeople = null; ResultsRepository results = null; new OptionSet { { "allpeople=", s => { allPeople = new PeopleRepository(File.ReadLines(s), s); } }, { "offlimits=", s => { offLimitsPeople = new PeopleRepository(File.ReadLines(s), s); } }, { "results=", s => { results = new ResultsRepository(s); } } }.Parse(args); var nextBirthday = results.NextBirthday(); var checkDate = new DateTime(DateTime.Now.Year, nextBirthday.Month, nextBirthday.Day).AddDays(1).AddSeconds(-1); // meh using (SystemClock.Stub(checkDate)) { var personSource = new PersonSource(allPeople.GetPeople()); var offLimitSource = new OffLimitsSource(offLimitsPeople.GetPeople(), personSource.GetAllPeople().Length); var matcher = new Matcher(personSource, offLimitSource); results.Save(matcher.Next()); offLimitsPeople.Save(matcher.GetOffLimits()); } }
private static void Displayed() { PersonSource ps = new PersonSource(); Console.WriteLine($"Имя: {ps.GetPerson().Name}"); Thread.Sleep(1000); }
public void given_a_start_date_Source_should_know_Next() { var today = new DateTime(2000, 8, 10); var source = new PersonSource(SampleData.People); source.GetNextRecipient(today).Name.ShouldBe("Iris"); }
public Source(int ID) { SourceID = ID; mapsource = new MapSource(SourceID); personsource1 = new PersonSource(0); personsource2 = new PersonSource(1); bombsource = new BombSource(SourceID); musicsource = new MusicSource(SourceID); }
public virtual void AddPersonSource(PersonSource ps) { if (this.PersonSources.Contains(ps)) { return; } this.PersonSources.Add(ps); }
private void DeletePersonSource(PersonSource ps) { if (ps != null) { ps.Source.RemovePersonSource(ps); ps.Person.RemovePersonSource(ps); this.personSourceRepo.Delete(ps); } }
public async Task SyncForPerson(int personId) { // see if we already have a scholar record for this person // TODO: query source values out of enum or resources var source = await this.dbContext.PeopleSources.SingleOrDefaultAsync(s => s.Source == "scholar" && s.PersonId == personId); if (source == null || string.IsNullOrWhiteSpace(source.SourceKey)) { // no source with key found if (source == null) { // use the existing source if available, otherwise create a new one source = new PersonSource { Source = "scholar", PersonId = personId }; this.dbContext.PeopleSources.Add(source); } // here we attempt to find source ID through search var personName = await this.dbContext.People.Where(p => p.Id == personId).Select(p => p.FullName).SingleOrDefaultAsync(); var matchingIds = await FindScholarIds(personName); if (matchingIds.Length == 1) { // if we have exactly one match, use that source.SourceKey = matchingIds[0]; } else { // else we have no match, just use the empty record until it can be manually updated if (source.Id == default(int)) { this.dbContext.Add(source); } source.LastUpdate = DateTime.UtcNow; await this.dbContext.SaveChangesAsync(); return; } } // go grab updated info var sourceData = await GetTagsAndPublicationsById(source.SourceKey); source.Data = JsonConvert.SerializeObject(sourceData); source.HasKeywords = sourceData.Tags.Any(); source.HasPubs = sourceData.Publications.Any(); source.LastUpdate = DateTime.UtcNow; // save changes to source object await this.dbContext.SaveChangesAsync(); }
public ActionResult Edit(int id) { PersonSource ps = this.sourceAttachmentTasks.GetPersonSource(id); if (ps != null) { PersonSourceViewModel vm = new PersonSourceViewModel(ps); vm.PopulateDropDowns(this.sourceTasks.GetReliabilities()); vm.PopulateSource(this.sourceTasks.GetSourceDTO(ps.Source.Id)); return(View(vm)); } return(new HttpNotFoundResult()); }
public void ReflectionMapping_Test() { var source = new PersonSource() { Name = "Junil, Um" }; var target = new PersonTarget(); var mapping = new ReflectionMapping(source, target); TestContext.WriteLine("SourcePerson's name is {0}", source.Name); TestContext.WriteLine("TargetPerson's name is {0} after Mapped ReflectionMapping", target.name); TestContext.WriteLine("{0} = {1}", source.Name, target.name); Assert.IsTrue(source.Name == target.name, "리플랙션으로 매핑된 Name 속성의 값이 틀립니다."); }
public PersonSource SavePersonSource(PersonSource ps) { ps.Person.AddPersonSource(ps); ps.Source.AddPersonSource(ps); if (!ps.Person.HasValidProfileStatus()) { ps.Person.ProfileStatus = this.personTasks.GetProfileStatus(ProfileStatus.ROUGH_OUTLINE); this.personTasks.SavePerson(ps.Person); } return(this.personSourceRepo.SaveOrUpdate(ps)); }
public void should_run() { var personSource = new PersonSource(SampleData.People); var matcher = new Matcher(personSource, new OffLimitsSource(new Person[0], SampleData.People.Length)); for (int i = 0; i < 250; i++) { using (SystemClock.Stub(DateTime.Now.AddMonths(i))) { Console.WriteLine(matcher.Next()); } } }
public JsonNetResult Delete(int id) { PersonSource ps = this.sourceAttachmentTasks.GetPersonSource(id); if (ps != null) { this.sourceAttachmentTasks.DeletePersonSource(ps.Id); Response.StatusCode = (int)HttpStatusCode.OK; return(JsonNet("Source successfully detached from person.")); } else { Response.StatusCode = (int)HttpStatusCode.NotFound; return(JsonNet("Person source not found.")); } }
public PersonSourceViewModel(PersonSource ps) { this.Id = ps.Id; if (ps.Person != null) { this.PersonId = ps.Person.Id; this.PersonName = ps.Person.Name; } if (ps.Reliability != null) { this.ReliabilityId = ps.Reliability.Id; this.ReliabilityName = ps.Reliability.ToString(); } this.Commentary = ps.Commentary; this.Notes = ps.Notes; }
public void MergePersonSourceDuplicates() { IList <ObjectSourceDuplicateDTO> duplicates = this.objectSourceDuplicatesQuery.GetPersonSourceDuplicates(); log.Info("Found " + duplicates.Count + " PersonSource duplicates."); foreach (ObjectSourceDuplicateDTO dto in duplicates) { log.Info("Merging " + dto.Count + " PersonSources PersonID=" + dto.ObjectID + " SourceID=" + dto.SourceID); // retrieve all duplicates IList <PersonSource> personSources = this.sourceAttachmentTasks.GetPersonSources( this.personTasks.GetPerson(dto.ObjectID), this.sourceTasks.GetSource(dto.SourceID)); // select PersonSource with highest PersonSource.Reliability PersonSource keep = personSources.OrderBy(x => x.Reliability).Last(); personSources.Remove(keep); // merge string mergedCommentary = keep.Commentary; string mergedNotes = keep.Notes; foreach (PersonSource ps in personSources) { if (!string.Equals(keep.Commentary, ps.Commentary)) { mergedCommentary += "; " + ps.Commentary; } if (!string.Equals(keep.Notes, ps.Notes)) { mergedNotes += "; " + ps.Notes; } this.sourceAttachmentTasks.DeletePersonSource(ps.Id); } // save merged PersonSource keep.Commentary = mergedCommentary; keep.Notes = "Merged with duplicates on " + string.Format("{0:ddd MMM yyyy}", DateTime.Now) + ".\n" + mergedNotes; this.sourceAttachmentTasks.SavePersonSource(keep); } log.Info("Finished merging PersonSource duplicates."); }
public JsonNetResult Add(PersonSourceViewModel vm) { if (ModelState.IsValid) { Source s = this.sourceTasks.GetSource(vm.SourceId.Value); Person p = this.personTasks.GetPerson(vm.PersonId.Value); if (s != null && p != null) { if (s.GetPersonSource(p) == null) { PersonSource ps = new PersonSource() { Source = s, Person = p, Commentary = vm.Commentary, Notes = vm.Notes }; if (vm.ReliabilityId.HasValue) { ps.Reliability = this.sourceTasks.GetReliability(vm.ReliabilityId.Value); } this.sourceAttachmentTasks.SavePersonSource(ps); return(JsonNet(string.Empty)); } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(JsonNet("Source already attached to this person.")); } } else { Response.StatusCode = (int)HttpStatusCode.NotFound; return(JsonNet("Person or source not found.")); } } else { return(JsonNet(this.GetErrorsForJson())); } }
public async Task <ActionResult <IList <GenderStatistics> > > GenderStatistics(int age) { var cacheKey = $"GenderStatistics"; var cachedValue = await CacheStore.GetObjectAsync <List <GenderStatistics> >(Cache, cacheKey); if (cachedValue == null) { var stats = await PersonSource.GenderStatistics(); if (stats == null) { return(NotFound()); } await CacheStore.SetObjectAsync <List <GenderStatistics> >(Cache, cacheKey, stats.ToList(), CacheTimeoutInSeconds); return(Ok(stats)); } return(Ok(cachedValue)); }
public async Task <ActionResult <IList <Person> > > GetByAge(int age) { var cacheKey = $"GetByAge{age}"; var cachedValue = await CacheStore.GetObjectAsync <List <Person> >(Cache, cacheKey); if (cachedValue == null) { var persons = await PersonSource.GetByAge(age); if (persons == null) { return(NotFound()); } await CacheStore.SetObjectAsync <List <Person> >(Cache, cacheKey, persons.ToList(), CacheTimeoutInSeconds); return(Ok(persons.ToList())); } return(Ok(cachedValue)); }
public async Task <ActionResult <Person> > GetById(int id) { var cacheKey = $"GetById_{id}"; var cachedValue = await CacheStore.GetObjectAsync <Person>(Cache, cacheKey); if (cachedValue == null) { var person = await PersonSource.GetById(id); if (person == null) { return(NotFound()); } await CacheStore.SetObjectAsync <Person>(Cache, cacheKey, person, CacheTimeoutInSeconds); return(Ok(person)); } return(Ok(cachedValue)); }
public JsonNetResult Person(PersonSourceViewModel vm) { if (vm.Id.HasValue) { this.sourceAttachmentTasks.DeletePersonSource(vm.Id.Value); Response.StatusCode = (int)HttpStatusCode.OK; return(JsonNet("Person successfully detached from source.")); } else if (ModelState.IsValid) { Source source = this.sourceTasks.GetSource(vm.SourceId.Value); Profiling2.Domain.Prf.Persons.Person person = this.personTasks.GetPerson(vm.PersonId.Value); if (source != null && person != null) { if (source.GetPersonSource(person) == null) { PersonSource ps = new PersonSource(); ps.Source = source; ps.Person = person; ps.Reliability = this.sourceTasks.GetReliability(vm.ReliabilityId.Value); ps.Commentary = vm.Commentary; ps.Notes = vm.Notes; this.sourceAttachmentTasks.SavePersonSource(ps); } Response.StatusCode = (int)HttpStatusCode.OK; return(JsonNet("Person successfully attached.")); } else { Response.StatusCode = (int)HttpStatusCode.NotFound; return(JsonNet("Person or source not found.")); } } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(JsonNet("Form data failed validation.")); } }
/// <summary> /// 通过来源获取第一个人员,若不存在则新 /// </summary> /// <param name="personSource"></param> /// <returns></returns> public virtual async Task <Person> GetDefaultPersonBySourceOrInsert(PersonSource personSource) { //先判断是否已有此人员 var reporter = await Repository.GetAll().Where(o => o.PersonSource == personSource).FirstOrDefaultAsync(); if (reporter == null) { reporter = new Person() { Name = personSource.ToString(), PersonSource = personSource }; await Repository.InsertAsync(reporter); await CurrentUnitOfWork.SaveChangesAsync(); } await Repository.UpdateAsync(reporter); await CurrentUnitOfWork.SaveChangesAsync(); return(reporter); }
public virtual void RemovePersonSource(PersonSource ps) { this.PersonSources.Remove(ps); }
public static void Displayed() { PersonSource ps = new PersonSource(); Console.WriteLine($"Имя: {ps.GetPerson().Name}"); }