Tuesday, September 20, 2011

Pie Chart is something everyone would like to try with Graphics Programming. I have given here the complete source code and output and downloadable VS2005 project and executables.



// PieChartForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace CSharpPieChart
{
    public partial class PieChartForm : Form
    {
        public PieChartForm()
        {
            InitializeComponent();
        }
 
        struct PieInfo
        {
            public string desc;
            public float percentage;
            public Color color;
            public PieInfo(string d, float p, Color c)
            {
                desc = d;
                percentage = p;
                color = c;
            }
        };
 
        private Pen myPen = new Pen(Color.Red);
 
        private PieInfo[] thePieInfo =
        {
            new PieInfo("Gold", 20, Color.Red),
            new PieInfo("Stocks", 15, Color.Blue),
            new PieInfo("Bonds", 35, Color.Magenta),
            new PieInfo("ETFs", 15, Color.YellowGreen),
            new PieInfo("Options", (float) 7.5, Color.Tomato),
            new PieInfo("Cash", (float) 7.5, Color.Beige)
        };
        int theSliceCount = 6;
 
 
 
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            float percent1 = 0;
            float percent2 = 0;
            float radius = 75;
            int xCenter = 90, yCenter = 150;
 
            Graphics myGraphics = e.Graphics;
            float x = xCenter - radius;
            float y = yCenter - radius;
            float width = radius * 2;
            float height = radius * 2;
 
            for (int i = 0; i < theSliceCount; i++)
            {
                if (i >= 1)
                    percent1 += thePieInfo[i - 1].percentage;
                percent2 += thePieInfo[i].percentage;
                float angle1 = percent1 / 100 * 360;
                float angle2 = percent2 / 100 * 360;
 
                Brush b = new SolidBrush(thePieInfo[i].color);
                myGraphics.FillPie(b, x, y, width, height, angle1, angle2 - angle1);
            }
 
            myPen.Color = Color.Black;
            myGraphics.DrawEllipse(myPen, x, y, width, height);
 
            float xpos = x + width + 20;
            float ypos = y - 25;
            for (int q = 0; q < theSliceCount; q++)
            {
                Brush b = new SolidBrush(thePieInfo[q].color);
                myGraphics.FillRectangle(b, xpos, ypos, 30, 30);
                myGraphics.DrawRectangle(myPen, xpos, ypos, 30, 30);
                Brush b2 = new SolidBrush(Color.Black);
                myGraphics.DrawString(thePieInfo[q].desc + ": " + thePieInfo[q].percentage.ToString() + "%", Font, b2, xpos + 35, ypos + 12);
 
                ypos += 35;
            }
 
            myGraphics.Dispose();
        }
    }
}
 
// PieChartForm.Designer.cs
namespace CSharpPieChart
{
    partial class PieChartForm
    {
        ///
        /// Required designer variable.
        ///
        private System.ComponentModel.IContainer components = null;
 
        ///
        /// Clean up any resources being used.
        ///
        /// true if managed resources should be disposed; otherwise, false.
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        ///
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        ///
        private void InitializeComponent()
        {
            this.SuspendLayout();
            //
            // PieChartForm
            //
            this.ClientSize = new System.Drawing.Size(323, 273);
            this.Name = "PieChartForm";
            this.Text = "C# Pie Chart - softwareandfinance.com";
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
            this.ResumeLayout(false);
 
        }
 
        #endregion
    }
}
 
 
// MainProgram.cs
 
using System;
using System.Collections.Generic;
using System.Windows.Forms;
 
namespace CSharpPieChart
{
    static class Program
    {
        ///
        /// The main entry point for the application.
        ///
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new PieChartForm());
        }
    }
}

Output


Thursday, August 4, 2011

Application Pool

Application Pool
Application pool is actually related with IIS where your web application resides. Every web application need some memory and application pool is for this. Application pool maintain connections, worker processes etc. Many application can share one application pool but it is good to separate pool for every application.
OR
Application pools are used to separate sets of IIS worker processes that share the same configuration and application boundaries. Application pools used to isolate our web application for better security, reliability, and availability and performance and keep running with out impacting each other . The worker process serves as the process boundary that separates each application pool so that when one worker process or application is having an issue or recycles, other applications or worker processes are not affected.
One Application Pool can have multiple worker process Also.

Main Point to Remember:
1. Isolation of Different Web Application
2. Individual worker process for different web application
3. More reliably web application
4. Better Performance


What is a Site Collection Administrator?
Site Collection definition: A set of Web sites on a virtual server that have the same owner and share administration settings. Each site collection contains a top-level Web site and can contain one or more subsites. The only role that has permission over the entire collection of sites is the Site Collection Administrator.

Site Collection Vs Application Pool

n every web application in Sharepoint has one default site collection and application pool. Site collection means a site which can contain many sites under it. One web application can have many site collections. Application pool is actually related with IIS where your web application resides. Every web application need some memory and application pool is for this. Application pool maintain connections, worker processes etc. Many application can share one application pool but it is good to separate pool for every application.

Worker Processes (IIS 6.0)

Worker Processes (IIS 6.0)
A worker process is user-mode code whose role is to process requests, such as processing requests to return a static page, invoking an ISAPI extension or filter, or running a Common Gateway Interface (CGI) handler.
In both application isolation modes, the worker process is controlled by the WWW service. However, in worker process isolation mode, a worker process runs as an executable file named W3wp.exe, and in IIS 5.0 isolation mode, a worker process is hosted by Inetinfo.exe. Figure 2.2, which depicts the architecture for IIS 5.0 isolation mode, uses a dashed line to suggest the relationship between the worker process and the WWW service.
Worker processes use HTTP.sys to receive requests and to send responses by using HTTP. Worker processes also run application code, such as ASP.NET applications and XML Web services. You can configure IIS to run multiple worker processes that serve different application pools concurrently. This design separates applications by process boundaries and helps achieve maximum Web server reliability.
By default, worker processes in worker process isolation mode run under the Network Service account, which has the strongest security (least access) compatible with the functionality that is required. For more information about Network Service accounts, including Windows Server 2003 built-in security accounts, see Running IIS 6.0 as an Application Server, and IIS and Built-in Accounts.

How to Get an Enum from a Number

Here’s the function that will be doing all the work:
public T NumToEnum<T>(int number)
{
return (T)Enum.ToObject(typeof(T), number);
}

This is a generic function that can convert a number to any type of enum. Let’s see some sample code that makes use of this function. First, let’s create some enums.
public enum DaysOfWeek{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
public enum MonthsInYear{
January,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
}

Now, let’s see some code that uses NumToEnum.
int day = 3;
int month
= 10;
DaysOfWeek d = NumToEnum<DaysOfWeek>(day);
//d is now DaysOfWeek.Thursday
MonthsInYear m = NumToEnum<MonthsInYear>(month);
//m is now MonthsInYear.November