27 Mayıs 2017 Cumartesi

Dependency Injection: What a Cool Phrase :)


If you want to change your business work flow on air you can use dependency injection in your programs. You can decide which class to use for your customers requirement dynamically via dependency injection method. Here is a sample code for dependency injection. 2 payment methods and 2 record saving methods implemented.



  interface IPay
    {
        void Pay(string amount);
    }

    class CreaditCardPay : IPay 
    {
        public void Pay(string amount)
        {
            Console.WriteLine("CreaditCardPay:" + amount);
        }
    }

    class CashPay : IPay
    {
        public void Pay(string amount)
        {
            Console.WriteLine("CashPay:" + amount);
        }
    }
--------------------------------------------------------------

    interface ISave
    {
         void Save(string amount);
    }

    class FileSave : ISave
    {
        public void Save(string Message)
        {
            Console.WriteLine("FileSave:" + Message);
        }
    }

    class DBSave : ISave 
    {
       public void Save(string Message)
        {
            Console.WriteLine("DBSave:" + Message);
        }
    }
------------------------------------------------------------------------
  <appSettings>
   
   
 
--------------------------------------------------------------------------
    class PrepareClass
    {
       public IPay createPayer()
        {
            IPay payer = null;
            if (ConfigurationSettings.AppSettings["pay"].Equals("CreaditCard"))
                payer = new CreaditCardPay();
            else
                payer = new CashPay();
            
            return payer;
        }


       public ISave createSaver()
        {
            ISave saver = null;

            if (ConfigurationSettings.AppSettings["log"].Equals("DB"))
                saver = new DBSave();
            else
                saver = new FileSave();

            return saver;

        }
    }
-------------------------------------------------------------------
    class Program
    {
        static void Main(string[] args)
        {
            PrepareClass p = new PrepareClass();
            ISave lg = p.createSaver();
            lg.Save("100$");

            IPay m = p.createPayer();
            m.Pay("100$");

           
        }
    }

3 Mayıs 2017 Çarşamba

How to migrate data from Local SqlServer to the Azure SqlServer DB via SSIS?

If you want to transfer your local SqlServer Data to the azure database you can use SSIS (Sql Server Integration Services). I like SSIS, it is a user friendly way of migration. I tried to explain how to do that below: 

1. SqlServer -> Select your DB -> Right Click-> Tasks -> Export Data



2. Next


3. Select your server and db 

4. Get your Azure Server Name from Azure Databases Page


 5. Write your server name and select your database

In this step you will get the errror below:

Firewall check failed. Cannot open server 'XXXXXXXXX' requested by the login. Client with IP address 'XXXXXXXXX' is not allowed to access the server. To enable access, use the SQL Azure Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.

In that case you need to apply the following steps to add IP of your Azure server to the firewall:

a. Click to "Set Server firewall" in DB page


Write your rule_name, and IP interval in the firewall settings page.

Wait 5 minutes and then try step 5 again.


 6. Next

7. Select the tables you want to migrate


8. Next


That's all :)