c# programming

20070724

GetDate Snippet

///<summary>
///    Returns a string representing the 

current date
///</summary>
///<returns>date as string; formatted as YYYYMMDD</returns>
public static string GetDateAsString()
{
    string date;
    DateTime now = DateTime.Now;
    date = now.Year.ToString();
    date += 

now.Month.ToString("00");
    date += 

now.Day.ToString("00");
    return (date);
}

///<summary>
///    Returns an integer representing 

the current date
///</summary>
///<returns>date as int; formatted as YYYYMMDD</returns>
///<seealso cref="GetDateAsString" 

/>
public static int GetDateAsInt()
{
    int date;
    date = 

Convert.ToInt32(GetDateAsString());
    return(date);
}

20070717

Easy Debugging in ASP.Net

to output text in a c# application (web or form)

Option #1:
include:
using System.Diagnostics;
private void main()
{
  functionName();
}

then outside of your functions
[Conditional("DEBUG")]
private void functionName()
{//this only displays when using debug compilation
  Console.WriteLine("debugging text output");
}

Option #2:
protected void Page_Load(object sender, EventArgs e)
{

  #if DEBUG
  //only displays when web.config compilation debug="true"
  Console.SetOut(Response.Output);
  Console.WriteLine("WEBSITE IS IN DEBUG MODE!");

  #endif
}
this is a good idea for web applications to remind you to disable debugging when you push a site to your production server.

Labels:

20060611

XAML - Displaying Text

XAML has several different ways to display text. The capabilities discussed in this article are for formatting text for printing. XAML uses anti-aliasing to display text so you can zoom in on the text, and it will still appear smooth.

First I will start with the FlowDocumentReader container. The FlowDocumentReader allows me to display what the other containers (FlowDocumentScrollViewer and FlowDocumentPageViewer) will look like. I will cover these other containers another time.

The text included is called Greeking, though I have been told that it is actually Latin. It is included to allow the text to flow over a couple pages.

<FlowDocumentReader
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    Margin="10"
    BorderBrush="Black" BorderThickness="1">
  <FlowDocument
      IsOptimalParagraphEnabled="True"
      IsHyphenationEnabled="True">
    <Paragraph>
Elitr referrentur duo at, ei has facer takimata, mei ei meliore interpretaris. Ea qui admodum blandit, sea ea dicta munere putent. Eu erat homero virtute quo, ad est probo officiis expetendis. Euismod vituperatoribus aeque at eam, quodsi dolorum necessitatibus ad pri. Novum aliquando eos ex. Qui sint lobortis incorrupte ei, impedit recusabo duo no.
    </Paragraph>
    <Paragraph>
Primis maluisset nam te. Senserit prodesset duo cu, wisi maluisset consectetuer ne mei. Eum probo aliquid minimum ad. Prima nullam persequeris cum ei, cum ad paulo assueverit consectetuer. Officiis atomorum est cu, et dolorem nusquam his, eam ea odio commodo. Unum autem dicam mea ad, malis tincidunt adversarium usu ea. Vocent fuisset singulis in eum, sea ad tation graeci iisque, cum ut essent volumus.
    </Paragraph>
    <Paragraph>
Et sea dico feugait definitiones, usu electram deterruisset interpretaris ex. His at vocent delenit, vis lucilius tractatos in. Affert explicari usu id. Eum amet suscipiantur ne, quem sale delenit mea in. In soluta doming vim, in quo virtute disputationi, in etiam nostrud appareat quo. Mei ad definitionem concludaturque.
    </Paragraph>
  </FlowDocument>
</FlowDocumentReader>

Let's look at what this code does. The FlowDocumentReader allows the user to choose how he would like to view the text. He is given the choice of "Page Mode", "Two Page Mode", and "Scroll Mode". The user is also given the ability to search the text and zoom in or zoom out.

It appears as though you must have only one FlowDocument tag inside the FlowDocumentReader tag. You can also have as many Paragraph tags inside the FlowDocument tag as you would like.

XAML Introduction

I am working on learning how XAML works, a relatively new and evolving format for developing Windows applications. For those of you who have built web pages using HTML, you will see that it is somewhat similar. XAML is a structured language using tagged data. A very basic HTML web page would be structured like this.

<html>
  <head>
    <title>Hello World</title>
  </head>
  <body>
    Hello World!
  </body>
</html>

Let's look at what this text does. the HTML tag (<html>) is the container for the web page. The head tag denotes the part of the page which is not displayed. It includes the page title and content that describes the page, or tells the page how to act. The body tag contains the content that is displayed on the web page, such as the text "Hello World!"

The spacing is not important, but is there for readability purposes. The basics of HTML are that you have an opening tag "<TagName>" and a closing tag "</TagName>" or you can have a single tag that opens and closes itself like "<TagName />".

HTML and XAML are both subsets of a structured highly structured text format called XML. HTML doesn't necessarily require all tags to be closed. A newer version of HTML called XHTML does require all tags to be closed, and thus is a true subset of XML.

So now that you have a very basic understanding of HTML, lets look at some XAML. By the way, you will need to either be running Microsoft Windows Vista and / or Internet Explorer 7 or have Microsoft WinFX (now called .Net 3.0) installed on Windows XP.

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <TextBlock>
    Hello World!
  </TextBlock>
</Canvas>

So now let's look at what the XAML instructions do. Their are several possible container tags depending on how the page should be layed out. In this example I am using the Canvas tag as the container. The TextBlock contains the text I want to display, "Hello World!"

So as the title says, this is an introduction to XAML. I will try to get more in depth as time allows, historically it hasn't allowed much. As I said in the opening, I am not expert, but am just learning this, so my examples aren't necessarily the best way to build XAML pages or applications. But hopefully as I learn more my examples will follow the recommended practices.

Microsoft Windows Vista β2

I have installed Vista β2 on my laptop, a Gateway 7426GX. It installed and runs very well. I have the laptop configured to dual boot with Windows XP Pro on another partition. Also it runs all the eye candy, including glass and the sidebar well.

The only issue is that their may be an issue with the modem driver, it would throw up some error about the modem every once in a while. I disabled the modem through the Device Manager, and now I don't get the warning.

I did have it hang up once when using Media Center, with movie files on the laptop. It didn't crash, but it locked the processor at 100% for several minutes. Then Vista noticed it, and spent another 10-15 minutes sending the report to Microsoft.

Overall I think Vista is a nice improvement. It is relatively stable for a beta operating system. I think the eye candy is nice, though not necessary. Once I decide what software I want to install, I may try to run the operating system under a limited-user account.