Tuesday, May 28, 2019

How to encrypt in C# and decrypt in Apex


public class Program
{
private static byte[] cryptkey = Encoding.ASCII.GetBytes("01234567890123456789abcdefabcdef");
private static byte[] initVector = Encoding.ASCII.GetBytes("0123456789012359");
public static void Main()
{
var testo1 = "test";
var testo2 = "pippo\n";
string value = CryptAES(testo1);
Console.WriteLine("Crittare '{0}' produce: {1}", testo1, CryptAES(testo1));
Console.WriteLine("Crittare '{0}' produce: {1}", testo2, CryptAES(testo2));
Console.ReadLine();
}
public static string DecryptAES(string cipherData)
{
try
{
using (var rijndaelManaged =
new RijndaelManaged { Key = cryptkey, IV = initVector, Mode = CipherMode.CBC })
using (var memoryStream =
new MemoryStream(Convert.FromBase64String(cipherData)))
using (var cryptoStream =
new CryptoStream(memoryStream,
rijndaelManaged.CreateDecryptor(cryptkey, initVector),
CryptoStreamMode.Read))
{
return new StreamReader(cryptoStream).ReadToEnd();
}
}
catch (CryptographicException e)
{
Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
return null;
}
}
public static string CryptAES(string textToCrypt)
{
try
{
using (var rijndaelManaged =
new RijndaelManaged { Key = cryptkey, IV = initVector, Mode = CipherMode.CBC })
using (var memoryStream = new MemoryStream())
using (var cryptoStream =
new CryptoStream(memoryStream,
rijndaelManaged.CreateEncryptor(cryptkey, initVector),
CryptoStreamMode.Write))
{
using (var ws = new StreamWriter(cryptoStream))
{
ws.Write(textToCrypt);
}
return Convert.ToBase64String(memoryStream.ToArray());
}
}
catch (CryptographicException e)
{
Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
return null;
}
}
}


Thursday, March 28, 2019

LINQ TO ENTITY: Removing special characters inside the “where” expression


IEnumerable<Person> personsList = (from person in repoPersons.All()
         where person.Phone.Replace("+", "").Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "").Contains(PhoneNumber)
         select person).ToList()

Thursday, November 15, 2018

System.ComponentModel.Win32Exception: The specified service already exists

