Code Snipets

Practical Example – Agile Methodology

Posted in Agile by mauliksoni on March 1, 2011

Here is a simple analogy to help you envision this process. You go to the mall on a serious shopping
spree and fill up your car with boxes, bags, and packages of all shapes and sizes. You arrive home and are
faced with the task of bringing everything into the house. You quickly realize that you can’t carry
everything in one trip, so you start planning the loads. Perhaps on the first trip you bring in the box of ice
cream that’s starting to melt. On the next trip you carry the big heavy box. On subsequent trips you carry
several lighter-weight items. As the car begins to empty, you find yourself figuring how many loads are
left.
You just applied the agile methodology to manage the project of unloading the car. The things you
brought in are the user stories, and each trip represents an iteration. You can only carry a certain
amount with each trip so at the beginning of the each trip you review what is left and plan the next load.
You can estimate how many trips (iterations) you’ll need, which will give you a good idea of when you’ll
be done.

Ref : Pro Project Management with SharePoint 2010

Silverlight Toolkit Column Series – Display Label on bar (Column Labels) ( datapoint labels )

Posted in Silverlight by mauliksoni on February 14, 2011

Silverlight Toolkit Column Series – Display Label on bar (Column Labels) ( datapoint labels )

Final Output:

Silverlight Toolkit Column Series – Display Label on bar (Column Labels) ( datapoint labels )

Silverlight Toolkit Column Series – Display Label on bar (Column Labels) ( datapoint labels )

<navigation:Page x:Class="SL4Test.Page1" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="Page1 Page" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
    <Grid x:Name="LayoutRoot"  Margin="0, -17, 0, 0">
        <toolkit:Chart HorizontalAlignment="Left" Margin="124,79,0,0" Name="chart1" Title="Labels on Bar" VerticalAlignment="Top" Height="317" Width="418">
            <toolkit:ColumnSeries DependentValuePath="X" IndependentValuePath="Y">
                <toolkit:ColumnSeries.DataPointStyle>
                    <Style TargetType="toolkit:ColumnDataPoint">
                        <Setter Property="Background" Value="Green"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="toolkit:ColumnDataPoint">
                                    <Grid>
                                        <Rectangle
                                    Fill="{TemplateBinding Background}"
                                    Stroke="Black"/>
                                        <Grid
                                    Background="#aaffffff"
                                    Margin="0 -40 -10 0"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Center">
                                            <TextBlock
                                        Text="{TemplateBinding FormattedDependentValue}"
                                        FontWeight="Bold" Width="40"
                                        Margin="2"/>
                                        </Grid>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </toolkit:ColumnSeries.DataPointStyle>
                <toolkit:ColumnSeries.ItemsSource>
                    <PointCollection>
                        <Point>1,10</Point>
                        <Point>2,20</Point>
                        <Point>3,30</Point>
                        <Point>4,40</Point>
                    </PointCollection>
                </toolkit:ColumnSeries.ItemsSource>
            </toolkit:ColumnSeries>
        </toolkit:Chart>
    </Grid>
</navigation:Page>

Silverlight 4 Pie Chart Customization – Palett color, Silce color change, Observable collection and 2 color pie chart

Posted in Silverlight by mauliksoni on February 10, 2011

Silverlight 4 Pie Chart Customization – Palett color, Silce color change, Observable collection and 2 color pie chart.

Output:

Silverlight Pie chart customization

Silverlight Pie chart customization


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Collections.ObjectModel;
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows.Controls.DataVisualization;

namespace SL4Test
{
    public partial class MainPage : UserControl
    {

        private ObservableCollection w;

        public MainPage()
        {
            InitializeComponent();

            PopulateChart();

        }

