Exemplo n.º 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();
 }
Exemplo n.º 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 });
        }
Exemplo n.º 3
0
 private static DreamMessage Map(MindTouchConflictException e, DekiResources resources) {
     return DreamMessage.Conflict(resources.Localize(e.Resource));
 }
Exemplo n.º 4
0
 private static DreamMessage Map(MindTouchFatalCallException e, DekiResources resources) {
     return DreamMessage.InternalError(resources.Localize(e.Resource));
 }
Exemplo n.º 5
0
 //--- generic ResourcedMindTouchException handlers ---
 private static DreamMessage Map(MindTouchInvalidCallException e, DekiResources resources) {
     return DreamMessage.BadRequest(resources.Localize(e.Resource));
 }
Exemplo n.º 6
0
 private static DreamMessage Map(AttachmentPreviewBadImageFatalException e, DekiResources resources) {
     return new DreamMessage(DreamStatus.InternalError, null, e.PreviewMimeType, e.PreviewImage);
 }
Exemplo n.º 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)));
 }
Exemplo n.º 8
0
 private static DreamMessage Map(MindTouchNotImplementedException e, DekiResources resources) {
     return DreamMessage.NotImplemented(resources.Localize(e.Resource));
 }
Exemplo n.º 9
0
 private static DreamMessage Map(TooManyResultsException e, DekiResources resources) {
     return DreamMessage.Forbidden(resources.Localize(DekiResources.SITE_TOO_BIG_TO_GENERATE_SITEMAP()));
 }
Exemplo n.º 10
0
 private static DreamMessage Map(HomePageNotFoundException e, DekiResources resources) {
     return DreamMessage.InternalError(resources.Localize(DekiResources.UNABLE_TO_FIND_HOME_PAGE()));
 }
Exemplo n.º 11
0
 private static DreamMessage Map(PageIdNotFoundException e, DekiResources resources) {
     return DreamMessage.InternalError(resources.Localize(DekiResources.UNABLE_TO_RETRIEVE_PAGE_FOR_ID(e.PageId)));
 }
Exemplo n.º 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)));
 }
Exemplo n.º 13
0
 private static DreamMessage Map(CommentConcurrencyException e, DekiResources resources) {
     return DreamMessage.Conflict(resources.Localize(DekiResources.COMMENT_CONCURRENCY_ERROR(e.PageId)));
 }
Exemplo n.º 14
0
 private static DreamMessage Map(ResourceConcurrencyException e, DekiResources resources) {
     return DreamMessage.Conflict(resources.Localize(DekiResources.PROPERTY_CONCURRENCY_ERROR(e.ResourceId)));
 }
Exemplo n.º 15
0
 private static DreamMessage Map(ResourceRevisionOutOfRangeException e, DekiResources resources) {
     return DreamMessage.Conflict(resources.Localize(DekiResources.RESOURCE_REVISION_OUT_OF_RANGE(e.Resource)));
 }
Exemplo n.º 16
0
 private static DreamMessage Map(MindTouchForbiddenException e, DekiResources resources) {
     return DreamMessage.Forbidden(resources.Localize(e.Resource));
 }
Exemplo n.º 17
0
 private static DreamMessage Map(MindTouchAccessDeniedException e, DekiResources resources) {
     return DreamMessage.AccessDenied(e.AuthRealm, resources.Localize(e.Resource));
 }
Exemplo n.º 18
0
 //--- Misc exception handlers ---
 private static DreamMessage Map(MindTouchInvalidOperationException e, DekiResources resources) {
     return DreamMessage.BadRequest(e.Message);
 }
Exemplo n.º 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;
        }
Exemplo n.º 20
0
 private static DreamMessage Map(DekiLicenseException e, DekiResources resources) {
     return DreamMessage.BadRequest(e.Message);
 }