Sunday, December 30, 2007
50 Great E-Businesses
Great fun to read, highly recommended.
Wednesday, December 26, 2007
volatile keyword
- The volatile keyword indicates that a field can be modified in the program by something such as the operating system, the hardware, or a concurrently executing thread.
- The system always reads the current value of a volatile object at the point it is requested, even if the previous instruction asked for a value from the same object. Also, the value of the object is written immediately on assignment.
- The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access. Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread.
- The type of a field marked as volatile is restricted to the following types:
* Any reference type.
* Any pointer type (in an unsafe context).
* The types sbyte, byte, short, ushort, int, uint, char, float, bool.
* An enum type with an enum base type of byte, sbyte, short, ushort, int, or uint.
Static Members (2) Things to note
Static members
- A static member belongs to the class rather than to the objects of the class.
- Static members are also known as class members and non-static members are known as instance members.
- Indexers in C# can't declared as static.
- All un-initialized static fields automatically get initialized to their default values when the class is loaded first time.
- A derived class can inherit a static member.
- But a static member in C# can't be marked as override, virtual or abstract. However it is possible to hide a base class static method in a derived class by using the keyword new.
Static constructor
- A static constructor is used to initialize any static data, or to perform a particular action that needs performed once only.
- It is called automatically before the first instance is created or any static members are referenced.
- A static constructor does not take access modifiers or have parameters.
- A static constructor cannot be called directly.
- The user has no control on when the static constructor is executed in the program.
- A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file.
- Static constructors are also useful when creating wrapper classes for unmanaged code, when the constructor can call the LoadLibrary method.
Tuesday, December 25, 2007
Static Members (1) A Test Program
using System;
namespace Console_CSharp
{
class TestStatic
{
static void Main(string[] args)
{
//----------Test_StaticField-----------
Console.WriteLine("{0},{1},{2}", Test_StaticField.x, Test_StaticField.y, Test_StaticField.z); //1,2,0
Test_StaticField t = new Test_StaticField(3);
Console.WriteLine("{0},{1},{2}", Test_StaticField.x, Test_StaticField.y, Test_StaticField.z); //3,3,3
//----------Test_StaticConstructor-----------
Console.WriteLine("{0},{1}", Test_StaticConstructor.x, Test_StaticConstructor.y); //100,200
//----------Test_StaticMethod-----------
Test_StaticMethod.Method(); //10,20
//----------Test_StaticProperty-----------
Test_StaticProperty.X = 20; //SET
int val = Test_StaticProperty.X; //GET
//----------TestInheritance-----------
Console.WriteLine(SubTest_Inheritance.x); //25
//----------Test_InheritanceHide-----------
SubTest_InheritanceHide.Method(); // Derived static method
Console.WriteLine(SubTest_InheritanceHide.x); //50
Console.ReadLine();
}
}
}
//--------------------------------------------------------------------------------------------------
class Test_StaticField
{
public static int x = 1;
public static int y = 2;
public static int z; //default value = 0 before initialization
public Test_StaticField(int i)
{
x = i; //normal constructor can access static members
y = i;
z = i;
}
}
//--------------------------------------------------------------------------------------------------
class Test_StaticConstructor
{
public static int x;
public static int y;
public int z; //default value = 0 before initialization
static Test_StaticConstructor() //static constructor is to initialize the static members
{
x = 100;
y = 200;
//z = 300; //compile error - static constructors can't access non-static data members
}
}
//--------------------------------------------------------------------------------------------------
class Test_StaticMethod
{
private static int x = 10;
private static int y = 20;
private int z = 30;
public static void Method()
{
Console.WriteLine("{0},{1}", x, y); //cannot access z here, static method can access only static members
}
}
//--------------------------------------------------------------------------------------------------
class Test_StaticProperty
{
public static int X
{
get
{
Console.WriteLine("GET");
return 10;
}
set
{
Console.WriteLine("SET");
}
}
}
//--------------------------------------------------------------------------------------------------
class Test_Inheritance
{
public static int x = 25;
}
class SubTest_Inheritance : Test_Inheritance
{
}
//--------------------------------------------------------------------------------------------------
class Test_InheritanceHide
{
public static int x = 25;
public static void Method()
{
Console.WriteLine("Base static method");
}
}
class SubTest_InheritanceHide : Test_InheritanceHide
{
public new static int x = 50;
//A static member can't be marked as override, virtual or abstract.
//However it is possible to hide a base class static method in a derived class by using the keyword new.
public new static void Method()
{
Console.WriteLine("Derived static method");
}
}
Modifiers
Modifiers
C# to VB.NET
- Internal (Friend in VB) types or members are accessible only within files in the same assembly
Constructors (1) Default Values Table
- If you do not provide a constructor for your object, C# will create one by default that instantiates the object and sets any member variables to the default values listed here: Default Values Table (C# Reference).
- Static classes and structs can also have constructors.
Formatting Numeric Results Table
Singleton Pattern (3) Things to note
- The constructor could be protected or private
- Do not implement ICloneable interface
- Do not use Serialization
- Will create more instances in a multi-threading environment
This article will talk about how to program a singleton into a fully lazily-loaded, thread-safe, simple and highly performant version: Implementing the Singleton Pattern in C#
Monday, December 24, 2007
Singleton Pattern (2) Lazy Initialization
"You have a holder for an object or data that is not filled with the contents until the code makes a request to the property or object. Thus the code is "lazy" because the work is not done unless the procedure explicitly requires it. No wasted data access or initialziation here."
Javascript example:
window.onload = Window_Load;
function Window_Load()
{
txtTitle().value = "Title";
}
var mTitle = null;
function txtTitle()
{
if(mTitle == null)
{
mTitle = document.getElementById("txtTitle");
}
return mTitle;
}
C# example:
private Customers mCustomer = null;
private Customers Customer
{
get
{
if(this.mCustomer == null)
{
this.mCustomer = (Customers)ObjectBroker.GetObject(typeof(Customers),primaryKey);
}
return this.mCustomer;
}
}
private void Page_Load(Object sender, System.EventArgs e)
{
this.txtCustomer.Name = this.Customer.Name;
}
Singleton Pattern (1) Structure
using System;
namespace DoFactory.GangOfFour.Singleton.Structural
{
class MainApp
{
static void Main()
{
// Constructor is protected -- cannot use new
Singleton s1 = Singleton.Instance(); //this will call: instance = new Singleton();
Singleton s2 = Singleton.Instance(); //this will use the reference created above
if (s1 == s2)
{
Console.WriteLine("Objects are the same instance");
}
Console.Read();
}
}
//-----------------------------------------------------------------------
class Singleton
{
//static field
private static Singleton instance; //use static because we don't want to create instance of the class
// protected constructor
protected Singleton()
{
}
//static method
public static Singleton Instance() //use static because we don't want to create instance of the class
{
// Uses lazy initialization
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
}
Saturday, December 22, 2007
Friday, December 21, 2007
A sequence column
Say we have a very simple table called MenuItem which may contains:
- MenuID
- MenuName
This table may be used to populate the menu items on top of each web pages. Now if we want to order the menu items, we need to add a sequence column, so you may want to add 1,2,3... for each items in the menu table. Now what if we want to add an item in future that needs to be in between of these items, you will need to reorder a lot of the columns, so instead of add 1,2,3.. you can add 10,20,30.. so that you have more flexibility in the future. Another thing is that since the number of menu items will be very limited, the data type should be tinyint.
Tuesday, December 18, 2007
Generics
List<T> has three major benefits:
- Code reusability
- Type safety: compile-time type checking
- Efficiency: avoid casting, boxing and unboxing
Monday, December 17, 2007
.NET Framework Type (1) Int32, Byte
1) Int32 Structure
- Represents a 32-bit signed integer. (4 bytes)
- Namespace: System
- Assembly: mscorlib (in mscorlib.dll)
2) Byte Structure
- Represents an 8-bit unsigned integer. (1 byte)
- Namespace: System
- Assembly: mscorlib (in mscorlib.dll)
- Range: 0 to 255
[SerializableAttribute]
[ComVisibleAttribute(true)]
public struct Int32 : IComparable, IFormattable,
IConvertible, IComparable<int>, IEquatable<int>
[SerializableAttribute]
[ComVisibleAttribute(true)]
public struct Byte : IComparable, IFormattable,
IConvertible, IComparable<byte>, IEquatable<byte>
Friday, December 14, 2007
Managing Software Projects (1)
We often hear about software projects that are late, over budget, or unable to satisfy customer needs. Why do so many software projects fail?
- unclear objectives
- bad planning
- new technology
- a lack of a project management methodology
- insufficient staff
Various aspects of project management, including
- effort estimation
- risk management
- project monitoring
- configuration management
- Although each proposed technique solves the problem it is designed to solve, it is not clear how to combine these techniques into a practical and workable process.
- For effective project management, the need of the hour is a practical, what is needed is a balanced process that covers the management of the entire project from inception to completion.
What is a project management process?
- A process encapsulates what the engineers and project managers have learned about successfully executing projects. Through the processes, the benefits of experience are conferred to everyone, including newcomers in the organization. These processes help managers and engineers emulate past successes and avoid the pitfalls that lead to failures.
- The project management processes specify how to:
- set milestones
- organize personnel
- manage risks
- monitor progress
- Project managers actually want to use processes but only if they're reasonable and will help them execute their projects better.
Benefits of having processes in place:
- Processes lower your anxiety level. The checklists inevitably cover 80 percent of what needs to be done. Hence, your task reduces to working out the remaining 20 percent.
- A process may have some extra steps, but you will not always know beforehand which ones are not needed, and hence you will increase your risks by taking shortcuts.
Thursday, December 13, 2007
SharePoint Object Model
SharePoint is much more than just an application, it is an application framework. That essentially means that SharePoint doesn't truly shine until you begin extending its reach and influence and integrating it with other applications and solutions.
- The Microsoft.Office.Server namespace is the root namespace of all Office Server objects.
- Microsoft.SharePoint is the root namespace for all WSS objects.
- Another reason you might find yourself creating code that utilizes the SharePoint object model is if you are creating Web Parts.
- The only practical way to consume SharePoint data and functionality from a remote client is to use the SharePoint web services.
- You might still want to expose specific SharePoint functionality contained in the object model in your own custom web service.
- The object model is not designed to support Remoting. If you need to expose a portion of the object model that you can't easily access with one of the stock web services, you should create your own web service rather than attempting to use Remoting.
Setting Up a Local Development Environment:
- The biggest advantage to the local development environment is the debugger.
- Developers will often have their own Windows Server 2003 installations that are rough approximations of the target environment so that they can have the benefits of coding locally.
- Browse to C:\program files\common files\microsoft shared\web server extensions\12\isapi, select the Microsoft.SharePoint.dll Assembly and add a reference to your solution.
Setting Up a Remote Development Environment:
- A remote development environment is a development environment that is not on a SharePoint server.
- Just need to copy the Microsoft.SharePoint.dll Assembly from the server to your development PC, and reference it from there.
Tuesday, December 11, 2007
WatiN
Saturday, December 8, 2007
Development Tools
More links:
- http://sharptoolbox.madgeek.com/
- http://www.dotnettoolbox.com/toolbox/
- http://www.econsultant.com/i-want-open-source-software/index.html
Here is a list of development tools/technology I have used or just know of:
Testing/Logging
- WatiN
- TestDriven.Net
- NUnit
- Apache log4net
Compare
- RedGate SQL Compare: Compares and synchronizes SQL Server database schemas
- RedGate SQL Data Compare: Compares and synchronizes SQL database contents
- Beyond Compare
- Compare and Merge
- DiffMerge (Free)
Code generator
- CodeSmith
Screen Shot
- HtmlCapture
- CopySourceAsHtml
.NET
- Reflector
- NHibernate for .NET
- Resharper
- HttpWatch
- Web Developer Helper (Debugging Ajax)
- Viewstate Decoder
- IIsAdmin.NET
- IE Developer Toolbar
- FireBug
- Fiddler
Html Editor
- NotePad ++
- UltraEdit
Source Control
- Visual SourceSafe
- CVS
- SVN
.NET Web Control
- I-Load ASP.NET WebControl (recommended)
- Telerik
- Web Link Validator
- Dynamic Controls Placeholder
Print To Pdf
Regex
VB/C# converter
- Instant C#
- Instant VB
Build tools
- TFS
- CruiseControl.NET
PowerShell
- Powershell is a .NET application.
- You can access .NET class through the powershell command line.
- You can embed powershell script in C#/VB.NET.
- It could be used to change the web.config settings through the command line
Windows PowerShell
Deployments made easy
Working with web.config to switch
Deployment made simple using Powershell
Managing ASP.Net connection strings with Powershell (1)
Tuesday, December 4, 2007
Using Session State (1)
- CookieMode—Enables you to specify whether cookieless sessions are enabled. Possible values are AutoDetect, UseCookies, UseDeviceProfile, and UseUri.
- Count—Enables you to retrieve the number of items in Session state.
- IsCookieless—Enables you to determine whether cookieless sessions are enabled.
- IsNewSession—Enables you to determine whether a new user session was created with the current request.
- IsReadOnly—Enables you to determine whether the Session state is read-only.
- Keys—Enables you to retrieve a list of item names stored in Session state.
- Mode—Enables you to determine the current Session state store provider. Possible values are Custom, InProc, Off, SqlServer, and StateServer.
- SessionID—Enables you to retrieve the unique session identifier.
- Timeout—Enables you to specify the amount of time in minutes before the web server assumes that the user has left and discards the session. The maximum value is 525,600 (1 year).
The HttpSessionState object also supports the following methods:
- Abandon—Enables you to end a user session.
- Clear—Enables you to clear all items from Session state.
- Remove—Enables you to remove a particular item from Session state.
Here are the things to note when using session:
- Unlike cookies, Session state has no size limitations. You could store gigabytes of data in Session state.
- When you use Session state, a session cookie named ASP.NET_SessionId is added to your browser automatically. This cookie contains a unique identifier. It is used to associate the correct data with the correct user.
- The main application programming interface for working with Session state is theHttpSessionState class.
- The Abandon() method enables you to end a user session programmatically. For example, you might want to end a user session automatically when a user logs out from your applicationto clear away all of a user's session state information.
Handling Session Events:
- There are two events related to Session state that you can handle in the Global.asax file: the Session Start and Session End events.
- The Session End event is not raised by all session store providers. The event is raised by the InProc session store provider (the default provider), but it is not raised by the StateServer or SQLServer state providers.
Controlling When a Session Times Out:
- By default, session will time out in 20 mins, you can verify this by examining the IIS settings. The disadvantage of increasing the Session timeout is that more memory is consumed by your application. The longer the Session timeout, the more server memory is potentially consumed. You can specify the Session timeout in the web configuration file or you can set the Session timeout programmatically.
Using Cookieless Session State:
- If you want Session state to work even when cookies are disabled, then you can take advantage of cookieless sessions. When cookieless sessions are enabled, a user's session ID is added to the page URL.
- You enable cookieless sessions by modifying the sessionState element in the web configuration file. The sessionState element includes a cookieless attribute that accepts the following values:
- AutoDetect—The Session ID is stored in a cookie when a browser has cookies enabled. Otherwise, the cookie is added to the URL.
- UseCookies—The Session ID is always stored in a cookie (the default value).
- UseDeviceProfile—The Session ID is stored in a cookie when a browser supports cookies. Otherwise, the cookie is added to the URL.
- UseUri—The Session ID is always added to the URL.
- When you enable cookieless session state, you should also enable this attribute regenerateExpiredSessionId="true", because it can help prevent users from inadvertently sharing session state.
Monday, December 3, 2007
BI (4) Client tools for end users
Cubes in Excel
- You can use Excel 2003 which allows user to use pivot tables to flatten the cubes.
- You must install the Office component called Microsoft Query for connecting to SSAS cubes in Excel 2003
- Microsoft Office 2007 fully supports data mining
Cubes in SSRS
- SSRS 2005 has deeply integrated support for generating reports using SSAS cube as a data source
- Visual query design of MDX (Multidimensional Expressions) language
Microsoft clients for SSAS
- Data Analyzer
- SharePoint - Web parts that include data generated from SSRS
- Performance Point Server
You can also develop custom clients
- Report Viewer controls in .NET 2.0 (win/web form)
Sunday, December 2, 2007
BI (3) Implement Sample Cube
2. Open samples from C:\Program Files\Microsoft SQL Server\90\Tools\Samples
3. Choose the Enterprise Edition sample
4. You will see a number of source folders:
5. Test connection by right click the Adventure Works.ds under the Data Sources folder and follow the dialog to test the connection
6. Take a look at the data source views, it can be used for people who doesn't have admin access to the data source to review the data and adjust the schema.
7. In the above window, choose a table and right click it and choose explore data, this will take you to this window:
8. If you double click the first sample cube, you can see that the fact table are highlighted in yellow, and dimension tables are highlighted in blue. There are a number of design tabs on the top in the cube designer.
9. At this point we just want to look at the result of the cube, so we click the browse tab. You will notice that an error window will appear. That is because we need to deploy the solution to make it available to the SQL Server Analysis Services before you can actually see the result.
10. Right click the solution and click deploy, this will take 5-10 mins, a green check mark will appear once the deployment completed, otherwise you will get a red X.
11. Once deployed, you can see on the left hand side, we got metadata browser that consists of a list of the measures and the dimensions. Drag one or more measure tables and drop them onto the totals or detail fields in the right window. Drag one or more dimension tables and drop them onto the row fields or column fields or filter fields or the top dimension slicer window.
12. There are two ways to look at dimension information, one is by looking at individual attributes, the other is by looking at the roll-ups hierarchies.
Saturday, December 1, 2007
BI (2) OLTP vs. OLAP
- OLTP: To support business processes.
- OLAP: To assist with making better business decisions.
Where the data comes from
- OLTP: Online entry, point of sale devices, data loggers etc.
- OLAP: OLTP databases, flat files.
Criticality
- OLTP: Generally considered missioncritical. Regularly back up to protect from data loss.
- OLAP: Important to decision support; however; organizations can continue to operate without it. Back up less often than OLTP databases.
Database Size
- OLTP: Relatively small database size if the history information is regularly archived. Can quickly bloat if history is not removed.
- OLAP: OLAP database can be very large. Contains historical information generated by various OLTP databases within an organization.
Concurrent Users
- OLTP: Potentially very high numbers of users. Some OLTP databases support thousands of concurrent users.
- OLAP: OLAP databases support a much lower number of users than their OLTP counterparts.
Response Time
- OLTP: All application queries should complete in less than a second.
- OLAP: Queries commonly take seconds, minutes, and hours.
Data Changes
- OLTP: High number of insert, update, and delete operations are generate by user transactions.
- OLAP: Very low number of data changes generated by users. Data is updated by bulk import batches.
Ad hoc querying
- OLTP: Poor ad hoc query performance. Indexes are only created to support defined application queries.
- OLAP: Very good ad hoc query performance. Indexes are created to support queries possible queries.
Querying complexity
- OLTP: Data is highly normalized requiring many joins to retrieve information.
- OLAP: Data is denormalized requiring few joins to retrieve information.
Professional SQL Server 2000 Data Warehousing with Analysis Services
BI (1) Intro
Why use OLAP?
- Queries run 1000% faster
- Click to query
- Near real-time information
- Reduce stress on your OLTP system
Two kinds of tables form a data warehouse:
Fact tables
- Also called measures.
- The fact table is the table that holds the facts of the business that need to be analysed, such as sales, profits, amount of storage at hand, etc.
- This type of data is often numeric.
- The values are quite often subject to aggregation (pre-calculating roll-ups of data over hierarchies, which subsequently yield improved query results).
- Building the fact table is an important step towards building your data warehouse.
Dimension Tables
- A dimension is a collection of properties along which we conduct our analysis of the facts.
- Dimensions allow us to view the fact in different contexts.
- Common dimensions used in sales -related data marts include:
- Time
- Geography
- Customer
- Salesperson
- Scenarios such as actual, budgeted, or estimated numbers
OLAP Schemas
- Star Schemas unite dimensions and facts
- De-normalized schemas (deliberately duplicate data for fast query result, so no need to join tables)
Professional SQL Server Analysis Services 2005 with MDX
Professional SQL Server 2000 Data Warehousing with Analysis Services