Archive

Posts Tagged ‘C#’

How to Partition Cube – using C#

There are many different ways you can partition a cube. Here I am talking about – how you can use C# to partition a cube from a DTS package?

Using  Microsoft.AnalysisServices  Object API, you can travel the whole Hierarchy of objects  and completely administer an Analysis Service Instance. From the connection Object you can get to the Server and database instances. And in database you can transverse the Cube and their different measures. Once you get hold of a measure then you can transverse the different partitions of measures and dig deep in to each partition query definitions etc.
Read more…

Linq and Extension methods

I wanted to read a blob of xml and then display some attribute and few elements as HTML. With the help of Linq and extension method, the code can be very clean and simple.

The xml I want to read looks like as follows:

  <Dictionary>
  <W S="Arrogate">
    <M>To claim or demand unduly.</M>
    <S> accroach, appropriate, assume </S>
    <A> appropriate, give, hand over </A>
    <E>The teenager arrogated that he must get pocket money.</E>
....

Here is the code to convert this XML into HTML in a very nice manner

 static void Main(string[] args)
        {
            string FileName = AppDomain.CurrentDomain.BaseDirectory + "Lesson1.xml";
            var doc = XElement.Load(FileName);
            var query = from ele in doc.Elements(@"W")
                        select ele;
            foreach (var v in query)
            {
               Console.WriteLine(v.ToHTMLReady ());
            }
         }

The function ToHTMLReady() is the function which does all the magic. However, there is no ‘ToHTMLReady’ function defined on XElement, so where does this come from? This is one of the beauty of extension method. This function is defined as follows:

public static class MyExtensionMethod
    {
  public static string ToHTMLReady(this XElement  ele)
        {
            return "<B>WORD: </B>" + (string)ele.Attribute("S") + " <B> Example: </B>" + ele.Element("E").Value;
        }
}

using this extension method concept you can do all the heavy lifting manuplating XML, while keeping the main code very clean and simple.

Categories: C#, LINQ, Uncategorized Tags: , ,