Category Archives: Other

TFS Merge goes funny unless you get latest version

Users of some other source control software are used to the fact that, any merge operation requires a workspace and if that workspace is on your local machine then you need to make sure it’s up-to-date with the branch it is a workspace for before merging into that branch.

TFS is less up front about this, but it does still use your local workspace as a workspace for merge. Therefore:

Before doing a merge with TFS, get latest of the target branch. Then start your merge.

For the paranoid: get specific version — Latest Version; and tick both ‘overwrite’ options.

How to Log WCF Message Bodies to Enterprise Library

Boy, was this painful. But there’s not much too it when it works. There are several bits of config, 3 classes and some gotchas involved, as follows.

Config Sections

<system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <!-- Gotcha: this element looks so easy but is a pain in the backside. 
             The type element has to *exactly* match the undocumented-and-fussier-than-anywhere-else-in-config required format
             If it has to change, the best way to do it is to delete the line and then use MS Service Configuration Tool to lookup the assembly and classname
             See e.g. http://stackoverflow.com/questions/1163996/adding-a-custom-wcf-behavior-extension-causes-a-configurationerrorsexception
             -->
        <add name="EnterpriseLibraryClientMessageBodyLogging"
type="MyNamespace.MyAppName.Implementation.LoggingServiceClientDecorators.EnterpriseLibraryMessageBodyLoggingClientBehaviorExtension, MyNamespace.MyAppName.Implementation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>

    <behaviors>
      <endpointBehaviors>
        <behavior name="LogAllMessageBodies">
          <EnterpriseLibraryClientMessageBodyLogging />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <client>
      <!-- Add atrribute 
          behaviorConfiguration="LogAllMessageBodies"
          to the endpoint element to enable WCF message in-and-out logging
          e.g.:
      -->
      <endpoint address="http://10.1.2.3/CalledServiceName/CalledServiceMethod.asmx"
          binding="basicHttpBinding" bindingConfiguration="UnsecuredBindingConfiguration"
          contract="CalledServiceMethod.CalledServiceMethodSoap"

          behaviorConfiguration="LogAllMessageBodies"

          name="CalledServiceMethodSoap"/>

      ... rest of your client section .....
    </client
... rest of your system.serviceModel section ...
</system.serviceModel>
  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="FullFlatFileTraceListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
        rollSizeKB="5000" rollFileExistsBehavior="Overwrite" timeStampPattern="yyyy-MM-dd" 
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
        fileName="FullLog.log" formatter="FullTextFormatter" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
        template="---------------------------------{newline}Timestamp: {timestamp}{newline}Message: {message}{newline}{newline}Extended Properties: {newline}{dictionary(  {key}: {value}{newline})}"
        name="FullTextFormatter" />
    </formatters>
    <categorySources/>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="FullFlatFileTraceListener"/>
        </listeners>
      </allEvents>
      <notProcessed switchValue="Off" name="Unprocessed Category" />
      <errors switchValue="Off" name="Logging Errors &amp; Warnings" />
    </specialSources>
  </loggingConfiguration>

Code

using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using Logger=namespaceWhichDefinesYourLoggerInterfaceIfAny;

namespace blah.LoggingServiceClientDecorators
{
    public class EnterpriseLibraryMessageBodyLoggingClientBehaviorExtension : BehaviorExtensionElement
    {
        protected override object CreateBehavior()
        {
            return new EnterpriseLibraryMessageBodyLoggingClientBehavior();
        }

        public override Type BehaviorType
        {
            get { return typeof (EnterpriseLibraryMessageBodyLoggingClientBehavior); }
        }
    }

    public class EnterpriseLibraryMessageBodyLoggingClientBehavior : IEndpointBehavior
    {
        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            clientRuntime.MessageInspectors.Add(
                new MessageBodyLoggingClientMessageInspector(new EnterpriseLibraryExceptionHandlingLogger())
                );
        }

        #region Irrelevant IEndpointBehavior Members
        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { }
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint,EndpointDispatcher endpointDispatcher){}
        public void Validate(ServiceEndpoint endpoint){}
        #endregion
    }

    public class MessageBodyLoggingClientMessageInspector : IClientMessageInspector
    {
        private readonly ILogger logger;

        public MessageBodyLoggingClientMessageInspector(ILogger logger)
        {
            this.logger = logger;
        }

        public void AfterReceiveReply(ref Message reply, object correlationState)
        {
            logger.Info("<MessageRecord Direction=\"In\">{0}</MessageRecord>", reply.ToString());
        }

        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            logger.Info("<MessageRecord Direction=\"Out\" Endpoint=\"{1}\">{0}</MessageRecord>", request.ToString(), channel.RemoteAddress.Uri);
            return null;
        }
    }
}