Installing windows service fails: service already exists
connected answer finally pointed Maine within the right direction (why I did not realize that in Google or SO's own search i do not know). Anyway, apparently the Designer.cs generated by Visual Studio additionally creates a process- and service-installer. that in fact install services with an equivalent name as my manually created installers. Removing my very own installers resolved the matter.

Tuesday, August 7, 2018

all countrys list

<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antigua & Barbuda">Antigua & Barbuda</option>
<option value="Argentina">Argentina</option>
<option value="Armenia">Armenia</option>
<option value="Aruba">Aruba</option>
<option value="Australia">Australia</option>
<option value="Austria">Austria</option>
<option value="Azerbaijan">Azerbaijan</option>
<option value="Bahamas, The">Bahamas, The</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Barbados">Barbados</option>
<option value="Belarus">Belarus</option>
<option value="Belgium">Belgium</option>
<option value="Belize">Belize</option>
<option value="Benin">Benin</option>
<option value="Bermuda">Bermuda</option>
<option value="Bhutan">Bhutan</option>
<option value="Bolivia">Bolivia</option>
<option value="Bosnia & Herzegovina">Bosnia & Herzegovina</option>
<option value="Botswana">Botswana</option>
<option value="Brazil">Brazil</option>
<option value="British Virgin Is.">British Virgin Is.</option>
<option value="Brunei">Brunei</option>
<option value="Bulgaria">Bulgaria</option>
<option value="Burkina Faso">Burkina Faso</option>
<option value="Burma">Burma</option>
<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>
<option value="Cameroon">Cameroon</option>
<option value="Canada">Canada</option>
<option value="Cape Verde">Cape Verde</option>
<option value="Cayman Islands">Cayman Islands</option>
<option value="Central African Rep.">Central African Rep.</option>
<option value="Chad">Chad</option>
<option value="Chile">Chile</option>
<option value="China">China</option>
<option value="Colombia">Colombia</option>
<option value="Comoros">Comoros</option>
<option value="Congo, Dem. Rep.">Congo, Dem. Rep.</option>
<option value="Congo, Repub. of the">Congo, Repub. of the</option>
<option value="Cook Islands">Cook Islands</option>
<option value="Costa Rica">Costa Rica</option>
<option value="Cote d'Ivoire">Cote d'Ivoire</option>
<option value="Croatia">Croatia</option>
<option value="Cuba">Cuba</option>
<option value="Cyprus">Cyprus</option>
<option value="Czech Republic">Czech Republic</option>
<option value="Denmark">Denmark</option>
<option value="Djibouti">Djibouti</option>
<option value="Dominica">Dominica</option>
<option value="Dominican Republic">Dominican Republic</option>
<option value="East Timor">East Timor</option>
<option value="Ecuador">Ecuador</option>
<option value="Egypt">Egypt</option>
<option value="El Salvador">El Salvador</option>
<option value="Equatorial Guinea">Equatorial Guinea</option>
<option value="Eritrea">Eritrea</option>
<option value="Estonia">Estonia</option>
<option value="Ethiopia">Ethiopia</option>
<option value="Faroe Islands">Faroe Islands</option>
<option value="Fiji">Fiji</option>
<option value="Finland">Finland</option>
<option value="France">France</option>
<option value="French Guiana">French Guiana</option>
<option value="French Polynesia">French Polynesia</option>
<option value="Gabon">Gabon</option>
<option value="Gambia, The">Gambia, The</option>
<option value="Gaza Strip">Gaza Strip</option>
<option value="Georgia">Georgia</option>
<option value="Germany">Germany</option>
<option value="Ghana">Ghana</option>
<option value="Gibraltar">Gibraltar</option>
<option value="Greece">Greece</option>
<option value="Greenland">Greenland</option>
<option value="Grenada">Grenada</option>
<option value="Guadeloupe">Guadeloupe</option>
<option value="Guam">Guam</option>
<option value="Guatemala">Guatemala</option>
<option value="Guernsey">Guernsey</option>
<option value="Guinea">Guinea</option>
<option value="Guinea-Bissau">Guinea-Bissau</option>
<option value="Guyana">Guyana</option>
<option value="Haiti">Haiti</option>
<option value="Honduras">Honduras</option>
<option value="Hong Kong">Hong Kong</option>
<option value="Hungary">Hungary</option>
<option value="Iceland">Iceland</option>
<option value="India">India</option>
<option value="Indonesia">Indonesia</option>
<option value="Iran">Iran</option>
<option value="Iraq">Iraq</option>
<option value="Ireland">Ireland</option>
<option value="Isle of Man">Isle of Man</option>
<option value="Israel">Israel</option>
<option value="Italy">Italy</option>
<option value="Jamaica">Jamaica</option>
<option value="Japan">Japan</option>
<option value="Jersey">Jersey</option>
<option value="Jordan">Jordan</option>
<option value="Kazakhstan">Kazakhstan</option>
<option value="Kenya">Kenya</option>
<option value="Kiribati">Kiribati</option>
<option value="Korea, North">Korea, North</option>
<option value="Korea, South">Korea, South</option>
<option value="Kuwait">Kuwait</option>
<option value="Kyrgyzstan">Kyrgyzstan</option>
<option value="Laos">Laos</option>
<option value="Latvia">Latvia</option>
<option value="Lebanon">Lebanon</option>
<option value="Lesotho">Lesotho</option>
<option value="Liberia">Liberia</option>
<option value="Libya">Libya</option>
<option value="Liechtenstein">Liechtenstein</option>
<option value="Lithuania">Lithuania</option>
<option value="Luxembourg">Luxembourg</option>
<option value="Macau">Macau</option>
<option value="Macedonia">Macedonia</option>
<option value="Madagascar">Madagascar</option>
<option value="Malawi">Malawi</option>
<option value="Malaysia">Malaysia</option>
<option value="Maldives">Maldives</option>
<option value="Mali">Mali</option>
<option value="Malta">Malta</option>
<option value="Marshall Islands">Marshall Islands</option>
<option value="Martinique">Martinique</option>
<option value="Mauritania">Mauritania</option>
<option value="Mauritius">Mauritius</option>
<option value="Mayotte">Mayotte</option>
<option value="Mexico">Mexico</option>
<option value="Micronesia, Fed. St.">Micronesia, Fed. St.</option>
<option value="Moldova">Moldova</option>
<option value="Monaco">Monaco</option>
<option value="Mongolia">Mongolia</option>
<option value="Montserrat">Montserrat</option>
<option value="Morocco">Morocco</option>
<option value="Mozambique">Mozambique</option>
<option value="Namibia">Namibia</option>
<option value="Nauru">Nauru</option>
<option value="Nepal">Nepal</option>
<option value="Netherlands">Netherlands</option>
<option value="Netherlands Antilles">Netherlands Antilles</option>
<option value="New Caledonia">New Caledonia</option>
<option value="New Zealand">New Zealand</option>
<option value="Nicaragua">Nicaragua</option>
<option value="Niger">Niger</option>
<option value="Nigeria">Nigeria</option>
<option value="N. Mariana Islands">N. Mariana Islands</option>
<option value="Norway">Norway</option>
<option value="Oman">Oman</option>
<option value="Pakistan">Pakistan</option>
<option value="Palau">Palau</option>
<option value="Panama">Panama</option>
<option value="Papua New Guinea">Papua New Guinea</option>
<option value="Paraguay">Paraguay</option>
<option value="Peru">Peru</option>
<option value="Philippines">Philippines</option>
<option value="Poland">Poland</option>
<option value="Portugal">Portugal</option>
<option value="Puerto Rico">Puerto Rico</option>
<option value="Qatar">Qatar</option>
<option value="Reunion">Reunion</option>
<option value="Romania">Romania</option>
<option value="Russia">Russia</option>
<option value="Rwanda">Rwanda</option>
<option value="Saint Helena">Saint Helena</option>
<option value="Saint Kitts & Nevis">Saint Kitts & Nevis</option>
<option value="Saint Lucia">Saint Lucia</option>
<option value="St Pierre & Miquelon">St Pierre & Miquelon</option>
<option value="Saint Vincent and the Grenadines">Saint Vincent and the Grenadines</option>
<option value="Samoa">Samoa</option>
<option value="San Marino">San Marino</option>
<option value="Sao Tome & Principe">Sao Tome & Principe</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Senegal">Senegal</option>
<option value="Serbia">Serbia</option>
<option value="Seychelles">Seychelles</option>
<option value="Sierra Leone">Sierra Leone</option>
<option value="Singapore">Singapore</option>
<option value="Slovakia">Slovakia</option>
<option value="Slovenia">Slovenia</option>
<option value="Solomon Islands">Solomon Islands</option>
<option value="Somalia">Somalia</option>
<option value="South Africa">South Africa</option>
<option value="Spain">Spain</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="Sudan">Sudan</option>
<option value="Suriname">Suriname</option>
<option value="Swaziland">Swaziland</option>
<option value="Sweden">Sweden</option>
<option value="Switzerland">Switzerland</option>
<option value="Syria">Syria</option>
<option value="Taiwan">Taiwan</option>
<option value="Tajikistan">Tajikistan</option>
<option value="Tanzania">Tanzania</option>
<option value="Thailand">Thailand</option>
<option value="Togo">Togo</option>
<option value="Tonga">Tonga</option>
<option value="Trinidad & Tobago">Trinidad & Tobago</option>
<option value="Tunisia">Tunisia</option>
<option value="Turkey">Turkey</option>
<option value="Turkmenistan">Turkmenistan</option>
<option value="Turks & Caicos Is">Turks & Caicos Is</option>
<option value="Tuvalu">Tuvalu</option>
<option value="Uganda">Uganda</option>
<option value="Ukraine">Ukraine</option>
<option value="United Arab Emirates">United Arab Emirates</option>
<option value="United Kingdom">United Kingdom</option>
<option value="United States">United States</option>
<option value="Uruguay">Uruguay</option>
<option value="Uzbekistan">Uzbekistan</option>
<option value="Vanuatu">Vanuatu</option>
<option value="Venezuela">Venezuela</option>
<option value="Vietnam">Vietnam</option>
<option value="Virgin Islands">Virgin Islands</option>
<option value="Wallis and Futuna">Wallis and Futuna</option>
<option value="West Bank">West Bank</option>
<option value="Western Sahara">Western Sahara</option>
<option value="Yemen">Yemen</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>

Thursday, January 18, 2018

How to create Web api And consuming web api in asp.net mvc application using http client

How to create api service in asp.net mvc

public class Student
        {
            public int studentId{get;set;}
            public string studentName{set;get;}

       }
public class StudentController : ApiController
    {

List<Student> _studentList=new List<Student>(){new Student(){ studentId=1, studentName=”A”}, new Student(){ studentId=2, studentName=”B”} };
     
        [Route("api/methodname")]
        [AcceptVerbs("GET")]
        public HttpResponseMessage GET()
        {
            ResponseModel responseStatus;
            try
            {
                return Request.CreateResponse(HttpStatusCode.OK, _studentList);       
            }
            catch (Exception ex)
            {
            }
        }

        public HttpResponseMessage GET(int studentId)
        {
             

         Student student=_studentList.FirstOrDefault(x=>x.studentId==studentId);
            if(student!=null)
             return Request.CreateResponse(HttpStatusCode.OK,student);       
           else
             return Request.CreateResponse(HttpStatusCode. NotFound
, null);       


        }

        [Route("api/Edit")]
        [AcceptVerbs("PUT")]
        public HttpResponseMessage PUT(int studentId,[FromBody]Student studentDetails)
        {
           
              Student student=_studentList.FirstOrDefault(x=>x.studentId==studentId);
            if(student!=null)
{
      student.studentName= studentDetails.studentName;

return Request.CreateResponse(HttpStatusCode.OK,student);       
}
 else
             return Request.CreateResponse(HttpStatusCode. NotFound
, null);       
            

        }
        [Route("api/Delete")]
        [AcceptVerbs("DELETE")]
        public HttpResponseMessage Delete (int studentId)
        {
           _studentList.Remove(studentList.FirstOrDefault(x=>x.studentId== studentId));
   return Request.CreateResponse(HttpStatusCode.OK,null);       

        }
[Route("api/POST")]
        [AcceptVerbs("POST")]
        public HttpResponseMessage POST(Student student)
        {
          //add syntax
           int i=1 //success
return Request.CreateResponse(HttpStatusCode.OK,null);       
 i=0 // insert fail
return Request.CreateResponse(HttpStatusCode.OK,i);       

        }

    }

How to consuming web api in asp.net mvc application using http client

                HttpClient client = new HttpClient();
                HttpResponseMessage response = new HttpResponseMessage();
                client.BaseAddress = new Uri(Uri);//api url ex: http://localhost:2454/api/
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
               
var result = client.GetAsync(“Get”).Result; //method name
if(result. IsSuccessStatusCode)
{
Var data = response.Content.ReadAsAsync<Student>().Result; //model class name : model type
}


//post and delete next session-- minor mistakes

Wednesday, January 10, 2018

Resolved :Failed to register URL "http://localhost:6264/" for site "Solution name(1)" application "/". Error description: Access is denied. (0x80070005)


Resolved[Resolved]
if you get an error like this while running Vs2012 project
Failed to register address "http://:/" for website "" application "/".
Error description: Access is denied. (0x80070005)
Solution
Open command prompt and run the following command as administrator
netsh http add urlacl url=http://localhost:6162/ user=everyone
Project answer > Properties > amendment Port range and make... njoyyyyyy

Tuesday, December 26, 2017

Remove last comma in a string c# WinForms

string Something = "1,5,12,34,";
Something = Something.TrimEnd(','); 

Friday, December 22, 2017

List of Entities to Datatable - Convert Entity List to DataTable

1). public static DataTable ConvertToDatatable<T>(List<T> data)
        {
            PropertyDescriptorCollection props =
                TypeDescriptor.GetProperties(typeof(T));
            DataTable table = new DataTable();
            for (int i = 0; i < props.Count; i++)
            {
                PropertyDescriptor prop = props[i];
                if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
                    table.Columns.Add(prop.Name, prop.PropertyType.GetGenericArguments()[0]);
                else
                    table.Columns.Add(prop.Name, prop.PropertyType);
            }
            object[] values = new object[props.Count];
            foreach (T item in data)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = props[i].GetValue(item);
                }
                table.Rows.Add(values);
            }
            return table;

        }

2). var table = entities.Select(x => new
                {
                    x.Id,
                    Contact = x.Contact.Name,
                    Address = x.Address.Address
                }).CopyToDataTable();
                

Emi calculation formula

Open Ms-Excel And type =PMT(1.3325,48,410000)

Red - interest rate 15.99% = 1.3325

black- 4 years = 48 months 

blue  -410000 - amount 

Tuesday, December 19, 2017

Sql Server Single User To Multi User

Step 1: select d.name, d.dbid, spid, login_time, nt_domain, nt_username, loginame
from sysprocesses p inner join sysdatabases d on p.dbid = d.dbid
where d.name = 'DBName'
go


Step 2: kill 122--(SpId)--spid

Step 3:ALTER DATABASE DBName

       SET MULTI_USER