DarioSantarelli.Blog(this);

Archive for July, 2007

Visual Studio 2008 Beta 2… available now!!!

Posted by dariosantarelli on July 26, 2007


Here you can find the first release of Visual Studio 2008 Beta 2 … have a nice download!!!!

Posted in Microsoft Technology | Leave a Comment »

SSIS: Setting a Custom Property in a Data Flow Component

Posted by dariosantarelli on July 26, 2007


If you want to set a Custom Property (like OpenRowSet) of a Data Flow Component (like an OLE DB Source) in a Data Flow Task you can use the code below:

using Microsoft.SqlServer.Dts.Runtime;
// Classes and interfaces to create Data Flow Components and automate Data Flow Tasks
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

TaskHost MyTaskHost = (TaskHost)package.Executables[0]; // Pay attention to the ordinal number 😉
// MainPipe: wrapper to configure a Data Flow Task programmatically
MainPipe
dataFlowTask = MyTaskHost.InnerObject as MainPipe;

// Each Data Flow Task component is represented by a ComponentMetadata

IDTSComponentMetaData90 MyComponentMetadata = dataFlowTask.ComponentMetaDataCollection[“MyComponentName”];

  // Access to the Custom Property “OpenRowset”
  IDTSCustomProperty90 CustomProperty = MyComponentMetadata.CustomPropertyCollection[“OpenRowset”];
  CustomProperty.Value = “MyValue”;  

 

Posted in .NET Framework, C# | 3 Comments »

C# 3.0: Object Initializers

Posted by dariosantarelli on July 20, 2007


 In C# 3.0, creating an object instance and initializing it is now possible by using the new “object initializers” . Here an example:

class Contact 
{ 
 public string Name; 
 public readonly Location location = new Location(); 
} 

... 

Contact myContact = new Contact 
{ 
  Name = "Dario", 
  Location = { Address="myAddress", City = "MyCity" } 
}; 

P.S.: This feature is NOT available in VB9 because it doesn’t support read-only properties/fields initialization.

Posted in .NET Framework, C# | Leave a Comment »

WPF Tools and Controls

Posted by dariosantarelli on July 15, 2007


I’d like to link Mike Swanson’s blog to pay attention to an interesting list of tools and controls you can use to build applications for the WPF.

Posted in .NET Framework, Microsoft Technology, WPF | Leave a Comment »

Microsoft Surface: Cool video

Posted by dariosantarelli on July 15, 2007


Here you can find an interesting video about Microsoft Surface Technology… very very cool!!!!

Posted in Microsoft Technology | Leave a Comment »

WPF: using IValueConverter

Posted by dariosantarelli on July 15, 2007


IValueConverter is a very useful interface (defined into the System.Windows.Data namespace in presentationframework.dll) that allows binding between different property types in WPF. Here is an example: we need a simple and reusable way to bind our custom properties (orders properties precisely) to a Listbox presentation properties. Well, by implementing the IValueConverter interface, for each ListBoxItem we can convert the value of the Priority property of our business object Order in the value of the Foreground property of the corresponding TextBlock which shows the Order name.
So, let’s define our Order class:

public class Order { private string _Name; private Priority _Priority; public Order() {} public Order(string name, Priority priority) { _Name = name; _Priority = priority; } public string Name { get { return _Name; } set { _Name = value; } } public Priority Priority { get { return _Priority; } set { _Priority = value; } } } public enum Priority : short { High=2,Normal=1,Low=0 } }

Now, by using XAML markup code we define a PriorityConverter class as a Converter inside the binding towards the Foreground property of the TextBlock containing the order name, while in the codebehind we define the PriorityConverter class as IValueConverter interface implementation:

<Window ... xmlns:mydata="clr-namespace:MyNamespace"> <Window.Resources> <DataTemplate DataType="{x:Type mydata:Order}"> <StackPanel Orientation="Vertical"> <TextBlock Text="{Binding Path=Name}"> <TextBlock.Foreground> <Binding Path="Priority"> <Binding.Converter> <mydata:PriorityConverter /> </Binding.Converter> </Binding> </TextBlock.Foreground> </TextBlock> </StackPanel> </DataTemplate> </Window.Resources> <StackPanel> <TextBlock>Orders List.</TextBlock> <ListBox Name="ordersListBox" ItemsSource="{Binding}"></ListBox> </StackPanel> </Window>

public class PriorityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null) { Priority priority = (Priority)value; BrushConverter colorConverter = new BrushConverter(); switch (priority) { case Priority.High: return colorConverter.ConvertFromString("#FF0000") as Brush; case Priority.Normal: return colorConverter.ConvertFromString("#000000") as Brush; case Priority.Low: return colorConverter.ConvertFromString("#0000FF") as Brush; default: break; } } return null; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } }

In this case, the ConvertBack method implementation isn’t necessary, because the needed binding is one-way, from business logic layer to presentation layer. Moreover, the BrushConverter object can return an object representing a Brush by invoking the ConvertFromString method on a hexadecimal string representation of a color.
An advantage of this approach is the reusability, because above all it allows very simple implementations in those contexts in which the presentation layer can be completely changed, mantaining the business logic layer unchanged.

Posted in .NET Framework, WPF | Leave a Comment »