Sunday, January 17, 2021

Integrate Salesforce with C# or ASP.NET MVC Application

 This tutorial explains the manual steps to authenticate Salesforce account using C# or ASP.NET MVC application. Even though the sample provided is C# Console application, we have implemented the same with ASP.NET MVC application for RainWorx's AuctionWorx software.

Pre-requisites

1. Salesforce Test Account
2. Visual Studio (C#)

Manual Steps for SalesForce Registration

1.Let's start by creating a new project with name - "SalesForceAuthSample". Open Visual Studio, New Project -> Visual C# -> Windows -> Console Application

img1
Figure 1: Visual Studio > New Project

2. Create Salesforce test acccount.

3. Add references for "DeveloperForce.force" using NuGet Package Manager in your project.

4. For Salesforce Integration, we need following information such as Security Token, Consumer Key, Consumer Secret, Username, Password and IsSandBoxUser.

Security Token: We will get Security Token from the following location - Dropdown with Username located at top right corner > My Settings > Personal > Reset My Security Token. On clicking "Reset Security Token" button , the new Security Token will be sent on registered email address.

img1
Figure 2: Salesforce > Security Token

Consumer Key and Consumer Secret: We will get Consumer Key and Consumer Secret from the following location - Set Up > Create > App > New. Enter all required data. Callback URL is very important for authentication purpose and then Save it.

img1
Figure 3: Salesforce > Consumer Secret and Consumer Key

After saving the API, it will show page similar to screenshot given below.

img1
Figure 4: Salesforce > Apps

Click on Connected App Name and you will get Consumer Secret and Consumer Key.

img1
Figure 5: Salesforce > Connected App Details

Username and Password: The Username and Password will be your test Salesforce account login username and password.

IsSandBoxUser: In code given below, we will set this parameter to "true".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Salesforce.Common;
using Salesforce.Force;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace SalesForceAuthSample
{
    class Program
    {
        private static readonly string SecurityToken = System.Configuration.ConfigurationManager.AppSettings["SecurityToken"];
        private static readonly string ConsumerKey = System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"];
        private static readonly string ConsumerSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"];
        private static readonly string Username = System.Configuration.ConfigurationManager.AppSettings["Username"];
        private static readonly string Password = System.Configuration.ConfigurationManager.AppSettings["Password"];
        private static readonly string IsSandboxUser = System.Configuration.ConfigurationManager.AppSettings["IsSandboxUser"];
        
 
        static void Main(string[] args)
        {
            try
            {
                var task = RunSample();
                task.Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                var innerException = e.InnerException;
                while (innerException != null)
                {
                    Console.WriteLine(innerException.Message);
                    Console.WriteLine(innerException.StackTrace);
                    innerException = innerException.InnerException;
                }
            }
        }
 
       
        private static async Task RunSample()
        {
            try
            {
                var auth = new AuthenticationClient();
                // Authenticate with Salesforce
                Console.WriteLine("Authenticating with Salesforce");
                var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
                    ? "https://login.salesforce.com/services/oauth2/token "
                    : "https://test.salesforce.com/services/oauth2/token";
                await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);
                Console.WriteLine("Connected to Salesforce");
                var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);
                // retrieve all accounts
                Console.WriteLine("Get Accounts");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
 
    }
}

 

In next blog, I will explain about simple CRUD operations which we can perform on Salesforce.
Link - Salesforce CRUD operations using C# in AuctionWorx (ASP.NET MVC application)


Sunday, December 27, 2020

Hadoop Questions and Answers – Spark with Hadoop – 1

 This set of Hadoop Multiple Choice Questions & Answers (MCQs) focuses on ” Spark with Hadoop – 1″.

1. Spark was initially started by ____________ at UC Berkeley AMPLab in 2009.
a) Mahek Zaharia
b) Matei Zaharia
c) Doug Cutting
d) Stonebraker
View Answer

Answer: b
Explanation: Apache Spark is an open-source cluster computing framework originally developed in the AMPLab at UC Berkeley.

2. Point out the correct statement.
a) RSS abstraction provides distributed task dispatching, scheduling, and basic I/O functionalities
b) For cluster manager, Spark supports standalone Hadoop YARN
c) Hive SQL is a component on top of Spark Core
d) None of the mentioned
View Answer

Answer: b
Explanation: Spark requires a cluster manager and a distributed storage system.

3. ____________ is a component on top of Spark Core.
a) Spark Streaming
b) Spark SQL
c) RDDs
d) All of the mentioned
View Answer

Answer: b
Explanation: Spark SQL introduces a new data abstraction called SchemaRDD, which provides support for structured and semi-structured data.

4. Spark SQL provides a domain-specific language to manipulate ___________ in Scala, Java, or Python.
a) Spark Streaming
b) Spark SQL
c) RDDs
d) All of the mentioned
View Answer

Answer: c
Explanation: Spark SQL provides SQL language support, with command-line interfaces and ODBC/JDBC server.

5. Point out the wrong statement.
a) For distributed storage, Spark can interface with a wide variety, including Hadoop Distributed File System (HDFS)
b) Spark also supports a pseudo-distributed mode, usually used only for development or testing purposes
c) Spark has over 465 contributors in 2014
d) All of the mentioned
View Answer

Answer: d
Explanation: Spark is the most active project in the Apache Software Foundation and among Big Data open source projects.

6. ______________ leverages Spark Core fast scheduling capability to perform streaming analytics.
a) MLlib
b) Spark Streaming
c) GraphX
d) RDDs
View Answer

Answer: b
Explanation: Spark Streaming ingests data in mini-batches and performs RDD transformations on those mini-batches of data.

7. ____________ is a distributed machine learning framework on top of Spark.
a) MLlib
b) Spark Streaming
c) GraphX
d) RDDs
View Answer

Answer: a
Explanation: MLlib implements many common machine learning and statistical algorithms to simplify large scale machine learning pipelines.

8. ________ is a distributed graph processing framework on top of Spark.
a) MLlib
b) Spark Streaming
c) GraphX
d) All of the mentioned
View Answer

Answer: c
Explanation: GraphX started initially as a research project at UC Berkeley AMPLab and Databricks, and was later donated to the Spark project.

9. GraphX provides an API for expressing graph computation that can model the __________ abstraction.
a) GaAdt
b) Spark Core
c) Pregel
d) None of the mentioned
View Answer

Answer: c
Explanation: GraphX is used for machine learning.

10. Spark architecture is ___________ times as fast as Hadoop disk-based Apache Mahout and even scales better than Vowpal Wabbit.
a) 10
b) 20
c) 50
d) 100
View Answer

Answer: a
Explanation: Spark architecture has proven scalability to over 8000 nodes in production.

Sanfoundry Global Education & Learning Series – Hadoop.

Lab 09: Publish and subscribe to Event Grid events

  Microsoft Azure user interface Given the dynamic nature of Microsoft cloud tools, you might experience Azure UI changes that occur after t...