本文整理汇总了C#中Job.toJson方法的典型用法代码示例。如果您正苦于以下问题:C# Job.toJson方法的具体用法?C# Job.toJson怎么用?C# Job.toJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Job
的用法示例。
在下文中一共展示了Job.toJson方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: updateJobsAsCompleted
private void updateJobsAsCompleted() {
logStart("Starting updating Jobs");
mQuery.beginBatch();
for (int i = 1; i < JOB_COUNT; i++) {
// 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, requires further fixing";
updatedValues.checkoutgeo = "1.11111,2.22222";
mQuery.updateId(Job.TABLE, "JOBID" + i, updatedValues.toJson());
}
// Also upload one test photo linked to the first JOB
File photo = new File();
photo.id = "JOBPHOTO1";
photo.name = "Sample Job Photo";
photo.mime = "image/jpeg";
photo.linkedtable = Job.TABLE;
photo.linkedid = "JOBID1";
string photoPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"JobSamplePhoto.jpg");
byte[] content = System.IO.File.ReadAllBytes(photoPath);
mQuery.uploadFile(photo, content);
mQuery.commitBatch();
logFinish("Finished updating Jobs");
}