        private void PopulateChart()
        {

            //Set chart color palette
            //We just want 2 colors red and green
            ResourceDictionaryCollection palette = new ResourceDictionaryCollection();
            for (int i = 0; i <= 1; i++)
            {
                byte r;
                byte g;
                if (i == 0) {r= Convert.ToByte(255);} else{ r = Convert.ToByte(0);}
                if (i == 0) {  g = Convert.ToByte(0); } else {  g = Convert.ToByte(255); }
                byte b = Convert.ToByte(0);
                Style style = new Style(typeof(Control));
                style.Setters.Add(new Setter(BackgroundProperty,
                new SolidColorBrush(Color.FromArgb(255, r, g, b))));
                //style.Setters.Add(new Setter(TemplateProperty, this.Resources["PieDataPointTemplate"]));
                ResourceDictionary dictionary = new ResourceDictionary();
                dictionary.Add("DataPointStyle", style);
                palette.Add(dictionary);
            }

            //Set the Chart Grid Background to transparent
            Style style1 = new Style(typeof(Grid));
            style1.Setters.Add(new Setter(Grid.BackgroundProperty, Colors.Transparent.ToString()));
            this.mychart.PlotAreaStyle = style1;

            //Set the new ( 2 color) palette to chart object
            this.mychart.Palette = palette;

            this.w = new ObservableCollection
			{
                new Counter { Name = "a",  Current =0 },
                new Counter { Name = "b", Current = 100 }

            };
            this.DataContext = this.w;

            TestDispatcherTimer();

        }

        private void TestDispatcherTimer()
        {
            DispatcherTimer timer = new DispatcherTimer();

            int iLast = 0;
            int iTotal = 100;

            if (timer.IsEnabled) timer.Stop(); else timer.Start();

            timer.Tick +=
                delegate(object s, EventArgs args)
                {
                    iLast += 10;
                    iTotal -= 10;

                    if (iTotal == 0) timer.Stop();

                    w.Clear();
                    this.mychart.DataContext = null;

                    w.Add(new Counter { Name = "a", Current = iLast });
                    w.Add(new Counter { Name = "b", Current = iTotal });

                    this.mychart.DataContext = w;
                    this.mychart.Palette = new Collection(mychart.Palette);

                };

            timer.Interval = new TimeSpan(0, 0, 1); // one second
            timer.Start();
        }
    }

    public class Counter
    {
        public string Name { get; set; }
        public int Current { get; set; }

    }
}


<UserControl x:Class="SL4Test.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
    xmlns:System_Windows_Controls_DataVisualization_Charting_Primitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    >

    <UserControl.Resources>
        <Style x:Key="ChartStyle1" TargetType="toolkit:Chart">
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="Padding" Value="10"/>
            <Setter Property="Palette">
                <Setter.Value>
                    <toolkit:ResourceDictionaryCollection>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFB9D6F7"/>
                                <GradientStop Color="#FF284B70" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFFBB7B5"/>
                                <GradientStop Color="#FF702828" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFB8C0AC"/>
                                <GradientStop Color="#FF5F7143" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFFDE79C"/>
                                <GradientStop Color="#FFF6BC0C" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFA9A3BD"/>
                                <GradientStop Color="#FF382C6C" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFB1A1B1"/>
                                <GradientStop Color="#FF50224F" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FF9DC2B3"/>
                                <GradientStop Color="#FF1D7554" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFB5B5B5"/>
                                <GradientStop Color="#FF4C4C4C" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FF98C1DC"/>
                                <GradientStop Color="#FF0271AE" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFC1C0AE"/>
                                <GradientStop Color="#FF706E41" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFADBDC0"/>
                                <GradientStop Color="#FF446A73" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FF2F8CE2"/>
                                <GradientStop Color="#FF0C3E69" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFDCDCDC"/>
                                <GradientStop Color="#FF757575" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFF4F4F4"/>
                                <GradientStop Color="#FFB7B7B7" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFF4F4F4"/>
                                <GradientStop Color="#FFA3A3A3" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                    </toolkit:ResourceDictionaryCollection>
                </Setter.Value>
            </Setter>
            <Setter Property="TitleStyle">
                <Setter.Value>
                    <Style TargetType="toolkit:Title">
                        <Setter Property="Width" Value="0"/>
                        <Setter Property="Height" Value="0"/>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="LegendStyle">
                <Setter.Value>
                    <Style TargetType="toolkit:Legend">
                        <Setter Property="Width" Value="0"/>
                        <Setter Property="Height" Value="0"/>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="ChartAreaStyle">
                <Setter.Value>
                    <Style TargetType="Panel">
                        <Setter Property="MinWidth" Value="100"/>
                        <Setter Property="MinHeight" Value="75"/>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="PlotAreaStyle">
                <Setter.Value>
                    <Style TargetType="Grid">
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="toolkit:Chart">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <toolkit:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}"/>
                                <Grid Margin="0,15,0,15" Grid.Row="1">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <toolkit:Legend x:Name="Legend" Grid.Column="1" Header="{TemplateBinding LegendTitle}" Style="{TemplateBinding LegendStyle}"/>
                                    <System_Windows_Controls_DataVisualization_Charting_Primitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}">
                                        <Grid Style="{TemplateBinding PlotAreaStyle}" Canvas.ZIndex="-1"/>
                                        <Border BorderBrush="#FF919191" BorderThickness="0" Canvas.ZIndex="10"/>
                                    </System_Windows_Controls_DataVisualization_Charting_Primitives:EdgePanel>
                                </Grid>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White">
        <Image Source="11.jpg" Height="Auto" Width="Auto"></Image>
        <toolkit:Chart x:Name="mychart"  Style="{StaticResource ChartStyle1}" HorizontalAlignment="Left" VerticalAlignment="Top" Opacity="1" Padding="0" BorderThickness="0" Margin="50">
            <toolkit:PieSeries  ItemsSource="{Binding}"
                                IndependentValueBinding="{Binding Name}"
                                DependentValueBinding="{Binding Current}" Width="Auto" Height="Auto" VerticalContentAlignment="Center" Opacity="1" Margin="0" Background="#01000000" BorderThickness="0">
                <toolkit:PieSeries.BorderBrush>
                    <SolidColorBrush />
                </toolkit:PieSeries.BorderBrush>
            </toolkit:PieSeries>
        </toolkit:Chart>
    </Grid>
