Nop Commerce Gmail Email Setup

March 27, 2020

nopCommerce


This is not nopCommerce issue, all you need to enable 3rd party application to access your gmail account. Follow this steps to fix this:

1. Login to your gmail account.
2. Visit this page https://accounts.google.com/DisplayUnlockCaptcha and click on button to allow access.
3. Visit this page https://www.google.com/settings/security/lesssecureapps and enable access for less secure apps.
4. Login to your nopCommerce admin portal and visit this page http://website_name.com/Admin/EmailAccount/List and click edit  and click to delete the account.
5. Now use following details:
   Email address: youraddress@gmail.com
   E display name: your website name
   Host: smtp.gmail.com
   User: youraddress@gmail.com
   Password: password, remember to click change password button if you are editing any existing account
   SSL: tick to select it
   Use default credentials: uncheck, do not select it
6. Click on save button above.
7. Test the mailing by entering your email id and click on send test email button.
Nop Commerce Gmail Email Setup Nop Commerce Gmail Email Setup Reviewed by Ashwani on March 27, 2020 Rating: 5

Azure Service Bus Vs Azure Web Job

March 25, 2020
Azure Service Bus is a messaging infrastructure that sits between applications allowing them to exchange messages for improved scale and resiliency. It offers the following capabilities:
Queues: offers simple first in, first out guaranteed message delivery.
When to use Azure Service Bus?
Service Bus queues are a general-purpose technology that can be used for a wide variety of scenarios:
  • Communication between web and worker roles in a multi-tier Azure application
  • Communication between on-premises apps and Azure hosted apps in a hybrid solution
  • Communication between components of a distributed application running on-premises in different organizations or departments of an organization
There are also Topics and Relay capabiliteis but we will talk about them in the future.
A figure that illustrates how Azure Service Bus works.
alt
There is a sender who send a message with some properties to the queue and then the queue may do some processing over the message and send it to a receiver.
    public class Program
    {
        public static string SericeBusConnectionString = "service_bus_connection_string";
        public static void Main(string[] args)
        {
            string queueName = "queue_name";
            var namespaceManager = NamespaceManager.CreateFromConnectionString(SericeBusConnectionString);
            if (!namespaceManager.QueueExists(queueName))
            {
                namespaceManager.CreateQueue(queueName);
            }
            QueueClient client = QueueClient.CreateFromConnectionString(SericeBusConnectionString, queueName);
            var message = new BrokeredMessage();
            message.Properties["first_name"] = "Test First Name";
            message.Properties["last_name"] = "Test Last Name";
            client.SendAsync(message);
        }
    }
Don't forget to replace the connection string in the code with your service bus connection string and you replace queue name with anything that can describe what does your queue do.
We can now send message to the service bus but we don't know when will a message be sent, It could be sent at any moment so how can we handle this?
Easy, we can handle that by using Azure WebJob, A webjob is a background service that can either be always running or run on schedule, but in the case of service bus, we will create one which will be running continuously because we never know when will a message be sent.
Let's create a console application that will be uploaded to azure as a webjob writing the code that will receive the service message bus.
    class Program
    {
        static void Main(string[] args)
        {
            string queueName = "queue_name";
            var _servicesBusConn = "servie_bus_connection_string";
            QueueClient client = QueueClient.CreateFromConnectionString(_servicesBusConn, queueName);
            while (true)
            {
                var msg = client.Receive();
                if (msg != null)
                {
                        string fn = msg.Properties["first_name"].ToString();
                        string ln = msg.Properties["last_name"].ToString();
                        string name = fn + " " + ln;
                        Console.WriteLine("Name = " + name);
                        Trace.TraceInformation("Name = " + name);
                        msg.Complete();
                    }
                }
            }
        }
    }
Now, we need to create a zip file for the project binaries to upload as a webjob, It's pretty easy to upload a webjob all what you need to do is uploading and choose run continuously.
Congratulations, You have already created a service bus queue and handled everything you need to.
Here is the sample of sender code and the receiver code.
Azure Service Bus Vs Azure Web Job Azure Service Bus Vs Azure Web Job Reviewed by Ashwani on March 25, 2020 Rating: 5

Store Data in to Micro-Services Static class using c# dot net core (Key Based API for Reduce Database hit)

March 25, 2020
1*KH-i7gZC9UEUELeMhnAugg.jpeg (1024×768)
Find Code From Here : Code

Testing : 1. 1st Time Entry with Null key value and Adding New Value into Class


Testing : 2 . 2nd Time Entry with unique key value and updating existing entry into Class


Testing : 3. Same Time Another Hit Came From different User for for update Data 



Testing 4: If Step is 4 then we are inserting data into our database and Deleting data from class


