Category name:.Net

MSN like idle behaviour in your application

I posted an article that includes a link to a class file I wrote today that can detect if a user is idle for a certain period and triggers an event.

This is my own quoted text from the article.

I’ve just created a little nice class that helps in building applications that need MSN like behaviour regarding detecting a users idle time. This can be very handy when your application notifies the user for some special event through a non intrusive popup for example. But will the user see this popup when it isn’t behind it’s computer?

This is where this class comes in. When you detect that the user is idle you stack the notification events until the user is active again to show them to your user.

I have seen some implementations that detect a user idle’ness this way but not a single one also includes an event that get’s fired when a user is available again.

Click here to read the IdleTimer to have MSN like behaviour in your application article.

WSE2 : KerberosToken and WSE policies

I had a weird problem today with a computer in our development domain. We currently use encryption and signing for webservice calls with WSE2. We use a WSE policy to achieve this but today a collegue of mine got an error when he tried to run the code on his machine. The first thing was that the webservice wasn’t running under the SYSTEM account. This account does not have enough priviledges to access the active directory information so it can’t access the data for the kerberos token. This isn’t a problem on Windows 2003 because .net webapplications run under a certain application pool.

But then we had a problem where the code didn’t run while it should! It was a very frustrating thing and we got keeping exceptions that said the username was incorrect. So we triple checked everything and couldn’t any problem. As a last resort I removed the computer from the domain and added it again and guess what. It worked afterwards.

So remove and add the machine to your domain if you are experiencing problems with kerberos token exceptions with WSE on one computer but not on another.

This isn’t mentioned at the WSE FAQ or it’s wiki. I will try to contribute to it this evening 🙂

StateMachine in c# and xml, v3 (updated)

Updated:
 – New archive to download (v3)
 – XML updated
 – Code rewrite with delegates and helper methods

I added unittest for a switch in version 1. Leslie had some troubles with building his trafficsign. I now added a trafficsign as a unittest and it outputs the following:

<?xml version="1.0"?>
<Machine Id="Switch" InitialState="On" xmlns="Exyll.StateMachine">
  <SubStates>
    <State Id="On" InitialState="Red">
      <SubStates>
        <State Id="Red">
          <Transitions>
            <Transition EventName="TimeTrigger" Target="Green" Guard="TimerIs4" Action="TimerReset" />
            <Transition EventName="TimeTrigger" Target="Red" Action="TimerIncrement" />
          </Transitions>
        </State>
        <State Id="Yellow">
          <Transitions>
            <Transition EventName="TimeTrigger" Target="Red" Guard="TimerIs2" Action="TimerReset" />
            <Transition EventName="TimeTrigger" Target="Yellow" Action="TimerIncrement" />
          </Transitions>
        </State>
        <State Id="Green">
          <Transitions>
            <Transition EventName="TimeTrigger" Target="Yellow" Guard="TimerIs4" Action="TimerReset" />
            <Transition EventName="TimeTrigger" Target="Green" Action="TimerIncrement" />
          </Transitions>
        </State>
      </SubStates>
      <Transitions>
        <Transition EventName="TurnOff" Target="Off" />
      </Transitions>
    </State>
    <State Id="Off">
      <Transitions>
        <Transition EventName="TurnOn" Target="On" />
      </Transitions>
    </State>
  </SubStates>
  <Events>
    <Event>TimeTrigger</Event>
    <Event>TurnOff</Event>
    <Event>TurnOn</Event>
  </Events>
</Machine>

Download link : StateMachine version 3

StateMachine in c# and xml

Yesterday I browsed through the new articles at codeproject.com. Leslie Sanford StateMachine articles had my attention. He has designed and implemented it in c#. A job done pretty well I think. I took a look at his code that reads an xml definition to deserialize its state design. My thoughts were that it wasn’t really readable and logical so I made a class design that serializes to a "self-describing" xml document.

An example:
<?xml version="1.0"?>
<Machine Id="Switch" InitialState="On" xmlns="Exyll.StateMachine">
  <SubStates>
    <State Id="On">
      <Transitions>
        <Transition EventName="TurnOff" Target="Off" />
      </Transitions>
    </State>
    <State Id="Off">
      <Transitions>
        <Transition EventName="TurnOn" Target="On" />
      </Transitions>
    </State>
  </SubStates>
  <Events>
    <Event>TurnOff</Event>
    <Event>TurnOn</Event>
  </Events>