</UserControl>

Access (Web Service Enhancements 3.0 ) secure web service using C# ASP.NET

Posted in ASP.NET, C# by mauliksoni on February 9, 2011

Access (Web Service Enhancements 3.0 ) secure web service using C# ASP.NET

You might get following errors if you try to use wsewsdl3.exe to generate proxy class for a secure web service.

  • “Unable to import biniding ‘xxxxx’ from namespace…”
  • “unable to import Operations:GetWeather”
  • “Found more than one parameter on method “GetWeather” while multiple parameters are not supported.”

What you need to do is following –

  • Install WSE 3
  • Reference your secure web service in Visual Studio.
  • Add a reference to Microsoft.Web.Services3 dll into your client project.
  • Open References.cs ( under web reference) and add following using statement at top.
  • using Microsoft.Web.Services3;
  • After  that inherit your web service proxy partial class from Microsoft.Web.Services3.WebServicesClientProtocol


Amazservice.WeatherWS pws = new Amazservice.WeatherWS();
Microsoft.Web.Services3.Security.Tokens.UsernameToken token = new Microsoft.Web.Services3.Security.Tokens.UsernameToken("username", "password", Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendPlainText);
SoapContext reqContext = pws.RequestSoapContext
reqContext.Security.Tokens.Add(token);
reqContext.Security.Timestamp.TtlInSeconds = 60;
string s = pws.GetWeatherForZip("382019");

Developer Dashboard to review sharepoint performance

Posted in Sharepoint by mauliksoni on February 3, 2011

Sharepoint 2010 – Developer Dashboard for performance review.

  • Open the command prompt.
  • Run the following command = Type in “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\stsadm.exe” -o setproperty -pn developer-dashboard -pv OnDemand
  • Type in iisreset and press Enter
  • When you oepn the share point site you will see little icon next to the logged-in user name on the right.

C#/Javascript – Shareponit 2010 List Update using Web Service

Posted in C#, JavaScript, Sharepoint by mauliksoni on January 24, 2011

C# – Shareponit 2010 List Update using Web Service

public static void LockDailyEntry(int rowID)
 {
 spws.Lists oSplistWs = new spws.Lists();
 /*Authenticate the current user by passing their default
 credentials to the Web service from the system credential cache.*/
 oSplistWs.Credentials = System.Net.CredentialCache.DefaultCredentials;

 /*Get Name attribute values (GUIDs) for list and view. */
 System.Xml.XmlNode ndListView = oSplistWs.GetListAndView("UnlockDailyEntry", "");
 string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
 string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;

 /*Create an XmlDocument object and construct a Batch element and its
 attributes. Note that an empty ViewName parameter causes the method to use the default view. */
 System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
 System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
 batchElement.SetAttribute("OnError", "Continue");
 batchElement.SetAttribute("ListVersion", "1");
 batchElement.SetAttribute("ViewName", strViewID);

 /*Specify methods for the batch post using CAML. To update or delete,
 specify the ID of the item, and to update or add, specify
 the value to place in the specified column.*/
 batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" +
 "<Field Name='ID'>" + rowID + "</Field>" +
 "<Field Name='Status'>Lock</Field>" +
 "</Method>";

 /*Update list items. This example uses the list GUID, which is recommended,
 but the list display name will also work.*/
 oSplistWs.UpdateListItems(strListID, batchElement);
 }

