MVC and MVVM

The controller is replaced with a View Model. The View Model sits below the UI layer. The View Model exposes the data and command objects that the view needs. You could think of this as a container object that view goes to to get its data and actions from. The View Model pulls its data from the model.

The sentence “The controller is replaced with a View Model” is not correct. In MVVM what does the role of the controller is databinding.

The main thrust of the Model/View/ViewModel architecture seems to be that on top of the data (”the Model”), there’s another layer of non-visual components (”the ViewModel”) that map the concepts of the data more closely to the concepts of the view of the data (”the View”). It’s the ViewModel that the View binds to, not the Model directly.

in MVVM, controllers will typically contain all processing logic and decide what data to display in which views using which view models.

From what we have seen so far the main benefit of the ViewModel pattern to remove code from XAML code-behind to make XAML editing a more independent task. We still create controllers, as and when needed, to control (no pun intended) the overall logic of our applications.

http://www.codeproject.com/Articles/165368/WPF-MVVM-Quick-Start-Tutorial

Posted in Uncategorized | Leave a comment

How to become a Software Architect

Architect is one who is very seasoned person, one who keeps on evaluating the technology, makes best out from technology by utilizing it to its stretch. Also if you have done mcsd (qualified all papers) then you can work as architect.

Becoming an architect is a serious journey you’ve chosen to take. It’s not about experience (though it is part of that) nor is it about technical proficiency (although, again, this will play into the mix).

