Friday, June 2, 2017

The "DebugType" parameter is not supported by the "XamlCTask" task. Xamarine Forms Android

If you getting the below error, then follow the solution to fix this.

The "DebugType" parameter is not supported by the "XamlCTask" task. Verify the parameter exists on the task, and it is a settable public instance property. CabPOC01.Android


Solution - Go to the below folder and removed the DebugType = "$(DebugType)" From Xamarin.Forms.targets File

\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20

Thursday, February 16, 2017

Azure Blob file download using API in C#

I am working a large Data Integration application and there was a need to share a large file (250+meg ) with vendor who was working on IPad UI application for our sales team. Vendor technology has some limitation to only get the data throug API layer they were adamant to connect to SFtp/DMZ file share etc.

To solve the above business problem we thought we will host the file in AZure Blob and will expose the file using API.

Setting up the Azure Blob to host the File

1. Create a new storage account using portal.azure.com. Make sure to select "General Purpose" option while creating account account. e.g. "apidemostorageaccount"

2. Create a container in the account. eg "ProjectFileContainer"

Code to upload the file to Azure Blob



   Config file
    <add key="StorageConnection" value="DefaultEndpointsProtocol=https;AccountName=??;AccountKey=??" />
    <add key="StorageContainer" value="projectfilecontainer"/>
    <add key="FileName" value="C:\Temp\Launchpad\CustomerMasterData.csv"/>

Code to download the file from Azure Blob


Step 1- Get Sas url


Step -2 GetBlob object url



Step 3 - Return File blob url from web service


Please note the above web service call will return the url of the file. the file url has to be called within 3 minutes to download the file other wise the file url will expire.



Thursday, January 26, 2017

Creating a list item in Sharepoint List from c#




    <add key="SharePointSIte" value="https://abc.com/sites/ISS/ts/buslead/"/>
    <add key="apiList" value="Business Lead QA list"/>


using Microsoft.SharePoint.Client;

ClientContext clientContext = new ClientContext(siteUrl);
                    SP.List oList = clientContext.Web.Lists.GetByTitle(apiList);

                    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                    ListItem oListItem = oList.AddItem(itemCreateInfo);
                    oListItem["Title"] = lead.LeadName;
                    oListItem["City"] = lead.City;
                    oListItem["Zip_x0020_Code"] = lead.Zip;
                    oListItem["Address_x0020_1"] = lead.Address1;
                   // oListItem["Address_x0020_2"] = lead.Address2;
                    oListItem["Phone_x0020_number"] = lead.UserPhone;
                    oListItem["Email_x0020_Address"] = lead.UserEmail;
                    oListItem["Branch_x0020_Code"] = lead.BranchCode;
                    oListItem["Branch_x0020_Name"] = lead.BranchName;
                    oListItem["FullName"] = lead.UserFullName;
                    oListItem["Notes"] = lead.Remark;
                    oListItem["Business_x0020_contact_x0020_nam"] = lead.LeadContactName;
                    oListItem["Business_x0020_contact_x0020_add"] = lead.LeadContactPhone;
                    oListItem["Business_x0020_contact_x0020_cit"] = lead.LeadContactEmail;
                    oListItem["Business_x0020_contact_x0020_sta"] = lead.LeadAcquisition;

                    oListItem.Update();

                    clientContext.ExecuteQuery();


Monday, November 7, 2016

Encrypting and Decrypting string in c# using System.Security.Cryptography

    Its pretty simple to encrypt and decrypt a string in c#.

using System.Security.Cryptography;
 
static string key = "ABC12@#a"; // you can set any key here.

public string Encrypt(string source, string key)
{
    TripleDESCryptoServiceProvider desCryptoProvider =
new TripleDESCryptoServiceProvider();
    MD5CryptoServiceProvider hashMD5Provider = new MD5CryptoServiceProvider();
    byte[] byteHash;
    byte[] byteBuff;
    byteHash = hashMD5Provider.ComputeHash(Encoding.UTF8.GetBytes(key));
    desCryptoProvider.Key = byteHash;
    desCryptoProvider.Mode = CipherMode.ECB; //CBC, CFB
    byteBuff = Encoding.UTF8.GetBytes(source);
    string encoded =
        Convert.ToBase64String(desCryptoProvider.CreateEncryptor().
TransformFinalBlock(byteBuff, 0, byteBuff.Length));
    return encoded;
}

