WCF, Certificate Issues, and Stackoverflow

I've been working on getting certificates setup for development with the WCF Web Services I'm building for the High Ball Project.  On a few topics I'm just completely new, like messing with the Certificates, X.509 and SSL and such.  I'm getting there, but road blocks are stopping me every once in a while.  One of my recent issues was how to view the values that the certificate has.  I searched and searched, for some reason I couldn't find something on MSDN or via Google that would do what I wanted it to do.  In addition to that, the reason I was looking for this application to begin with, I was having issues with getting my web.config settings correct for finding the local certificate I had created with makecert.exe.

Stack Overflow!

That's when it clicked in my head, hey, I should try this stackoverflow site out!  So I shot over there and posed these two questions and within less than a 24 hr period on the WEEKEND, I got some solid answers.  I gotta say the guys over at stackoverflow are onto something here!

My first question, "Cannot find the X.509 Certificate using the following search criteria:…" and second question "Tool for Viewing X.509 Certificates?" have two great answers.  So check em' out, and if you aren't signed up with an OpenID get one and go log into the site!  It rocks.  In addition, for you dot netters out there like me, know that the site is built on ASP.NET MVC!  It's solid and FAST!

Making Maths Functions n' Stuff Part 6

First off I changed up the UI a little bit to accommodate the changes I wanted to make.  I mainly wanted to show how, at the same time utilizing the functions, the way WPF controls work.  Numerous controls work in ways they never have before, utilizing a more object oriented patterns and practices oriented nomenclature.  I like it, but at the same time it is a learning curve to think of the controls less in their ancient VB4 and VB6 days and more like the real objects that they now are.

   1:  <Window x:Class="Maths.MathsCooking"
   2:      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:      Title="Maths Cooking" Height="768" Width="1024">
   5:      <Grid>
   6:          <TextBox Height="65" Margin="10,0,14,50" Name="textAnswers" VerticalAlignment="Bottom" />
   7:          <Button Height="23" HorizontalAlignment="Right" Margin="0,0,14,14" Name="exitApplicationButton" VerticalAlignment="Bottom" Width="75" Click="exitApplicationButton_Click">Exit</Button>
   8:          <GroupBox Header="Fraction Functions" Margin="18,20,489,0" Name="groupBox1" Height="187" VerticalAlignment="Top">
   9:              <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
  10:                  <Button BorderThickness="3" Click="getApproximateEqualityButton_Click" Height="23" HorizontalAlignment="Right" Margin="0,0,18,23.085" Name="getApproximateEqualityButton" VerticalAlignment="Bottom" Width="150">Get Approximate Equality</Button>
  11:                  <TextBox Height="23" Margin="190,10,198,0" Name="textNumerator" VerticalAlignment="Top"/>
  12:                  <TextBox Height="23" Margin="190,0,198,57.723" Name="textValue" VerticalAlignment="Bottom" />
  13:                  <TextBox Height="23" Margin="190,0,198,21.723" Name="textEpsilon" VerticalAlignment="Bottom"/>
  14:                  <TextBox Height="23" Margin="190,48,198,0" Name="textDenominator" VerticalAlignment="Top"/>
  15:                  <Label Height="28" HorizontalAlignment="Left" Margin="10,10,0,0" Name="labelNumerator" VerticalAlignment="Top" Width="150">Numerator</Label>
  16:                  <Label Height="28" HorizontalAlignment="Left" Margin="10,48,0,0" Name="labelDenominator" VerticalAlignment="Top" Width="150">Denominator</Label>
  17:                  <Label Height="28" HorizontalAlignment="Left" Margin="10,0,0,16.723" Name="labelEpsilon" VerticalAlignment="Bottom" Width="150">Epsilon</Label>
  18:                  <Label Height="28" HorizontalAlignment="Left" Margin="10,0,0,52.723" Name="labelValue" VerticalAlignment="Bottom" Width="150">A Value (Float or Double)</Label>
  19:                  <Button BorderThickness="3" Click="getDecimalButton_Click" Height="23" HorizontalAlignment="Right" Margin="0,46.638,18,0" Name="getDecimalButton" VerticalAlignment="Top" Width="150">Get Decimal</Button>
  20:              </Grid>
  21:          </GroupBox>
  22:          <GroupBox Header="Is Numeric Check" Margin="18,223,489,0" Name="groupBox2" Height="103" VerticalAlignment="Top">
  23:              <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
  24:                  <Button Height="23" HorizontalAlignment="Right" Margin="0,15,18,0" Name="getAnalysisOfString" VerticalAlignment="Top" Width="150" Click="getAnalysisOfString_Click">Analyze</Button>
  25:                  <TextBox Height="23" Margin="10,15,0,0" Name="textIsNumeric" VerticalAlignment="Top" HorizontalAlignment="Left" Width="95" />
  26:                  <CheckBox Height="16" Margin="142,18,222,0" Name="checkIsNumeric" VerticalAlignment="Top">Is Numeric?</CheckBox>
  27:                  <CheckBox Height="16" Margin="142,0,222,26" Name="checkIsEven" VerticalAlignment="Bottom">Is Even?</CheckBox>
  28:              </Grid>
  29:          </GroupBox>
  30:          <GroupBox Header="GroupBox" Height="187" HorizontalAlignment="Right" Margin="0,20,24,0" Name="groupRounding" VerticalAlignment="Top" Width="446">
  31:              <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
  32:                  <Button Click="getRoundedAnswers_Click" Height="23" HorizontalAlignment="Right" Margin="0,0,19,23.085" Name="getRoundedAnswers" VerticalAlignment="Bottom" Width="150">Round</Button>
  33:                  <Label Height="28" Margin="160,0,154,54.723" Name="labelRoundDown" VerticalAlignment="Bottom">Down</Label>
  34:                  <Label Height="28" Margin="160,45.999,154,0" Name="lableRoundUp" VerticalAlignment="Top">Up</Label>
  35:                  <Label Height="28" Margin="160,10,154,0" Name="labelRoundIeee" VerticalAlignment="Top">IEEE</Label>
  36:                  <TextBox Height="23" Margin="0,48,19,0" Name="textRoundUp" VerticalAlignment="Top" HorizontalAlignment="Right" Width="120" />
  37:                  <TextBox Height="23" HorizontalAlignment="Right" Margin="0,12,19,0" Name="textRoundIeee" VerticalAlignment="Top" Width="120" />
  38:                  <TextBox Height="23" HorizontalAlignment="Right" Margin="0,0,19,57.723" Name="textRoundDown" VerticalAlignment="Bottom" Width="120" />
  39:                  <TextBox Height="23" HorizontalAlignment="Left" Margin="19,48,0,0" Name="textNumberToRound" VerticalAlignment="Top" Width="120" />
  40:                  <Label HorizontalAlignment="Left" Margin="19,10,0,0" Name="labelNumberToRound" Width="120" Height="28" VerticalAlignment="Top">Round This</Label>
  41:              </Grid>
  42:          </GroupBox>
  43:      </Grid>
  44:  </Window>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

