public T GetRecordType <T>(string recordTypeName, string sObjectType)
        {
            var recordType = Activator.CreateInstance <T>();

            try
            {
                String connectionString = SalesforceCxn.SalesforceConnectionString();
                string sql =
                    String.Format("SELECT Id, Name,SobjectType FROM RecordType where Name='{0}' and SobjectType = '{1}'",
                                  recordTypeName, sObjectType);


                using (SalesforceConnection connection = new SalesforceConnection(connectionString))
                {
                    SalesforceCommand cmd = new SalesforceCommand(sql, connection);

                    SalesforceDataReader rdr = cmd.ExecuteReader();
                    recordType = SfdcReflectionUtil.PopulateBaseModelFromReader <T>(rdr);
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", String.Format(MethodBase.GetCurrentMethod().Name + " method failed in SalesforceContext class") + "\n" + ex);
                throw;
            }
            return(recordType);
        }
        public T CreateJobForBatchInSalesforce <T>(string salesforceObjectName, string action, string concurrency)
        {
            var salesforceBulkJob = Activator.CreateInstance <T>();

            try
            {
                String connectionString = SalesforceCxn.SalesforceConnectionString();

                using (SalesforceConnection connection = new SalesforceConnection(connectionString))
                {
                    SalesforceCommand cmd = new SalesforceCommand("CreateJob", connection);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SalesforceParameter("@ObjectName", salesforceObjectName)); //ex. "Account"
                    cmd.Parameters.Add(new SalesforceParameter("@Action", action));                   // ex. "Insert"
                    cmd.Parameters.Add(new SalesforceParameter("@ConcurrencyMode", concurrency));     // ex. "Serial"
                    cmd.Parameters.Add(new SalesforceParameter("@ExternalIdColumn", ""));

                    SalesforceDataReader rdr = cmd.ExecuteReader();
                    salesforceBulkJob = SfdcReflectionUtil.PopulateBaseModelFromReader <T>(rdr);
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", String.Format(MethodBase.GetCurrentMethod().Name + " method failed in SalesforceContext class") + "\n" + ex);
                throw;
            }
            return(salesforceBulkJob);
        }
        public List <SfVirtualParentChildAccount> GetVirtualAccountParentChildList(string customerRecordTypeId, string virtualRecordTypeId)
        {
            List <SfVirtualParentChildAccount> sfVirtualParentAcctList = new List <SfVirtualParentChildAccount>();

            try
            {
                String connectionString = SalesforceCxn.SalesforceConnectionString();
                var    sql =
                    "SELECT Id, Name, ParentId FROM Account WHERE ParentId <> '' AND Account.IsDeleted = 'False' AND Account.RecordTypeId in('" + customerRecordTypeId + "', '" + virtualRecordTypeId + "') ORDER BY Name ";
                using (SalesforceConnection connection = new SalesforceConnection(connectionString))
                {
                    SalesforceCommand cmd = new SalesforceCommand(sql, connection);

                    SalesforceDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        SfVirtualParentChildAccount sfVirtualParentChildAcct = new SfVirtualParentChildAccount();
                        sfVirtualParentChildAcct.AccountName = rdr["Name"].ToString();
                        sfVirtualParentChildAcct.SfIdAccount = rdr["Id"].ToString();
                        sfVirtualParentChildAcct.SfIdParent  = rdr["ParentId"].ToString();

                        sfVirtualParentChildAcct = GetParentInfo(sfVirtualParentChildAcct);

                        sfVirtualParentAcctList.Add(sfVirtualParentChildAcct);
                    }

                    return(sfVirtualParentAcctList);
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", String.Format(MethodBase.GetCurrentMethod().Name + " method failed in SalesforceContext class") + "\n" + ex);
                throw;
            }
        }
        public static SfVirtualParentChildAccount GetParentInfo(SfVirtualParentChildAccount childAcct)
        {
            try
            {
                String connectionString = SalesforceCxn.SalesforceConnectionString();

                using (SalesforceConnection connection = new SalesforceConnection(connectionString))
                {
                    SalesforceCommand cmd = new SalesforceCommand("SELECT Account.Name, Account.CCAN__c , Record_type_Name__c FROM Account Where Id = " + childAcct.SfIdParent, connection);

                    SalesforceDataReader rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        childAcct.ParentAccountName = rdr["Name"].ToString();
                        if (!string.IsNullOrEmpty(rdr["CCAN__c"].ToString()))
                        {
                            childAcct.Ccan = Convert.ToDecimal(rdr["CCAN__c"].ToString());
                        }
                        childAcct.ParentRecordType = rdr["Record_type_Name__c"].ToString();
                    }

                    return(childAcct);
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", String.Format(MethodBase.GetCurrentMethod().Name + " method failed in SalesforceContext class") + "\n" + ex);
                throw;
            }
        }
        public T CloseJobInSalesforce <T>(string jobId)
        {
            var jobDetails = Activator.CreateInstance <T>();

            try
            {
                String connectionString = SalesforceCxn.SalesforceConnectionString();

                using (SalesforceConnection connection = new SalesforceConnection(connectionString))
                {
                    SalesforceCommand cmd = new SalesforceCommand("CloseJob", connection);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SalesforceParameter("@jobId", jobId));

                    SalesforceDataReader rdr = cmd.ExecuteReader();
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", String.Format(MethodBase.GetCurrentMethod().Name + " method failed in SalesforceContext class") + "\n" + ex);
                throw;
            }


            return(jobDetails);
        }
        public List <T> GetAllLeaseAssignmentsToVirtual <T>(string recordTypeId)
        {
            List <T> vLeaseList = new List <T>();

            try
            {
                String connectionString = SalesforceCxn.SalesforceConnectionString();

                using (SalesforceConnection connection = new SalesforceConnection(connectionString))
                {
                    SalesforceCommand cmd = new SalesforceCommand("SELECT  Lease__c.Name, Lease__c.Id, Account.Name AS AccountName, Account.Id AS AccountId FROM Lease__c, Account WHERE Account.Id = Lease__c.Contract_Customer__c AND (Account.RecordTypeId = " + recordTypeId + ") AND (Lease__c.IsDeleted = 'False')", connection);

                    SalesforceDataReader rdr = cmd.ExecuteReader();

                    vLeaseList = SfdcReflectionUtil.PopulateListFromReader <T>(rdr);
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", String.Format(MethodBase.GetCurrentMethod().Name + " method failed in SalesforceContext class") + "\n" + ex);
                throw;
            }

            return(vLeaseList);
        }
        public T GetJobFromSalesforce <T>(string jobId)
        {
            var salesforceBulkJob = Activator.CreateInstance <T>();


            try
            {
                String connectionString = SalesforceCxn.SalesforceConnectionString();
                using (SalesforceConnection connection = new SalesforceConnection(connectionString))
                {
                    SalesforceCommand cmd = new SalesforceCommand("GetJob", connection);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SalesforceParameter("@jobId", jobId));

                    SalesforceDataReader rdr = cmd.ExecuteReader();
                    salesforceBulkJob = SfdcReflectionUtil.PopulateBaseModelFromReader <T>(rdr);
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", String.Format(MethodBase.GetCurrentMethod().Name + " method failed in SalesforceContext class") + "\n" + ex);
                throw;
            }

            return(salesforceBulkJob);
        }
        public List <T> GetSalesforceRecords <T>(string sql)
        {
            List <T> recordList = new List <T>();

            try
            {
                String connectionString = SalesforceCxn.SalesforceConnectionString();

                using (SalesforceConnection connection = new SalesforceConnection(connectionString))
                {
                    SalesforceCommand cmd = new SalesforceCommand(sql, connection);

                    SalesforceDataReader rdr = cmd.ExecuteReader();

                    recordList = SfdcReflectionUtil.PopulateListFromReader <T>(rdr);
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", String.Format(MethodBase.GetCurrentMethod().Name + " method failed in SalesforceContext class") + "\n" + ex);
                throw;
            }

            return(recordList);
        }
        public TT GetSalesforceBulkBatchResult <TT, T>(string jobId, string batchId)
            where TT : BaseModelList <T>
            where T : BaseModel
        {
            try
            {
                String connectionString = SalesforceCxn.SalesforceConnectionString();

                using (SalesforceConnection connection = new SalesforceConnection(connectionString))
                {
                    SalesforceCommand cmd = new SalesforceCommand("GetBatchResults", connection);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SalesforceParameter("@JobId", jobId));
                    cmd.Parameters.Add(new SalesforceParameter("@BatchId", batchId));

                    SalesforceDataReader rdr = cmd.ExecuteReader();

                    var salesforceBulkBatchResults = SfdcReflectionUtil.PopulateBaseModelListFromReader <TT, T>(rdr);
                    return(salesforceBulkBatchResults);
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", String.Format(MethodBase.GetCurrentMethod().Name + " method failed in SalesforceContext class") + "\n" + ex);
                throw;
            }
        }
        public TT GetRecordTypesFromSalesforce <TT, T>()
            where TT : BaseModelList <T>
            where T : BaseModel
        {
            try
            {
                String connectionString = SalesforceCxn.SalesforceConnectionString();
                string sql =
                    String.Format("SELECT Id, Name,SobjectType FROM RecordType");

                using (SalesforceConnection connection = new SalesforceConnection(connectionString))
                {
                    SalesforceCommand    cmd = new SalesforceCommand(sql, connection);
                    SalesforceDataReader rdr = cmd.ExecuteReader();

                    var sfRecordTypes = SfdcReflectionUtil.PopulateBaseModelListFromReader <TT, T>(rdr);
                    return(sfRecordTypes);
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", String.Format(MethodBase.GetCurrentMethod().Name + " method failed in SalesforceContext class") + "\n" + ex);
                throw;
            }
        }
예제 #11
0
        public static string OracleSfdcConnectionString()
        {
            string connectionString = null;
            string connName         = null;
            string dataSource       = null;


            if (ConfigurationManager.AppSettings["OracleSfdcConnectionString"] != null)
            {
                connName = ConfigurationManager.AppSettings["OracleSfdcConnectionString"];
            }

            try
            {
                if (string.IsNullOrEmpty(SalesforceLoaderInfo.OracleSfdcConnectionString))
                {
                    var c = new ConnSvc.ConnectionsClient();
                    c.Endpoint.Address =
                        new System.ServiceModel.EndpointAddress(ConfigurationManager.AppSettings["ConnectionUrl"]);
                    var result = c.ConnectionInfo(connName);

                    var dSource = Encryption.Decrypt(result.DataSource);
                    dataSource = dSource.Split('|')[0];
                    string userName = Encryption.Decrypt(result.UserName);
                    string password = Encryption.Decrypt(result.Password);

                    connectionString = String.Format("Data Source={0};User Id={1};Password={2}", dataSource.ToUpper(),
                                                     userName, password);
                    SalesforceLoaderInfo.OracleSfdcConnectionString = connectionString;
                }
                else
                {
                    connectionString = SalesforceLoaderInfo.OracleSfdcConnectionString;
                }
            }
            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", string.Format(MethodBase.GetCurrentMethod().Name + " method faied in DbCxn class \n" + ex));
                throw;
            }


            return(connectionString);
        }
        public static string SalesforceConnectionString()
        {
            string connectionString = null;
            string connName         = null;
            string dataSource       = null;


            if (ConfigurationManager.AppSettings["SalesforceConnectionString"] != null)
            {
                connName = ConfigurationManager.AppSettings["SalesforceConnectionString"];
            }

            try
            {
                if (string.IsNullOrEmpty(SalesforceLoaderInfo.SalesforceConnectionString))
                {
                    var c = new ConnSvc.ConnectionsClient();
                    c.Endpoint.Address =
                        new System.ServiceModel.EndpointAddress(ConfigurationManager.AppSettings["ConnectionUrl"]);
                    var result = c.ConnectionInfo(connName);

                    string connUser          = String.Empty;
                    string connPassword      = String.Empty;
                    string connSecurityToken = String.Empty;
                    string connUseSandbox    = String.Empty;
                    string connOffline       = String.Empty;

                    foreach (var item in result.ExtendedProperties)
                    {
                        switch (item.Key.ToLower())
                        {
                        case "user":
                            connUser = Encryption.Decrypt(item.Value);
                            break;

                        case "password":
                            connPassword = Encryption.Decrypt(item.Value);
                            break;

                        case "security token":
                            connSecurityToken = Encryption.Decrypt(item.Value);
                            break;

                        case "use sandbox":
                            connUseSandbox = Encryption.Decrypt(item.Value);
                            break;

                        case "offline":
                            connOffline = Encryption.Decrypt(item.Value);
                            break;
                        }
                    }

                    connectionString = String.Format("User={0};Password={1};Security Token={2};Offline={3}; Use Sandbox={4}", connUser, connPassword, connSecurityToken, connOffline, connUseSandbox);


                    SalesforceLoaderInfo.SalesforceConnectionString = connectionString;
                }
                else
                {
                    connectionString = SalesforceLoaderInfo.SalesforceConnectionString;
                }
                return(connectionString);
            }

            catch (Exception ex)
            {
                CfsLogging.LogFatal("Error occured Salesforce Data Loader", string.Format(MethodBase.GetCurrentMethod().Name + " method faied in SalesforceCxn class \n" + ex));
                throw;
            }
        }