TURKISH BLOG   |  ABOUT ME  |  ARCHIVES  | DELETE LANGUAGE COOKIE

Enes TAYLAN

Mind Hegemony - Mood 1.0 - Total Control Edition

MULTI - TIER SOFTWARE DESIGN

clock June 20, 2009 23:35

Multi-tier or n-tier software design is a buzzword in recent years. To recap it in few words, it divides functionality, components, and code for a projects. There are generally 4 of them ( some people define 3 tiers not mentioning data store) multi-tier

1. Presentation Layer: This is the user interface. In this tier, the code defines what a user should see on the screen. To do so, it invokes the lower tier and get the data, shape and format it, maybe cast it considering its specific purpose and present data to user. 

2. Business Logic Layer (BLL): The code that takes the data from data access layer ( generally in the form of relational data ) and exposes it to the Presentation Layer in a more abstracted and intuitive way, hiding low level details. ( such as database schema, constraints) Also this tier grants input validation and ensures that the input is safe and consistent.

3. Data Access Layer: The code that takes of retrieving and manipulating raw data in the data store. It gives commands to data store ( to an RDMBS ) to create, read, update and delete information. The developer that prepares this layer should have knowledge about exactly all internal details of database: its constraints, columns - their names and data types and specific information about how RDMS works.In .NET environment this can be achieved by ADO.NET 

4. Data Store: This is where the data resides. This can be a RDMS, an XML file, a text file.

In small projects these tiers can be united, for example BLL and DAL can be implemented in a single class. However, in big projects that many developers work, multi - tier design with each tier is independent from the other ones is a very important and ease the work much.



WHICH ONE IS BETTER FOR SITE LAYOUT: "DIV" or "TABLE"

clock June 20, 2009 07:45
Sometimes developers use HTML tables to control the positioning of items to create a layout in webpage. This is a very common practice but not the best one. Also W3C discourages it by saying that <table> should be used to mark up tabular data such as sign up pages with many fields but not to create page layout. To create a layout <div> tags with "css" features should be used. These are why:
 
1. By using <div> and a separate stylesheet then we don't need to repeat this definition. This leads a site that is both faster to develop and easier to maintain.
 
2. Seperate .css files are cached by the browser but not html tables. So when we use <div> with .css files we get much faster loaded web sites. This is much more important in heavily loaded websites because sending less few bytes with thousands of users means much more efficient bandwidth usage.

3. By using <div> and separate stylesheet we can define multiple different themes and style sheets that users can select by considering preferences. These preferences can be colors, pictures and layout of <div> tags. (at top, at right etc.) Especially when changing position of some columns using <table> (i.e. exchanging positions of left and right column) is much more difficult than manipulating <div> tags.

4. For different screen resolutions, especially for PDA's to adapt the output for them is very easy by defining different stylesheets. Also hiding some content (i.e. some banner) by <div> is much easier than <table>
 


.NET IO - 2 ( Reading from and Writing to Files )

clock June 19, 2009 21:16
We are continuing from where we left in System.IO. (for the first article click) In .NET IO to write or read, we should use a stream or specific stream classes that extends abstract base class Stream. For example:

  • System.IO.FileStream
  • System.IO.MemoryStream
  • System.Net.Sockets.NetworkStream
  • System.IO.BufferedStream
In this article I'll use System.IO.FileStream to read from and write to a file. Let's look at this code:
 FileStream fs = new FileStream(Server.MapPath("example.txt"), FileMode.Open);
 //By using FileStream, we start to read the file. "FileMode.Open" means that this
 //file will be used just for reading not another operations. Other possible values are:
 //Append,Create,Truncate,CreateNew,OpenOrCreate 

byte[] data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length);
//we read the whole file by "from 0 to fs.length" 

foreach (byte k in data) 
{ 
    Response.Write(k.ToString()); 
} 
//and we send the result to the user 
When we run this example, we can get some meaningless results. The reason is "FileStream" gives us the result as "byte". If we don't want to transform these bytes to human-readable form, we should use "System.IO.StreamWriter" and "System.IO.StreamReader".
StreamWriter writer = new StreamWriter(File.Open(Server.MapPath("enes.txt"), FileMode.Open)); 
//file.open() -->> creates a filestream for streamwriter 
writer.Write("write to the file");
writer.Close(); 

////////////////////////////////////////////////////////// 

StreamReader reader = new StreamReader(File.Open(Server.MapPath("enes.txt"), FileMode.Open));
Label1.Text = reader.ReadLine(); 
reader.Close(); 
"System.IO.StreamWriter" and "System.IO.StreamReader" creates "System.IO.FileStream" themselves (so we don't need to create them)  "Label1.Text = reader.ReadLine(); " enables us to read file line by line. If we wanted to read whole file as a single chunk, we would write  "Label1.Text = reader.ReadToEnd(); " Besides these methods there are other static methods in System.IO that allows us carry out these operations easier:
 string k = File.ReadAllText(Server.MapPath("enes.txt")); 
and
 File.WriteAllText(@"C:\temp.txt",data); 


Tips and Tricks 2: HOW TO SWITCH MASTER PAGES AT RUNTIME

clock June 15, 2009 08:58
When designing user specific layout, besides themes and .css files we have also option of switching master pages. To do so we should write below code in PreInit event . ( this change can be occur just in PreInit, since after that, merging phase of content and master pages is already happened )
protected void Page_PreInit(object sender, EventArgs e)
{
     this.MasterPageFile = "~/otherMasterPage.master";
}


WHICH FEATURES A GOOD WEBSITE SHOULD HAVE?

clock June 13, 2009 03:35
Websites that are data-driven, content-based, real-world, have some shared features. This features are much more important than the past, because we have in the era of social media and competence is heavier. These features are:

1. An appealing user interface: Appearance is very important, because it is the first thing that a user face with. But interface doesn't mean just graphics. Also the site should be well-organized, reachable and easily accessible. The site must be able to provide a great user experience, means users can easily browse and interact. Another important thing is cross-browser compatibility, ensuring that the site looks and behaves fine from different platforms and browsers.

2. User loyalty: A successful content-based website requires users' loyalty so that they regularly visit the site. To do so, users can have the opportunity to write their own content, participate in polls and be informed about special events. This requires an authentication / authorization infrastructure so each user can have an identity, distinguishes him / her from other users. This infrastructure also grant and restrict access to different areas of the site.

3. Easily updatable: A mechanism that allows the content easily be updated: The site needs constant supply of fresh content to stay alive and vibrant. To have this constant stream of new content, editors or administrators should be able to update easily.

4. Newsletters: Not all users visit the site so that application should inform them about the new content by RSS and most importantly newsletters.
 
5. Getting feedback from users: What users like most and does not like? To get this feedback, users should have some kind of user-to-site communication.

6. Sociality: In the era of social media, user-to-user communication is very important. This also creates a community of loyal users, who come the site frequently to chat, discuss news and events, and ask about the content. To give users a feeling of membership will pay off in both in the short and long run.

7. Home page:
This is so important because after site grows and have big amount of information, it starts to contain non-related info about users. Everyone wants to see information about what he interested in. Hence, a mechanism should give the chance them to build their own home page.  


HOW TO DEVELOP A PROJECT, IN WHICH WAY?

clock June 13, 2009 02:19
In all programming projects, developers need a path to implement their projects. The most efficient path, development way can be achieved by defining corner stones. These corners are: problem, design and solution. With this clearly defined, separated, precisely and concisely understood path, development process can be quite easy and funny. So let’s look at these steps ( corner stones ) more closely:
 
1. Problem: Every project ( application ) comes from a need, a problem. This need can be a small need ( i.e. you may develop a diary program to organize your writings ) or can be a quite large project. ( you or your consumer needs an e-commerce store ) The point is to understand the need, the problem. In this Problem Stage developer tries to understand the question clearly, concisely and boldly. To reach this understanding, first of all, you should get the general statement of the problem. (i.e. this guy needs a news site ) Then he tries to detail the problem in the second stage, Design Stage. I can say that, Problem Stage is the most important stage. If you start wrongly, then you can get very silly solutions.
 
2. Design: This is the corner that you get a pen and a sheet of paper and start to understand business logic. For example, if the project is an e-commerce store, which type of store?, what admin needs?, what is the audience of this site, ordinary people or a specific group of people etc. Then you should design the interface in a general-high level. Most probably you will need a database design with its tables, constraints, security issues etc. Also classes and hierarchy between them should be written.

3. Solution: After first two stages, this part will be so quick and funny. By knowing the problem well and a good draft for its user interface, class hierarchies; just code the project. You have the manual, because.


COMPRESSING HTTP OUTPUT WITH AN HTTPMODULE

clock June 12, 2009 19:55
The communication between Server and Client is carried out via HTTP messages by sending necessary data. The workload of server and net speed is exactly how much time this messages requires to be sent. Therefore, to decrease message ( by using compressing algorithm and techniques ) size means higher speed and efficient bandwidth. Almost all new browsers can use "gzip" and "deflate" compression algorithms. ( they can decompress messages that comes from server) ASP.NET gives us compressing ability.

We will use "HttpModule" in this article. First create a Windows Class Library in C#.

Note: HttpModule' s are the controls that manipulates Request and Response messages. 



Name project as "CompressionModule" and with same name add a new class. Right-Click to the project, select "Add Reference" , browse "System.Web". Then write below code  :
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Web;  
  
namespace ZipModule  
{  
    //to get HttpModule capabilities implement "IHttpModule" interface
  
    public class CompressionModule : IHttpModule    
    {  
 
        #region IHttpModule Members  
  
        public void Dispose()  
        {  
            throw new NotImplementedException();  
        }  
  
        public void Init(HttpApplication context)  
        {  
            context.BeginRequest += new EventHandler(context_BeginRequest);  
        //besides default event handler we should write our custom one
        //context -->> current application that invokes our HttpModule
        }  
  
        void context_BeginRequest(object sender, EventArgs e)  
        {  
            HttpApplication app = (HttpApplication)sender;  
        //name this application as sender
  
            string encodings = app.Request.Headers.Get("Accept-Encoding");  
        //"Accept-Encoding" is the Http Header that informs us
        //whether the browser can use encoding algorithms
  
            if (encodings == null) //if it can't return
                return;  
  
            Stream s = app.Response.Filter;  
        //if can filter the response message
  
            encodings = encodings.ToLower();  
  
            if (encodings.Contains("gzip"))  
            {  
                app.Response.Filter = new GZipStream(s, CompressionMode.Compress);  
            //here is the core of the code
	//we zip the code here  
              
                app.Response.AppendHeader("Compression Tecnique", "gzip");  
            //we add a header to message so that we will be able
            //trace whether our module is working or not
          
                app.Context.Trace.Warn("GZIP Compression on");  
            }  
  
            else  
            {  
                app.Response.Filter = new DeflateStream(s, CompressionMode.Compress);  
            //if browser can't use "gzip" compress the message 
	//with "deflate"  
              
                app.Response.AppendHeader("Content-Encoding", "deflate");  
                app.Context.Trace.Warn("Deflate compression on");  
            }  
  
        }  
 
        #endregion  
    }  
}  
Build the project, copy the "ZipModule.dll" from "bin" directory. Add this .dll to your new website. Again like we did above right-click the website name and browse the "ZipModule.dll" and select it. To use this HttpModule we should configure "web.config" :
<httpModules>
    <add name="HttpCompressionModule" type="ZipModule.CompressionModule"/>
</httpModules>
<trace enabled="true"/>

By writing "<trace enabled="true"/>" we can trace our application and see exactly what happens in Request and Response messages. After making above configuration settings our HttpModule should work and compress the Http Messages. In browser url part, write "../Default.aspx/trace.axd". Click "View Details", if you see "Gzip compression on" ( like below snapshot ) then your HttpModule is working and you can send compressed Http Messages.  Congratulations.....
 


CISCO'S STRATEGY FOR FUTURE TRENDS

clock June 12, 2009 19:19

Cisco boss John Chambers told a conference that "video is the future and if you ask what excites me most, it's probably how video's going to change our lives - cisco logoboth personally and the way we work." Even Cisco predicts that video from small communication devices like cell phones will be the main e-mail technique. By using video in every aspect of the internet, internet traffic will reach 667 exabytes and 90% of that will be made up of video according the recent research. ( now internet size is about 500 exabyte - 1 exabyte is 1 million terabyte ) The traffic, equivalent of 10 billion DVDs worth of information, would cross the internet monthly said Cisco."If this prediction holds true, it would take more than a half a million years to watch all the online video"

What is Cisco?

Cisco Systems, Inc. is a multinational corporation with more than 66,000 employees and annual revenue of US$39 billion as of 2008. Headquartered in San Jose, California, it designs and sells networking and communications technology and services. According to 2008 data, Cisco net income of about 8 billion $. In Fortune 500 list, Cisco takes place as 57th.



FACEBOOK TRANSFERRED GREG BADROS FROM GOOGLE

clock June 12, 2009 18:49
Few days ago, Facebook transferred Greg Badros, a Google Senior Director of Engineering. As a man who graduated from Math and Computer Science simultaneously, Badros had been working in Google since 2003. He will be, like in Google, Director of Engineering in Facebook. What makes his transfer interesting is Badros was the team leader in several Google projects like "Google Calendar, Google Reader, Gmail team" and especially Google AdSense Team. This shows how much Facebook gives importance to online ad services in the times of people discussing whether social websites’ ad capabilities is more powerful than traditional search engine ad services. Moreover, this can be another big challenge for Google recently, after Microsoft's announcement of Bing Search Engine.
 
Here’s Facebook’s official statement :

    “Greg Badros has joined Facebook as a director of engineering, reporting to Mike Schroepfer. Greg is one of the most accomplished engineering talents at Google, and it’s wonderful that he has decided to bring these talents to Facebook and take on numerous responsibilities across the engineering organization.”


HOW TO MAINTAIN SCROLL POSITION AFTER PAGE REFRESH, POSTBACK?

clock June 12, 2009 08:51
In ASP.NET, after PagePostBack is done, to maintain the scroll position can be quite important in long web pages. ASP.NET gives us 3 methods to do this. They are:

       1. In Web.config :

               <pages maintainScrollPositionOnPostBack="true">

       2. In single Page :

              <%@ Page MaintainScrollPositionOnPostback="true" ...

       3. Programatically :

              Page.MaintainScrollPositionOnPostBack = true;


.NET IO - 1 ( Creating and Deleting Files and Directories and Listing subfiles and subdirectories )

clock June 10, 2009 07:13
There are advanced classes in .NET for IO processing. Even though we have some classes that allow us to carry out low level IO operations, we can usually do our work with several static methods. Now let's see how a directory and a file is created, deleted and how directory hierarchy in a disk volume or in a directory can be displayed in tree view. Although IO operations are same in all .NET projects, to make easier our article I use ASP.NET. Hence you can easily copy and paste code below in, for example, WPF. Classes, we will use, are:

  • DriveInfo
  • DirectoryInfo
  • FileInfo
  • Directory
  • File
To create a directory or file
Directory and File classes in System.IO namespace allow us to create and delete directories or files:
Directory.Create(@"C:\exampleDirectory");
Directory.Delete(@"C:\exampleDirectory");
If we want to work on files and directories in current project folder, 
Directory.Create(@"Server.MapPath("exampleDirectory"));  
Directory.Delete(@"Server.MapPath("exampleDirectory"));  
we can use. When operating on files, use File class:
File.Create(@"C:\exampleFile.doc")
File.Delete(@"C:\exampleFile.doc")
or
File.Create(@"Server.MapPath("exampleFile"));  
File.Delete(@"Server.MapPath("exampleFile"));  
Now let's work on displaying directory and file hierarchy in treeView like "windows explorer" style. We will use these classes:

  • System.IO.DriveInfo        //allows us to access the name, available space, total space etc. of a disk volume
  • System.IO.DirectoryInfo    //allows us to access the name, available space, total space etc. of directory
Create a new site, add TreeView and wrote below code in Page_Load event:
rotected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            System.IO.DriveInfo drive = new System.IO.DriveInfo(@"D:\"); 
            //work on local disk D
            TreeNode node = new TreeNode(); 
            //we create TreeNode's dinamically

            node.Value = drive.Name;  
            TreeView1.Nodes.Add(node); 
            //add local disk D to main node

            loadDirectories (node, drive.Name);//in this recursive method,
            // we pass name and full address of the local disk 
            // as parameters            
        }
    }

    private void loadDirectories(TreeNode parent, string path)
    {
        System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(path); 
        //now we don't work on drives but directories

        try
        {
           //with  GetDirectories(), we get all sub directories
            foreach (System.IO.DirectoryInfo d in directory.GetDirectories()) 
            {
                TreeNode node = new TreeNode(d.Name, d.FullName);                

                parent.ChildNodes.Add(node);  

                //call the same method (call "loadDirectories()" recursively )
                loadDirectories(node, d.FullName);        
            }
        }
        catch (System.UnauthorizedAccessException e)
        {
            parent.Text += "(acces forbiddeni)";
        }

        catch (System.IO.IOException e)
        {
            parent.Text += "(unknown error hata: " + e.Message + ")";
        }   
    }
We displayed just content of volume D by writing ?System.IO.DriveInfo drive = new System.IO.DriveInfo(@"D:\");". If we wanted to display all files and directories in computer hard disk, we would write:
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())  
            //to work on all volumes
            {
                TreeNode node = new TreeNode();
                node.Value = drive.Name;

                if (drive.IsReady)
                {
                    node.Text = drive.Name;
                    loadDirectories(node, drive.Name);
                }                            

                TreeView1.Nodes.Add(node);
            } 
        }
}
The code below takes several minutes. As you can estimate,  our recursive method "loadDirectories()" needs many IO operations.

Now add a GridView to the project. We want to select a file from the TreeView we just created, and see alll subfiles and subdirectories with their name, space, last access time etc. Select SelectedNodeChanged event in "Properties Window" after clicking on TreeView and write the code below.
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        DirectoryInfo directory = new DirectoryInfo(TreeView1.SelectedNode.Value);

        GridView1.DataSource = directory.GetFiles();
        GridView1.DataBind();
    }
We learned how to create and delete files and directories and displaying all subdirectories and files in a disk, hierarchically in a TreeView.


WOLFRAM ALPHA

clock May 30, 2009 01:43
Wolfram Alpha In the last days Wolfram Alpha is highly discussed. It is an answer engine not a search engine that is its difference. What makes it an answer engine is: it doesn't give you a list of search results and waits you select one, rather it gives a single answer, if it can. Now it is in Alpha stage and generally gives the warning "Wolfram|Alpha isn't sure what to do with your input." I've tried some queries like “What is the average temperature in Turkey” and Wolfram Alpha answered "18 degree". Wolfram can understand now simple, not so complex and generally statistical, mathematical queries. (It is especially very powerful in math since it has "Mathematica" in background)
 
How Wolfram Alpha works? It has huge databases and several algorithms to get and filter information from these databases. In its algorithm base, it has many formulas from physics, math, economy and other science fields. When we enter the query and search, Wolfram gets necessary info and gives us a single answer not a list. This point is stressed by it is founder Stephen Wolfram in a press conference; he said "Wolfram is breakpoint in Web" because of this single answer style.
 
What will be the effect of Wolfram on search engine market? What will be the answer of Microsoft and Google? How they determine new strategies? Google, which has 64.2% share inStephen Wolfram the market, gave its first answer. In late April, when Stephen Wolfram give his first speech about the release of Wolfram , Google announced its new future that is now it has access to actual governmental data in order to be able to give up-to-date results and with this results custom , actual graphics. Also, Microsoft CEO announced the release of new search engine www.bing.com. So the market is vivid and is ready to new news.
 
What about Stephen Wolfram, the founder of Wolfram Alpha? Who is he? In Wikipedia, he is a physicist, mathematician and computer scientist, author and a businessman. (I remembered Benjamin Franklin when I read about him- Franklin was author, politician, painter, politician, political theorist and statesman) Wolfram, 50, is an English man. He was child prodigy and at 16 published an article. His annual profit is 22 million $. He said about his project, I want to produce useful things not make money. Let's see what will be result of his project in search engine market and searching techniques? Maybe in the future we can see alliances of big players (Google, Wolfram and Microsoft) in the market?


SERVICE ORIENTED ARCHITECTURE (SOA)

clock May 7, 2009 05:14
Service Oriented Architecture (SOA) is a very important concept of our age of big systems and applications. In these big systems and organizations there are different platforms, different operating systems(OS) and communication between these parts is difficult and so important.The solution to this commnunication problem is using services between servers.For example,imagine a situation in Facebook.SOA,Service Oriented ArchitectureFacebook has several servers and each server group has profile information of different people. (I don't know Facebook's organization details but our scenario is most probably correct::))) Also assume that different server groups have different operating systems and different architectures.So the question: how these servers can communicate effectively when you see friend list that each one's profile comes from a different server?The easiest way is using services and construct a Service Oriented Architecture between these servers.How? Using a universal, flexible language (SOAP,XML,both etc.) to communicate.Additinally by sending this information on HTTP wires that is common in almost all systems, problem is solved.Therefore, all server groups send information to a master server via services and master server prepare the list by joining them.However, some extra information other than profile info, in our example , is needed in other words metadata, because XML is so flexible so how to use it in receiving end of the communication can't be known without this guidelines.By using this SOA architecture there is no need to worry about the new server groups, they all can be added to system easily.MICROSOFT's solution in SOA area is WCF(Windows Communication Foundation) (there is also XML based ASP.NET webservice but to build a fully functional service layer, WCF is needed) WCF is a framework and involves other past MICROSOFT SOA technologies (like COM,DCOM,MSMQ etc.) In next post, I will show how to build and consume a WCF service.