quarta-feira, 16 de abril de 2014

This is gonna blow your mind - Operation System Identification

You know there's a lot of  routines to identify Operation System, but none of them are as classy or as elegant as the following one.

This code is not mine. My friend Cicero came to me with this code and found it fantastic!

I know it's VB6, it's old stuff. But with all this fuss about Operational System migration (people leaving Windows XP and adoptint Windows 7 and or Windows 8) I believe a code like that will be extremely useful.
Look at the elegance. Amazing!

Public Function MyOSVersion() As String
    Dim lstrResult As String
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", , 48)
    For Each objItem In colItems
        lstrResult = "OS Name: " & objItem.Caption & vbNewLine & "Version: " & objItem.Version
        Exit For
    Next
    MyOSVersion = lstrResult
End Function

Public Function isWindows8() As Boolean
      Dim lstrResult As String
      lstrResult = MyOSVersion
      isWindows8 = (InStr(1, lstrResult, "Microsoft Windows 8") > 0)
End Function


Public Function isWindowsXP() As Boolean
      Dim lstrResult As String
      lstrResult = MyOSVersion
      isWindowsXP = (InStr(1, lstrResult, "Microsoft Windows XP") > 0)
End Function

segunda-feira, 14 de abril de 2014

How do I call a controller from another controller?

Hi!

Have you ever had this problem? You are on a certain page and you want to call a different Controller?

@Html.ActionLink([The name that will appear on the webpage], [The Action], [The name of the controller], [The parameters (Example.. new { code = item.code})], null)


Text, Action, Controller, Parameters, HttpObj.

The secret is to use the right overload. On the last parameter you have to pass null. If you use the overload with three parameters, for some reason I don't know, it doesn't work.

That's it!

terça-feira, 8 de abril de 2014

Parse, Regular Expression

Vira e mexe eu tenho que fazer um parse de um método VB. Finalmente achei uma forma elegante é simples de fazê-lo.

 string Content = [A string que será usada como base];

string myRegExp = "(?<=Sub)(.*?)(?=End Sub)"; // A expressão para o Regular Expression

Regex r = new Regex(myRegExp, RegexOptions.Singleline); // Execução

Match m = r.Match(Content); // Et Voilà!! And done!

quarta-feira, 19 de fevereiro de 2014

Activate the WCF trace

Hi!

Sometimes you can't find out whata hell is going on with your WCF service.
In those times you should youse this amazing tool.

Put those tags at the and of your config file.

Really usefull!


<system.diagnostics>
   <sources>
       <source name="UserTraceSource" switchValue="Warning, ActivityTracing" >
          <listeners>
              <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="C:\logs\MyTrace.svclog" />
          </listeners>
       </source>
   </sources>
   <trace autoflush="true" /> 
</system.diagnostics>