Esempio n. 1
0
        public static bool TryCreate(IDirectoryInfo eventDirectory, IFileSystemItem parent, out IFileSystemItem directory)
        {
            directory = null;

            var name = eventDirectory.Name;

            var expectedClubChar = parent.GetClubChar();
            var expectedYear     = parent.GetYear();

            var regex = new Regex(Patterns.EventDirectory);

            var match = regex.Match(name);

            if (!match.Success)
            {
                return(false);
            }

            if (match.Groups.Count != 6)
            {
                return(false);
            }

            var actualClubChar  = match.Groups[1].Value;
            var actualYear      = match.Groups[2].Value;
            var actualMonth     = match.Groups[3].Value;
            var actualDay       = match.Groups[4].Value;
            var actualEventName = match.Groups[5].Value;

            var doesClubCharMatch = expectedClubChar == actualClubChar;
            var doesYearMatch     = expectedYear == actualYear;
            var isValid           = doesClubCharMatch && doesYearMatch;

            directory = new EventDirectory(eventDirectory, parent, isValid, actualClubChar, actualYear, actualMonth, actualDay, actualEventName);
            return(true);
        }