Ejemplo n.º 1
0
 internal Yield DeleteSiteLogo(DreamContext context, DreamMessage request, Result <DreamMessage> response)
 {
     DekiContext.Current.Instance.Storage.DeleteSiteFile(LOGO_LABEL);
     ConfigBL.DeleteInstanceSettingsValue(ConfigBL.UI_LOGO_UPLOADED);
     response.Return(DreamMessage.Ok());
     yield break;
 }
Ejemplo n.º 2
0
        internal Yield PutSiteLogo(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            //Confirm image type
            if (!new MimeType("image/*").Match(request.ContentType))
            {
                throw new SiteImageMimetypeInvalidArgumentException();
            }
            try {
                //Save file to storage provider
                DekiContext.Current.Instance.Storage.PutSiteFile(LOGO_LABEL, new StreamInfo(request.AsStream(), request.ContentLength, request.ContentType));
                ConfigBL.SetInstanceSettingsValue(ConfigBL.UI_LOGO_UPLOADED, "true");
            } catch (Exception x) {
                DekiContext.Current.Instance.Log.Warn("Failed to save logo to storage provider", x);
                ConfigBL.DeleteInstanceSettingsValue(ConfigBL.UI_LOGO_UPLOADED);
                throw;
            }

            StreamInfo file = DekiContext.Current.Instance.Storage.GetSiteFile(LOGO_LABEL, false);

            if (file != null)
            {
                StreamInfo thumb = AttachmentPreviewBL.BuildThumb(file, FormatType.PNG, RatioType.UNDEFINED, DekiContext.Current.Instance.LogoWidth, DekiContext.Current.Instance.LogoHeight);
                if (thumb != null)
                {
                    DekiContext.Current.Instance.Storage.PutSiteFile(LOGO_LABEL, thumb);
                }
                else
                {
                    DekiContext.Current.Instance.Log.WarnMethodCall("PUT:site/logo", "Unable to process logo through imagemagick");
                    DekiContext.Current.ApiPlug.At("site", "logo").Delete();
                    throw new SiteUnableToProcessLogoInvalidOperationException();
                }
            }
            else
            {
                DekiContext.Current.Instance.Log.WarnMethodCall("PUT:site/logo", "Unable to retrieve saved logo");
            }
            response.Return(DreamMessage.Ok());
            yield break;
        }