15 Ocak 2011 Cumartesi

Aero Style Forms

        #region ----- Aero Form

 

        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]

        public struct MARGINS

        {

            public int Left;

            public int Right;

            public int Top;

            public int Bottom;

        }

 

        private MARGINS margins;

        [System.Runtime.InteropServices.DllImport("dwmapi.dll", PreserveSig = false)]

        public static extern void DwmExtendFrameIntoClientArea

                        (IntPtr hwnd, ref MARGINS margins);

 

        [System.Runtime.InteropServices.DllImport("dwmapi.dll", PreserveSig = false)]

        public static extern bool DwmIsCompositionEnabled();

 

        protected override void OnLoad(EventArgs e)

        {

            base.OnLoad(e);

            if (DwmIsCompositionEnabled())

            {

                // Paint the glass effect.

                margins = new MARGINS();

                margins.Top = 50;

                DwmExtendFrameIntoClientArea(this.Handle, ref margins);

            }

        }

 

        protected override void OnPaintBackground(PaintEventArgs e)

        {

            base.OnPaint(e);

            if (DwmIsCompositionEnabled())

            {

                // paint background black to enable include glass regions

 

                e.Graphics.Clear(Color.Black);

                // revert the non-glass rectangle back to it's original colour

 

                Rectangle clientArea = new Rectangle(

                        margins.Left,

                        margins.Top,

                        this.ClientRectangle.Width - margins.Left - margins.Right,

                        this.ClientRectangle.Height - margins.Top - margins.Bottom

                    );

                Brush b = new SolidBrush(this.BackColor);

                e.Graphics.FillRectangle(b, clientArea);

            }

        }

 

        #endregion

 

9 Ekim 2010 Cumartesi

Service Broker kullanımı

SQL Server 2005 veya 2008 üzerinde service broker nesnesinin kullanımı.

ornekdb isimli bir database oluşturulması

ornekdb service broker erişimi ve service broker’ın aktifleştirilmesi

Select is_broker_enabled From sys.databases Where database_id=db_id()

ALTER DATABASE ornekdb SET ENABLE_BROKER

tanımların yapılması



CREATE MESSAGE TYPE mesaj VALIDATION = WELL_FORMED_XML ;

CREATE CONTRACT kontrat ( mesaj SENT BY INITIATOR);

CREATE QUEUE [dbo].[gondermeKuyrugu];
CREATE QUEUE [dbo].[almaKuyrugu];

CREATE SERVICE gondermeServisi ON QUEUE [dbo].[gondermeKuyrugu];
CREATE SERVICE almaServisi ON QUEUE [dbo].[almaKuyrugu] (kontrat);

mesaj gönderme



BEGIN TRANSACTION ; 

-- mesaj oluşturulması

DECLARE @mesaj XML ;
SET @mesaj = N'<mesaj>Merhaba, Dünya!</mesaj>' ;

-- baslatılan karsilasmanın referansının
-- tutulması

DECLARE @karsilasmaReferansi UNIQUEIDENTIFIER ;

-- Karşılaşma.

BEGIN DIALOG CONVERSATION @karsilasmaReferansi
FROM SERVICE gondermeServisi
TO SERVICE 'almaServisi'
ON CONTRACT kontrat
WITH ENCRYPTION = OFF;

-- Send the message on the dialog.

SEND ON CONVERSATION @karsilasmaReferansi
MESSAGE TYPE mesaj
(@mesaj) ;

-- işlem tamalanıyor. Service Broker
-- mesaj hedefe ulaştırılır

COMMIT TRANSACTION ;
GO

mesaj alma



-- Grup bazında işlem
WHILE (1 = 1)
BEGIN

DECLARE @karsilasmaReferansi UNIQUEIDENTIFIER,
@karsilasmaGrup UNIQUEIDENTIFIER,
@mesajIcerigi XML,
@mesajTipAdi NVARCHAR(128);

BEGIN TRANSACTION ;

-- grubun tutulması

WAITFOR(
GET CONVERSATION GROUP @karsilasmaGrup FROM [dbo].[almaKuyrugu]),
TIMEOUT 500 ;

-- eger karşılaşma grubu kalmadıysa işlemin
-- dış döngünün dışına çıkarılması

IF @karsilasmaGrup IS NULL
BEGIN
ROLLBACK TRANSACTION ;
BREAK ;
END ;

