当前位置: 首页>>代码示例>>C#>>正文


C# Query.commitBatch方法代码示例

本文整理汇总了C#中Query.commitBatch方法的典型用法代码示例。如果您正苦于以下问题:C# Query.commitBatch方法的具体用法?C# Query.commitBatch怎么用?C# Query.commitBatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Query的用法示例。


在下文中一共展示了Query.commitBatch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: run

        public void run() {
            string token = Query.login("[email protected]", "demobiz");
            mQuery = new Query(token);

            // Step 1: make a query to Upvise Cloud and get all contacts
            //store them as a (name, id) dictionary in mUpviseContactIndex
            selectUpviseContacts();

            // Step 2: load and parse local XML
            // add the jobs and the contact to create into mJobList and mContactList
            string xmlFilename = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"JobSampleBatch.xml");
            loadJobsFromXml(xmlFilename /*@"c:\temp\JobSampleBatch.xml"*/);

            // Step 3: Reverse geocode jobs
            reverseGeocodeJobs();

            // Step 4: Batch Insert Jobs ad Contact
            mQuery.beginBatch();

            foreach (Job job in mJobList) {
                mQuery.insert(Job.TABLE, job.toJson());
            }

            foreach (Contact contact in mContactList) {
                mQuery.insert(Contact.TABLE, contact.toJson());
            }

            mQuery.commitBatch();
            Console.WriteLine("Jobs inserted: " + mJobList.Count);
            Console.WriteLine("Contacts inserted: " + mContactList.Count);
        }
开发者ID:prestanneth,项目名称:UpviseSDK,代码行数:31,代码来源:JobSampleBatch.cs

示例2: run

        public void run() {
            try {
                // Login
                string token = Query.login("[email protected]", "demobiz");
                Query query = new Query(token);

                // 1. Start a batch operation
                query.beginBatch();
                for (var i = 1; i < 5; i++) {
                    // 2. Create a new contact
                    Contact contact = new Contact();
                    contact.id = "JOHN_ID" + i;
                    contact.name = "John " + i;
                    contact.email = "John" + i + "@gmail.com";
                    // this add the insert query to the internal batch query buffer
                    query.insert(Contact.TABLE, contact.toJson());
                }
                // this performs one HTTPS web service call and executes all previous queries
                query.commitBatch();

                // 2. Now Batch Update the Records
                query.beginBatch();
                for (var i = 1; i < 5; i++) {
                    Contact updatedValues = new Contact();
                    updatedValues.email = "john" + i + "@yahoo.com";
                    query.updateId(Contact.TABLE, "JOHN_ID" + i, updatedValues.toJson());
                }
                query.commitBatch();

                // 3. Now Batch Delete the Records
                query.beginBatch();
                for (var i = 1; i < 5; i++) {
                    query.deleteId(Contact.TABLE, "JOHN_ID" + i);
                }
                query.commitBatch();
            } catch (Exception e) {
                Console.WriteLine("Error:" + e.Message);
            }
        }
开发者ID:prestanneth,项目名称:UpviseSDK,代码行数:39,代码来源:ContactSampleBatch.cs

示例3: run

        public void run() {
            string token = Query.login("[email protected]", "demobiz");
            Query query = new Query(token);

            // 1. insert one job
            Job newjob = new Job();
            newjob.id = "ID1";
            newjob.status = Job.OPEN;
            newjob.name = "Maintain Air Conditining";
            newjob.note = "Verify gaz pressure";
            newjob.duedate = DateTime.Now.AddHours(2);
            newjob.owner = "John"; // if you want to assign a Job, set the Upvise user Display name here
            newjob.street = "1 infinite Loop";
            newjob.city = "Cupertino";
            newjob.zipcode = "";
            newjob.country = "USA";
            newjob.geo = "12,3.444"; // set the coordinates for the job
            newjob.priority = Job.HIGHPRIORITY; // High priority

            // set some custom fields values
            newjob.setCustomField("F1", "WATER");
            newjob.setCustomField("F2", "12");

            query.insert(Job.TABLE, newjob.toJson());

            // 2. Update the existing job and mark it complete
            Job updatedValues = new Job();
            updatedValues.status = Job.COMPLETED;
            updatedValues.checkout = DateTime.Now;
            updatedValues.checkoutnote = "Aircon is leaking, requirews further fixing";

            query.updateId(Job.TABLE, "ID1", updatedValues.toJson());

            // 3. Select All Completed Jobs
            JSONObject where = new JSONObject();
            where.put("status", Job.COMPLETED);
            JSONObject[] completedJobs = query.select(Job.TABLE, where);
            foreach (JSONObject obj in completedJobs) {
                Job job = Job.fromJson(obj);

                Console.Write("Checkout note: " + job.checkoutnote);
                Console.Write("Custom Field 1: " + job.getCustomField("F1"));
                Console.Write("Custom Field 2: " + job.getCustomField("F2"));
                
                // Download all photos for the Job
                File[] files = query.selectFiles(Job.TABLE, job.id);
                foreach (File file in files) {
                    if (file.mime == "image/jpeg") {
                        byte[] content = query.downloadFile(file.id);
                        string filename = @"c:\temp\" + file.name + ".jpeg";
                        System.IO.File.WriteAllBytes(filename, content);
                    }
                }

                // Get All forms for the Job
                JSONObject formWhere = new JSONObject();
                formWhere.put("linkedid", job.id);
                JSONObject[] forms = query.select(Form.TABLE, formWhere);
                foreach (JSONObject formObj in forms) {
                    Form form = Form.fromJson(formObj, query);
                    Console.WriteLine("Form : " + formObj.ToString());
                }
            }

            // 4. Delete completed Jobs in batch mode
            query.beginBatch();
            foreach (JSONObject obj in completedJobs) {
                string jobid = obj.getString("id");
                query.deleteId(Job.TABLE, jobid);
            }
            query.commitBatch();
        }
