private void HandleGetCCImage(ApiRequest request)
 {
     lock (request)
     {
         try
         {
             Image licenseImage;
             var   token = request.Parameters.GetValues("token");
             if (token != null)
             {
                 licenseImage = CreativeCommonsLicense.FromToken(token[0]).GetImage();
             }
             else
             {
                 licenseImage = request.CurrentBook.GetLicenseMetadata().License.GetImage();
             }
             // ReplyWithImage uses the extension to determine the content type
             using (TempFile tempFile = TempFile.WithExtension(".png"))
             {
                 licenseImage.Save(tempFile.Path);
                 request.ReplyWithImage(tempFile.Path);
             }
             licenseImage.Dispose();
         }
         catch (Exception e)
         {
             Logger.WriteError("Unable to get cc license image for dialog", e);
             request.Failed();
         }
     }
 }
        private Metadata GetMetadataFromJson(ApiRequest request, bool forBook)
        {
            var json     = request.RequiredPostJson();
            var settings = DynamicJson.Parse(json);

            if (forBook)
            {
                Model.CurrentBook.BookInfo.MetaData.UseOriginalCopyright = settings.derivativeInfo.useOriginalCopyright;

                if (settings.derivativeInfo.useOriginalCopyright)
                {
                    return(BookCopyrightAndLicense.GetOriginalMetadata(Model.CurrentBook.Storage.Dom, Model.CurrentBook.BookData));
                }
            }

            var metadata = new Metadata {
                Creator = settings.copyrightInfo.imageCreator
            };

            metadata.SetCopyrightNotice(settings.copyrightInfo.copyrightYear, settings.copyrightInfo.copyrightHolder);

            if (settings.licenseInfo.licenseType == "creativeCommons")
            {
                metadata.License = new CreativeCommonsLicense(
                    true,
                    settings.licenseInfo.creativeCommonsInfo.allowCommercial == "yes",
                    GetCcDerivativeRule(settings.licenseInfo.creativeCommonsInfo.allowDerivatives))
                {
                    IntergovernmentalOriganizationQualifier = settings.licenseInfo.creativeCommonsInfo.intergovernmentalVersion
                };
            }
            else if (settings.licenseInfo.licenseType == "publicDomain")
            {
                metadata.License = CreativeCommonsLicense.FromToken("cc0");
            }
            else if (settings.licenseInfo.licenseType == "contact")
            {
                metadata.License = new NullLicense();
            }
            else
            {
                metadata.License = new CustomLicense();
            }

            metadata.License.RightsStatement = settings.licenseInfo.rightsStatement;

            return(metadata);
        }
        public void ShowFullDialogTwiceToCheckRoundTripping()
        {
            var m = new Metadata();

            m.License = CreativeCommonsLicense.FromToken("by");
            m.License.RightsStatement = "some restrictions";

            using (var dlg = new MetadataEditorDialog(m))
            {
                dlg.ShowDialog();
                m = dlg.Metadata;
            }

            using (var dlg = new MetadataEditorDialog(m))
            {
                dlg.ShowDialog();
            }
        }