当前位置: 首页>>代码示例>>C#>>正文


C# DreamMessage.AsStream方法代码示例

本文整理汇总了C#中MindTouch.Dream.DreamMessage.AsStream方法的典型用法代码示例。如果您正苦于以下问题:C# DreamMessage.AsStream方法的具体用法?C# DreamMessage.AsStream怎么用?C# DreamMessage.AsStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MindTouch.Dream.DreamMessage的用法示例。


在下文中一共展示了DreamMessage.AsStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PutSiteLogo

        internal Yield PutSiteLogo(DreamContext context, DreamMessage request, Result<DreamMessage> response) {

            //Confirm image type
            if(!new MimeType("image/*").Match(request.ContentType)) {
                throw new DreamAbortException(DreamMessage.BadRequest(DekiResources.EXPECTED_IMAGE_MIMETYPE));
            }
            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 DreamBadRequestException(DekiResources.CANNOT_PROCESS_LOGO_IMAGE);
                }
            } else {
                DekiContext.Current.Instance.Log.WarnMethodCall("PUT:site/logo", "Unable to retrieve saved logo");
            }
            response.Return(DreamMessage.Ok());
            yield break;
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:32,代码来源:DekiWiki-Site.cs

示例2: PutFile

        public Yield PutFile(DreamContext context, DreamMessage request, Result<DreamMessage> response) {

            // Retrieve the file
            PageBE page;
            string userFileName;
            AttachmentBE file = GetAttachmentFromUrl(false, out page, false, false);
            
            // If the file does not exist, attempt to retrieve the page
            if (null == file) {
                if (null == page) {
                    if (null != DreamContext.Current.GetParam<string>("fileid")) {
                        throw new DreamAbortException(DreamMessage.NotFound(DekiResources.COULD_NOT_FIND_FILE));
                    }
                    page = PageBL.GetPageFromUrl();
                }
                userFileName = GetFilenameFromPathSegment(DreamContext.Current.GetParam<string>("filename"));
            } else {
                string fileNameParam = DreamContext.Current.GetParam("filename", null);
                if (fileNameParam == null) {
                    userFileName = file.Name;
                } else {
                    userFileName = GetFilenameFromPathSegment(fileNameParam);
                }
            }

            // Retrieve the file description
            string userDescription = context.GetParam("description", string.Empty);
            if(userDescription.Length > AttachmentBL.MAX_DESCRIPTION_LENGTH) {
                userDescription = userDescription.Substring(0, AttachmentBL.MAX_DESCRIPTION_LENGTH);
            }

            // Validate the page
            PageBL.AuthorizePage(DekiContext.Current.User, Permissions.UPDATE, page, false);

            // Get entire stream so it can be reused
            AttachmentBE savedFileRevision = AttachmentBL.Instance.AddAttachment(file, request.AsStream(), request.ContentLength, request.ContentType, page, userDescription, userFileName);

            // report an error on failure, and don't redirect
            if (savedFileRevision == null) {
                response.Return(DreamMessage.InternalError(DekiResources.FAILED_TO_SAVE_UPLOAD));
                yield break;
            }
            response.Return(DreamMessage.Ok(AttachmentBL.Instance.GetFileXml(savedFileRevision, true, null, null)));
            yield break;
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:45,代码来源:DekiWiki-Files.cs

示例3: CreateDbSerializedContentFromRequest

 public ResourceContentBE CreateDbSerializedContentFromRequest(DreamMessage request) {
     return CreateDbSerializedContentFromStream(request.AsStream(), request.ContentLength, request.ContentType);
 }
开发者ID:heran,项目名称:DekiWiki,代码行数:3,代码来源:ResourceContentBL.cs

示例4: PutResourcePropertyHelper

        private Yield PutResourcePropertyHelper(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
            uint? parentId;
            ResourceBE.Type parentType;
            XUri parentUri;

            string etag = request.Headers.ETag ?? context.GetParam("etag", null);
            string description = context.GetParam("description", string.Empty);
            AbortEnum abort = SysUtil.ChangeType<AbortEnum>(context.GetParam("abort", "modified"));
            string name;

            PropertyBE prop = GetPropertyFromRequest(context, Permissions.UPDATE, false, false, out name, out parentId, out parentType, out parentUri);
            if(prop == null) {

                // abort if the user specified to abort on 'modified' and provided an 'etag'; since no etag exists, they are not the same
                if((abort == AbortEnum.Modified) && !string.IsNullOrEmpty(etag)) {
                    throw new DreamAbortException(DreamMessage.Conflict(DekiResources.PROPERTY_EDIT_NONEXISTING_CONFLICT));
                }

                // create the resource
                ResourceBE parentResource;
                PageBE parentPage;
                AuthorizeParent(context, Permissions.UPDATE, out parentId, out parentType, out parentUri, out parentPage, out parentResource);
                ResourceContentBE resourceContent = PropertyBL.Instance.CreateDbSerializedContentFromStream(request.AsStream(), request.ContentLength, request.ContentType);
                prop = PropertyBL.Instance.Create(parentId, parentUri, parentType, parentResource, name, resourceContent, description, etag, abort);
            } else if(abort == AbortEnum.Exists) {
                throw new DreamAbortException(DreamMessage.Conflict(string.Format(DekiResources.PROPERTY_EXISTS_CONFLICT, name)));
            } else {
                ResourceContentBE resourceContent = PropertyBL.Instance.CreateDbSerializedContentFromStream(request.AsStream(), request.ContentLength, request.ContentType);
                prop = PropertyBL.Instance.UpdateContent(prop, resourceContent, description, etag, abort, parentUri, parentType);
            }
            XDoc ret = PropertyBL.Instance.GetPropertyXml(prop, parentUri, null, null);
            response.Return(DreamMessage.Ok(ret));
            yield break;
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:34,代码来源:DekiWiki-Properties.cs

示例5: PostResourcePropertyHelper

        private Yield PostResourcePropertyHelper(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
            uint? parentId;
            ResourceBE.Type parentType;
            XUri parentUri;
            ResourceBE parentResource;
            PageBE parentPage;
            AuthorizeParent(context, Permissions.UPDATE, out parentId, out parentType, out parentUri, out parentPage, out parentResource);

            string etag = request.Headers.ETag ?? context.GetParam("etag", null);
            AbortEnum abort = SysUtil.ChangeType<AbortEnum>(context.GetParam("abort", "exists"));
            string description = context.GetParam("description", string.Empty);
            string name = XUri.Decode(request.Headers[SLUGHEADER]);
            if(string.IsNullOrEmpty(name)) {
                throw new DreamBadRequestException(DekiResources.PROPERTY_CREATE_MISSING_SLUG);
            }


            ResourceContentBE resourceContent = PropertyBL.Instance.CreateDbSerializedContentFromStream(request.AsStream(), request.ContentLength, request.ContentType);
            PropertyBE property = PropertyBL.Instance.Create(parentId, parentUri, parentType, parentResource, name, resourceContent, description, etag, abort);
            XDoc ret = PropertyBL.Instance.GetPropertyXml(property, parentUri, null, null);
            response.Return(DreamMessage.Ok(ret));
            yield break;
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:23,代码来源:DekiWiki-Properties.cs

示例6: PutFile

        public Yield PutFile(DreamContext context, DreamMessage request, Result<DreamMessage> response) {

            // Retrieve the file
            PageBE page;
            string userFileName;
            ResourceBE file = GetAttachmentFromUrl(context, false, out page, false, false);

            // If the file does not exist, attempt to retrieve the page
            if(null == file) {
                if(null == page) {
                    if(null != DreamContext.Current.GetParam<string>("fileid")) {
                        throw new AttachmentNotFoundException();
                    }
                    page = PageBL_GetPageFromUrl(context, true);
                }
                userFileName = GetFilenameFromPathSegment(DreamContext.Current.GetParam<string>("filename"));
            } else {
                string fileNameParam = DreamContext.Current.GetParam("filename", null);
                if(fileNameParam == null) {
                    userFileName = file.Name;
                } else {
                    userFileName = GetFilenameFromPathSegment(fileNameParam);
                }
            }

            // Retrieve the file description
            string userDescription = context.GetParam("description", string.Empty);
            if(userDescription.Length > AttachmentBL.MAX_DESCRIPTION_LENGTH) {
                userDescription = userDescription.Substring(0, AttachmentBL.MAX_DESCRIPTION_LENGTH);
            }

            // Validate the page
            PageBL.AuthorizePage(DekiContext.Current.User, Permissions.UPDATE, page, false);

            // Get entire stream so it can be reused
            var isMSWebDAV = MSWEBDAV_USER_AGENT_REGEX.IsMatch(request.Headers.UserAgent ?? string.Empty);
            ResourceBE savedFileRevision = AttachmentBL.Instance.AddAttachment(file, request.AsStream(), request.ContentLength, request.ContentType, page, userDescription, userFileName, isMSWebDAV);

            // report an error on failure, and don't redirect
            if(savedFileRevision == null) {
                throw new AttachmentUploadSaveFatalException();
            }
            response.Return(DreamMessage.Ok(AttachmentBL.Instance.GetFileXml(savedFileRevision, true, null, null)));
            yield break;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:45,代码来源:DekiWiki-Files.cs


注:本文中的MindTouch.Dream.DreamMessage.AsStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。