Obviously, the first question you’ve to answer is “what is a solution architect?”. You’ll find heaps of different definitions on the net and probably each architect has his or her own opinion on the matter. I’m no exception and for me a SA is a person who has has all the competencies needed to deliver a successful solution architecture.   Yes, I know this doesn’t help too much, so let’s break that into what a solution architecture entails. A solution architecture of a software project is the blueprints of how, technically, a solution works. It should contain the following aspects:
•Technology Composition – this is where you define what technologies you’re going to use, e.g. COTS (http://en.wikipedia.org/wiki/Commercial_off-the-shelf) like AD, SharePoint, BizTalk, Office tools, Internet Explorer but also development platform like WCF and WPF.
•Information Model – this is where you define what information repositories you will have and how information will flow in the system
•Logical Composition – this is where you define the logical components, including custom development, and how they interact in the system
•Topology and Environments – this is where you define the service topology (e.g. servers and networks) of your system   Now, in order to design a successful solution architecture, you’ve to know a lot of technical information and be aware of many trends and options available for you to use. However, that’s not the end of the story, as you also have to possess soft skills and human dynamics skills to successfully communicate with both the business and the technical team to fully identify concerns and influences forces affecting your designs.

In essence, you’ve to be an absolute brilliant technical person with great communication skills, and have good knowledge of Project Management practices. Oh, and obviously, you have to have perfect abstraction abilities or else you’ll drawn in the sea of details.   All right, so now we know what a solution architect is. The next question should be “how do I become one?”. Well, here the response is much simpler – all you’ve to do is follow the development path painted by the IASA (http://www.iasahome.org/web/home/home) , here’s you’re staring point: http://www.iasahome.org/web/home/education . The International Association of Solution Architects (IASA) is the body of knowledge you should align your career development with. They identified the skills and competencies you should have as an architect, and also provide good learning materials and options to get there.

I would start with these 2 articles. Although not in perfect alignment of how I see the role of the architect, they do provide a holistic understanding of what is expected from you:
•The Role of the Software Architect: Caring and Communicating, by Magnus Mårtensson March 2008 (http://msdn.microsoft.com/en-us/library/cc304371.aspx)
•The Need for an Architectural Body of Knowledge, by Miha Kralj, from The Architecgure Journal, April 2008 (http://msdn.microsoft.com/en-us/architecture/cc505967.aspx)
• How to become a software architect (http://www.kanneganti.com/technical/architect/)

Reference: http://social.msdn.microsoft.com/Forums/en-US/architecturegeneral/thread/f8369df3-c382-471a-aab7-704c529beb73/

Posted in Coding & Standard | Leave a comment

C# Interfaces

An interface contains definitions for a group of related functionalities that a class or a struct can implement.

An interface has the following properties:

  • An interface is like an abstract base class. Any class or struct that implements the interface must implement all its members.
  • An interface can’t be instantiated directly. Its members are implemented by any class or struct that implements the interface.
  • Interfaces can contain events, indexers, methods, and properties.
  • Interfaces contain no implementation of methods.
  • A class or struct can implement multiple interfaces. A class can inherit a base class and also implement one or more interfaces.
  • IEnumerable (and IEnumerable): for use with foreach and LINQ
  • IDisposable: for resources requiring cleanup, used with using
  • IQueryable: lets you execute requests against queriable data sources.
  • INotifyPropertyChange : For data binding to UI classes in WPF, winforms and silverlight
  • IComparable and IComparer: for generalized sorting
  • IEquatable and IEqualityComparer: for generalized equality
  • IList and ICollection: for mutable collections
  • IDictionary: for lookup collections
  •  IQueryable or IQueryProvider
  • ISerializable
    • ICloneable and
    • IFormatter / IFormatProvider
    • IDisposable
    • IComparer<T>
    • IComparable<T>
    • ISerializable
    • IEquatable<T>
    • ICollection<T>
    • INotifyPropertyChanged
    • IEditableObject (used in RIA services a fair bit)
Example of IEquatable Interface:

public class Car : IEquatable
{
    public string Make {get; set;}
    public string Model { get; set; }
    public string Year { get; set; }

    // Implementation of IEquatable interface 
    public bool Equals(Car car)
    {
        if (this.Make == car.Make &&
            this.Model == car.Model &&
            this.Year == car.Year)
        {
            return true;
        }
        else 
            return false;
    }
}
Posted in C# | Leave a comment

Implementing a Dispose Design Pattern

The pattern for disposing an object, referred to as a dispose pattern, imposes order on the lifetime of an object. The dispose pattern is used only for objects that access unmanaged resources. This is because the garbage collector is very efficient at reclaiming unused managed objects.

There is no performance benefit in implementing the Dispose method on types that use only managed resources (such as arrays) because they are automatically reclaimed by the garbage collector. Use the Dispose method primarily on managed objects that use native resources and on COM objects that are exposed to the .NET Framework.


C# Code

public class DisposableResource : IDisposable
{
    private Stream _resource;
    private bool _disposed;

    public void Dispose()
    {
        Dispose(true);

        // Use SupressFinalize in case a subclass
        // of this type implements a finalizer.
        GC.SuppressFinalize(this);
    }
}
Posted in Coding & Standard | Leave a comment

How to add style in C# to .xlsx file using OpenXML?

using (SpreadsheetDocument xlsx = SpreadsheetDocument.Create(ms, 
SpreadsheetDocumentType.Workbook))
{                         
    // Add a WorkbookPart to the document.                         
    WorkbookPart mainPart = xlsx.AddWorkbookPart();                         
    mainPart.Workbook = new Workbook();

    // Add a StylePart to the WorkBookPart
    WorkbookStylesPart stylePart = mainPart.AddNewPart
                        <WorkbookStylesPart>();
    stylePart.Stylesheet = CreateStylesheet();
    stylePart.Stylesheet.Save(); 
    . 
    . 
    .
}

private static Stylesheet CreateStylesheet()
{             
    Stylesheet stylesheet1 = new Stylesheet() { MCAttributes = 
    new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } };
    stylesheet1.AddNamespaceDeclaration("mc", "
    http://schemas.openxmlformats.org/markup-compatibility/2006");
    stylesheet1.AddNamespaceDeclaration("x14ac", "
    http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");

    Fonts fonts1 = new Fonts() { Count = (UInt32Value)1U, KnownFonts
     = true };
    //Normal Font
    DocumentFormat.OpenXml.Spreadsheet.Font font1 = 
    new DocumentFormat.OpenXml.Spreadsheet.Font();
    DocumentFormat.OpenXml.Spreadsheet.FontSize fontSize1 = 
    new DocumentFormat.OpenXml.Spreadsheet.FontSize(){ Val = 11D };
    DocumentFormat.OpenXml.Spreadsheet.Color color1 = 
    new DocumentFormat.OpenXml.Spreadsheet.Color() 
    { Theme = (UInt32Value)1U };
    FontName fontName1 = new FontName() { Val = "Calibri" };
    FontFamilyNumbering fontFamilyNumbering1 = 
    new FontFamilyNumbering() { Val = 2 };
    FontScheme fontScheme1 = new FontScheme() 
    { Val = FontSchemeValues.Minor };

    font1.Append(fontSize1);
    font1.Append(color1);
    font1.Append(fontName1);
    font1.Append(fontFamilyNumbering1);
    font1.Append(fontScheme1);
    fonts1.Append(font1);

    //Bold Font
    DocumentFormat.OpenXml.Spreadsheet.Font bFont = 
    new DocumentFormat.OpenXml.Spreadsheet.Font();                     
    DocumentFormat.OpenXml.Spreadsheet.FontSize bfontSize = 
    new DocumentFormat.OpenXml.Spreadsheet.FontSize(){ Val = 11D };
    DocumentFormat.OpenXml.Spreadsheet.Color bcolor = 
    new DocumentFormat.OpenXml.Spreadsheet.Color()
    { Theme = (UInt32Value)1U };
    FontName bfontName = new FontName() { Val = "Calibri" };
    FontFamilyNumbering bfontFamilyNumbering = 
    new FontFamilyNumbering() { Val = 2 };
    FontScheme bfontScheme = new FontScheme() 
    { Val = FontSchemeValues.Minor };
    Bold bFontBold = new Bold();

    bFont.Append(bfontSize);
    bFont.Append(bcolor);
    bFont.Append(bfontName);    
    bFont.Append(bfontFamilyNumbering);
    bFont.Append(bfontScheme);
    bFont.Append(bFontBold);

    fonts1.Append(bFont);

    Fills fills1 = new Fills() { Count = (UInt32Value)5U };

    // FillId = 0
    Fill fill1 = new Fill();
    PatternFill patternFill1 = new PatternFill() 
    { PatternType = PatternValues.None };
    fill1.Append(patternFill1);

    // FillId = 1
    Fill fill2 = new Fill();
    PatternFill patternFill2 = new PatternFill() 
    { PatternType = PatternValues.Gray125 };             
    fill2.Append(patternFill2);

    // FillId = 2,RED             
    Fill fill3 = new Fill();             
    PatternFill patternFill3 = new PatternFill() 
    { PatternType = PatternValues.Solid };             
    ForegroundColor foregroundColor1 = new ForegroundColor() 
    { Rgb = "FFB6C1" };             
    BackgroundColor backgroundColor1 = new BackgroundColor() 
    { Indexed = (UInt32Value)64U };             
    patternFill3.Append(foregroundColor1);             
    patternFill3.Append(backgroundColor1);             
    fill3.Append(patternFill3);

    // FillId = 3,GREEN             
    Fill fill4 = new Fill();             
    PatternFill patternFill4 = new PatternFill() 
    { PatternType = PatternValues.Solid };             
    ForegroundColor foregroundColor2 = new ForegroundColor() 
    { Rgb = "90EE90" };             
    BackgroundColor backgroundColor2 = new BackgroundColor() 
    { Indexed = (UInt32Value)64U };             
    patternFill4.Append(foregroundColor2);             
    patternFill4.Append(backgroundColor2);             
    fill4.Append(patternFill4);

    // FillId = 4,YELLO             
    Fill fill5 = new Fill();             
    PatternFill patternFill5 = new PatternFill() 
    { PatternType = PatternValues.Solid };             
    ForegroundColor foregroundColor3 = new ForegroundColor() 
    { Rgb = "FFFF00" };             
    BackgroundColor backgroundColor3 = new BackgroundColor() 
    { Indexed = (UInt32Value)64U };             
    patternFill5.Append(foregroundColor3);             
    patternFill5.Append(backgroundColor3);             
    fill5.Append(patternFill5);

    // FillId = 5,RED and BOLD Text             
    Fill fill6 = new Fill();             
    PatternFill patternFill6 = new PatternFill() 
    { PatternType = PatternValues.Solid };             
    ForegroundColor foregroundColor4 = new ForegroundColor() 
    { Rgb = "FFB6C1" };             
    BackgroundColor backgroundColor4 = new BackgroundColor() 
    { Indexed = (UInt32Value)64U };             
    Bold bold1 = new Bold();             
    patternFill6.Append(foregroundColor4);             
    patternFill6.Append(backgroundColor4);             
    fill6.Append(patternFill6);

    fills1.Append(fill1);             
    fills1.Append(fill2);             
    fills1.Append(fill3);             
    fills1.Append(fill4);             
    fills1.Append(fill5);             
    fills1.Append(fill6);

    Borders borders1 = new Borders() { Count = (UInt32Value)1U };

    Border border1 = new Border();             
    LeftBorder leftBorder1 = new LeftBorder();             
    RightBorder rightBorder1 = new RightBorder();            
    TopBorder topBorder1 = new TopBorder();             
    BottomBorder bottomBorder1 = new BottomBorder();             
    DiagonalBorder diagonalBorder1 = new DiagonalBorder();

    border1.Append(leftBorder1);             
    border1.Append(rightBorder1);             
    border1.Append(topBorder1);             
    border1.Append(bottomBorder1);             
    border1.Append(diagonalBorder1);

    borders1.Append(border1);

    CellStyleFormats cellStyleFormats1 = new CellStyleFormats() 
    { Count = (UInt32Value)1U };             
    CellFormat cellFormat1 = new CellFormat() { NumberFormatId = 
    UInt32Value)0U, FontId = (UInt32Value)0U, 
    FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U };

    cellStyleFormats1.Append(cellFormat1);

    CellFormats cellFormats1 = new CellFormats() { Count = 
    (UInt32Value)4U };             
    CellFormat cellFormat2 = new CellFormat() { NumberFormatId = 
    (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = 
    (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = 
    (UInt32Value)0U };             
    CellFormat cellFormat3 = new CellFormat() { NumberFormatId = 
    (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = 
    (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = 
    (UInt32Value)0U, ApplyFill = true };             
    CellFormat cellFormat4 = new CellFormat() { NumberFormatId = 
    (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = 
    (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = 
    (UInt32Value)0U, ApplyFill = true };             
    CellFormat cellFormat5 = new CellFormat() { NumberFormatId = 
    (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = 
    (UInt32Value)4U, BorderId = (UInt32Value)0U, FormatId = 
    (UInt32Value)0U, ApplyFill = true };             
    CellFormat cellFormat6 = new CellFormat() { NumberFormatId = 
    (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = 
    (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = 
    (UInt32Value)0U, ApplyFill = true };             
    CellFormat cellFormat7 = new CellFormat() { NumberFormatId = 
    (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = 
    (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = 
    (UInt32Value)0U, ApplyFill = true };             
    CellFormat cellFormat8 = new CellFormat() { NumberFormatId = 
    (UInt32Value)0U, FontId = (UInt32Value)1U, FillId =     
    (UInt32Value)4U, BorderId = (UInt32Value)0U, FormatId = 
    (UInt32Value)0U, ApplyFill = true };

    cellFormats1.Append(cellFormat2);             
    cellFormats1.Append(cellFormat3);             
    cellFormats1.Append(cellFormat4);             
    cellFormats1.Append(cellFormat5);             
    cellFormats1.Append(cellFormat6);             
    cellFormats1.Append(cellFormat7);             
    cellFormats1.Append(cellFormat8);

    CellStyles cellStyles1 = new CellStyles() 
    { Count = (UInt32Value)1U };             
    CellStyle cellStyle1 = new CellStyle() { Name = "Normal", 
    FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U };

    cellStyles1.Append(cellStyle1);             
    DifferentialFormats differentialFormats1 = 
    new DifferentialFormats() { Count = (UInt32Value)0U };             
    TableStyles tableStyles1 = new TableStyles() 
    { Count = (UInt32Value)0U, DefaultTableStyle = 
    "TableStyleMedium2", DefaultPivotStyle = "PivotStyleMedium9" };

    stylesheet1.Append(fonts1);             
    stylesheet1.Append(fills1);             
    stylesheet1.Append(borders1);             
    stylesheet1.Append(cellStyleFormats1);             
    stylesheet1.Append(cellFormats1);             
    stylesheet1.Append(cellStyles1);             
    stylesheet1.Append(differentialFormats1);             
    stylesheet1.Append(tableStyles1);

    return stylesheet1;         
}

How to use above styles? 
Cell dataCell = CreateTextCell(i + 1, rowIndex, value); 
dataCell.StyleIndex = isOverride ? (UInt32Value)4 : (UInt32Value)1;
//StyleIndex = 1 = Red; 4 = Red BOLD Text
Posted in C# | 3 Comments