Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andreas Gehrke 20 posts 44 karma points
    Oct 15, 2010 @ 15:11
    Andreas Gehrke
    0

    Multiple MediaFactory for same extension - Chain of resposibility

    Hello.

    I need to upload files in a specific directory as a specific Media Type. I can implement this using a custom IMediaFactory and configure DMU to use this factory for "*" extensions. However I do not want to use this MediaFactory for each and every unmapped extension.

    What I suggest is to implement a Chain of resposibility pattern [1] in the Config.GetMediaFactory() method. Instead of quering the XML for only one mediaFactory, you could select all that matches the file extension. Then loop through the factories and call a IMediaFactory.CanCreate(int parentNodeId, HttpPostedFile uploadFile) method. If this call returns true the factory can be used to create the Media item. This allows IMediaFactory implementations to do complex logic for validating whether or not they should be used to create the media item for the upload file.

    How does this sound? I can implement the functionality and post a patch file if someone is interested..

    [1] http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern

    Btw, what is the reason behind separating the assembly and type attribute the XML config? Most standard .NET config settings use one type attribute:

    type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

     

    Anyway, thanks for a great product!

    /Andreas

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 25, 2010 @ 15:27
    Matt Brailsford
    0

    Hi Andreas,

    My appologies, I totally forgot to reply to you.

    Definatley sounds like a nice idea, so by all means create a patch and I'll try it out.

    Re the seperation of assembley and type isn't for any particular reason, other than it just make it easier to reference each part, plus it tends to be how other configs in umbraco work.

    All the best

    Matt

  • Andreas Gehrke 20 posts 44 karma points
    Oct 25, 2010 @ 17:54
    Andreas Gehrke
    0

    Hi Matt,

    I have posted a patch on your codefkex page [1]. I was very tempted to correct the typo of "mediaFacory" in the config XML file, but I choose not to :-)

    I guess the typo and must of the config schema is borrowed from the Multiple File Upload plugin..

    [1] http://dmu4umb.codeplex.com/workitem/2

    /Andreas

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 28, 2010 @ 09:46
    Matt Brailsford
    0

    Hi Andreas,

    Great work, I'll get this incorporated into the next release (I have a few other updates to do, so will get them all sorted at the same time). I'll also fix the spelling issue to (I did use a lot of the Multiple File Upload plugin as a base for DMU)

    Thanks again.

    Matt

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 28, 2010 @ 09:48
    Matt Brailsford
    0

    PS I'd be interested to know what other refactorings you have made? Is it specific to your needs? Or something you think the whole project would benefit from?

    Matt

  • Andreas Gehrke 20 posts 44 karma points
    Oct 28, 2010 @ 10:11
    Andreas Gehrke
    0

    Sounds good Matt. I will be happy to help if needed.

    Well, the refactoring started as an interest to extract the GetMediaFactory() method in the Config class. It seems misplaced to me. During the refactoring I also wanted to change the logic in factory method to fix with the bug (in my patch) I described on your codeflex page. I then started to implement a MediaFactoryCreator (a MediaFactory factory) which caches the created media factories and reuses them. I will also just parse the config XML once. The MediaFactoryCreator could either be a static class or a singleton.

    Its basically just an internal refactoring that no end-users would benefit from, but I would be happy to share the code. Though its not completed yet.

    Btw, all that thumbnail generation code, is that really necessary? There's no way for Umbraco to create the thumbnails? It just feels wrong.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 29, 2010 @ 09:30
    Matt Brailsford
    0

    Hi Andreas,

    I'd definatley be intersted to see what you come up with. I'm all for making improvments =)

    RE the thumbnails, I'm not sure, again, most of this is borrowed from eslewhere (I don't confess to being the best coder in the world, I just know how to reuse code, and get things done =) I'll have a look in the core source though to see if there is anything we could reuse.

    All the best

    Matt

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Nov 01, 2010 @ 10:57
    Matt Brailsford
    0

    Hey Andreas,

    Just to let you know, the chain of responsibility pattern has been applied to the latest version (2.0.2) which was released yesterday.

    If you have any other ideas for improvements, don't hesitate to let me know.

    Many thanks

    Matt

  • Andreas Gehrke 20 posts 44 karma points
    Nov 01, 2010 @ 11:09
    Andreas Gehrke
    0

    Sounds great Matt :-) I will post my other refactorings when I have properly tested them. I will post a msg on the codeplex page.

    /Andreas

Please Sign in or register to post replies

Write your reply to:

Draft