Sayfalar

28 Mart 2012 Çarşamba

Changing Executable Path Of Windows Services

Open regedit (start=>run=>"regedit" command and enter)  

Go this directory 

HKEY_LOCAL_MACHINE=>SYSTEM=>CurrentControlSet(May be Control Set1 or Control Set1 )=> Services =>YourServiceName=> ImagePath

27 Mart 2012 Salı

HTML Filtering



This blog explain how to filter your html. You may want to replace some word with another or you may delete some world in html.You have to configure your webconfig file and write your module in the <modules> tab .This code handle client  request and change it when posting this request to client.

Code
/// <summary>
    /// Html içeriğinin kelime filtrelemsini sağlayan modül
    /// </summary>
    public class WordFilterModule : IHttpModule
    {
        /// <summary>
        /// Oluşturulduğunda çalışacak metod
        /// </summary>
        /// <param name="app"></param>
        public void Init(HttpApplication app)
        {
            app.ReleaseRequestState += new EventHandler(InstallResponseFilter);
        }

        /// <summary>
        /// Filtrenin yüklenmesini sağlayan metod
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InstallResponseFilter(object sender, EventArgs e)
        {
            HttpResponse response = HttpContext.Current.Response;
            HttpRequest request = HttpContext.Current.Request;
            //if (GeneralFunction.UsersResponces.ContainsKey(HttpContext.Current.User.Identity.Name))
            //{
            //    GeneralFunction.UsersResponces[HttpContext.Current.User.Identity.Name] = HttpContext.Current;
            //}
            //else
            //{
            //    GeneralFunction.UsersResponces.Add(HttpContext.Current.User.Identity.Name, HttpContext.Current);
            //}

            if (response.ContentType == "text/html")
            {
                //Debug.Write("in InstallResponseFilter()");
                response.Filter = new ModifyHtmlContentFilter(response.Filter);
            }
        }

        /// <summary>
        ///Nesne ramden silindiğinde çalışacak metod
        /// </summary>
        public void Dispose()
        { }
    }

Code to Deleting Folder and All Content In It From Command Promp

Code to Deleting Folder and All Content In It From Command Promp


rd /s /q  c:\rootFolder


This code deletes rootFolder , if root folder is imported for you


md c:\rootFolder 


this code creates a folder

Frekans Bölgesi ve Fourier Dönüşümü


Frekans Bölgesi ve Fourier Dönüşümü
Şekilleri sin ve cos fonksiyonları kullanarak ifade etmeye Fourier Dönüşümü denir. Doğadaki nesne şekilleri sin ve cos fonksiyonlarının toplamı şeklinde ifade edilebilir.



 Şekil 1 deki resme forurier dönüşümü uygulandığında Şekil 2 deki resim oluşur.Bu resmin görünebilmesi için bir takım değişiklikler yapılmıştır. Aksi taktirde ortadaki kare o kadar açık renktedir ki aradaki tonlama farkı bunu ifade edemez.

Sekil 1
Kod
rk=imread('r_kare.bmp');
f=fft2(rgb2gray(rk));
 imshow(fftshift(log(1+abs(f))),[]);

Şekil2
Frekans uzayını  yükselen ve alçalan değerler ile çarpma
Eğer frekans uzayını yükselen değerler ile çarparsak renk geçişleri daha belirgin olur , bir başka değişle kenarları çizmiş oluruz.Eğer alçalan değer ile çarparsak yüksek renk geçişleri düşer yani kenarlar belirginsizleşir ve resim matlaşır. Burada anlatılacak kodlarda sadece maske(“m”) değişkeni değişmektedir.
Kod
r=rgb2gray(imread('r_robot.bmp'));
f=fft2(r);
m=fft2([-1 -1 -1;-1 8 -1;-1 -1 -1],128,128);
g=m.*f;
t=ifft2(g);
imshow(abs(t),[]);
Yüksen
Birinci Maske

-1
-1
-1
-1
8
-1
-1
-1
-1

M1=fft2([-1 -1 -1;-1 8 -1;-1 -1 -1],128,128);
İkinci Maske
0
-1
0
-1
4
-1
0
-1
0

M2==fft2([0 -1 0;-1 4 -1;0 -1 0],128,128);

Alçalan
Birinci Maske
1
2
1
2
4
2
1
2
1

M3=fft2([1 2 1; 2 4 2;1 2 1],128,128);
İkinci Maske
1
1
1
1
1
1
1
1
1


M4=fft2([1 1 1; 1 1 1;1 1 1],128,128);