-- grup içerisindeki mesajların işleme alınması.

WHILE 1 = 1
BEGIN

-- grup için mesajın alınması 'where' yazımı ile
-- aynı gruba ait mesajın işleme alınması

RECEIVE
TOP(1)
@karsilasmaReferansi = conversation_handle,
@mesajTipAdi = message_type_name,
@mesajIcerigi =
CASE
WHEN validation = 'X' THEN CAST(message_body AS XML)
ELSE CAST(N'<none/>' AS XML)
END
FROM [dbo].[almaKuyrugu]
WHERE conversation_group_id = @karsilasmaGrup ;

-- eger mesaj yoksa veya hata olustuysa işlemi durdur,

IF @@ROWCOUNT = 0 OR @@ERROR <> 0 BREAK;

-- gelen mesajın gösterilmesi / seçilmesi

SELECT 'Conversation Group Id' = @karsilasmaGrup,
'Conversation Handle' = @karsilasmaReferansi,
'Message Type Name' = @mesajTipAdi,
'Message Body' = @mesajIcerigi ;

-- karşılaşmanın sonlandırılması

END CONVERSATION @karsilasmaReferansi ;

END;

-- işlemlerin onaylanması

COMMIT TRANSACTION ;

END ; -- bütün gruplar
GO





MVC Page URL Relative

<link href="<%= 
Page.ResolveUrl("
~/Content/core/css/smoothness/jquery-ui-1.8.1.custom.css") %>"
rel="stylesheet"
type="text/css" />
<link href='<%=
Url.Content("~/Plugins/Views/Webilan/Content/Main.css") %>'
rel="stylesheet"
type="text/css">
<link rel="stylesheet" type="text/css" media="screen"
href
='<%= VirtualPathUtility.ToAbsolute(
string.Format("~/Content/{0}/css/Site.css",
PostSystem.ThemeName )) %
>' />

19 Eylül 2010 Pazar

LINQ to SQL query with dynamic OrderBy

