コード例 #1
0
        public void ToSetAction_Should_SetValue()
        {
            var person = new PersonStub("Stefan", "Wentink");
            var action = ExpressionExtensions.ToSetAction <PersonStub, string>(x => x.FirstName);

            Assert.Equal("Stefan", person.FirstName);

            action(person, "John");
            Assert.Equal("John", person.FirstName);

            action(person, "Dick");
            Assert.Equal("Dick", person.FirstName);
        }
コード例 #2
0
        public void ToAddAction_Should_SetValue()
        {
            var person = new PersonStub("Stefan", "Wentink", 12);
            var action = ExpressionExtensions.ToAddAction <PersonStub, int>(x => x.Age);

            Assert.Equal(12, person.Age);

            action(person, 3);
            Assert.Equal(15, person.Age);

            action(person, -5);
            Assert.Equal(10, person.Age);
        }
コード例 #3
0
 private List <string> Execute(PersonStub person)
 {
     var handler = new HandlerContainer <PersonStub>(
         new List <IHandler <PersonStub> > {
         new ValidationHandler <PersonStub>(
             x => !string.IsNullOrWhiteSpace(x.FirstName),
             x => $"{nameof(PersonStub.FirstName)} [{x.FirstName}] should not be null or whitespace."),
         new ActionHandler <PersonStub>(
             x => x.Initials = x.FirstName.Substring(0, 1),
             x => x.Initials == default && (x.FirstName?.Length ?? 0) > 0),
         new ValidationHandler <PersonStub>(
             x => !string.IsNullOrWhiteSpace(x.Initials),
             x => $"{nameof(PersonStub.Initials)} [{x.Initials}] should not be null or whitespace.")
     });
コード例 #4
0
        private string Execute(PersonStub person)
        {
            var handler = new ValidationHandler <PersonStub>(
                x => !string.IsNullOrWhiteSpace(x.FirstName),
                x => $"{nameof(PersonStub.FirstName)} [{x.FirstName}] should not be null or whitespace.");

            var message = string.Empty;

            handler.InvalidResult                     += (object sender, Contract.EventArgs.ValidationHandlerArgs e) =>
                                               message = e.ValidationResult.ErrorMessage;

            handler.Execute(person);

            return(message);
        }
コード例 #5
0
        public void ToAddAction_ShouldSetValue_With_ValueExpressionClosure()
        {
            var person = new PersonStub("Stefan", "Wentink", 12);
            var age    = 3;
            var action = ExpressionExtensions.ToAddAction <PersonStub, int>(x => x.Age, () => age);

            Assert.Equal(12, person.Age);

            action(person);
            Assert.Equal(15, person.Age);

            age = -5;
            action(person);
            Assert.Equal(10, person.Age);
        }
コード例 #6
0
        public void ToSetAction_ShouldSetValue_With_ValueExpressionClosure()
        {
            var person = new PersonStub("Stefan", "Wentink");
            var name   = "John";
            var action = ExpressionExtensions.ToSetAction <PersonStub, string>(x => x.FirstName, () => name);

            Assert.Equal("Stefan", person.FirstName);

            action(person);
            Assert.Equal("John", person.FirstName);

            name = "Dick";
            action(person);
            Assert.Equal("Dick", person.FirstName);
        }
コード例 #7
0
        /// <summary>
        /// Tries to parse a <see cref="PersonStub"/> object
        /// </summary>
        /// <param name="element"><see cref="XElement"/> to read from</param>
        /// <param name="nfoDirectoryFsra"><see cref="IFileSystemResourceAccessor"/> pointing to the parent directory of the nfo-file</param>
        /// <returns>
        /// The filled <see cref="PersonStub"/> object or <c>null</c> if
        /// - element is null
        /// - element does not contain child elements
        /// - element does not contain a child element with the name "name" or such child element is empty or contains a value from _settings.IgnoreStrings
        /// </returns>
        protected async Task <PersonStub> ParsePerson(XElement element, IFileSystemResourceAccessor nfoDirectoryFsra)
        {
            // Example of a valid element:
            // <[ElementName]>
            //   <name>John Pyper-Ferguson</name>
            //   <role>Le père dans le minibus</role>
            //   <order>1</order>
            //   <thumb>http://site.com/MakenzieVega-35443.jpg</thumb>
            //   <imdb>nmXXXXXXX</imdb>
            //   <birthdate>01-01-2000</birthdate>
            //   <birthplace></birthplace>
            //   <deathdate>12-12-2050</deathdate>
            //   <deathplace></deathplace>
            //   <minibiography></minibiography>
            //   <biography></biography>
            // </[ElementName]>
            // The <name> child element is mandatory, all other child elements are optional
            if (element == null)
            {
                return(null);
            }
            if (!element.HasElements)
            {
                _debugLogger.Warn("[#{0}]: The following element was supposed to contain a person's data in child elements, but it doesn't contain child elements: {1}", _miNumber, element);
                return(null);
            }
            var value = new PersonStub();

            if ((value.Name = ParseSimpleString(element.Element("name"))) == null)
            {
                return(null);
            }
            value.Role  = ParseSimpleString(element.Element("role"));
            value.Order = ParseSimpleInt(element.Element("order"));
            //ToDo: Reenable parsing <thumb> child elements once we can store them in the MediaLibrary
            value.Thumb = await Task.FromResult <byte[]>(null); //ParseSimpleImageAsync(element.Element("thumb"), nfoDirectoryFsra).ConfigureAwait(false);

            value.ImdbId        = ParseSimpleString(element.Element("imdb"));
            value.Birthdate     = ParseSimpleDateTime(element.Element("birthdate"));
            value.Birthplace    = ParseSimpleString(element.Element("birthplace"));
            value.Deathdate     = ParseSimpleDateTime(element.Element("deathdate"));
            value.Deathplace    = ParseSimpleString(element.Element("deathplace"));
            value.MiniBiography = ParseSimpleString(element.Element("minibiography"));
            value.Biography     = ParseSimpleString(element.Element("biography"));
            return(value);
        }
コード例 #8
0
 private bool TryWriteArtistAspect(PersonStub person, IDictionary <Guid, IList <MediaItemAspect> > extractedAspectData)
 {
     return(TryWritePersonAspect(person, PersonAspect.OCCUPATION_ARTIST, extractedAspectData));
 }
コード例 #9
0
        public static void StorePersonAndCharacter(IDictionary <Guid, IList <MediaItemAspect> > aspects, PersonStub person, string occupation, bool forSeries)
        {
            MultipleMediaItemAspect personAspect = MediaItemAspect.CreateAspect(aspects, TempPersonAspect.Metadata);

            personAspect.SetAttribute(TempPersonAspect.ATTR_IMDBID, person.ImdbId);
            personAspect.SetAttribute(TempPersonAspect.ATTR_NAME, person.Name);
            personAspect.SetAttribute(TempPersonAspect.ATTR_OCCUPATION, occupation);
            personAspect.SetAttribute(TempPersonAspect.ATTR_CHARACTER, person.Role);
            personAspect.SetAttribute(TempPersonAspect.ATTR_BIOGRAPHY, !string.IsNullOrEmpty(person.Biography) ? person.Biography : person.MiniBiography);
            personAspect.SetAttribute(TempPersonAspect.ATTR_DATEOFBIRTH, person.Birthdate);
            personAspect.SetAttribute(TempPersonAspect.ATTR_DATEOFDEATH, person.Deathdate);
            personAspect.SetAttribute(TempPersonAspect.ATTR_ORDER, person.Order);
            personAspect.SetAttribute(TempPersonAspect.ATTR_ORIGIN, person.Birthplace);
            personAspect.SetAttribute(TempPersonAspect.ATTR_FROMSERIES, forSeries);
        }
コード例 #10
0
ファイル: EventManager.cs プロジェクト: jameswestbv/basecamp
 public IEnumerable <Event> GetForPerson(PersonStub person, DateTime since)
 {
     return(GetForProject(person.Id, since));
 }
コード例 #11
0
ファイル: PeopleManager.cs プロジェクト: alifianif/Buru
 public bool Delete(PersonStub person)
 {
     return(Delete(person.Id));
 }
コード例 #12
0
ファイル: AccessManager.cs プロジェクト: alifianif/Buru
        /*public IEnumerable<PersonStub> GetPeopleWithAccessToCalendar(CalendarStub calendar)
         * {
         *  return GetPeopleWithAccessToProject(calendar.Id);
         * }
         *
         * //calendars/1/accesses.json
         * public IEnumerable<PersonStub> GetPeopleWithAccessToCalendar(int calendarId)
         * {
         *  var action = "/calendars/{0}/accesses.json".FormatWith(calendarId);
         *  var people = Api.Get<IEnumerable<PersonStub>>(action);
         *  return people;
         * }*/


        public bool RemoveAccessToProject(ProjectStub project, PersonStub person)
        {
            return(RemoveAccessToProject(project.Id, person.Id));
        }
コード例 #13
0
 public bool RemoveAccessToCalendar(CalendarStub calendar, PersonStub person)
 {
     return(RemoveAccessToProject(calendar.Id, person.Id));
 }