Visual Studio 2015 .Net 2.0 and dotnetfx3.5 setup

Dism /online /enable-feature /featurename:NetFX3 /All /Source:D:\sources\sxs /LimitAccess

Converting Business Entities Using Explicit Keyword

Use the explicit keyword to define the conversion of one business entity to another. The conversion method will be invoked when the conversion is requested in code. Here is the sample conversion code.

class Program
    {
        static void Main(string[] args)
        {
            ExternalEntity entity = new ExternalEntity()
            {
                Id = 1001,
                FirstName = "Dave",
                LastName = "Johnson"
            };
            MyEntity convertedEntity = (MyEntity)entity;
        }
    }
 
    class MyEntity
    {
        public int Id { get; set; }
        public string FullName { get; set; }
 
        public static explicit operator MyEntity(ExternalEntity externalEntity)
        {
            return new MyEntity()
            {
                Id = externalEntity.Id,
                FullName = externalEntity.FirstName + " " + externalEntity.LastName
            };
        }
    }
 
    class ExternalEntity
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
Posted by: ayhan | 25/04/2016

Read File Header Item Data

Header ve linelardan oluşan bir text dosyasını istediğiniz bir belirteç ile (header olduğunu belirten)
belirtip satır satır okuyabileceğiniz kod bloğu aşağıdaki şekildedir.

namespace ReadFile
{
    class Item
    {
        public List<string> Indexes;
        public string Header;

        public Item()
        {
            Indexes = new List<string>();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            List<Item> items = new List<Item>();

            var lines = File.ReadAllLines("../../TestFile1.txt");
            Item currentItem = null;
            foreach (var line in lines)
            {
                if (line.StartsWith("H"))
                {
                    if (currentItem != null)
                    {
                        items.Add(currentItem);
                    }
                    currentItem = new Item();
                    currentItem.Header = line;
                }
                else if (currentItem != null)
                {
                    currentItem.Indexes.Add(line);
                }
            }
            if (currentItem != null)
                items.Add(currentItem);
        }
    }
}

TestFile1
Posted by: ayhan | 19/08/2015

SQL server databases stuck in restoring state

SQL Server: Database stuck in “Restoring” state

SQL Server: Database stuck in “Restoring” state

RESTORE DATABASE QABSI
FROM DISK = ‘C:\QABSI_BACKUP_20150819.bak’
WITH REPLACE,RECOVERY

Posted by: ayhan | 07/07/2015

Windows servis kurma-kaldırma

CommandPrompt u admin olarak açıp (bazen yetki kaynaklı sorun oluyor) aşağıdaki şekilde kodları çalıştırabiliriz.

Windows Servis Kurma

“C:\Windows\Microsoft.NET\Framework\v4.0.30319>InstallUtil.exe” “D:\Team Projects 2013\Ongoing Services\Notification Service\NotificationSrv-R12\NotificationService.WindowsService\bin\Debug\NotificationService.WindowsService.exe”

Windows Servis Kaldırma

“C:\Windows\Microsoft.NET\Framework\v4.0.30319>InstallUtil.exe” -u “D:\Team Projects 2013\Ongoing Services\Notification Service\NotificationSrv-R12\NotificationService.WindowsService\bin\Debug\NotificationService.WindowsService.exe”

Posted by: ayhan | 25/06/2015

MVC get page parameter value in js

var id = ‘@ViewContext.RouteData.Values[“id”]’;

Yukarıdaki kod bloğu ile aşağıdaki şekilde bir pageurl içinden id değerini alabiliriz.

http://localhost/CourtesyCar/VehicleHistory/Index/ASD5A12340

Kodun çıkıtısı ‘ASD5A12340’ olacaktır.

Posted by: ayhan | 12/02/2015

SQL PATINDEX

Sql sorgularında parametre olarak birden fazla değer gönderebilmek için kullanılabilecek bir sorgu yazım şekli

DECLARE @UserIds VARCHAR(50) = ‘4,5,7,8’
SELECT * FROM Users
WHERE PATINDEX(‘%,’ + CAST(Id as varchar(20)) + ‘,%’, ‘,’ + @UserIds + ‘,’) > (CASE @UserIds WHEN ” THEN -1 ELSE 0 END)

Posted by: ayhan | 30/05/2014

HttpApplicationState.Page.Application

Nedir bu Application? Session’dan ne farkı vardır? Çok pratik bir şekilde işimi görünce paylaşayım dedim.

Application, uygulamanın tümüyle ilgili bilgileri (değişkenleri, nesneleri ve metodları) tutar; Session ise ziyaretçinin sitemize girmesinden itibaren izini sürer. Örneğin bir e-ticaret sitesine giriş yapan kullanıcı browserdan sitenin adını yazıp ana sayfayı açtığı andan itibaren kullanıcının tüm davranışlarını tespit edip tutabilme olanağını bize Session sağlar. Yani başka bir deyişle kullanıcı siteye geldiğinde yeni bir session, oturum açmış olur. Application nesnesi, uygulama ilk ayağa kalktığında veritabanına erişmekten tutun da alışveriş yapmaya kadar sitede yapılacak bütün işlerin bütün kurallarını bilecek ve uygulayabilecektir.

Benim yaşadığım sorun ise DevEx kontrolleriyle alakalı. Zira TreeList içinde FileUpload kontrolü kullandım upload ettiğim resme kendim bir GUID oluşturup unique bir isim vermek istedim. Ancak TreeList’in Insert methodunda bu isme ihtiyaç duyduğumdan erişmem gerekiyordu Session bu noktada çaresiz kalıyor. FileUpload a özel bir durum bir tarafta sessiona attığınız objeyi diğer tarafta okuyamıyorsunuz. Ancak Application ile yazdığımızda server bazlı olduğu için aynı ismi diğer methodda da kullanabiliyoruz.

Burada dikkat edilmesi gereken durum (gerçi session için de geçerli) işimiz biter bitmez application üzerinden bu nesneyi temizlemek.

Posted by: ayhan | 22/05/2014

SQL INNER UPDATE QUERY

UPDATE ProductTypes
SET ProductTypes.ERPCode = NewERPCodes.NewERPCode
FROM ProductTypes
INNER JOIN NewERPCodes ON NewERPCodes.ProductTypeID = ProductTypes.ProductTypeID

Posted by: ayhan | 26/03/2014

HttpWebRequest Exam

url = ” “;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);

string line;
while ((line = readStream.ReadLine()) != null)
{
line = line.Replace(“document.write(‘”, “”);
line = line.Remove(line.Length – 3, 3);
divBanner.InnerHtml = line;
}
response.Close();
readStream.Close();

Older Posts »

Categories