Example #1
0
 public string Localize(DekiResources resources) {
     var _builder = new StringBuilder();
     foreach(var item in _resourceChain) {
         var resource = item as DekiResource;
         if(resource == null) {
             _builder.Append(item);
         } else {
             _builder.Append(resources.Localize(resource));
         }
     }
     return _builder.ToString();
 }
Example #2
0
        //--- Class Methods ---

        // TODO: if we need more arguments, need to make the dispatcher smarter to pass in the desired arguments, so that the other handler
        // signatures don't have to change
        public static DreamMessage Map(Exception exception, DekiResources resources) {
            var exceptionType = exception.GetType();
            MethodInfo handler;
            lock(_handlers) {
                if(!_handlers.TryGetValue(exceptionType, out handler)) {
                    handler = (from method in typeof(DekiExceptionMapper).GetMethods(BindingFlags.NonPublic | BindingFlags.Static)
                               let parameters = method.GetParameters()
                               where parameters.Length == 2 && parameters[0].ParameterType.IsAssignableFrom(exceptionType)
                               let depth = GetInheritanceChain(parameters[0].ParameterType, 0)
                               orderby depth descending
                               select method).FirstOrDefault();
                    if(handler == null) {
                        return null;
                    }
                    _handlers[exceptionType] = handler;
                }
            }
            return (DreamMessage)handler.Invoke(null, new object[] { exception, resources });
        }
Example #3
0
 private static DreamMessage Map(MindTouchConflictException e, DekiResources resources) {
     return DreamMessage.Conflict(resources.Localize(e.Resource));
 }
Example #4
0
 private static DreamMessage Map(MindTouchFatalCallException e, DekiResources resources) {
     return DreamMessage.InternalError(resources.Localize(e.Resource));
 }
Example #5
0
 //--- generic ResourcedMindTouchException handlers ---
 private static DreamMessage Map(MindTouchInvalidCallException e, DekiResources resources) {
     return DreamMessage.BadRequest(resources.Localize(e.Resource));
 }
Example #6
0
 private static DreamMessage Map(AttachmentPreviewBadImageFatalException e, DekiResources resources) {
     return new DreamMessage(DreamStatus.InternalError, null, e.PreviewMimeType, e.PreviewImage);
 }
Example #7
0
 //--- DekiDataException handlers ---
 private static DreamMessage Map(ResourceExpectedHeadException e, DekiResources resources) {
     return DreamMessage.Conflict(resources.Localize(DekiResources.RESOURCE_EXPECTED_HEAD_REVISION(e.HeadRevision, e.Revision)));
 }
Example #8
0
 private static DreamMessage Map(MindTouchNotImplementedException e, DekiResources resources) {
     return DreamMessage.NotImplemented(resources.Localize(e.Resource));
 }
Example #9
0
 private static DreamMessage Map(TooManyResultsException e, DekiResources resources) {
     return DreamMessage.Forbidden(resources.Localize(DekiResources.SITE_TOO_BIG_TO_GENERATE_SITEMAP()));
 }
Example #10
0
 private static DreamMessage Map(HomePageNotFoundException e, DekiResources resources) {
     return DreamMessage.InternalError(resources.Localize(DekiResources.UNABLE_TO_FIND_HOME_PAGE()));
 }
Example #11
0
 private static DreamMessage Map(PageIdNotFoundException e, DekiResources resources) {
     return DreamMessage.InternalError(resources.Localize(DekiResources.UNABLE_TO_RETRIEVE_PAGE_FOR_ID(e.PageId)));
 }
Example #12
0
 private static DreamMessage Map(OldIdNotFoundException e, DekiResources resources) {
     return DreamMessage.InternalError(resources.Localize(DekiResources.UNABLE_TO_FIND_OLD_PAGE_FOR_ID(e.OldId, e.TimeStamp)));
 }
Example #13
0
 private static DreamMessage Map(CommentConcurrencyException e, DekiResources resources) {
     return DreamMessage.Conflict(resources.Localize(DekiResources.COMMENT_CONCURRENCY_ERROR(e.PageId)));
 }
Example #14
0
 private static DreamMessage Map(ResourceConcurrencyException e, DekiResources resources) {
     return DreamMessage.Conflict(resources.Localize(DekiResources.PROPERTY_CONCURRENCY_ERROR(e.ResourceId)));
 }
Example #15
0
 private static DreamMessage Map(ResourceRevisionOutOfRangeException e, DekiResources resources) {
     return DreamMessage.Conflict(resources.Localize(DekiResources.RESOURCE_REVISION_OUT_OF_RANGE(e.Resource)));
 }
Example #16
0
 private static DreamMessage Map(MindTouchForbiddenException e, DekiResources resources) {
     return DreamMessage.Forbidden(resources.Localize(e.Resource));
 }
Example #17
0
 private static DreamMessage Map(MindTouchAccessDeniedException e, DekiResources resources) {
     return DreamMessage.AccessDenied(e.AuthRealm, resources.Localize(e.Resource));
 }
Example #18
0
 //--- Misc exception handlers ---
 private static DreamMessage Map(MindTouchInvalidOperationException e, DekiResources resources) {
     return DreamMessage.BadRequest(e.Message);
 }
Example #19
0
        private static DreamMessage Map(ExternalServiceResponseException e, DekiResources resources) {

            // Note (arnec): the attached resource is just silently dropped here... doesn't seem right.
            // also e.Resource in this case can be null, so beware.
            return e.ExternalServiceResponse;
        }
Example #20
0
 private static DreamMessage Map(DekiLicenseException e, DekiResources resources) {
     return DreamMessage.BadRequest(e.Message);
 }