7 July 2012

Cloud Computing

Cloud Computing



Cloud computing is the delivery of computing and storage capacity [1] as a service [2] to a heterogeneous community of end-recipients. The name comes from the use of a cloud-shaped symbol[3] as an abstraction for the complex infrastructure it contains in system diagrams[4]. Cloud computing entrusts services with a user's data, software and computation over a network.
There are three types of cloud computing:[5]



Using Infrastructure as a Service, users rent use of servers (as many as needed during the rental period) provided by one or more cloud providers. 
Using Platform as a Service, users rent use of servers and the system software to use in them. 
Using Software as a Service, users also rent application software and databases. The cloud providers manage the infrastructure and platforms on which the applications run.
End users access cloud-based applications through a web browser or a light-weight desktop or mobile app while the business software and user's data are stored on servers at a remote location.
Proponents claim that cloud computing allows enterprises to get their applications up and running faster, with improved manageability and less maintenance, and enables IT to more rapidly adjust resources to meet fluctuating and unpredictable business demand.
Cloud computing relies on sharing of resources to achieve coherence and economies of scale similar to a utility (like theelectricity grid) over a network (typically the Internet). At the foundation of cloud computing is the broader concept of converged infrastructure and shared services.


4 July 2012

CalendarExtender show only years asp.net ajax control

Calendar Extender show only years asp.net ajax control 
reference -> ajaxcontroltoolkit.dll

   < form id="form1" runat="server">
  < ajaxToolkit:ToolkitScriptManager runat="Server" EnableScriptGlobalization="true"
        EnableScriptLocalization="true" ID="ScriptManager1" ScriptMode="Debug" CombineScripts="false" />

<script type="text/javascript" language="javascript">
    function onCalendarShown() {
        var cal = $find("calendar1");
        cal._switchMode("years", true);
        if (cal._yearsBody) {
            for (var i = 0; i < cal._yearsBody.rows.length; i++) {
                var row = cal._yearsBody.rows[i];
                for (var j = 0; j < row.cells.length; j++) {
                    Sys.UI.DomEvent.addHandler(row.cells[j].firstChild, "click", call);
                }
            }
        }
    }

    function onCalendarHidden() {
        var cal = $find("calendar1");
        if (cal._yearsBody) {
            for (var i = 0; i < cal._yearsBody.rows.length; i++) {
                var row = cal._yearsBody.rows[i];
                for (var j = 0; j < row.cells.length; j++) {
                    Sys.UI.DomEvent.removeHandler(row.cells[j].firstChild, "click", call);
                }
            }
        }
    }

    function call(eventElement) {
        var target = eventElement.target;
        switch (target.mode) {
            case "year":
                var cal = $find("calendar1");
                cal.set_selectedDate(target.date);
                cal._blur.post(true);
                cal.raiseDateSelectionChanged(); break;
        }
    }
</script>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" OnClientHidden="onCalendarHidden"  
 OnClientShown="onCalendarShown" Format="yyyy" BehaviorID="calendar1"  TargetControlID="TextBox1">
</ajaxToolkit:CalendarExtender>
</div>
</form>

26 June 2012

To delete the column in sql server


To delete the column in sql server

ALTER TABLE TableName
DROP COLUMN ColumnName



The script for renaming any object (table, sp etc) in Sql Server :


The script for renaming any object (table, sp etc) in Sql Server :


sp_RENAME '[OldTableName]' , '[NewTableName]'




Script for renaming column in table in Sql Server


Script for renaming column in table in Sql Server :

sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'



8 June 2012

Check connection string is valid or not in C#


//Check connection string is valid or not in C#

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace SupportingToolsforCode
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string connectionstring = ConfigurationManager.AppSettings["ConnectionString"];

         ///

        /// check connection string is valid or not
        ///

        ///
        ///
        private void btnCheck_Click(object sender, EventArgs e)
        {
           
           
            if(!(String.IsNullOrEmpty(connectionstring)))
            {
                try
                {

                    //To check using SqlHelper
                    // SqlHelper objSqlHelper = new SqlHelper(connectionstring);

                    using (SqlConnection conn = new SqlConnection(connectionstring))
                    {
                        conn.Open();
                        MessageBox.Show("Connection String is valid");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(Convert.ToString(ex));
                }              
            }

        }
}



Event Viewer read, write and clear in C#

Event Viewer read, write and clear in C#