21 Mart 2012 Çarşamba

Serilizing objects to string and Deserilizing objects from string


If you like working with object this solution help you. You may save your class and use this class when you want.
Code

public static class Extensions
{
 public static object GetClassFromString<T>(this string str)
    {
        T rtnObject;
        using (StringReader reader = new StringReader(str))
        {
            XmlSerializer ser = new XmlSerializer(typeof(T));
            rtnObject = (T)ser.Deserialize(reader);
            reader.Close();
        }
        return rtnObject;
    }
  public static string GetXmlStringFromClass(this object obje)
        {
            string XmlData = null;
            using (MemoryStream mstr = new MemoryStream())
            {
                XmlTextWriter xtw = new XmlTextWriter(mstr, Encoding.Default);
                XmlSerializer xs = new XmlSerializer(obje.GetType());
                xs.Serialize(xtw, obje);
                UTF8Encoding enc = new UTF8Encoding();
                XmlData = enc.GetString(mstr.ToArray());
                xtw.Close();
                mstr.Close();
            }
            return XmlData;
        }
}  

Adding and Deleting Role From SPList and SPListItem

When you create a list on sharepoint,It will inherite all permission from paren web. If you want to edit it's permission you must breake role inheritance then add new role. Permission relation between list and parent web is same as list item and list.
Code

Extension For List Item

public static class ExtensionForListItem
{
 public static void DeleteAllRoleAssigments(this SPListItem splistItem)
    {
        if (!splistItem.HasUniqueRoleAssignments)
        {
            splistItem.BreakRoleInheritance(true);
        }
        for (int i = splistItem.RoleAssignments.Count - 1; i >= 0; i--)
        {
            SPRoleAssignment assignment = splistItem.RoleAssignments[i];
            splistItem.RoleAssignments.Remove(assignment.Member);
        }
    }
  public static void AddRole(this SPListItem listItem, SPRoleType RoleType, params SPPrincipal[] RoleOwner)
    {
       SPRoleDefinition contributorRoleDefinition= listItem.ParentList.ParentWeb.RoleDefinitions.GetByType  (RoleType);
        foreach (var item in RoleOwner)
        {
            SPRoleAssignment roleAssignment = new SPRoleAssignment(item);
            roleAssignment.RoleDefinitionBindings.Add(contributorRoleDefinition);
            listItem.RoleAssignments.Add(roleAssignment);
        }
    }
}

Extension For List 
public static class ExtensionForList
{
 public static void DeleteAllRoleAssigments(this SPList dList)
    {
        if (!dList.HasUniqueRoleAssignments)
        {
            dList.BreakRoleInheritance(true);
        }
        for (int i = dList.RoleAssignments.Count - 1; i >= 0; i--)
        {
            SPRoleAssignment assignment = dList.RoleAssignments[i];
            dList.RoleAssignments.Remove(assignment.Member);
        }
    }
 public static void AddRole(this SPList list, SPRoleType RoleType, params SPPrincipal[] RoleOwner)
    {
        SPRoleDefinition contributorRoleDefinition = list.ParentWeb.RoleDefinitions.GetByType(RoleType);
        foreach (var item in RoleOwner)
        {
            SPRoleAssignment roleAssignment = new SPRoleAssignment(item);
            roleAssignment.RoleDefinitionBindings.Add(contributorRoleDefinition);
            list.RoleAssignments.Add(roleAssignment);
        }
    }
}

19 Mart 2012 Pazartesi

Median Filter For Salt and Papper Noise

Median Filter For Salt and Papper Noise
Salt is refer to max and papper refer to min. In this reason median filter is clear min-max values from image and replace avarage of neighbord pixels. This neighboring may be matris of 3x3 or larger. We test this neighboring and finding optimal solution for this reason.

 Kodding Problem(For matlab)
This function has tre parameters. The first parameter is image,you may read the image code of  "imread('filepath')".The second parameter is mask you may enter  the code of "ones(3,3)". The last parameter is filter type, you must write "median" for median filter.