After I made the UI changes I altered some of the code and added some code.  The first change was to the but that used to check for numeric value, that now does multiple checks.  The Analyze Button now looks like this.

   1:          private void getAnalysisOfString_Click(object sender, RoutedEventArgs e)
   2:          {
   3:              if (textIsNumeric.Text != string.Empty)
   4:              {
   5:                  bool isNumberic = Functions.IsNumeric(textIsNumeric.Text);
   6:   
   7:                  checkIsNumeric.IsChecked = isNumberic;
   8:   
   9:                  bool isEven;
  10:                  if (isNumberic)
  11:                  {
  12:                      Int64 numeric = Convert.ToInt64(textIsNumeric.Text);
  13:                      isEven = Functions.IsEven(numeric);
  14:                      checkIsEven.IsChecked = isEven;
  15:                      textAnswers.Text = "Numeric? " + isNumberic + ". Even? " + isEven + ".";
  16:                  }
  17:                  else
  18:                  {
  19:                      textAnswers.Text = "Numeric? " + isNumberic + ".";
  20:                  }
  21:              }
  22:              else
  23:              {
  24:                  MessageBox.Show(
  25:                      "Technically string.empty is not numeric, but it is more useful if you enter a value to check.",
  26:                      "Enter a value!",
  27:                      MessageBoxButton.OK,
  28:                      MessageBoxImage.Hand,
  29:                      MessageBoxResult.OK);
  30:              }
  31:          }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

