Skip to main content

Posts

Showing posts from 2014

Converts a byte array to a string

///   ///   Converts a byte array to a string ///   ///   Byte array to be converted ///   string representation of the byte array private   static   string  byteArrayToString( byte [] arrInput) { StringBuilder  sb =  new   StringBuilder (arrInput.Length * 2); for  ( int  i = 0; i < arrInput.Length; i++) sb.Append(arrInput[i]. ToString( "X2" )); return  sb.ToString().ToUpper(); } private   static   byte [] StringToByteArray( string  textString) { UTF8Encoding  encoding =  new   UTF8Encoding (); return  encoding.GetBytes(textString); }

Serialization

Serialization is a process where an object is converted to a form , able to store and transport to different places. Used for: to store object to hard drive send object over the network [Without serialization the remoting will be impossible] To serialize a class add [Serializable]  attribute in front of the class definition if you dont want to serialize something in this 'serialized' class use [NonSerialized]  before it Note: properties are not serialized To store the data of a class into a file in binary format     Store myStore = new Store(); // create object of a class to be serialized     myStore.stockCount = 50; // pass value to the variable     FileStream flStream = new FileStream("MyStore.dat", FileMode.OpenOrCreate, FileAccess.Write);     try     {         BinaryFormatter binFormatter = new BinaryFormatter(); //to store the data to a file in binary format.         binFormatter.Serialize( flStream, myStore);        //Seralize method stores the dat

Random Notes

Infragistic controls / 3rd party controls are slow. bcos they have additional properties .. they need time to load which can slow a website. By replacing these conrols by user deigned .net controls  we made the websit faster frm 3.3 seconds to 2 sec.  also redesign the pages to have better look and feel SQL profiler is used to see the performance of a sql script. By % how much time taken by what To return 2 values from a method... 1 can be returned by normal process, other by reference SQL also has an Execution palnner -> (Query->include execution planner ) Ctrl + M to get the current user of the system -  @System.Security.Principal.WindowsIdentity.GetCurrent().Name;

Create a Maintainance Plan on SQL

- There are two ways to create a maintenance plan: you can create a plan using the Maintenance Plan Wizard, or you can create a plan using the design surface. The Wizard is best for creating basic maintenance plans, while creating a plan using the design surface allows you to utilize enhanced workflow. To create or manage Maintenance Plans, you must be a member of the sysadmin fixed server role. Note that Object Explorer only displays maintenance plans if the user is a member of the sysadmin fixed server role. The Maintenance Plan Wizard helps you set up the core maintenance tasks to make sure that your database performs well, is regularly backed up, and is free of inconsistencies. The Maintenance Plan Wizard creates one or more SQL Server Agent jobs that perform these tasks on local servers or on target servers in a multiserver environment. Execution can be at scheduled intervals or on demand. Maintenance plans can be created to perform the following tasks: - Reorganize the

WebService - all about it

This is from  4guysfromrolla.com A Web Service is an external interface provided by a Web site that can be called from other Web sites. For example, a financial company may make up to the minute stock quotes available via a Web Service for those who do their trading with that company. This information could be read from a Web page and displayed, or read from a stand-alone application on a customer's desktop computer. my Web Service should provide other Web sites the ability to: 1.      View a listing of all of the FAQ categories 2.      View a listing of all of the FAQs for a particular category 3.      View the "Question" (but not the Answer) for a particular FAQ Creating Web Services is quite simple. Start by creating a  .asmx  file.  The Web Service is created as an ordinary class; the methods that have the   macro before them indicate the method is accessible via the Web Service. For the ASPFAQs.com Web Service, we will create three Web Service-acces

Threading in C#

C# supports parallel execution of code through multithreading A thread is an independent execution path, able to run simultaneously with other thread http://www.albahari.com/ threading/

WCF Basic

WCF - windows communication foundation (.net 3.0) - communication framework - enables us to expose CLR type services and consume exisitng services as CLR types - Different communication technologies in the world - webservices (asmx), web services enhancements(wse), messaging (msmq), .net enterprise services (ES), .net remoting - used for building service oriented applications - eg: websevice for weather - consumes zip code and outputs forecast - wcf service is based on contract ( implemented  as an interface decorated with the attribute [ServiceContractAttribute] ) [ServiceContract] public interface IWeatherForecastService {     [OperationContract]     public WeatherForecast GetForeCast(int zipCode); } - Address : where the service will be found [ServiceContract] public interface IWeatherForecastService {     [OperationContract]     public WeatherForecast GetForeCast(int zipCode); } ABC od WCF - Address: where the service will be found scheme://domaon[:port]/path (e.g.:  http

