Esempio n. 1
0
        private void HandleCopyImageCreditsForWholeBook(ApiRequest request)
        {
            var names = BookStorage.GetImagePathsRelativeToBook(_bookSelection.CurrentSelection.RawDom.DocumentElement);
            IEnumerable <string> langs = null;

            if (request.CurrentCollectionSettings != null)
            {
                langs = request.CurrentCollectionSettings.LicenseDescriptionLanguagePriorities;
            }
            else
            {
                langs = new List <string> {
                    "en"
                }
            };                                                                  // emergency fall back -- probably never used.
            var credits        = new List <string>();
            var missingCredits = new List <string>();

            foreach (var name in names)
            {
                var path = _bookSelection.CurrentSelection.FolderPath.CombineForPath(name);
                if (RobustFile.Exists(path))
                {
                    var    meta = Metadata.FromFile(path);
                    string id;
                    var    credit = meta.MinimalCredits(langs, out id);
                    if (String.IsNullOrEmpty(credit) && name.ToLowerInvariant() != "license.png" && name.ToLowerInvariant() != "placeholder.png")
                    {
                        missingCredits.Add(name);
                    }
                    if (!String.IsNullOrEmpty(credit) && !credits.Contains(credit))
                    {
                        credits.Add(credit);
                    }
                }
            }
            var total = credits.Aggregate(new StringBuilder(), (all, credit) => {
                all.AppendFormat("<p>{0}</p>{1}", credit, System.Environment.NewLine);
                return(all);
            });

            // Notify the user of images with missing credits.
            if (missingCredits.Count > 0)
            {
                var missing = LocalizationManager.GetString("EditTab.FrontMatter.PasteMissingCredits", "Missing credits:");
                total.AppendFormat("<p>{0}", missing);
                for (var i = 0; i < missingCredits.Count; ++i)
                {
                    if (i > 0)
                    {
                        total.Append(",");
                    }
                    total.AppendFormat(" {0}", missingCredits[i]);
                }
                total.AppendFormat("</p>{0}", System.Environment.NewLine);
            }
            request.ReplyWithText(total.ToString());
        }