Javascript – Shareponit 2010 List Update using Web Service

function SaveListItem() {
 var soapRequest = '<?xml version="1.0" encoding="utf-8"?>' +
 '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">' +
 ' <soap12:Body>' +
 ' <UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">' +
 ' <listName>UnlockDailyEntry</listName>' +
 ' <updates>' +
 '<Batch OnError="Continue">' +
 ' <Method ID="1" Cmd="Insert">' +
 ' <Field Name="Status">Lock</Field>' +
 ' </Method>' +
 '</Batch>' +
 ' </updates>' +
 ' </UpdateListItems>' +
 ' </soap12:Body>' +
 '</soap12:Envelope>';

 xmlHttp = new XMLHttpRequest();
 xmlHttp.open('post', 'http://spserver:18000/_vti_bin/lists.asmx', true);
 xmlHttp.setRequestHeader('Content-Type', 'application/soap+xml; charset=utf-8');

 xmlHttp.send(soapRequest);
 }

NLog Configuration Email Provider

Posted in NLog by mauliksoni on January 7, 2011


<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

 <targets>
 <target name="file" xsi:type="File" fileName="${basedir}/log.txt" />

 <target
 name="mail" xsi:type="Mail" smtpServer="outbound-mail.test.com" smtpPort="25"
 from="test@gmail.com" to="test2@gmail.com"
 subject="${longdate} ${machinename}: ${message}"
 body="${longdate}|${level:uppercase=true}|${logger}|${callsite}|${message}|${exception}|${stacktrace}"
/>
 </targets>

 <rules>
 <logger name="*" minlevel="Debug" writeTo="file,mail" />
 </rules>
</nlog>

Linq to SQL – table join with multiple where clause

Posted in C#, Linq by mauliksoni on December 30, 2010


public IQueryable<CustomerActivity> GetCustomerActivityResult(string sUser,DateTime ReportDate)
 {
 CustomerDataClassesDataContext db = new CustomerDataClassesDataContext();

 var customeractivity = from ca in db.CustomerActivities
 join acts in db.ActivitySummaries
 on ca.ActivitySummaryID equals acts.ActivitySummaryID
 where acts.Name == sUser && acts.Date == ReportDate
 select ca;
 return customeractivity;
 }

Tagged with:

Fix ASP.NET Response.Redirect Relative URL

Posted in ASP.NET by mauliksoni on December 30, 2010

Last week, when we move our asp.net web application to Internet Production Server, somehow Response.Redirect was not able to redirect to correct page. As everyone know, Response.Redirect uses relative url paths.

Possible Error – Your redirect code will not work.

Possible Error – Your resources could not show up (because resources like image or any other might also have relative url)

FIX

<configuration>
   <system.web>
      <httpRuntime maxRequestLength = "4000"
          useFullyQualifiedRedirectUrl = "true"
          executionTimeout = "45" />
    </system.web>
</configuration>

useFullyQualifiedRedirectUrl – Indicates whether client-side redirects are fully qualified ( which is necessary for some mobile controls ). If not, relative redirects are instead sent to the client ( the default ).

List all dates between start and end date

Posted in C# by mauliksoni on December 29, 2010

The following code returns List<string> of dates between 2 dates.

public List<SearchResult> GetSearchResult(string sUser,DateTime dtStartDate, DateTime dtEndDate)
        {
            List<SearchResult> searchresult = new List<SearchResult>();
            
            while (dtStartDate.AddDays(1) <= dtEndDate)
            {
                dtStartDate = dtStartDate.AddDays(1);
                searchresult.Add(new SearchResult { Date = String.Format("{0:dd-MMM-yy}", dtStartDate) , Status = "New" });
            }

            return searchresult;
        }

Follow

Get every new post delivered to your Inbox.