开发者ID:prestanneth,项目名称:UpviseSDK,代码行数:72,代码来源:JobSample.cs

示例4: run

        public void run() {
            try {
                // Login
                string token = Query.login("[email protected]", "demobiz");
                Console.WriteLine("Login OK");

                // Create an instance of hte query class
                Query query = new Query(token);

                // Select all open tasks from the "Tasks.tasks" table 
                // You can go to your Upvise web account in the Task app and create some tasks first
                JSONObject where = new JSONObject();
                where.put("status", 0);
                JSONObject[] tasks = query.select("Tasks.tasks", where);
                Console.WriteLine("Found " + tasks.Length + " open tasks in this database");
                foreach (JSONObject task in tasks) {
                    Console.WriteLine("Task ID: " + task.getString("id"));
                    Console.WriteLine("Name: " + task.getString("name"));
                    Console.WriteLine("Due Date: " + task.getDate("duedate"));
                    Console.WriteLine("Owner: " + task.getString("owner"));
                    Console.WriteLine("Status:" + task.getInt("status"));
                }

                // Create a bunch of tasks using Batch operation
                Console.WriteLine("Creating 10 new tasks...");
                query.beginBatch();
                for (int i = 0; i < 10; i ++) {
                    JSONObject task = new JSONObject();
                    task.put("id", "TASKID_" + i);
                    task.put("name", "My Task " + i);
                    task.put("owner", "John");
                    task.put("status", 0);
                    task.putDate("duedate", DateTime.Now.AddDays(2));

                    query.insert("Tasks.tasks", task);
                }
                query.commitBatch();
                
                // update All open John's Tasks and mark them complete (status=1)
                where.put("owner", "John");
                where.put("status", 0);
                JSONObject[] myTasks = query.select("Tasks.tasks", where);
                Console.WriteLine("found " + myTasks.Length  + " open tasks for John");
                // Start a new batch operation to group all updates into one HTTPS request for best performance
                query.beginBatch();
                foreach(JSONObject task in myTasks) {
                    string id = task.getString("id");
                    JSONObject values = new JSONObject();
                    values.putDate("duedate", DateTime.Now);
                    values.put("status", 1);
                    query.updateId("Tasks.tasks", id, values);
                }
                query.commitBatch();
                Console.WriteLine("Updated the tasks to Complete");

                // Now Get All John's completed Tasks, export them in a file and delete them
                where.put("owner", "John");
                where.put("status", 1);
                JSONObject[] completedTasks = query.select("Tasks.tasks", where);
                Console.WriteLine("found " + completedTasks.Length + " completed tasks for John");

                StringBuilder buffer = new StringBuilder();
                // Start a new batch operation
                query.beginBatch();
                foreach (JSONObject task in completedTasks) {
                    string id = task.getString("id");
                    // Add the task data in the buffer
                    buffer.AppendLine(task.ToString());
                    query.deleteId("Tasks.tasks", id);

                }
                query.commitBatch();
                Console.WriteLine("Deleted completed tasks for John");
                // Save the file to disk
                System.IO.File.WriteAllText(@"C:\\temp\completedTasks.txt", buffer.ToString());
                
            } catch (Exception e) {
                Console.WriteLine("Error:" + e.Message);
            }
        }
开发者ID:prestanneth,项目名称:UpviseSDK,代码行数:80,代码来源:TaskSample.cs

示例5: run

        public void run() {
            try {
                // Login
                string token = Query.login("[email protected]", "demobiz");
                Query query = new Query(token);

                
                // Create a new test Contact
                string contactId = "TESTCONTACT1";
                JSONObject contact = new JSONObject();
                contact.put("id", contactId);
                contact.put("name", "John Smith");
                query.insert("Contacts.contacts", contact);

                //  Now upload 5 simple test files linked to the test contact
                for (var i = 0; i < 5; i++) {
                    File file = new File();
                    file.id = "TESTFILE" + i;
                    file.name = "Test File " + i;
                    file.mime = "txt";

                    file.linkedtable = "unybiz.contacts.contacts";
                    file.linkedid = contactId;

                    byte[] content = Encoding.UTF8.GetBytes("This is a text file content");
                    // You can also load from a local file
                    // byte[] content = System.IO.File.ReadAllBytes(@"c:\temp\test.txt");


                    query.uploadFile(file, content);
                    Console.WriteLine("Uploaded one file : " + file.id);
                }
                
                // Select All Files for the contact and download their content
                JSONObject where = new JSONObject();
                where.put("linkedrecid", contactId);
                JSONObject[] files = query.select(File.TABLE, where);
                foreach (JSONObject obj in files) {
                    File file = File.fromJson(obj);
                    Console.WriteLine("File ID: " + file.id);
                    Console.Write(" Name: " + file.name);
                    Console.Write(" Size: " + file.size + " bytes");
                    Console.Write(" Creation Date: " + file.date);

                    // Download and write in disk the file content
                    byte[] content = query.downloadFile(file.id);
                    System.IO.File.WriteAllBytes(@"C:\temp\" + file.name + ".txt", content);
                }

                // Delete All Files in batch operation
                query.beginBatch();
                foreach (JSONObject obj in files) {
                    query.deleteId(File.TABLE, obj.getString("id"));
                }
                query.commitBatch();
                Console.Write(" Deleted Files!");

            } catch (Exception e) {
                Console.WriteLine("Error:" + e.Message);
            }
        }
开发者ID:prestanneth,项目名称:UpviseSDK,代码行数:61,代码来源:FileSample.cs


注:本文中的Query.commitBatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。