예제 #1
0
        private static ApexSharpConfig GetNewConnection(ApexSharpConfig config)
        {
            var xml = @"
                <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:enterprise.soap.sforce.com"">
                    <soapenv:Header>
                        <urn:LoginScopeHeader>
                        <urn:organizationId></urn:organizationId>
                        <urn:portalId></urn:portalId>
                        </urn:LoginScopeHeader>
                    </soapenv:Header>
                    <soapenv:Body>
                        <urn:login>
                            <urn:username>" + config.SalesForceUserId + "</urn:username>" +
                      "<urn:password>" + config.SalesForcePassword + config.SalesForcePasswordToken + "</urn:password>" +
                      "</urn:login>" +
                      "</soapenv:Body>" +
                      "</soapenv:Envelope>";


            var returnXml = PostLoginTask(config.SalesForceSoapUrl, xml);

            if (returnXml.Contains("INVALID_LOGIN"))
            {
                throw new SalesForceInvalidLoginException("Invalid Login");
            }
            else if (returnXml.Contains("API_DISABLED_FOR_ORG"))
            {
                throw new SalesForceInvalidLoginException("Webservice API is disabled for this login or organization.");
            }

            try
            {
                Envelope envelope = UtilXml.DeSerilizeFromXML <Envelope>(returnXml);


                var soapIndex =
                    envelope.Body.loginResponse.result.serverUrl.IndexOf(@"/Soap", StringComparison.Ordinal);
                var restUrl       = envelope.Body.loginResponse.result.serverUrl.Substring(0, soapIndex);
                var restSessionId = "Bearer " + envelope.Body.loginResponse.result.sessionId;


                config.SalesForceSoapUrl       = envelope.Body.loginResponse.result.serverUrl;
                config.RestUrl                 = restUrl;
                config.RestSessionId           = restSessionId;
                config.SessionCreationDateTime = DateTimeOffset.Now.ToUnixTimeSeconds() +
                                                 envelope.Body.loginResponse.result.userInfo.sessionSecondsValid;

                return(config);
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("Fix the error and restart " + e);
                Console.ReadLine();
                System.Environment.Exit(0);
            }

            return(null);
        }
예제 #2
0
        public string BulkRequest <T>(int checkIntervel)
        {
            SoqlCreator soql  = new SoqlCreator();
            string      query = soql.GetSoql <T>();

            var objectName = GetSalesForceObjectName <T>();

            var url     = "/async/36.0/job/";
            var jobInfo = new JobInfoRequest
            {
                operation       = "query",
                @object         = objectName,
                concurrencyMode = "Parallel",
                contentType     = "JSON",
            };
            var xml = UtilXml.SerializeToXML(jobInfo);

            var waitTask = Post(url, xml, "application/xml");

            waitTask.Wait();

            var jobInfoReply = UtilXml.DeSerilizeFromXML <JobInfoReply>(waitTask.Result);

            waitTask = Post(url + jobInfoReply.id + "/batch", query, "application/json");
            waitTask.Wait();

            var batchJobReply = JsonConvert.DeserializeObject <BatchJobReply>(waitTask.Result);

            while (batchJobReply.state != "Completed")
            {
                waitTask = Get(url + jobInfoReply.id + "/batch/" + batchJobReply.id);
                waitTask.Wait();
                var json = waitTask.Result;
                batchJobReply = JsonConvert.DeserializeObject <BatchJobReply>(json,
                                                                              new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });

                if (batchJobReply.state != "Completed")
                {
                    Console.WriteLine($"Job {batchJobReply.state}, Waiting for {checkIntervel} miliseconds");
                    Thread.Sleep(checkIntervel);
                }
            }


            waitTask = Get(url + jobInfoReply.id + "/batch/" + batchJobReply.id + "/result");
            waitTask.Wait();

            var resultLength = waitTask.Result.Length;
            var result       = waitTask.Result.Substring(2, resultLength - 4);

            waitTask = Get(url + jobInfoReply.id + "/batch/" + batchJobReply.id + "/result/" + result);
            waitTask.Wait();

            return(waitTask.Result);
        }
예제 #3
0
        public static void CreateInstanceBinder()
        {
            string xml          = File.ReadAllText(ApexSharp.GetSession().SalesForceLocation + @"\labels\CustomLabels.labels");
            var    customLabels = UtilXml.DeSerilizeFromXML <CustomLabels>(xml);

            foreach (var customLabel in customLabels.labels)
            {
                Console.WriteLine(customLabel.fullName + "  " + customLabel.value);
            }
        }
예제 #4
0
        private static ApexSharpConfig GetNewConnection(ApexSharpConfig config)
        {
            var xml = @"
                <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:enterprise.soap.sforce.com"">
                    <soapenv:Header>
                        <urn:LoginScopeHeader>
                        <urn:organizationId></urn:organizationId>
                        <urn:portalId></urn:portalId>
                        </urn:LoginScopeHeader>
                    </soapenv:Header>
                    <soapenv:Body>
                        <urn:login>
                            <urn:username>" + config.SalesForceUserId + "</urn:username>" +
                      "<urn:password>" + config.SalesForcePassword + config.SalesForcePasswordToken + "</urn:password>" +
                      "</urn:login>" +
                      "</soapenv:Body>" +
                      "</soapenv:Envelope>";


            var retrunXml = PostLoginTask(config.SalesForceUrl, xml);

            if (retrunXml.Contains("INVALID_LOGIN"))
            {
                throw new SalesForceInvalidLoginException("Invalid Login");
            }
            Envelope envelope = UtilXml.DeSerilizeFromXML <Envelope>(retrunXml);

            var soapIndex     = envelope.Body.loginResponse.result.serverUrl.IndexOf(@"/Soap", StringComparison.Ordinal);
            var restUrl       = envelope.Body.loginResponse.result.serverUrl.Substring(0, soapIndex);
            var restSessionId = "Bearer " + envelope.Body.loginResponse.result.sessionId;


            config.SalesForceUrl           = envelope.Body.loginResponse.result.serverUrl;
            config.SessionId               = envelope.Body.loginResponse.result.sessionId;
            config.RestUrl                 = restUrl;
            config.RestSessionId           = restSessionId;
            config.SessionCreationDateTime = DateTimeOffset.Now.ToUnixTimeSeconds() + envelope.Body.loginResponse.result.userInfo.sessionSecondsValid;

            return(config);
        }