-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
79 lines (63 loc) · 2.81 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using InLooxOData;
using IQmedialab.InLoox.Data.BusinessObjects;
using Microsoft.OData.Client;
using System;
using System.Linq;
namespace InLooxnowClient
{
class Program
{
static void Main(string[] args)
{
var endPoint = new Uri("https://app.inlooxnow.com/");
var endPointOdata = new Uri(endPoint, "odata/");
var username = "user@inloox.com";
var password = "";
var tokenResponse = ODataBasics.GetToken(endPoint, username, password).Result;
// in case multiple accounts exists
if (tokenResponse.Error != null && tokenResponse.Error != "invalid_grant")
{
var accounts = tokenResponse.GetAccounts();
// filter correct account by name
var myAccount = accounts.FirstOrDefault(k => k.Name.StartsWith("000000"));
tokenResponse = ODataBasics.GetToken(endPoint, username, password, myAccount.Id).Result;
}
if (tokenResponse?.AccessToken == null)
{
Console.WriteLine("Login invalid");
return;
}
var context = ODataBasics.GetInLooxContext(endPointOdata, tokenResponse.AccessToken);
// lookup custom field "DocTest" id
var ceDefaults = context.customexpanddefaultextend.ToList();
var cedDocument = ceDefaults.FirstOrDefault(k => k.DisplayName == "DocTest");
if (cedDocument == null)
{
Console.WriteLine("Custom field 'DocTest' not found");
return;
}
// build query for all documents with custom field 'DocTest' set to true.
var query = context.documentview
.Where(k => k.CustomExpand.Any(ce => ce.CustomExpandDefaultId == cedDocument.CustomExpandDefaultId && ce.BoolValue == true))
.OrderBy(k => k.FileName)
.Skip(0)
.Take(10);
// need to use DataServiceCollection to use the PostOnlySetProperties feature
// if you only need to read from the query a ToList() is ok.
var docs = new DataServiceCollection<DocumentView>(query);
Console.WriteLine($"found {docs.Count()} document{(docs.Count() > 1 ? "s" : String.Empty)}:");
foreach (var d in docs)
Console.WriteLine(d.FileName);
// change document state
if (docs.Count > 0)
{
var doc = docs.FirstOrDefault();
doc.State = "Updated " + DateTime.Now;
// only update the modfied properties
context.SaveChangesDefaultOptions = SaveChangesOptions.PostOnlySetProperties;
context.UpdateObject(doc);
context.SaveChanges();
}
}
}
}