The Gotchas

  1. Note this is a completely different route to what you’ll find if you search for ‘WCF message logging’ What you’ll find there is how to switch on WCF logging. Which logs everything – and I mean everything – except the message bodies.
  2. The typename in the behaviorExtensions section above is hard to type exactly as required
  3. The typename in the behaviorExtensions must specify an exact version number which is a pain when it changes
  4. Note that you can’t do anything more sophisticated with the messages in the IClientMessageInspector because by design Messages are Read Once. If you want to extract the innards of the message, you have to copy it to a buffer, then and set the ref parameter to a new copy of the message.

Notes on the slide, Marriage According the Bible

A friend forwarded me a slide entitled “Marriage According to the Bible” which suggests that marriage according to the bible is mostly about men claiming sexual rights and women (especially rape victims, prisoners of war, polygamously-married women and widows) having to lie back and take it. The slide raises questions that are worth serious debate, and especially I can see that faced with someone saying ‘bring back the Old Testament law in the modern world!’ one would be somewhat alarmed. But I think my outline ‘opening argument for the defense’ would be something like the following. I say ‘defense’ because in spite of it’s neutral tone, the slide does to me meant as an attack. It’s not an objective reading certainly. But more on that below.

Rape, polygamy, prisoners of war and slavery were never fair in the ancient world any more than in the modern world. They happened and still happen. Your choices as Government of the realm are, regulate for it or pretend it’s not happening, but modern governments (for all their powers undreamed-of by predecessors 3 millenia ago) are still unable to erase them.

I think the law of Moses pragmatically addresses problems that we no longer have in the western world. For most of us (not being either iron age subsistence farmers or ancient historians) we don’t see the problem being addressed. We certainly don’t ‘get’ the offered solution.

The most serious problem for a subsistence farming community (I believe that was 99% of the world until a few hundred years ago) was, ‘how will I keep me and my family alive for the next 6 months?’ To get a feel for what that’s like, you could try imagining being unemployed for a year longer than all your money, savings, and sale of possessions would last. Then go back 100 years (before the welfare state) and consider your options. Begging? Stealing? Prostitution? Then move to a country where average annual annual income is less than 2 dollars a day (In 2011, that’s nearly half the world according to globalrichlist.com). Preferable of course you could fall back on family, if they’re alive. But if they aren’t …

So the problem to address is: how will a rape victim, prisoner of war or widow keep herself and children alive if she’s one of the 99% of the world who aren’t wealthy.

I do think that the author of the slide has just misread the obligations of the OT law. The marriage obligations were obligations on the man not the woman. The point is to protect a woman from destitution, by not leaving her without an income.
– a rape victim was not obliged to marry her rapist, that’s an error on the slide. Rape was a capital offence, she could push for the death sentence.
– the reference cited on the slide under rape is rather the case of a man who ‘seduces’ (I did check the word in Hebrew, I don’t think there’s any better or more certain translation) an unattached woman: he (not she) becomes obliged to marry her rather than abandon her, a point that a reader of Jane Austen would feel the force of.
– ‘levirate’ marriage (you husband dies, you marry his brother) is again an obligation on the man not the woman. I think it’s fairly clear in the text that the point of the law is that the woman can legally claim the right to a replacement husband (Deut 25:5ff). Husbands keep the wolves from the door. And other predators.
– I suppooooose it’s true that a wife ‘must submit sexually’ although I think that bit of the slide is a little bit made up; there’s no citation for it. Again the obligation is more enforceable the other way round: I think a woman whose husband failed to provide food, clothing or ‘marital rights’ had, if all else failed the option of appeal to legal rights to those 3 things. A new testament perspective on ‘sexual rights’ is “a husband’s body does not belong to him but to his wife, and vice versa.” You can see it’s a joint enterprise view, not an individual rights view, of marriage.

So, I’d say that to produce this slide you’d have to (1) not really know how life even as little as 500 years ago differed economically and therefore socially from our own and (2) read the text with some hostility. I don’t see you could produce this slide from a fair minded attempt to ask “what did this law mean for a woman 3000 years ago”

Am I being unfair? There is a serious debate to be had about some of it, I guess the above is the opening argument, not necessarily a final position.

What is this svchost.exe (LocalServiceAndNoImpersonation) using all my CPU?

If you’ve got Win7 you can find out which actual service is using your CPU via the Resource Monitor, ResMon.exe.

On the CPU tab, the second frame down is “Services” You can right-click on the offender and stop it. Often a stop and restart will fix it, at least till next time.

svchost.exe (LocalServiceAndNoImpersonation) using about 30% of core i5..