public static class DynamicOrderBy
{

public static IQueryable<TEntity> OrderBy<TEntity>(this IQueryable<TEntity> source, string orderByProperty,
bool desc) where TEntity : class
{

string command = desc ? "OrderByDescending" : "OrderBy";

var type
= typeof(TEntity);
var property
= type.GetProperty(orderByProperty);
var parameter
= System.Linq.Expressions.Expression.Parameter(type, "p");
var propertyAccess
= System.Linq.Expressions.Expression.MakeMemberAccess(parameter, property);
var orderByExpression
= System.Linq.Expressions.Expression.Lambda(propertyAccess, parameter);

var resultExpression
=
System.Linq.Expressions.Expression.Call(
typeof(Queryable), command, new Type[] { type, property.PropertyType },
source.Expression, System.Linq.Expressions.Expression.Quote(orderByExpression));

return source.Provider.CreateQuery<TEntity>(resultExpression);

}


 



reference :



http://blogs.msdn.com/b/swiss_dpe_team/archive/2008/06/05/composable-linq-to-sql-query-with-dynamic-orderby.aspx



http://stackoverflow.com/questions/307512/how-do-i-apply-orderby-on-an-iqueryable-using-a-string-column-name-within-a-gener

8 Eylül 2010 Çarşamba

C#: Equivalent of JavaScript escape function

Uri.EscapeDataString("KC's trick /Hello") gives:
"KC's%20trick%20%2FHello"
Uri.EscapeUriString("KC's trick /Hello") gives:
"KC's%20trick%20/Hello"
System.Web.HttpUtility.UrlEncode("KC's trick /Hello") gives:
"KC's+trick+%2fHello"
System.Web.HttpUtility.UrlPathEncode("KC's trick /Hello") gives:
"KC's%20trick%20/Hello"

 

reference :http://kseesharp.blogspot.com/2008/01/c-equivalent-of-javascript-escape.html

7 Temmuz 2010 Çarşamba

XML node

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlFile.NameTable);
nsmgr.AddNamespace(
"smap", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");
string xpath
= "//smap:siteMapNode[@url=\"{0}\"]";
string url
= "~/Index";

return GetSiteMapNodeFromElement((XmlElement)xmlFile.SelectSingleNode(String.Format(xpath, url), nsmgr));

13 Haziran 2010 Pazar

Google Font api

 

 









The Google Font API helps you add web fonts to any web page.


Benefits of the Google Font API include:



  • A choice of high quality open source fonts.

  • Works in most browsers.

  • Extremely easy to use.


For example, the following text uses a web font called Tangerine:



Making the Web Beautiful!

Applying a font is easy: just add a special stylesheet link to your web page, then use the font in a CSS style.


For details, see the quick start example.



Google Font Directory


To give developers a choice of high-quality fonts when using the Font API, we have created the Google Font Directory. There you can browse our catalog of available fonts, learn about the font designers who created them, and copy the code required to use them on your web page.


The fonts in the directory are all released under open source licenses; you can use them on any non-commercial or commercial project.



Visit the Google Font Directory now


 

refer: http://code.google.com/intl/tr-TR/apis/webfonts/

10 Haziran 2010 Perşembe

MVC virtualPathProvider


private string GetViewPath(string[] locations, string viewName,string controllerName)
{

for (int i = 0; i < locations.Length; i++)
{
path
= string.Format(System.Globalization.CultureInfo.InvariantCulture, locations[i],
new object[] { viewName, controllerName });
if (this.VirtualPathProvider.FileExists(path))
{
return path;
}
}
return null;
}


private string GetViewPath(string[] locations, string viewName,string controllerName)
{
return pPaths.Where(pp => pp.Name == controllerName && pp.ciewName= viewName ).First().Path();
}

26 Mayıs 2010 Çarşamba

C# notes

class DelegateTests
{
public void Run()
{
// there are many ways to call method Test
// 1, declare Func<int, string> delegate
Func<int, string> func1 = MyFunc;
Test(func1);

// 2, implicit delegate
Test(MyFunc);

// 3, inline delegate
Test(delegate(int i) { return i.ToString(); });

// 4, lambda expression
Test(n => n.ToString());
}

public void Test(Func<int, string> func)
{
Console.WriteLine(func(
123));
}

private string MyFunc(int i)
{
return i.ToString();
}
}

List Join

+++ Program that joins List of strings (C# .NET 4.0) +++

using System;
using System.Collections.Generic;

class Program
{
static void Main()
{
// Create a List of three strings.
var list = new List<string>() { "cat", "dog", "rat" };
// Join the strings from the List.
string joined = string.Join<string>("*", list);
// Display.
Console.WriteLine(joined);
}
}


 



   1.
IEnumerable
<long> ids = new long[]{1,3,4,5};
2.
string delimitedIds = string.Join(",", ids.Select(x => x.ToString()).ToArray());



 



            // Array ToString "," separated
int[] intArray = { 1, 2, 3 };
Console.WriteLine(intArray.ToString(
","));
// output: 1,2,3

// ArrayList ToString ":" separated
ArrayList arrayList = new ArrayList() { 1, 2, 3 };
Console.WriteLine(arrayList.ToString(
":"));
// output 1:2:3

// A class object List ToString " - " separated
List<Foo> foos = new List<Foo>()
{
new Foo() { Name = "foo1", Number = 1 },
new Foo() { Name = "foo2", Number = 2 },
new Foo() { Name = "foo3", Number = 3 },
};
Console.WriteLine(foos.ToString(
" - "));
// output 'foo1 1' - 'foo2 2' - 'foo3 3'

// A struct List ToString "||" separated
List<StructFoo> sfoos = new List< StructFoo >()
{
new StructFoo() { Name = "sfoo1", Number = 1 },
new StructFoo() { Name = "sfoo2", Number = 2 },
new StructFoo() { Name = "sfoo3", Number = 3 },
};
Console.WriteLine(sfoos.ToString(
"||"));
// output 'sfoo1 1'||'sfoo2 2'||'sfoo3 3'

// A generic dictionary ToString "," separated
Dictionary< int, Foo > dictionary = new Dictionary< int, Foo >()
{
{
1, new Foo() { Name = "foo1", Number = 1 }},
{
2, new Foo() { Name = "foo2", Number = 2 }},
{
3, new Foo() { Name = "foo3", Number = 3 }},
};
Console.WriteLine(dictionary.ToString(
","));
// output: [1, 'foo1 1'],[2, 'foo2 2'],[3, 'foo3 3']

// string as IEnumerable char
string text = "abcdefg";
Console.WriteLine(text.ToString(
","));
// output: a,b,c,d,e,f,g