Tuesday, April 27, 2010

Is Boho a Windows Phone 7?

The short answer is no. If for no other reason than Silverlight is absent.
But it is also lacking in the minimal feature set which specifies minimum screen, camera and memory.

Saturday, April 24, 2010

Race Condition as Illustrated with Racer X and Speed Racer

Sometimes nothing works better than a simple example.

Below is a short program that demonstrates a race condition that occurs when two threads share some bit of state. It is written in C# and if you run it several times you should see inconsistent behaviors.

Sometimes Speed Racers thread finishes first and resets the SharedState to true and sometimes Racer X wins. This is the heart of threading problems, shared state and inconsistent results.

Now lets looks at a proposed fix. In RacerX there is a commented line
//System.Threading.Thread.Sleep(100);

By uncommenting it,  the inconsistent behaviour changes. Sometimes the program finishes because RacerX finished first and waited long enough for Speed Racer to finish. (You know he was the older brother and always looking out for Speed Racer)

But sometimes Speed Racer finishes first and he doesn't wait for RacerX. So Racer X keeps circling around. (Keep in mind Speed did not know that Racer X was his older brother)

So in this case it appears that the code has gotten better because the bug is now showing only half the time. But in reality it is just as flaky. The bug has now become intermittant and harder to reproduce.


class Program
{
static bool SharedState = true;

static void Main(string[] args)
{
Thread racerX = new Thread(RacerX);
racerX.Start();
Thread speedRacer = new Thread(SpeedRacer);
speedRacer.Start();
System.Threading.Thread.Sleep(2000);
SharedState = false;
}


static void RacerX()
{
while (SharedState)
{
Console.WriteLine("RacerX");
}
//System.Threading.Thread.Sleep(100);
SharedState = true;
}


static void SpeedRacer()
{
while (SharedState)
{
Console.WriteLine("SpeedRacer");
}
SharedState = true;
}
}

Friday, April 23, 2010

Notes: Sharepoint Exam 70-631

Just found these old notes from prepping for Sharepoint exam.
Might as well throw them on the blog in case I want them later.

Back to back firewall configuration Two firewall devices back to back
Internet Edge firewall configuration
Multi-homed firewall configuration
Multi-Edge firewall configuration
Not supported


Mobility Redirect
stsadm -o activatefeature -name MobilityRedirect -URL http://url/


Performance Counters for Processor Issues
System\Processor Queue Length
System\Context Switches/sec
Processor\% Processor Time


Two Stage Recycle Bin
First Stage retains document on user's computer for 30 days
Second Stage can be used by site administrator


Stsadm listing options
stsadm -o adduser
add a user account to a WSS site
stsadm -o enumroles
display all site groups for a WSS site
stsadm -o enumsites
display all sites under a virtual server
stsadm -o userole
set group membership for a user


Prescan.exe
used to identify readiness to upgrade to WSS 3.0


Content Migration Tool
Used to migrate content, example Content Management Server 2002


Information Rights Management
Provide more restrictive access controls on documents in SharePoint libraries and lists


Sharepoint Products and Technologies Configuration Wizard
Automates installation and configuration tasks


stsadm feature and custom application deployment
stsadm -o activatefeature
Enables features already deployed on a server
stsadm -o addsolution
Adds solution files to the configuration database store
stsadm -o deploysolution
Deploys solution files form configuration database to web servers
stsadm -o installfeature
Installs a WSS feature


DNS Record types
host (A)
Host record, provides address of a host
CNAME
Canonical name record, used to create alias for a host name
MX
Mail exchanger record, provides address of mail exchange server
SRV
Service record, provides address of servers providing specified services


MOM 2005
Centrally monitor status and performance of many products


ISA, Internet Security and Acceleration


SSO, Single Sign On


Included Permission Levels
Full Control
Not customizable
Design
Customizable
Contribute
Customizable
Read
Customizable
Limited Access
Not customizable


Upgrade Methods
Content database migration
-To move from one server to another
Gradual
-Allows 3.0 while retaining 2.0
In-place
-Best for single server, where all sites are to be upgraded

Thursday, April 22, 2010

Powershell Script to Read and Write a File


Powershell Script to Read and Write a File


function Copy-File ($infile, $outfile)
{
    $file = gc $infile
    Clear-Content $outfile
    foreach( $line in $file)
    {
        $line | Out-File -filepath $outfile -encoding utf8 -append
    }
}
Copy-File infile.txt outfile.txt

The bug that never happened.

I was demonstrating some F# code in Visual Studio 2010. It is shown below and it defines and then computes the discriminant function for quadratics.

let quadratic = fun a b c -> (b * b) - (4 * a *c)
let discriminant = quadratic 4 5 6
printfn "discriminant = %d" discriminant

Everything works, no surprise. But then as I modified the code. In particular as I changed the last line to:

printfn "discriminant = %d %d" discriminant

A compile warning occurred! So the compiler parsed the formatting string as well and checked that there where enough parameters provided. No doubt there is a nuance to functional programming that is requiring this level of checking.

But compare this to a line of C#

string wrongNumberOfArgs = string.Format("{0} {1}", 12);

The c# compiler is perfectly okay with this and it is only at runtime that you get the crash. In the simple case that I have shown this does not matter. But simple cases are not where this occurs. It is when it is complex that it occurs. So in the C# case you will find this out when you execute the code, when your mind has switched contexts.

In the F# case, the compiler warning is immediate because of the incremental compiles. You are best positioned to fix the code because you just keyed it in. In fact this is a bug that never happened.