</Machine>

If you are interested in this class design and the xmlattributes I had to add to achieve this xml format then download StateMachine code.

LINQ features

September 14, 2005 / 1 Comment on LINQ features

I was just browsing a bit to get more information about LINQ. Our fellow blogger Joshua already posted something about it.

LINQ seems very usable. The old c omega project is transformed into LINQ so those guys that did that R&D project have a nice salary now 😉

So we have DLINQ for dataaccess to do easier selects etc. but I am wondering if I would want to do my DB access this way. I think that I don’t want to do this. The other dataaccess relating thing I noted is the O/R mapper attributes in the overview document. Haven’t seen good samples with this but if the LINQ library has logic like some O/R mappers like creating optimized dataaccess queries then this could become a hit. I really dive into this topic to get to know the details.

XLINQ is for the xml integration within your code. The samples that I’ve seen only show things about xml document creation. What would be a very interesting thing if is XLINQ has support for xsl-t within your code and to easily do thing within that xsl-t that require c# of vb.net code so that you don’t have to call another method but can merge xsl-t and c# code to walk through your xml document.

The bad thing is that I also saw afwul samples about anonymous types. I don’t think that you want to write those classes by hand. It is only interesting for run-time creation of certain object types. I think all options within LINQ rely heavily on this feature. Why on earth would a developer want to create such classes? Hard to understand, hard to maintain and the fucking code police will drop you from the 10th floor head down!

Barry Garving has created a nice LINQ Resources post.

WM_QueryEndSession use WndProc not DefWndProc

Well this could become the most emberrasing thing this month I think. I added a handler for the WM_QUERYENDSESSION message. I override the DefWndProc method and the WM_QUERYENDSESSION message was never received. I thought it had something to do with the window not being the top window so I tried to hunt down the ‘evil’ code. The problem was there wasn’t bad code at all.

After a few hours and removing/commenting out code the only executing code remaining was my message loop override and I still was amazed that I didn’t get the WM_QUERYENDSESSION message. So I decided to create a new test project and added an override for WndProc and all worked as it should. Then I compared both source files and *finally* saw that I had overriden DefWndProc. I really don’t know why I did that.. I think it is because I used intellisense, scrolled down and when I read DefWndProc I just smashed the tab key.

So watch out that you override WndProc and not DefWndProc when intercepting system messages!

Please leave a comment that I’m a complete dickhead. Thank you!

SourceSafe Spy – A monitor tool

Sourcesafe Spy by Ramon Smits

Description | Download | History | License | Copyright

Description:

I was fed up that there aren’t any notification options within Sourcesafe so decided to make my own. There are probably thousands of such tools available but anyway I think it’s quite a nice tool. Although you could ask yourself why I did it especially with VS2005 in vicinity.

So what does it do? Sourcesafe Spy monitors your Visual Sourcesafe Journal file for changes and notifies them if changed actually occur. You could say that it is a sourcesafe monitor tool.

It has four nice features:

  • SMTP notification.
  • Non intrusive popup.
  • Minimizes to systemtray.

And these are the interesting details for developers:

  • Uses the file watcher instead of polling.
  • Uses delayed event handling for reading the changes from the journal.
  • Close gets intercepted. When the user session ends the application closes normally.
  • Most labels are shrunk to fit.
  • Tray icon menu is cloned from the application menu.
  • Minimize message is intercepted to minimize the application to the icon tray.
  • Global exception handler that shows a non intrusive info balloon and logs the exception to the event log.

Sourcesafe Spy can monitor any SourceSafe repository that has journaling enabled.

Download:

You can visit the Sourcesafe Spy site to download Sourcesafe Spy version 0.4 .

History:

Legend:

+ Added
Removed
* Changed
! Fixed

0.4 Public release

* Won’t loop at start anymore when the journal file can’t be opened because for example the drive was not mapped correctly or the network share was not available.
* Opacity is back! Now sets the correct control styles to reduce incorrect painting.
* Not referencing Genghis anymore. Only used Genghis for the popup. I’ve made changes to it so needed to recompile Genghis but decided to merge AniForm with SourceSafe Spy.
+ AniForm now fades in and out.
+ AniForm now ‘steps’ to the left when the popup stack gets higher then the screen.
+ Application now ask if you really want to quit when you press the close button. Should not show up when the user session is ending or when the user selects Exit from the menu.
* Popup now uses the system colors for a control background.
* Uses new version of Exyll general library. Fixes sound issue.
+ Labels are shortened. Uses the SmartLabel control in Exyll library. Code is based on code by Jan Schreuder from bloggingabout.net.
+ Added support for multiple datetime formats. It seems that sourcesafe doesn’t log entries in one format. It depends on the regional settigns. Currently supports ‘d-MM-yy H:mm’ (NL) and ‘M-dd-yy h:mmt’ (US).