using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace AppForStaticCls.Controllers
{
    [Route("api/[controller]")]
    public class MutiplePostController : Controller
    {
        // GET: api/<controller>
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }


        // POST api/<controller>
        [HttpPost]
        public List<TestDataRes> Post(string key, string step, string name, string address, string country)
        {
            string newKey = "";
            List<TestDataRes> testDataResList = new List<TestDataRes>();
            if (TestData.count == 0)
            {
                newKey = Guid.NewGuid().ToString();
                DataColumn nme = new DataColumn("name");
                DataColumn adrs = new DataColumn("address");
                DataColumn cntry = new DataColumn("country");
                DataColumn createdDate = new DataColumn("dateTime");
                DataColumn dtKey = new DataColumn("key");

                TestData.Dt = new DataTable();
                TestData.Dt.Columns.Add(nme);
                TestData.Dt.Columns.Add(adrs);
                TestData.Dt.Columns.Add(cntry);
                TestData.Dt.Columns.Add(createdDate);

                TestData.Dt.Columns.Add(dtKey);
                TestData.count = TestData.count + 1;

                DataRow row = TestData.Dt.NewRow();
                row["key"] = newKey;
                row["dateTime"] = DateTime.Now;
                TestData.Dt.Rows.Add(row);
                UpdateData(newKey, name, address, country);
            }
            else
            {
                if (!UpdateData(key, name, address, country))
                {
                    newKey = Guid.NewGuid().ToString();
                    DataRow row = TestData.Dt.NewRow();
                    row["dateTime"] = DateTime.Now;
                    row["key"] = newKey;
                    TestData.Dt.Rows.Add(row);
                    UpdateData(newKey, name, address, country);
                }
            }
            if (step == "4")
            {
                //will call database
                IEnumerable<DataRow> rows = TestData.Dt.Rows.Cast<DataRow>().Where(r => r["key"].ToString() == key);
                rows.ToList().ForEach(r => r.Delete());
            }
            if (key != null)
            {
                testDataResList = AddData(key);
            }
            else
            {
                testDataResList = AddData(newKey);
            }
            Flush();
            return testDataResList;
        }


        public bool Flush()
        {
            IEnumerable<DataRow> rows = TestData.Dt.Rows.Cast<DataRow>().Where(r => Convert.ToDateTime(r["dateTime"]) <= DateTime.Now.AddMinutes(-30));
            rows.ToList().ForEach(r => r.Delete());
            return true;
        }

        public List<TestDataRes> AddData(string key)
        {
            List<TestDataRes> testDataResList = new List<TestDataRes>();

            foreach (DataRow item in TestData.Dt.Rows.Cast<DataRow>().Where(r => r["key"].ToString() == key))
            {
                testDataResList.Add(new TestDataRes { name = item["name"].ToString(), address = item["address"].ToString(), country = item["country"].ToString(), key = key });
            }
            return testDataResList;
        }

        public bool UpdateData(string Key, string name, string address, string country)
        {
            if (!string.IsNullOrEmpty(Key))
            {
                IEnumerable<DataRow> rows = TestData.Dt.Rows.Cast<DataRow>().Where(r => r["key"].ToString() == Key);

                if (!string.IsNullOrEmpty(name))
                {
                    rows.ToList().ForEach(r => r.SetField("name", name));
                }
                if (!string.IsNullOrEmpty(address))
                {
                    rows.ToList().ForEach(r => r.SetField("address", address));
                }
                if (!string.IsNullOrEmpty(country))
                {
                    rows.ToList().ForEach(r => r.SetField("country", country));
                }
                return true;
            }
            else
            {
                return false;
            }
        }

    }



    public static class TestData
    {
        public static DataTable Dt { get; set; }
        public static int count { get; set; }
    }
    public class TestDataRes
    {
        public string name { get; set; }
        public string address { get; set; }
        public string country { get; set; }
        public string key { get; set; }

    }
}

Store Data in to Micro-Services Static class using c# dot net core (Key Based API for Reduce Database hit) Store Data in  to Micro-Services Static class using c# dot net core (Key Based API for Reduce Database hit) Reviewed by Ashwani on March 25, 2020 Rating: 5

SQL Large File Execution from CMD

March 14, 2020
DBSERVER


sqlcmd -s DatabaseServerName -i FilePath

SQL Large File Execution from CMD SQL Large File Execution from CMD Reviewed by Ashwani on March 14, 2020 Rating: 5

Convert Nested XML to C# class object and C# Class object to Nested XML File

December 18, 2019

Convert Nested XML to C# class object and C# Class object to Nested XML File

  • Introduction
In this Article we learn how to deserialize XML to C# objects and reverse from C# objects to XML files. In this article we will do practical with example with demo class and xml files.

using System;
using System.Collections;
using System.IO;
using System.Xml.Serialization;

namespace TestApp
{
    public class Serializer
    {     
        public T Deserialize<T>(string input) where T : class
        {
            System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(T));

            using (StringReader sr = new StringReader(input))
            {
                return (T)ser.Deserialize(sr);
            }
        }

        public string Serialize<T>(T ObjectToSerialize)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(ObjectToSerialize.GetType());

            using (StringWriter textWriter = new StringWriter())
            {
                xmlSerializer.Serialize(textWriter, ObjectToSerialize);
                return textWriter.ToString();
            }
        }
    }
}
Convert Nested XML to C# class object and C# Class object to Nested XML File Convert Nested XML to C# class object and C# Class object to Nested XML File Reviewed by Ashwani on December 18, 2019 Rating: 5
Powered by Blogger.