예제 #1
0
        private PhotoCreditInfo GetPhotoCredit(DirectoryInfo crawlDI)
        {
            var photoCredit = new PhotoCreditInfo();

            try
            {
                var photoCreditFiles = crawlDI.GetFiles("fotocredit_*.txt");

                if (photoCreditFiles.Length == 1)
                {
                    string photoCreditFileName = photoCreditFiles[0].FullName;
                    string rootPhotoCreditPath = System.IO.Path.Combine(_rootDir, photoCreditFiles[0].Name);
                    if (System.IO.File.Exists(rootPhotoCreditPath))
                    {
                        photoCredit.RootFileFound = true;
                        photoCreditFileName       = rootPhotoCreditPath;
                    }
                    string photoCreditFileContent = System.IO.File.ReadAllText(photoCreditFileName);

                    if (!string.IsNullOrEmpty(photoCreditFileContent))
                    {
                        var photoCreditFileContentParts = photoCreditFileContent.Split(':');
                        if (photoCreditFileContentParts.Length == 2)
                        {
                            photoCredit.ContentFound = true;
                            var photoCreditParts = photoCreditFileContentParts[1].Split('/');
                            photoCredit.Fullname = photoCreditParts[0].Trim();
                            var nameParts = photoCredit.Fullname.Split(' ');
                            photoCredit.Lastname = nameParts.Last();
                            if (nameParts.Length > 1)
                            {
                                photoCredit.Firstname = string.Join(" ", nameParts.Take(nameParts.Length - 1));
                            }

                            if (photoCreditParts.Length >= 2)
                            {
                                photoCredit.Organisation = photoCreditParts[1];
                            }
                        }
                        else
                        {
                            photoCredit.Error = "'photocredit_*.txt' file has unexpected format";
                        }
                    }
                    else
                    {
                        photoCredit.Error = "'photocredit_*.txt' file empty";
                    }
                }
                else if (photoCreditFiles.Length > 1)
                {
                    photoCredit.Error = "More than one 'photocredit_*.txt' file found";
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Fehler: {ex.Message}");
            }

            return(photoCredit);
        }
예제 #2
0
        private string GenerateFileName(FileInfo fileFI, DirectoryInfo crawlDI, int fileIndex, PhotoCreditInfo photoCredit)
        {
            var photoCreditParts = new List <string>();

            if (!string.IsNullOrEmpty(photoCredit.FullnameForFilename))
            {
                photoCreditParts.Add(photoCredit.FullnameForFilename);
            }
            if (!string.IsNullOrEmpty(photoCredit.OrganisationForFilename))
            {
                photoCreditParts.Add(photoCredit.OrganisationForFilename);
            }
            return($"KUG_{fileIndex.ToString().PadLeft(3, '0')}_{crawlDI.Name}{(photoCreditParts.Count > 0 ? "_Foto_" + string.Join("_", photoCreditParts) : "")}{fileFI.Extension}");
        }