public static string Decrypt(string encodedText, string key)
{
    TripleDESCryptoServiceProvider desCryptoProvider =
new TripleDESCryptoServiceProvider();
    MD5CryptoServiceProvider hashMD5Provider = new MD5CryptoServiceProvider();
    byte[] byteHash;
    byte[] byteBuff;
    byteHash = hashMD5Provider.ComputeHash(Encoding.UTF8.GetBytes(key));
    desCryptoProvider.Key = byteHash;
    desCryptoProvider.Mode = CipherMode.ECB; //CBC, CFB
    byteBuff = Convert.FromBase64String(encodedText);
    string plaintext = Encoding.UTF8.GetString(desCryptoProvider.
CreateDecryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
    return plaintext;
}

Thursday, October 15, 2015

Data Access Class for .net Apps


A generic data access class for .net apps.



    public class DataAccessClient
    {      
        public DataSet ExecuteStoredProc(string StoredPorc,string ConString,SqlParameter[] Parameters)
        {                     
            DataSet dsResult = new DataSet();
            using (SqlConnection sqlCon = new SqlConnection(ConString))
            {                             
                try
                {                  
                    sqlCon.Open();
                    SqlCommand sqlCmd = sqlCon.CreateCommand();
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.CommandText = StoredPorc;
                    sqlCmd.CommandTimeout = 1200;
                    foreach (SqlParameter Param in Parameters)
                    {
                        sqlCmd.Parameters.Add(Param);
                    }                  
                    SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
                    sqlDa.Fill(dsResult);
                    return dsResult;
                }
                catch (Exception ex)
                {
                    Logger.TextLogger log = new Logger.TextLogger();
                    log.WriteLog(ex.ToString());
                    //return null;
                    throw;
                }
                finally
                {
                    dsResult.Dispose();
                    sqlCon.Close();
                    sqlCon.Dispose();
                }
            }
        }             
        public DataSet ExecuteQuery(string ConString, string Query)
        {
            DataSet dsResult = new DataSet();
            using (SqlConnection sqlCon = new SqlConnection(ConString))
            {
                try
                {
                    sqlCon.Open();
                    using (SqlCommand sqlCmd = sqlCon.CreateCommand())
                    {
                        sqlCmd.CommandType = CommandType.Text;
                        sqlCmd.CommandText = Query;
                        SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
                        sqlDa.Fill(dsResult);
                    }
                    return dsResult;
                }
                catch (Exception ex)
                {
                    Logger.TextLogger log = new Logger.TextLogger();
                    log.WriteLog(ex.ToString());
                   // return null;
                    throw;
                }
                finally
                {
                    dsResult.Dispose();
                    sqlCon.Close();
                    sqlCon.Dispose();
                }
            }
        }
        public bool ExecuteInsertQuery(string Query,string ConnectionString)
        {
            bool isDataInserted = false;
            int insertedRows = 0;
            using (SqlConnection sqlCon = new SqlConnection(ConnectionString))
            {
                try
                {
                    sqlCon.Open();
                    using (SqlCommand sqlCmd = sqlCon.CreateCommand())
                    {
                        sqlCmd.CommandType = CommandType.Text;
                        sqlCmd.CommandText = Query;
                        sqlCmd.CommandTimeout = 1200;
                        insertedRows = sqlCmd.ExecuteNonQuery();
                    }
                    if (insertedRows > 0)
                    {
                        isDataInserted = true;
                    }
                    return isDataInserted;
                }
                catch (Exception ex)
                {
                    Logger.TextLogger log = new Logger.TextLogger();
                    log.WriteLog(ex.ToString());
                   // return false;
                    throw;
                }
                finally
                {
                    sqlCon.Close();
                    sqlCon.Dispose();
                }
            }          
        }
      
        public List<T> ConvertDtToList<T>(DataSet ds)
        {
            DataTable dt = ds.Tables[0];
            List<T> CustomerListData = new List<T>();
            foreach (DataRow row in dt.Rows)
            {
                T item = GetItem<T>(row);
                CustomerListData.Add(item);
            }
            return CustomerListData;
        }
        public T GetItem<T>(DataRow dr)
        {
            Type temp = typeof(T);
            T obj = Activator.CreateInstance<T>();
            foreach (DataColumn column in dr.Table.Columns)
            {
                foreach (PropertyInfo pro in temp.GetProperties())
                {
                    if (pro.Name == column.ColumnName)
                        pro.SetValue(obj, dr[column.ColumnName], null);
                    else
                        continue;
                }
            }
            return obj;
        }      
    }

To call any method


                DataAccessClient client = new DataAccessClient();
                SqlParameter[] Parameters = new SqlParameter[2];
                SqlParameter param1 = new SqlParameter("@Param1", SqlDbType.VarChar, 50);
                param1.Value = value1;
                SqlParameter param2 = new SqlParameter("@Param2", SqlDbType.VarChar, 50);
                ParentHierUniqueCode.Value = value2;
                Parameters[0] = hierType;
                Parameters[1] = ParentHierUniqueCode;
   
                string spname = "Stored Proc Name";
                ds = client.ExecuteStoredProc(spname, connectionstring, Parameters);