Posts Tagged .net

LINQ Short Takes – Number 1 – Enumerable.Range()


Introduction

This blog post is the first of a series of shorter posts that will cover a number of brief LINQ topics.

This post will cover the Enumerable.Rangemethod. This is a ‘for free’ (part of the .Net Framework) method that I have found very useful. There have been a number of circumstances where I have used this method. This method offers a simple data source vital to addressing a number of classes of problems. With the use of this simple data source, some problems become trivial, rather than extremely complex with ‘vanilla’ LINQ.

There are a couple of subsequent posts, I will write, which build on the use of the Enumerable.Range method.

The Enumerable Range Method

This is quite a simple method. The MSDN documentation (see: Enumerable.Range) describes the method as follows.

“Generates a sequence of integral numbers within a specified range.”

This statement is almost dismissive of the many ways that this method provides a very flexible data source.

Some Examples Using Enumerable.Range

The following are a couple of simple examples of the use of the Enumerable.Range.

private void Simple_Range_Demos()
{
    // A Simple Range Example var Test1 = from seq in Enumerable.Range(0, 10)
                select seq;
    Test1.ToOutput();

    // Build a year calendar using Range DateTime Jan1 = new DateTime(2012, 1, 1);
    int Days = 0;
    if (DateTime.IsLeapYear(2012)) Days = 366;
    else Days = 365;
    var YearCalendar = from seq in Enumerable.Range(0, Days)
                       select Jan1.AddDays(seq);
    return;
}

Conclusions

These presented examples may seem trite and overly simple. In forthcoming post I will build upon the use of the Enumerable.Range to achieve some interesting, and useful LINQ techniques.

, , , , , , ,

3 Comments

Debug.WriteLine in C# 4.0 and .Net Framework 4.0


Introduction

This is one is a very short blog post. There is a one improvement which has made its way into the C# 4.0 and .Net Framework, which I wish to share.

This improvement is a very simple one. If I had a paranoid streak, I would say Microsoft must have been watching the code I’ve been writing. Why? Because the code I write is littered with the following:

int i = 0;
// The old way
Debug.WriteLine(String.Format("What is i {0} - old way", i));

I use the debug output window in Visual Studio heavily. I find shoving formatted strings into the debug output window is one my standard ways of producing debug diagnostics from programs in development.

The Enhancement

[ConditionalAttribute("DEBUG")]
public static void WriteLine(
    string format,
    params Object[] args
);

The above is the prototype of the addition to the Debug class, another overload of the WriteLine method. This WriteLine method is document here : Debug.WriteLine.

Simply put this is a WriteLine method which encapsulates the String.Format call. Which results in code like:

int i = 0;
// The old way
Debug.WriteLine(String.Format("What is i {0} - old way", i));
// New in Version 4 of C# and .Net Framework
Debug.WriteLine("What is i {0} - New C# 4.0 way", i);

Conclusion

It’s a great improvement. It will save me a lot of keystrokes when I’m developing. But this enhancement , has a downside, now I need to remember to use it!

, , , , , , , , , , ,

Leave a comment

Analysis Services and XMLA


Introduction

Last week was a week in "BI Boot camp”, learning how to work with Microsoft SQL Server Integration, Analysis and Reporting Services. The week was very worthwhile. The three of us from the migrate to Microsoft project really did get us all “up to speed” with all of the tools which we have at our disposal. There should be a big thankyou to Bill Chestnut for presenting a very good weeks worth of training.

Having just completed the training in SQL Server BI tools, this week has been full steam into continuing the migration project. The area of interest I started exploring is the whole deployment side of the project. We will have cubes in out development environment which will need to be migrated to a User Acceptance, Test (if we run with the environments) and Production environments. Apart from the “getting the space” issue, which will resolve itself as new SAN (storage area network) hardware is installed. The issue of developing a deployment methodology has been consuming my time for the last couple of days.

The Strategy

  • Use XMLA to transfer the definition of the cubes from Development into another environment.
  • Use Powershell to script the deployment process.

The Glitches

  1. Learning Powershell. This will be a learning curve for the next couple of weeks. I’ve found some many resources on the net on Powershell. Nothing I’d strongly recommend at this point. There is plenty on the MSDN web site on the product.
  2. Generating XMLA for a Cube, programmatically. The way I’ve found to do this is using the Scripter Class, and the WriteCreate static method. I’ll post some sample code (in C# and Poweshell) which demonstrates this (later, need to get the code together). The method does generate XMLA as advertised, and once you know where it is is not too hard to use.
    • There is a wrinkle to using this class you need to have a reference to the “Assembly: Microsoft.AnalysisServices (in microsoft.analysisservices.dll)”. A search for the assembly was required to find it on the machine.
  3. Applying XMLA. This one had me going for a while. There are two options I found:
  4. Generated XMLA for a Cube. The XMLA generated for a Cube, has references to a DataSource and a DataSourceView. The absence of these in the target database (would appear) to cause the XMLA execution to fail. I’m in the process of building the process so that it creates these, if necessary (sample code to come later).
  5. Powershell integration. I’ve a concern that what’s developing is something which is a “bit to .Net programming” for Powershell to comfortably accommodate.  A subsequent step in this journey, may be the creation of some (or maybe one) Powershell cmdlet . More on this as the project progresses.
Digg This

, , , ,

Leave a comment

%d bloggers like this: