本文整理汇总了C#中Query.downloadFile方法的典型用法代码示例。如果您正苦于以下问题:C# Query.downloadFile方法的具体用法?C# Query.downloadFile怎么用?C# Query.downloadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Query
的用法示例。
在下文中一共展示了Query.downloadFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: run
public void run() {
string token = Query.login("[email protected]", "demobiz");
Query query = new Query(token);
// 1. Get the Template Id for a given Template Name
JSONObject where = new JSONObject();
where.put("name", "My Template");
Template template = null;
JSONObject[] templates = query.select(Template.TABLE, where);
if (templates.Length == 0) {
// no template, creating a new one
} else {
template = Template.fromJson(templates[0]);
}
// 2. Selecting all submitted Forms for this template
JSONObject where2 = new JSONObject();
where2.put("templateid", template.id);
where2.put("status", Form.SUBMITTED);
JSONObject[] forms = query.select(Form.TABLE, where2);
foreach (JSONObject formObj in forms) {
Form form = Form.fromJson(formObj, query);
// Iterate on each form field and print out its value
foreach(FormField field in form.fields) {
Console.Write(" Label: " + field.label);
Console.Write(" Value: " + field.value);
Console.Write(" Type " + field.type);
Console.WriteLine(" ID: " + field.name);
// For photo fields, Download all photos for the field
if (field.type == "photo") {
File[] files = query.selectFiles("unybiz.forms.forms", (string) field.value);
foreach(File file in files) {
byte[] content = query.downloadFile(file.id);
// TODO Save it to disk
}
}
}
}
}
示例2: 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();
}
示例3: 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);
}
}