0.3 Public release

! When sourcesafe releases the log file then multiple changes could be written.
+ Delayed event handling (DEH) for file change event.
+ Minimize will minimize to the tray.
Minimize menu item removed because of added minimize windows message interceptor.

0.2 Beta release

* No opacity. Caused a lot of graphical glitches.
+ Sound notification add popup.
+ SMTP notification. See “%USERPROFILE%Application DataExyll.SSSpy.Smtp+Settings.config”.
Unhandled exceptions are stored in the event log and the user gets a balloon notification.

0.1 Internal release

No bugs 😉

License:

The is software is provided ‘as-is’, without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial environment, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software complementary to a product, an acknowledgment in the product documentation is required, as shown here:

    SourceSafeSpy by Ramon Smits (http://bloggingabout.net/blogs/Ramon/).

  2. No substantial portion of the source code of this library may be redistributed without the express written permission of the copyright holders, where “substantial” is defined as enough code to be recognizably from this library.

Copyright:

Copyright © 2005 Ramon Smits
Portions copyright © 2002-2004 The Genghis Group (http://www.genghisgroup.com/).

KB887818 : “Cannot copy assembly”…

I am really fed up with this error in VisualStudio. Luckily I am not the only one experiencing this problem. Frans Bouma as an ISV is also pretty anoyed that the fix can’t be downloaded directly. Well I always forget to put the hotfix on my usb memory key and have to call (again…) to get this hotfix.

Here is the knowledge base article for those that need some extra information:

  FIX: You receive the “Cannot copy assembly” message when you build a c# solution in VS.NET2003 

So what is AJAX?

That immediately reminds me that I build AJAX like websites years ago with IE5, ASP and the Microsoft SOAP toolkit. Those days it really paid of to do lots of things in the browser because of bandwidth and server capacity. Now we are in the badass ban

fxcop : Explicit method implementations in unsealed classes should provide alternate methods with protected accessibility

Well that is the formatted message of the following fxCop rule name ExplicitMethodImplementationsInUnsealedClassesHaveVisibleAlternates. Today I had this strange fxCop error that I really had to read about five times before I understood about 95% of the error. This error clearly needed some investigation instead of the usual refactoring with ReSharper (if you use VS2003 and fxCop then ReFactor is definitaly a time saver!). The error I am talking about is "Explicit method implementations in unsealed classes should provide alternate methods with protected accessibility". Which is a bigass name to begin with!

So lets read the extra information about this error:

Explicit method implementations are defined with private accessibility. Classes that derive from classes with explicit method implementations and choose to re-declare them on the class will not be able to call into the base class implementation unless the base class has provided an alternate method with appropriate accessibility.

When overriding a base class method that has been hidden by explicit interface implementation, in order to call into the base class implementation, a derived class must cast the base pointer to the relevant interface. When calling through this reference, however, the derived class implementation will actually be invoked, resulting in recursion and an eventual stack overflow.

The problem here was that I had a class implementing an interface method as follows.

A.

void ITest.SomeMethod()  { ...}

The interface could also be implemented as the following alternative.

B.

public void SomeMethod() { ...}

In situation A you can’t call ITest.SomeMethod from within your implementing object directly. The only way is to cast this to an ITest reference to call ITest.SomeMethod(). I knew that but I didn’t need it because I would write the code as in situation B. ofcourse. Funny thing is that I forgot to seal to class and fxCop reminded me to do this with this error. But this means that you should normally just use situation B. as the primary way of implementating an interface. Problems arise when implementing two interfaces that share methods with the same signature but would have different implementations.

Normally I don’t seal classes that often but I was working an a class that did some communication with unmanaged resources and had some unsafe code in it as well. It is a device driver wrapper and I wanted it sealed so people would think not twice but a hundred times before changing logic and would make the driver unstable by inheriting from it. We use IOC a lot at the current project for external resources.  Having someone around that change the driver factory configuration to supply a new driver because they would think they can easily add some functinality to it would not really make me a happy person.

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta