Tags: , , , , , , , | Categories: Genel Posted by okutbay on 30.03.2010 10:55 | Yorumlar (5)

Bazen iki tarihin arasında geçen süreyi bulmanız gerekir. Bu kişinin şu anki yaşı olabileceği gibi bir işçinin o gün çalıştığı süre de olabilir. C# bize bu konuda yardımcı olmak için TimeSpan tipini sunar. Bu tipi kullanarak iki tarih arasında geçen süreyi farklı şekillerde alabiliriz. Örneğin iki tarih arasında kaç saat olduğunu bulmak istiyorsak TotalHours özelliğini kullanabiliriz. Eğer iki tarih arasında geçen sürenin sadece saat kısmı bizi ilgilendiriyorsa Hours özelliğini kullanabiliriz.

    1 DateTime myStartTime = Convert.ToDateTime("30.03.2010 08:04:00");

    2 DateTime myEndTime = Convert.ToDateTime("30.03.2010 18:02:00");

    3 TimeSpan myWorkingTime = myEndTime - myStartTime;

    4 double myWorkingHours = myWorkingTime.TotalHours;

Bu işi uygulamanız içinde birden çok kullanacaksanız bir method haline getirmek faydalı olacaktır.

    1 public static double GetWorkingHours(DateTime startTime, DateTime endTime)

    2 {

    3     TimeSpan workingTime = endTime - startTime;

    4     double workingHours = workingTime.TotalHours;

    5     return workingHours;

    6 }

 

bu yeni metodu soyle kullanirsiniz.

    1 DateTime myStartTime = Convert.ToDateTime("30.03.2010 08:04:00");

    2 DateTime myEndTime = Convert.ToDateTime("30.03.2010 18:02:00");

    3 double myWorkingHours = GetWorkingHours(myStartTime, myEndTime);

 

Not:Methodun ve kodun aynı classta olduğu varsayılmıştır...

Kolay gelsin...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , | Categories: Genel, MCP, News Posted by okutbay on 19.03.2010 10:51 | Yorumlar (0)

Virtual Business Cards (VBCs) are now available as a new benefit for MCPs. Use VBCs to show off your expertise, knowledge, and achievements--creatively, securely, and interactively. Brand yourself and let everyone know what credentials you hold by using them on the Web or in your e-mail signature.

myVirtualCard_blurred

You can start to create your card from this url: http://www.mcpvirtualbusinesscard.com/

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , | Categories: Programlama, Genel, Tanıtım Posted by okutbay on 26.02.2010 16:03 | Yorumlar (0)

There is an open source project to use with your projects. It's easy to use.

dotnetzip.codeplex.com

Let's zip a folder :)

    1 using (ZipFile zip = new ZipFile())

    2 {

    3     zip.AddDirectory("c:\somedirectory");

    4     zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");

    5     zip.Save("nameofthezipfile.zip");

    6 }

Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , | Categories: Tip, Programlama, Genel Posted by okutbay on 26.02.2010 11:41 | Yorumlar (0)

You can always write comment to your codes. But comment itself can be outdated and misleads a developer. So writing self-documented codes must our first aim to make our code more maintainable.

In my opinion a big step to achieve self-documented code begins writing if clauses.

If a developer understands if clause, he/she understand purpose of the code block more easily.

But how can we write more readable if clause.

Very easy: Don't write logical comparisons into if clause.

    1 if ((preprocessedFailedEmails.Count > 0) || (failedEmails.Count > 0))

    2 {

    3     //some code

    4 }

Although this is a very simple if clause it's a bit hard to get what is happening there. Let's make it more readable.

    1 bool hasErrors = ((preprocessedFailedEmails.Count > 0) || (failedEmails.Count > 0));

    2 if (hasErrors)

    3 {

    4     //some code

    5 }

Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Categories: IDE, Genel, Tip Posted by okutbay on 25.02.2010 19:08 | Yorumlar (0)

If you're working with lot of projects, or you want to release your DLL to specific location you may need to add some extra actions to to your build.

For example. You have project that uses a DLL of another project of another solution. Sometimes you build your DLL in debug mode, sometimes you build your DLL in release mode. When you build your class library output directory depends on the build mode. Question is: Which DLL will be referenced by your project? To prevent this confusion you can add an copy operation to your post-build events. Then reference the copied DLL.

Here is the sample macro to do this:

cd $(OutDir)
copy $(TargetFileName) D:\Sources\DLLReferences\MyProjectOutpu

Just go to your project properties. Switch "Build Events" tab. Add this sample macro to Post-build event command line. When you build your it will copy result file to specified location.

build-events

Figure 1: Build events window of your project.

post-build-events-command-line-window

Figure 2: A Build event Command line window

You can find a list of macros and their descriptions here:

$(ConfigurationName)

The name of the current project configuration, for example, "Debug|Any CPU".

$(OutDir)

Path to the output file directory, relative to the project directory. This resolves to the value for the Output Directory property. It includes the trailing backslash '\'.

$(DevEnvDir)

The installation directory of Visual Studio 2005 (defined with drive and path); includes the trailing backslash '\'.

$(PlatformName)

The name of the currently targeted platform. For example, "AnyCPU".

$(ProjectDir)

The directory of the project (defined with drive and path); includes the trailing backslash '\'.

$(ProjectPath)

The absolute path name of the project (defined with drive, path, base name, and file extension).

$(ProjectName)

The base name of the project.

$(ProjectFileName)

The file name of the project (defined with base name and file extension).

$(ProjectExt)

The file extension of the project. It includes the '.' before the file extension.

$(SolutionDir)

The directory of the solution (defined with drive and path); includes the trailing backslash '\'.

$(SolutionPath)

The absolute path name of the solution (defined with drive, path, base name, and file extension).

$(SolutionName)

The base name of the solution.

$(SolutionFileName)

The file name of the solution (defined with base name and file extension).

$(SolutionExt)

The file extension of the solution. It includes the '.' before the file extension.

$(TargetDir)

The directory of the primary output file for the build (defined with drive and path). It includes the trailing backslash '\'.

$(TargetPath)

The absolute path name of the primary output file for the build (defined with drive, path, base name, and file extension).

$(TargetName)

The base name of the primary output file for the build.

$(TargetFileName)

The file name of the primary output file for the build (defined as base name and file extension).

$(TargetExt)

The file extension of the primary output file for the build. It includes the '.' before the file extension.

Reference: Pre-build Event/Post-build Event Command Line Dialog Box

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , , , | Categories: Genel, Programlama Posted by okutbay on 23.02.2010 16:49 | Yorumlar (0)

This is sample application to serializes sample object

    1 using System;

    2 using System.Collections.Generic;

    3 using System.Text;

    4 

    5 using System.IO;

    6 using System.Xml.Serialization;

    7 

    8 namespace ConsoleApplication1

    9 {

   10     class Program

   11     {

   12         static void Main(string[] args)

   13         {

   14             SampleObject sampleObject = new SampleObject();

   15             sampleObject.Id = 35;

   16             sampleObject.Name = "Ozan K. BAYRAM";

   17 

   18             XmlSerializer serializer2 = new XmlSerializer(typeof(SampleObject));

   19             MemoryStream ms = new MemoryStream();

   20             XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces();

   21             xmlSerializerNamespaces.Add("", ""); //if you want namespace for your XML define here

   22             serializer2.Serialize(ms, sampleObject, xmlSerializerNamespaces);

   23             StringBuilder XMLText = new StringBuilder();

   24             ms.Position = 0;

   25             using (StreamReader Reader = new StreamReader(ms))

   26             {

   27                 XMLText.Append(Reader.ReadToEnd());

   28             }

   29 

   30             string serializedObject = XMLText.ToString();

   31         }

   32     }

   33 }

Output string

xmlserializationoutput

 

Sample class to use

    1 [Serializable]

    2 [System.Xml.Serialization.XmlRoot("sampleobject")]

    3 public class SampleObject

    4 {

    5     [System.Xml.Serialization.XmlAttribute("id")]

    6     public int Id { get; set; }

    7 

    8     [System.Xml.Serialization.XmlElement("name")]

    9     public string Name { get; set; }

   10 }

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Categories: Genel Posted by okutbay on 27.01.2010 18:15 | Yorumlar (0)

Still got a printed copy of these codes in my wallet. I was very handy while in console application programming era. But still needs sometimes.

9hxt0028.vc38qp1(en-us,VS.71)

60ecse8t.vc38qo1(en-us,VS.71)

Hope these help. Happy coding…

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , , , , | Categories: Genel, Uygulama Posted by okutbay on 12.11.2009 12:54 | Yorumlar (0)

We, the developers sometimes need work with different languages for some projects. Especially if you are a .NET developer you will need a conversion tool to convert C# to VB.NET or VB.NET to C#.

Here is a useful free tools for that need.

C Sharp to VB.NET

VB.NET to C Sharp

You can check other tool from Toolbox section 

 

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Categories: Genel Posted by okutbay on 27.10.2009 16:01 | Yorumlar (0)
"You know, when you have a program that does something really 
cool, and you wrote it from scratch, and it took a 
significant part of your life, you grow fond of it. When it's 
finished, it feels like some kind of amorphous sculpture that 
you've created. It has an abstract shape in your head that's 
completely independent of its actual purpose. Elegant, 
simple, beautiful. Then, only a year later, after making 
dozens of pragmatic alterations to suit the people who use 
it, not only has your Venus- de-Milo lost both arms, she also 
has a giraffe's head sticking out of her chest and a cherubic 
penis that squirts colored water into a plastic bucket. The 
romance has become so painful that each day you struggle with 
an overwhelming urge to smash the fucking thing to pieces 
with a hammer."  - Nick Foster ("Life as a programmer")
 
taken from the http://www.lillypadsoftware.com/ 

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , , , , | Categories: Genel Posted by okutbay on 08.10.2009 16:01 | Yorumlar (0)

According to business rule all footballer name and surname must be capitalized and not longer than 8 chars length.

Very simple to develop. We develop a wrapper method for this job. Seems working fine. Until this morning. Game masters of the http://icanfootball.com noticed that some player names violates this business rule. After my first debuging i found the problem. ToLowerInvariant method is the guilty. No, infact the developer who uses this method is guilty. Because this methods unable to convert "i" to "İ", "ı" to "I" or reverse. This chars specific to Turkish locale and this methods are invariant (means Culture Indepentend and works same as calling ToLower or ToUpper method with CultureInfo.InvariantCulture enum). 

So in my opinion this methods are useless. Please use ToLower or ToUpper method with appropriate culture info.

You can check this sample code.

 

    1 string a = "ı I ş Ş ç Ç ğ Ğ ö Ö ü Ü i İ";

    2 

    3 string b = a.ToLowerInvariant();//b = "ı i ş ş ç ç ğ ğ ö ö ü ü i İ" fails to convert

    4 string d = a.ToUpperInvariant();//c = "ı I Ş Ş Ç Ç Ğ Ğ Ö Ö Ü Ü I İ" fails to convert

    5 

    6 string culture = "tr-TR";

    7 System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo(culture);

    8 

    9 string c = a.ToLower(cultureInfo);//d = "ı ı ş ş ç ç ğ ğ ö ö ü ü i i"

   10 string e = a.ToUpper(cultureInfo);//e = "I I Ş Ş Ç Ç Ğ Ğ Ö Ö Ü Ü İ İ"

 

 

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5