The other functionality I then added was the rounding group box.  The code is included below.

   1:          private void getRoundedAnswers_Click(object sender, RoutedEventArgs e)
   2:          {
   3:              if(Functions.IsNumeric( textNumberToRound.Text))
   4:              {
   5:                  double numberToRound = Convert.ToDouble(textNumberToRound.Text);
   6:                  string roundedUp= Functions.Round(Functions.RoundDirection.Up, numberToRound).ToString();
   7:                  string roundedDown= Functions.Round(Functions.RoundDirection.Down, numberToRound).ToString();
   8:                  string roundedIeee= Functions.Round(Functions.RoundDirection.IeeeStandard, numberToRound).ToString();
   9:                  textRoundUp.Text = roundedUp;
  10:                  textRoundDown.Text = roundedDown;
  11:                  textRoundIeee.Text = roundedIeee;
  12:              }
  13:              else
  14:              {
  15:                  MessageBox.Show(
  16:                      "You must enter numeric values in the text box to round.",
  17:                      "Enter a numeric value!",
  18:                      MessageBoxButton.OK,
  19:                      MessageBoxImage.Hand,
  20:                      MessageBoxResult.OK);
  21:              }
  22:          }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

I still have many things I’ll be adding to this strange and haphazard application, as the cooking is never done.  Over the next few months and weeks I intend to add string manipulations and other useful things to the application.  The idea of course, is to use it as reference, and possibly, as something for finding out information!

The code for this entire solution is available at CodePlex: http://www.codeplex.com/csharpcooking

Making Maths Functions n' Stuff Part 5

There are a few more math functions and such that I wanted to add to the math application before calling it finished.  If anyone out in the ole’ blogosphere has any other math functions they’d like to have added to the application please shoot me an e-mail or two on which ones to add.  Neil?  Any mathematicians out there?

