Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Michal Grzegorzewski

  • Building Communities. Driving Communities


    It is now about 1.5 year we here in Warsaw are trying to build local .net community. I thought that in such a big city it is going to be quite easy. But I was wrong.
    After few meetings it showed up, that just few guys were interested in building community and nobody else. We had a static home page prepared by one of our members and used one of public forums (based on communityserver) to share some info about meetings, etc. But we met, went home and nothing happened.
    Unfortunately working with such a small enthusiasm was rather a bad idea. So one of the creators decided to give up and left the group, then we had some meetings with an audience of 5-8 guests, everything went wrong and we were very close to make a decision of closing the group.
    But what went wrong? We had a very nice place - MS building with very nice conference room, some gifts for prelegents (books, etc.), really good presenters, some help from MS itself - so, what was wrong?!
    Actually I was not too much involved in building this community, although from time to time I suggested some presenters, who drove really good sessions. About a month ago I was called by the last guy driving this community, who said, that if I'm not going to take a part in this group, then he gives up and 'that's all folks'. After some time and few conversations with my family I decided to help in driving this group.

    Firstly I decided to change the way we communicate. We had lots of problems with the group's page, so the only way was to left it out and move to other place. Actually the only place I can consider as a 'community incubator' at the moment is 'google groups', ie. groups.google.com. So, we moved from http://wawadotnet.aspweb.cz to http://groups.google.com/group/wg-net. That gave us a big kick.
    Secondly, I suggested that we have to meet much more frequent, than we had used to before. As a group we met in the period of 17 months only 9 times... So my suggestion was one meeting every 2 weeks.
    Next, we decided to cooperate with Polish SQL Group, and have meetings altogether every two weeks.
    Now we discuss and exchange ideas on the group, working together on the plan of meetings, etc. Using the tool (google groups) we have opened the community to the world.
    Next suggestion was to change a bit the way we drive the sessions. Not as formal as previously with slideshow, etc.. More work with VS and other tools, involving audience to help presenters...

    I'm not sure if it helps. We'll see.

    What are your experiences in building and then driving .net communities? Any other ideas?

  • The MyGeneration tool is open source now!

    I missed this event (mid of the June '07!!!) and now, when I've finally discovered that one of the greatest tools I use in my job is available on sf.net with source code included, I'm really excited about this! What I really regret is not too big contribution to this project; actually I've added just one small template which helps generating soodaschema.xml file for Sooda O/RM.
    The license is based on BSD, which is quite liberal. I believe this is a very good decision, which can help building even nicer tools using MyGen.
    Good job, guys! Thanks, Mike (Griffin) & Justin (Greenwod)!!!
    BTW. In Zine.NET Magazine, #2 (March 2007) I've added small article with some info on MyGenration (unfortunately only in polish :( ).

  • Surface - what did they do with the input!?

    I think everyone has seen any webcast preview about the amazing Surface. Some of our friends are so keen on it, that change their job just to earn some money to buy it :))
    But have you thought a bit: 'how to heck have they done it?!'. And not the engineering stuff with cables, cameras, etc., but software. (Everything is about the software!). As they say: at the bottom they've got the Vista system and WPF apps. Nothing more.
    When you look at any webcast dedicated to Surface you are sure they did something with the input. But then you may doubt if they changed the core of the windowing subsystem or simply started to interpret the input coming from devices differently at the app level.
    Some time ago John Robbins wrote some words about Microsoft UI Automation and talked about the best session he had ever seen. It was about multiple input queues, which supposed to be in Vista (and/or Longhorn), but these features unfortunately are missing. They had to do it different way.
    When you connect the second mouse / keyboard to your system nothing happens. They're fighting with each other for the control, another cursor doesn't appear. But - it works! So - the problem is with the interpretation of the device id (simply omitted), not the windowing subsytem. I was sure someone has already done something with the device id at the message level - and after few google clicks I found the project coming - no wonder! - from Microsoft Research :)
    Two different cursors working at the same moment. Amazing! The libs are available for free with some quickstarts on wpf. Have a look (ctp release of the sdk). Also consider watching 30 mins webcast on ch9.
    Of course, at the Surface they may have different approach - I think they have one input device connected to the system of cameras / other stuff with many logical lines interpreted by the driver (400 megabits (usb2) of information is enough to transfer much more than just 52 finger's inputs!). But - if you don't want to wait for your own Surface table, you may do it yourself - using wpf and free libs from MS :)
    I don't know how about you, but I was amazed and had lots of fun playing with two cursors. What a potential!

  • Y2K7 problem - ymmdd pattern in AssemblyInfoVersion

    The problem is well-known - all four parts of the version number are limited to 16-bit numbers. So, when you used versioning like this: x.y.z.ymmdd, thus when the 2007.01.01 arrived, you were in trouble and got the infamous csc error:

    [csc] error CS0647: Error emitting 'System.Reflection.AssemblyVersionAttribute' attribute -- 'The version specified '1.0.1.70102' is invalid'

    The users of the AssemblyInfoTask for msbuild had to do something when they got back to work just after the new-year's party ;). Actually I use NAnt instead of msbuild, but I really loved this way of 'stamping' my assemblies, so I used the pattern too. For example, in DotNetNuke modules, the version number consists of three numbers, so the last one (revision) is a very good place to store the build date.

      <tstamp property="build.date" pattern="yMMdd"/>
      <property name="build.version" value="${build.major}.${build.minor}.${build.build}.${build.date}" />

    (other numbers coming from other place)
    I didn't want to jump to the 'BuildDay' pattern, so I decided to cut the number % 50000.

      <property name="build.version" value="${build.major}.${build.minor}.${build.build}.${int::parse(build.date)%50000}" />

    That way I've got now 5 years to change other numbers to not to get in trouble with 'previous version'... :) After all, I'm not fully satisfied with this solution and here comes the question: how do you play (if you do ;)) with the build-date in your assemblies?
  • NVelocity in partial trust environment?

    The question is: How do you play with nvelocity in shared hosting environments where medium trust is a common standard?
    As I mentioned in my previous post, it's not so easy to go around it - even if we would like to disable CAS temporarily using the 'Mutex method', we have no permissions to do this ;).
    The problem is mostly because of the ReflectionPermission required by NVelocity itself (this is the only way to instantiate objects referenced in templates).
    NVelocity project is dead since October 2003, although we may download from sf.net svn repository sources imported 6 months ago from castleproject. I'm not sure about this, but I think the nvelocity team is not going to take care of the project any more.
    I know that some of you use MonoRails with NVelocity as a template engine - don't you have problems with partial trust? Don't you develop any modules for DotNetNuke with some help from NVelocity (I do ;))? Now every one 'good' dnn module has to pass the 'medium trust requirement', so the potential usage of NVelocity in dnn is rather small... :(
    Don't you find it as a MS battle against different template engines? We may use heavy asp.net templates, because 'the asp.net engine is good and signed by MS' and we cannot use other engines, because 'it is highly recommended to work on medium trust' and so - we do. Of course we may ask our admin to specify for our app custom policy file, but have you ever tried to do this?
  • Yet Another Reflection Helper Tool

    This text is based on the reflection tip'n'trick from the incoming zine.net magazine (unfortunately entirely written in Polish), written by me and a friend of mine, Wojciech Gebczyk. I am permitted to publish his tool and anything else I need to :)

    Generally if there's better solution, we should always choose not to reflect. Reflection is bad because it prevents type safety at compile time and because it's slow. Both reasons are based on the string based nature of the reflection. We use strings to provide the name of the type, method, etc. and CLR has to scan through an assembly's metadata to find the string we're asking for. But there are some cases, when reflection is very helpful. Everyone uses serialization, intellisense and designer helpers. All of them need information from the metadata to give us what we want.
    There are also other uses of the reflection - which are not so obvious.
    Reflection gives us access to lots of stuff, which isn't accessible in any other way. Thanks to the reflection we’ve got access to the private members.
    TypeWrapper (included in the attachment to this post) is an example of a tool that uses reflection to give us access to private members. It simply wraps all the stuff from selected type and uses reflections to access them. But why should we use private members? Let’s imagine, that we have in our application a text box where user puts in his password. Of course, we use system’s password char to hide the actual content of the field, but we would like to give the user opportunity to see what’s in the box. There are many ways to accomplish this. For example we may send a ‘EM_SETPASSWORDCHAR’ message to the control with wParam set to 0. The only problem is, we have to P/Invoke Win32 SendMessage. But, wait a minute – there already is such a method imported in the System.Windows.Forms.Control class, and it’s private!
    The main view of the TypeWrapper tool
    Using TypeWrapper lets us do it really fast:
    1. Using TypeWrapper import System.Windows.Forms.dll, select the Control type and using context menu generate the wrapper (you may specify here the name of the namespace). Generated text put into the clipboard (use buttons).
    2. Using VS2005 generate new project and add new class. Select the stub generated by VS and replace it with the contents from clipboard.
    3. Now, in the code where you want to use the wrapped SendMessage method use the code below:

    TextBox with system's password char applied -> TextBox with user text
    That’s all! Now we have the textbox with an unhidden input.
    The funny thing here is, it's not so easy to protect our architecture from being abused. As Jeff Richter states in his great book “CLR via c#, second edition” (a frame on p. 577) we may use ReflectionPermission and strong name LinkDemand to restrict access to our private members, but when we work in a full-trust environment security checks are assumed to be successful :(. That’s why it’s really important to check if our code can successfully run in medium trust, which should be obligatory in shared hosting environments.
    Thanks God, MS did some work to help admins in their job. In 1.1 ‘caspol –s off’ simply added the ‘HKLM\SOFTWARE\Microsoft\.NETFramework\Security\Policy\GlobalSettings’ with value of 0x0000001f and all checks against CAS on/off were done by querying the key. Of course, only admins, system and power users have full access to this key, but as from 2.0 it’s even harder. ‘caspol –s off’ firstly checks if we are admins and if so, creates a mutex named ‘Global\CLR_CASOFF_MUTEX’ and sets local admins as its owner (the code below comes from Reflector). Then CLR checks the existence of such an object and verifies if local admins are the owners.



    To create a mutex we need a SecurityPermission we don’t have in medium trust, or at least (:) ) permission to do it via P/Invoke (which is blocked even in the High level because of the SecurityPermission.UnmanagedCode), so in the Medium Trust we are safe. This time we need an application which is running all the time to let the mutex live, so it looks pretty safer than before, when we had only registry key. I think such a restriction is very good for most of admins, who now need to rethink the design of the security if they based everything on the registry key. It’s also good for developers, who may produce secure software much easier. As from 2.0 we’ve got new tools, for example ‘permcalc’, which helps us specify security requirements for our app.
    Very useful method which we can use to check current permission level is System.Security.SecurityManager.IsGranted(System.Security.IPermission perm), so we may find out if the user running our code has necessary permissions. So – if we are trying to protect our private methods we may use this method to check if the user has ReflectionPermission and if so – throw an exception ;). Of course this approach is very weak and don’t take it too serious.
    At the end of the story I’d like to share with you my confusion about VS2K5 & disabling code access security. Simply execute ‘caspol –s off’, then run Visual Studio 2005 and try to load any of your c# projects. On my machine it ends up with:
    ‘Unable to read the project file 'Some.csproj'. Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)’
    and the project stays unloaded. I consider this as a bug, because turning on CAS with the same VS session doesn’t change the situation. And vice versa – firing the VS and then disabling CAS has no impact on loading projects – VS works just fine. So – VS caches somehow at the init information about the CAS being on/off and doesn’t care about global changes.
  • Modifying collection while foreach'ing? Why not?!

    As most of you know, changing collection while iterating is strictly forbidden. Or, actually – not forbidden, but gets us into serious problems, which ends up with an exception. As an example:


    Now, when trying to get third element of the collection (not removing the second one!!!) we receive beautiful message "Collection was modified; enumeration operation may not execute."
    There's a small trick we may use, but please – don't laugh too loud!:)

    This time we have no exception and the collection is being modified. What about the cost! But who cares! ;)
    And finally, for some enumerables we may use the 'inline' shortcut, the 'tricky' one:


    No additional classes, very simple usage of the List(IEnumerable ie) ctor. Nice, isn't it?
  • Iterators for admins

    As a developer-admin (or even better – admin-developer) in one person I'm really fascinated in many features which appeared in c# with .net 2.0. And, of course, I love to 'yield'! And I love internal iterators in the anonymous methods' skin!
    As an example of a basic usage of these cool features I'm going to use them for a very common admin task – traversing of a directory structure.
    One of our network shares is a place, where all domain users have an access and may create/delete/modify/view different files. This is a 'sack', where they can share files and restrict access to diferent objects for different groups.
    This approach to sharing files leads us to different problems, which we have to face from time to time. One of them is related to the size of the drive, where all these objects live. For this reason I need a tool, which gives me some info about files, their sizes and owners.
    First, let's get the owner of the object. Since I'm using .net 2.0 I have a System.Security.AccessControl namespace, where I can find many classes, which can help me.

    Then we need to get to the file level to get some sec and other info. Always recursive! And, having thousends of directories and tens of thousends of files within, I don't like 'SearchOption.AllDirectories' option in the 'GetFiles()' method any more.
    First approach uses anonymous methods with very basic delegate.
    And somewhere in the code

    Second approach utilizes external iterators in the 2.0 form – with the 'yield' keyword.
    This time we are yielding the file name and don't care what it's going to be used for.

    And finally in the client code

    Returning control to the client code gives me lots of potential uses of the iterators. For example, I may write a very basic tool named, let's say 'ForFile', which could do specific task for every file which is visited. Tasks are easy to extract from the tool by putting them into external library and load them on-demand, while working actually on the IFileTask inside the tool. As a decorator for the iterator we may use some IFileFilter, which could narrow the search results (by file name, file size, file content, etc.)
More Posts

Our Sponsors

Red-Gate!

Proudly Partnered With