コード例 #1
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);
        }
コード例 #2
0
        public static SoqlQuery <T> Query <T>() where T : SObject
        {
            // prepare query text
            var soqlCreator = new SoqlCreator();
            var soql        = soqlCreator.GetSoql <T>();

            // prepare query result
            var lasyResult = new Lazy <List <T> >(() =>
            {
                return(PerformQuery <T>(soql));
            });

            // return as polymorphic query instance
            return(new SoqlQuery <T>(lasyResult, soql));
        }