function [ rtn] = Conv( image,mask, type )
irl=size(image,1);
icl=size(image,2);
result=zeros(size(image,1),size(image,2));
mr_=size(mask,1)/2;
mc_=size(mask,2)/2;
mr=uint32(mr_);
mc=uint32(mc_);
for i=1:size(image,1)
    for j=1:size(image,2)
        ri=i;
        rs=i;
        ci=j;
        cs=j;
       
          while(ri-1>0&&ri-1>i-mr)
            ri=ri-1;
          end
          while(rs+1<irl&&rs+1<i+mr)
            rs=rs+1;
          end
          while(ci-1>0&&ci-1>j-mc)
            ci=ci-1;
          end
          while(cs+1<icl&&cs+1<j+mc)
            cs=cs+1;
          end
        croppedimage=uint16(image(ri:1:rs,ci:1:cs));
        croppedmask=uint16(mask(mr-(i-ri):1:mr+(rs-i),mc-(j-ci):1:mc+(cs-j)));
        mask_mxn=size(croppedmask,1)*size(croppedmask,2);
        pixel=0;
        switch lower(type)
             case{'median'}
                temp=croppedimage(:);
                temp=sort(temp);
                pixel=temp(uint16((mask_mxn/2)));
            case{'yoldas1'}
                temp=croppedimage(:);
                temp=sort(temp);
                tempMinMax=temp(uint8(mask_mxn/3):1:uint8(mask_mxn*2/3));
                pixel=(max(tempMinMax)+min(tempMinMax))/2;
        end 
        result(i,j)=pixel;
    end
end
if( max(result)>256)
   result=mod(result,256);
end
  rtn=uint8(result);
end

Picture 1 Salt and Papper problem

 Picture 2: Median filtered picture for mask of(3x3)
Picture 3: Median filtered picture for mask of 5x5 

11 Mart 2012 Pazar

Bussiness Inteligance and Data Warehousing

Bussiness integance is one of the data minning solutions. Bussiness integance database type is dimensional. This database uses only reporting and analizing data. If you have a large company and you want to learn how to make better your company you chose this solution.

For Bussiness Inteligance,
  1. Do datawarehouse with using dimensional model. You may have a few relational database but you have to only one datawarehouse for your solution. You may have a city table each database,But you must concat this table and do matching table for this concated table.
  2. Doing ETL(extract-transform-load) to your datawarehouse from your realtional databases
  3. If dimensional database schema type is star schema, your cubes will be simple and readable
  4. SSIS is one of the ETL solutions. SSIS concept consist of those elements:  packages to write ETL configuration, database to house this packages and SQL Agent to execute this packages a part of time recusively.
  5. ETL configuration consists of three main items. Extract : Getting data from relational database, Transform: Change and formating data what you want, Load: Writing this configured data to your datawarehouse. SSIS has a lot of component for extract data from oledb,odbc,exel  databases  and transform this data using c# script, sql query builder components with simple user interface.
  6. Creating cube in BIDS. Create your dimension and measure with existing table in your datawarehouse. Then deploy your cube to analysis service
  7. Final requirement is browser for viewing data. OLAP browsers create mdx query and send this queries to analysis server. Analysis server execute this query and returns a result. Working with OLAP browser is very simple because all thing drag and drob.

Creating Linq to Sharepoint Framework

This is my firs post of my blog. I explain how to coding entity framework like "Link to SQL" to sharepoint.
  1. Your generator have to tree const, those are root sitename,where the generate code (your project file path), and main namespace of code whice generated codes uses this own's left exc: mainnamespace.myentity1.myobjectset1
  2. You have to a regex or a function to getting truth field name from sharepoint field title exc: You don not define a field whice have space characters in c#.One of the sharepoint field is "Mail Adress",if you want to generate this object you must replace space characters.May be  "MailAdress"
  3. This generated object have to atrributes defined its internal name's or id's. This attributes provides us to access sharepoint objects.
  4. Yo have to a function to mapping your entity object to sharepoint object.This function get all of the mapping information from object attributes
  5. You may use poco code generator scrips or your own code generator class. I used my own.
  6. For generating entity class visit your root sharepoint site to access all site and visit each site's lists end each list's fields end write your generating script on this level
  7. Take care to special world of your ide. exc: c# do not support go,string,as,this ...etc. as e field name
  8. You have to user interface to generate your code from your sharepoint site when you want.This user interface maybe webpart,new project in your project,windows application ...etc.
  9. Linq to SQL use Expression<Func<T,bool>> parameters to generate SQL query.Like this you may use this parameter to generate caml query. Firstly you visit all expression and finding binary expression.Next step is convertion this binary expression to caml query.exc: entity1==a is a binary expression.Read entity1 attribute and get internal name,field type,list name and site name, write your caml query  "<FieldRef Name="entity1_internalname"/> <Value Type="Text>a</Value>" like this. And bind your entity object with returning object from sharepoint lists
  10. Finally your entity to sharepoint project is finished and you use entity to access sharepoint object and also you use linq to querying your sharepoint lists.