//Event Viewer read, write and clear in C#

using System;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;

namespace EventViewer
{
    public partial class EventViewer : Form
    {
        public EventViewer()
        {
            InitializeComponent();
        }

     
        ///

        /// Read the Logs from Event Viewer - Application
        ///

        public void ReadLogs()
        {
            //logType can be Application, Security, System or any other Custom Log.
            string logType = "Application";

            DataTable dtable = new DataTable("EventViewer");

            DataColumn column;
            DataRow row;
            int i=0;
            int LastLogToShow = 0;

            // Create new DataColumn, set DataType,
            // ColumnName and add to DataTable.  

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "InstanceID";
            column.ReadOnly = true;

            // Add the Column to the DataColumnCollection.
            dtable.Columns.Add(column);

            // Create new DataColumn, set DataType,
            // ColumnName and add to DataTable.  
            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Source";
            column.ReadOnly = true;
         
            // Add the Column to the DataColumnCollection.
            dtable.Columns.Add(column);

            // Create new DataColumn, set DataType,
            // ColumnName and add to DataTable.  
            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "EntryType";
            column.ReadOnly = true;

            // Add the Column to the DataColumnCollection.
            dtable.Columns.Add(column);

            // Create new DataColumn, set DataType,
            // ColumnName and add to DataTable.  
            column = new DataColumn();
            column.DataType = System.Type.GetType("System.DateTime");
            column.ColumnName = "Date";
            column.ReadOnly = true;

            // Add the Column to the DataColumnCollection.
            dtable.Columns.Add(column);

         
            // Create new DataColumn, set DataType,
            // ColumnName and add to DataTable.  
            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Message";
            column.ReadOnly = true;

            // Add the Column to the DataColumnCollection.
            dtable.Columns.Add(column);


            try
            {

                EventLog ev = new EventLog(logType, System.Environment.MachineName);
                LastLogToShow = ev.Entries.Count;

                if (LastLogToShow <= 0)
                {
                    dgvShow.DataSource = null;
                    MessageBox.Show("No log in the Event Viewer");
                    return;
                }

                             
                for (i = ev.Entries.Count - 1 ; i > 0; i--)
                {
                    EventLogEntry CurrentEntry = ev.Entries[i];

                    row = dtable.NewRow();

                    row["InstanceID"] = CurrentEntry.InstanceId;
                    row["EntryType"] = Convert.ToString(CurrentEntry.EntryType);
                    row["Date"] = Convert.ToDateTime(CurrentEntry.TimeGenerated);
                    row["Source"] = Convert.ToString(CurrentEntry.Source);
                    row["Message"] = Convert.ToString(CurrentEntry.Message);
                   
                    dtable.Rows.Add(row);        
         
           
                }
                ev.Close();


                if (dtable.Rows.Count > 0)
                {

                    dgvShow.DataSource = dtable;

                }
             

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        ///

        /// EventView Click Event - Used to bind the Log message in the grid
        ///

        ///
        ///
        private void btnEventViewer_Click(object sender, EventArgs e)
        {
            ReadLogs();
        }

        ///

        /// Write the log in the Eventviewer
        ///

        void WriteLog()
        {
                 
            try

            {
                //See if the source exists.
                if (!(EventLog.SourceExists("MySystemSource", System.Environment.MachineName)))
                    EventLog.CreateEventSource("MySystemSource", "System", System.Environment.MachineName);

                EventLog ev = new EventLog("System", System.Environment.MachineName, "MySystemSource");
                /* Writing to system log, in the similar way you can write to other
                 * logs that you have appropriate permissions to write to
                 */
                ev.WriteEntry("Warning is written to system Log", EventLogEntryType.Warning, 10001);
                MessageBox.Show("Warning is written to System Log");
                ev.Close();  
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void btnWrite_Click(object sender, EventArgs e)
        {
            WriteLog();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {

          DialogResult result = MessageBox.Show("Are You sure want to Delete","Important Question",MessageBoxButtons.YesNo);

          try
          {

              if (Convert.ToString(result) == "Yes")
              {


                  //Create an EventLog instance and pass log name and MachineName where the log resides.
                  EventLog ev = new EventLog("Security", System.Environment.MachineName);
                  ev.Clear();
                  ev.Close();
              }
          }
          catch (Exception ex)
          {
              throw ex;
          }
       
        }      
     
    }
}



Implementing OAuth validation in a Web API

 I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...