19 11 2014

Android Studio No Connect USB Device

- Check usb cable to your android device.
- If device seems connected as usb storage, open device developer settings and grant permission debugging.
- If there is no connection again, go computer control panel, open device manager, and find usb devices, if there is ! sign, driver update required.
- There is driver file at following link, download and install universal driver.
Android Usb Driver

10 11 2014

Dapper Nedir ? Nasıl kullanılır? Örnekli anlatım

Bu yazımızda, bir StackExchange projesi olan mikro ORM frameworku DAPPER in kullanımına örnek vereceğiz.
Dapper , bizlere özellikle performans anlamında katkı sağlıyor. dynamic tipinde dönüşlerde bile entitiy framework 'e nazaran 20 kata varan performans sağladığı yapılan ölçümlerde görülmüştür.

Dapper'i projemize NuGet vasıtasıyla kolayca ekleyebiliriz.


Bu işlemden sonra projemizin references kısmına bakarak dapper dll in geldiğini görerek emin olabiliriz.

Sorguyu yazdıgımız class ların içersinde de using kısmına ekliyoruz.
..
using Dapper;
..


Şimdi örneğimize bakalım,

 using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[typeof(Tdatabase).Name].ConnectionString))
            {
                conn.Open();
                // int userid = conn.Query("select id from people where inc=@id",new {id=5})
               
                // dynamic users = conn.Query("select * from people where inc=@id",new {id=5})
                //int a = users.inc;
                //string name = users.name;


                // poco
                // class MyUser {
                    //public int id {get;set;}
                    // public string name {get;set;}
                    // public DateTime birthdate {get;set;}
                //    }

                // tek sonuc dondugunu biliyorsak
                // MyUser users = conn.Query("select inc as id, name, birthdate from people where inc=@id",new {id=5})

                // sonuc kumesi donuyorsa
                // List users = conn.Query>("select inc as id, name, birthdate from people where name like '%JO%'",)


            }



Kalıbı özetlersek,

sql sorgusu çağırırken,

                   return conn.Query(sql, parameters  );

stored procedure çağırırken,


                    return conn.Query(sql, parameters, commandType: CommandType.StoredProcedure);


Sonucunu ölçümlerseniz özellikle EF5 e göre 20 kata yakın performans, EF6 ya göre ise 2 katına yakın performans elde ettiğnizi görebilirsiniz.

Dapper in daha pek çok önemli özelliği var , bunlardan biri de QueryMultiple.

Tek seferde birden fazla sonuç kumesi getirebiliyor ve bu muthis bir perfomans artısı saglıyor.
using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection))
{
    sqlConnection.Open();

    var query = @"
               SELECT * FROM dbo.Suppliers WHERE Id = @Id

               SELECT * FROM dbo.Products WHERE SupplierID = @Id

                ";

    // return a GridReader
    using (var result = sqlConnection.QueryMultiple(query, new {Id = 1}))
    {
        var supplier = result.Read().Single();
        var products = result.Read().ToList();

        ObjectDumper.Write(supplier);

        Console.WriteLine(string.Format("Total Products {0}", products.Count));
        
        ObjectDumper.Write(products);
    }   sqlConnection.Close(); 
}



15 09 2014

Android Tips - Formatting Text with Html Tags

Android Tips #1


Formatting Text with Html.fromHtml()


Android gives you the possibility to easily format text with HTML markup. 

Supported HTMLTags
TagsFormat
b, strongBold
i, em, cite, dfnItalics
uUnderline
subSubtext
supSupertext
bigBig
smallSmall
ttMonospace
h1 … h6Headlines
imgImage
fontFont face and color
blockquoteFor longer quotes
aLink
div, pParagraph
brLinefeed

Formatting text from your strings.xml

If you want to support text formatting from within your strings.xml file, you have to escape the tags – or use a CDATA section. Otherwise Android simply ignores them when reading the resource file.
To escape the tags you just need to replace all "<" characters. Luckily you do not have to escape the ">" characters as well. That way the HTML structure is still at least kind of readable. But only kind of.
If you use many HTML tags a CDATA section is better. For the sample above it looks like this:
1<string name="htmlFormattedText">
2      <![CDATA[
3      Text with markup for bold
4      and italic text.
5      There is also support for a
6      teletype-style font.
7      But no use for the code
8      tag!
9      ]]></string>
Even if you can add a lot of HTML tags, you are better off using only minor styling as mixing too much styles makes your text look uneasy instead of being more striking.
The following snippet shows how to use this string from within your Java code:
1TextView view = (TextView)findViewById(R.id.sampleText);
2String formattedText = getString(R.string.htmlFormattedText);
3Spanned result = Html.fromHtml(formattedText);
4view.setText(result);

Alternatives to consider

For longer texts that use HTML tags, I recommend to use raw files instead.
For more complicated formatting a WebView probably would be better.

8 03 2014

How To Clone A Generic List in C#

static class Extensions
{
    public static IList<T> Clone<T>(this IList<T> listToClone) where T: ICloneable
    {
        return listToClone.Select(item => (T)item.Clone()).ToList();
    }
}

Share It