Exemplo n.º 1
0
        public void DreamResponseException_from_message_contains_status_message_as_exception_message()
        {
            var msg       = DreamMessage.Conflict("huh?");
            var exception = new DreamResponseException(msg);

            Assert.AreEqual(DreamMessage.GetStatusStringOrNull(msg), exception.Message);
        }
Exemplo n.º 2
0
        public void DreamResponseException_from_message_contains_status_message_in_ToString()
        {
            var msg       = DreamMessage.Conflict("huh?");
            var exception = new DreamResponseException(msg);

            Assert.IsTrue(exception.ToString().Contains(DreamMessage.GetStatusStringOrNull(msg)));
        }
Exemplo n.º 3
0
        public Yield PutFile(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            string   filepath   = GetPath(context);
            string   folderpath = Path.GetDirectoryName(filepath);
            double   ttl        = context.GetParam("ttl", 0.0);
            TimeSpan?timeToLive = null;

            if (ttl > 0.0)
            {
                timeToLive = TimeSpan.FromSeconds(ttl);
            }
            if (Directory.Exists(filepath))
            {
                // filepath is actually an existing directory
                response.Return(DreamMessage.Conflict("there exists a directory at the specified file path"));
                yield break;
            }

            // create folder if need be
            if (!Directory.Exists(folderpath))
            {
                Directory.CreateDirectory(folderpath);
            }

            // save request stream in target file
            DreamMessage result;

            try {
                request.ToStream().CopyToFile(filepath, request.ContentLength);
                WriteMeta(filepath, timeToLive, null);
                result = DreamMessage.Ok();
            } catch (DirectoryNotFoundException) {
                result = DreamMessage.NotFound("directory not found");
            } catch (PathTooLongException) {
                result = DreamMessage.BadRequest("path too long");
            } catch (NotSupportedException) {
                result = DreamMessage.BadRequest("not supported");
            }
            response.Return(result);
            yield break;
        }
 private static DreamMessage Map(MindTouchConflictException e, DekiResources resources)
 {
     return(DreamMessage.Conflict(resources.Localize(e.Resource)));
 }
 private static DreamMessage Map(CommentConcurrencyException e, DekiResources resources)
 {
     return(DreamMessage.Conflict(resources.Localize(DekiResources.COMMENT_CONCURRENCY_ERROR(e.PageId))));
 }
 private static DreamMessage Map(ResourceConcurrencyException e, DekiResources resources)
 {
     return(DreamMessage.Conflict(resources.Localize(DekiResources.PROPERTY_CONCURRENCY_ERROR(e.ResourceId))));
 }
 private static DreamMessage Map(ResourceRevisionOutOfRangeException e, DekiResources resources)
 {
     return(DreamMessage.Conflict(resources.Localize(DekiResources.RESOURCE_REVISION_OUT_OF_RANGE(e.Resource))));
 }
 //--- DekiDataException handlers ---
 private static DreamMessage Map(ResourceExpectedHeadException e, DekiResources resources)
 {
     return(DreamMessage.Conflict(resources.Localize(DekiResources.RESOURCE_EXPECTED_HEAD_REVISION(e.HeadRevision, e.Revision))));
 }
Exemplo n.º 9
0
        public void Can_get_status_message_from_message()
        {
            var msg = DreamMessage.Conflict("huh?");

            Assert.AreEqual(string.Format("HTTP Status: {0}({1})", msg.Status, (int)msg.Status), DreamMessage.GetStatusStringOrNull(msg));
        }