First of the final additions.  Let’s throw an even or odd method in there.  As always, got to have a test or two.

   1:          [Test]
   2:          public void TestIsEvenYesLong()
   3:          {
   4:              // Just to prove the point.
   5:              const long evenNumber = 9223372036854775806;
   6:              Console.WriteLine("Test Number: " + evenNumber);
   7:              Console.WriteLine("Is Even? " + MathCookbook.Functions.IsEven(evenNumber));
   8:              Assert.IsTrue(MathCookbook.Functions.IsEven(evenNumber));
   9:          }
  10:   
  11:          [Test]
  12:          public void TestIsEvenNoLong()
  13:          {
  14:              // Just to prove the point.
  15:              const long oddNumber = 9223372036854775807;
  16:              Console.WriteLine("Test Number: " + oddNumber);
  17:              Console.WriteLine("Is Even? " + MathCookbook.Functions.IsEven(oddNumber));
  18:              Assert.IsFalse(MathCookbook.Functions.IsEven(oddNumber));
  19:          }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Then toss the method in.

   1:          /// <summary>
   2:          /// This method returns true for an even number and false for an odd number.
   3:          /// </summary>
   4:          /// <param name="number">Enter the number to check for even or odd value.</param>
   5:          /// <returns>This method returns true for an even number and false for an odd number.</returns>
   6:          public static bool IsEven(long number)
   7:          {
   8:              return ((number & 1)==0);
   9:          }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Next of the final additions is a method to obtain rounding based on rounding up, down, or following the IEEE Standard 754, section 4, which rounds to the even number regardless of up or down.  Kind of odd, but here’s the tests.

   1:          [RowTest]
   2:          [Row(3.5, 4)]
   3:          [Row(3.3, 3)]
   4:          [Row(3.7, 4)]
   5:          [Row(2.5, 3)]
   6:          public void TestRoundUp(double roundThis, long answer)
   7:          {
   8:              Assert.AreEqual(
   9:                  MathCookbook.Functions.Round(
  10:                      MathCookbook.Functions.RoundDirection.Up, roundThis),
  11:                  answer);
  12:          }
  13:   
  14:          [RowTest]
  15:          [Row(3.5, 3)]
  16:          [Row(3.3, 3)]
  17:          [Row(3.7, 4)]
  18:          [Row(2.5, 2)]
  19:          public void TestRoundDown(double roundThis, long answer)
  20:          {
  21:              Assert.AreEqual(
  22:                  MathCookbook.Functions.Round(
  23:                      MathCookbook.Functions.RoundDirection.Down, roundThis),
  24:                  answer);
  25:          }
  26:   
  27:          [RowTest]
  28:          [Row(3.5, 4)]
  29:          [Row(3.3, 3)]
  30:          [Row(3.7, 4)]
  31:          [Row(2.5, 2)]
  32:          public void TestRoundIeeeStyle(double roundThis, long answer)
  33:          {
  34:              Assert.AreEqual(
  35:                  MathCookbook.Functions.Round(
  36:                      MathCookbook.Functions.RoundDirection.IeeeStandard, roundThis),
  37:                  answer);
  38:          }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Here’s the method.

   1:          /// <summary>
   2:          /// This method rounds up using the up, down, or IEEE standard rounding direction.
   3:          /// </summary>
   4:          /// <param name="direction">Enter the direction of rounding to use.</param>
   5:          /// <param name="roundThis">Enter the number in which to round.</param>
   6:          /// <returns>A double type rounded to the nearest number based on the round direction.</returns>
   7:          public static double Round(RoundDirection direction, double roundThis)
   8:          {
   9:              switch (direction)
  10:              {
  11:                  case RoundDirection.Up:
  12:                      return Math.Floor(roundThis + .5);                    
  13:                  case RoundDirection.Down:
  14:                      double floorValue = Math.Floor(roundThis);
  15:                      return (roundThis - floorValue) > .5 ? floorValue + 1 : floorValue;
  16:                  case RoundDirection.IeeeStandard:
  17:                      return Math.Round(roundThis);
  18:              }
  19:              return 0;
  20:          }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

The final addition is the temperature measurement conversions.  Test first.

   1:          [RowTest]
   2:          [Row(0, 32)]
   3:          [Row(29.444444444444446, 85)]
   4:          [Row(7.5, 45.5)]
   5:          public void TestCelsiusToFehrenheit(double celsius, double fahrenheit)
   6:          {
   7:              Assert.AreEqual(MathCookbook.Functions.GetCelsiusToFahrenheit(celsius), fahrenheit);
   8:          }
   9:   
  10:          [RowTest]
  11:          [Row(0, 32)]
  12:          [Row(29.444444444444446, 85)]
  13:          [Row(7.5, 45.5)]
  14:          public void TestFehrenheitToCelsius(double fahrenheit, double celsius)
  15:          {
  16:              Assert.AreEqual(MathCookbook.Functions.GetFahrenheitToCelsius(celsius), fahrenheit);
  17:          }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

The method.

   1:          /// <summary>
   2:          /// This method converts fahrenheit to celsius.
   3:          /// </summary>
   4:          /// <param name="fahrenheit">Enter the fahrenheit temperature to convert.</param>
   5:          /// <returns>A double type of the celsius temperature.</returns>
   6:          public static double GetFahrenheitToCelsius(double fahrenheit)
   7:          {
   8:              return ((.5 / .9) * (fahrenheit - 32));
   9:          }
  10:   
  11:          /// <summary>
  12:          /// This method converts celsius to fahrenheit.
  13:          /// </summary>
  14:          /// <param name="celsius">Enter the celsius temperature to convert.</param>
  15:          /// <returns>A double type of the fahrenheit temperature.</returns>
  16:          public static double GetCelsiusToFahrenheit(double celsius)
  17:          {
  18:              return (((.9 / .5) * celsius) + 32);
  19:          }