GetNoOfPagesPDF & Merge

  //public static int  GetNoOfPagesPDF(string  FileName)          //{          //    int result = 0;          //    FileStream fs =  new FileStream(FileName,  FileMode.Open, FileAccess. Read);          //    StreamReader r =  new StreamReader(fs);          //    string pdfText =  r.ReadToEnd();          //    System.Text. RegularExpressions.Regex regx  = new Regex(@"/Type\s*/Page[^ s]");          //    System.Text. RegularExpressions. MatchCollection matches =  regx.Matches(pdfText);          //    result =  matches.Count;          //    return result;          //}   public   void  merge( string   sFile1,  string  sFile2)         {              FileStream  fs1 =  n ull ;              FileStream  fs2 =  n ull ;              try             {                 fs1 =  File . Open(sFile1,  FileMode .Append);                 fs2 =  File . Open(sFile2,  FileMode .Open);                  byte []  fs2Content =  new   byte [fs2. Length];                 fs2.Read( fs2C

Connecting to multiple databases in MVC web application

In your web.config file, you could define your two connection strings: < add name = "DevelopmentDB" providerName = "System.Data. SqlClient" connectionString = "Data Source= sql-dev.example.com ; Initial Catalog=MyDB;User Id=MyUser;Password=MyPassword" /> < add name = "ProductionDB" providerName = "System.Data. SqlClient" connectionString = "Data Source= sql-prod.example.com ; Initial Catalog=MyDB;User Id=MyUser;Password=MyPassword" /> </ connectionStrings > Then, in your (base) controller, you could create a method that returns the appropriate connection string based upon the request, such as: internal string ConnectionString { get { return getConnectionStringByServerNam e ( this . HttpContext . Request . Ser verVariables [ "SERVER_NAME" ]); } } internal string getConnectionStringByServerNam e ( string serverName ) { if

IEnumerator and IEnumerable interfaces in the .NET framework

Enumerators can be an incredibly powerful way of iterating through data. Iterators are also very useful in situations where the amount of data is not easily known at the start of the process. - and for deserialisation of a file The iterator reads the file, calls the necessary factory methods and passes back objects that it have been constructed based on data in the file.  using a while loop accessing the IEnumerator based object directly, and second, using a foreach loop accessing the enumerator through the IEnumerable interface. As enumerators are always initially pointed to just before the first element, this index is set to -1. The Reset() method also sets the current index back to -1. ========================= IEnumerator interface The IEnumerator interface provides iterative capability for a collection that is internal to a class. IEnumerator requires that you implement three methods:     * The MoveNext method, which increments the collection index by 1 and returns a bool that in

Classes and Property Grid

The property grid is fairly easy to use.The hard part is making the class that you want to display in the grid "Property Grid Friendly". 1.  Create public properties for fields you want to expose.  All properties should have  get  and  set  methods.(If you don't have a get method, the property won't show up in the PropertyGrid). 2.  System.ComponentModel  namespace have the following attribute  a.  CategoryAttribute:  This attribute places your property in the appropriate category in a node on the property grid.  b.  DescriptionAttribute:  This attribute places a description of your property at the bottom of the property grid  c.  BrowsableAttribut:  This is used to determine whether or not the property is shown or hidden in the property grid  d.  ReadOnlyAttribute:  Use this attribute to make your property read only inside the property grid  e. DefaultValueAttribute:  Specifies the default value of the property shown in the property grid  f:  DefaultPropertyAttribut

Sp_updatestats

select   B . name as TableName , c . name IndexName , A . OBJECT_ID , avg_fragmentation_in_percent       , ' ALTER INDEX [' + c . name  + '] ON ' + B . name +                 CASE WHEN avg_fragmentation_in_percent >= 40.0                         THEN ' REBUILD'                     WHEN avg_fragmentation_in_percent >= 10.0 AND avg_fragmentation_in_percent < 40.0                         THEN ' REORGANIZE'                   ELSE                         ''                   END AS FixIndexCommand       --,A.* from SYS . objects B JOIN SYS . indexes C ON B . object_id = C . object_id JOIN SYS . dm_db_index_physical_stats ( DB_ID (),NULL,NULL,NULL,NULL) A       ON A . object_id = B . object_id AND A . database_ID = DB_ID ()             AND a . index_id = C . index_id where c . name is not null --and  B.name like 'TableName' and A . avg_fragmentation_in_percent