Making Maths Functions n' Stuff Part 4

This time I’ll add one more test, a respective method, and then put together the WPF UI for the additional methods added in this part and part 3.  With this additional method I’ll toss in a little validation too.  So first I’ll go ahead and get the validation of string as a number method out of the way.  First things first, going to get a couple tests running.

   1:          [Test]
   2:          public void TestStringIsNumberWithNumber()
   3:          {
   4:              string theTestString = "52";
   5:              Console.WriteLine(theTestString);
   6:              Console.WriteLine(MathCookbook.Functions.IsNumeric(theTestString));
   7:              Assert.IsTrue(MathCookbook.Functions.IsNumeric(theTestString));
   8:          }
   9:   
  10:          [Test]
  11:          public void TestStringIsNumberWithString()
  12:          {
  13:              string theTestString = "ThisIsObviouslyNotNumber";
  14:              Console.WriteLine(theTestString);
  15:              Console.WriteLine(MathCookbook.Functions.IsNumeric(theTestString));
  16:              Assert.IsFalse(MathCookbook.Functions.IsNumeric(theTestString));
  17:          }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Then I’ll throw in the method needed to get a green light.

   1:          /// <summary>
   2:          /// This method returns a true or false depending on the passed parameter being a numeric value or not.
   3:          /// </summary>
   4:          /// <param name="valueToCheck">Enter the string value to check for numeric type.</param>
   5:          /// <returns>Returns true if the string is a number or false if it is alphanumeric.</returns>
   6:          public static bool IsNumeric(string valueToCheck)
   7:          {
   8:              Regex reg = new Regex(@"^[\+\-]?\d*\.?[Ee]?[\+\-]?\d*$", RegexOptions.Compiled);
   9:   
  10:              valueToCheck = valueToCheck.Trim();
  11:              Match m = reg.Match(valueToCheck);
  12:              return m.Value != string.Empty;
  13:          }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Next I’ll start putting together the WPF needed to test execute these new methods.  First the additional UI changes.

   1:  <Window x:Class="Maths.MathsCooking"
   2:      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:      Title="Maths Cooking" Height="768" Width="1024">
   5:      <Grid>
   6:          <TextBox Height="65" Margin="10,0,14,50" Name="textAnswers" VerticalAlignment="Bottom" />
   7:          <Button Height="23" HorizontalAlignment="Right" Margin="0,0,14,14" Name="exitApplicationButton" VerticalAlignment="Bottom" Width="75" Click="exitApplicationButton_Click">Exit</Button>
   8:          <GroupBox Header="Fraction Functions" Margin="18,20,489,0" Name="groupBox1" Height="187" VerticalAlignment="Top">
   9:              <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
  10:                  <Button BorderThickness="3" Click="getApproximateEqualityButton_Click" Height="23" HorizontalAlignment="Right" Margin="0,0,18,23.085" Name="getApproximateEqualityButton" VerticalAlignment="Bottom" Width="150">Get Approximate Equality</Button>
  11:                  <TextBox Height="23" Margin="190,10,198,0" Name="textNumerator" VerticalAlignment="Top" />
  12:                  <TextBox Height="23" Margin="190,0,198,57.723" Name="textValue" VerticalAlignment="Bottom" />
  13:                  <TextBox Height="23" Margin="190,0,198,21.723" Name="textEpsilon" VerticalAlignment="Bottom" />
  14:                  <TextBox Height="23" Margin="190,48,198,0" Name="textDenominator" VerticalAlignment="Top" />
  15:                  <Label Height="28" HorizontalAlignment="Left" Margin="10,10,0,0" Name="labelNumerator" VerticalAlignment="Top" Width="150">Numerator</Label>
  16:                  <Label Height="28" HorizontalAlignment="Left" Margin="10,48,0,0" Name="labelDenominator" VerticalAlignment="Top" Width="150">Denominator</Label>
  17:                  <Label Height="28" HorizontalAlignment="Left" Margin="10,0,0,16.723" Name="labelEpsilon" VerticalAlignment="Bottom" Width="150">Epsilon</Label>
  18:                  <Label Height="28" HorizontalAlignment="Left" Margin="10,0,0,52.723" Name="labelValue" VerticalAlignment="Bottom" Width="150">A Value (Float or Double)</Label>
  19:                  <Button BorderThickness="3" Click="getDecimalButton_Click" Height="23" HorizontalAlignment="Right" Margin="0,46.638,18,0" Name="getDecimalButton" VerticalAlignment="Top" Width="150">Get Decimal</Button>
  20:              </Grid>
  21:          </GroupBox>
  22:          <GroupBox Header="Is Numeric Check" Margin="18,223,489,0" Name="groupBox2" Height="69" VerticalAlignment="Top">
  23:              <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
  24:                  <Button HorizontalAlignment="Right" Margin="0,12,18,14.723" Name="getIsNumberic" Width="150" Click="getIsNumberic_Click">Is Numeric</Button>
  25:                  <Label HorizontalAlignment="Left" Margin="10,10,0,11.723" Name="labelIsNumeric" Width="120">Is Numeric?</Label>
  26:                  <TextBox Margin="190,12,198,14.723" Name="textIsNumeric" />
  27:              </Grid>
  28:          </GroupBox>
  29:      </Grid>
  30:  </Window>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Now the additional functionality.

   1:          private void exitApplicationButton_Click(object sender, RoutedEventArgs e)
   2:          {
   3:              Close();
   4:          }
   5:   
   6:          private void getIsNumberic_Click(object sender, RoutedEventArgs e)
   7:          {
   8:              textAnswers.Text = Functions.IsNumeric(textIsNumeric.Text).ToString();
   9:          }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Last but not least I’ll put in the validation so I don’t fat finger the wrong value types in the text boxes.  This is a little tricky, but it works.  In most environments you’d want to setup a decent validation framework for this, which might be one of my next blog entries.

   1:  #region
   2:   
   3:  using System;
   4:  using System.Windows;
   5:  using System.Windows.Controls;
   6:  using MathCookbook;
   7:   
   8:  #endregion
   9:   
  10:  namespace Maths
  11:  {
  12:      public partial class MathsCooking : Window
  13:      {
  14:          public MathsCooking()
  15:          {
  16:              InitializeComponent();
  17:          }
  18:   
  19:          private void getDecimalButton_Click(object sender, RoutedEventArgs e)
  20:          {
  21:              if (textNumerator.Text != string.Empty && Functions.IsNumeric(textNumerator.Text) &&
  22:                  textDenominator.Text != string.Empty && Functions.IsNumeric(textDenominator.Text))
  23:              {
  24:                  textAnswers.Text = Functions.GetDecimalOfFraction(
  25:                      Convert.ToDouble(textNumerator.Text),
  26:                      Convert.ToDouble(textDenominator.Text)).ToString();
  27:              }
  28:              else
  29:              {
  30:                  MessageBox.Show(
  31:                      "You must enter numeric values in the numerator and denominator text boxes.",
  32:                      "Enter values!",
  33:                      MessageBoxButton.OK,
  34:                      MessageBoxImage.Hand,
  35:                      MessageBoxResult.OK);
  36:              }
  37:          }
  38:   
  39:          private void getApproximateEqualityButton_Click(object sender, RoutedEventArgs e)
  40:          {
  41:              if (textNumerator.Text != string.Empty && Functions.IsNumeric(textNumerator.Text) &&
  42:                  textDenominator.Text != string.Empty && Functions.IsNumeric(textDenominator.Text) &&
  43:                  textValue.Text != string.Empty && Functions.IsNumeric(textValue.Text) &&
  44:                  textEpsilon.Text != string.Empty && Functions.IsNumeric(textEpsilon.Text))
  45:              {
  46:                  textAnswers.Text = Functions.IsApproximatelyEqualTo(
  47:                      Convert.ToDouble(textNumerator.Text),
  48:                      Convert.ToDouble(textDenominator.Text),
  49:                      Convert.ToDouble(textValue.Text),
  50:                      Convert.ToDouble(textEpsilon.Text)).ToString();
  51:              }
  52:              else
  53:              {
  54:                  MessageBox.Show(
  55:                      "You must enter numeric values in the numerator, denominator, value, and epsilon text boxes.",
  56:                      "Enter values!",
  57:                      MessageBoxButton.OK,
  58:                      MessageBoxImage.Hand,
  59:                      MessageBoxResult.OK);
  60:              }
  61:          }
  62:   
  63:          private void exitApplicationButton_Click(object sender, RoutedEventArgs e)
  64:          {
  65:              Close();
  66:          }
  67:   
  68:          private void getIsNumberic_Click(object sender, RoutedEventArgs e)
  69:          {
  70:              if (textIsNumeric.Text != string.Empty)
  71:              {
  72:                  textAnswers.Text = Functions.IsNumeric(textIsNumeric.Text).ToString();
  73:              }
  74:              else
  75:              {
  76:                  MessageBox.Show(
  77:                      "Technically string.empty is not numeric, but it is more useful if you enter a value to check.",
  78:                      "Enter a value!",
  79:                      MessageBoxButton.OK,
  80:                      MessageBoxImage.Hand,
  81:                      MessageBoxResult.OK);
  82:              }
  83:          }
  84:      }
  85:  }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

That’s that.  Now I have a simple application available for providing some simple mathematical calculations.  I’ll be creating another multi-part series, but next on the list will be something a bit different then some mathematical calculations.  Instead I’ll be focusing on putting together some architectural pieces of an application.

The finished code can be downloaded from Codeplex, via the C# Cooking Project I’ve created.

WebTrends at Day 2

Day 2 has started. First things first is to start ramping and get more of the material reviewed, and familiarity with Compass2, specific to my new position here at WebTrends. I must say, I'm glad to be back.


One of the big tasks that is still follow up from day 1 is getting the workstation installed with all the appropriate software. I have to say, getting a Microsoft Windows up and running is vastly easier, but more time consuming than an Ubuntu Linux Development Workstation. It is however much more time consuming than getting an Apple OS-X box running with Ruby on Rails. But this is a bit more expansive than a Ruby on Rails OS-X installation and I've not much experience setting up other installations on OS-X. Maybe I'll get the opportunity at a later time to expand my knowledge with RoR and OS-X. I'm still thinking that an Apple may be my next machine. I know for sure that my next machine will have Ubuntu as the pre-loaded OS and NOT Microsoft whatever.

During setup of the development workstation two major pieces of software were the big time consumers. SQL Server 2008, which is what actually caused the other big time consumption, Visual Studio.NET 2008 Service Pack 1! The later, SP1, took about 2 hours to download and is a required piece for SQL Server 2008 if one has Visual Studio 2008 installed on their box. I'm suspecting, that SP1 adds the necessary tools for the integration between SQL Server 2008 and Visual Studio 2008. That's fine, but JEEZ it's freaking huge. SQL Server 2008 installed over a network connection went fairly smoothly and quickly, albeit in a relative sense.

Once those things were installed I got started working toward getting things hooked up to the Team Foundation Server (08') and reviewing some code. I've already got numerous tasks assigned so I'll start working on those first thing tomorrow. Until then I'm out and off to Bailey's Tap Room for a good brew and good conversation with friends. If you're geek, goth, freak, or whatever, swing on by and have one yourself with some conversation.