Skip to content

Commit 5c10792

Browse files
committed
Initial commit.
0 parents  commit 5c10792

File tree

12 files changed

+541
-0
lines changed

12 files changed

+541
-0
lines changed

.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#Autosave files
2+
*~
3+
4+
#build
5+
[Oo]bj/
6+
[Bb]in/
7+
packages/
8+
TestResults/
9+
10+
# globs
11+
Makefile.in
12+
*.DS_Store
13+
*.sln.cache
14+
*.suo
15+
*.cache
16+
*.pidb
17+
*.userprefs
18+
*.usertasks
19+
config.log
20+
config.make
21+
config.status
22+
aclocal.m4
23+
install-sh
24+
autom4te.cache/
25+
*.user
26+
*.tar.gz
27+
tarballs/
28+
test-results/
29+
Thumbs.db
30+
31+
#Mac bundle stuff
32+
*.dmg
33+
*.app
34+
35+
#resharper
36+
*_Resharper.*
37+
*.Resharper
38+
39+
#dotCover
40+
*.dotCover

KloudlessDemo.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KloudlessDemo", "KloudlessDemo\KloudlessDemo.csproj", "{7B160D6C-98EC-49EF-846C-A0FC5BEF73E1}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|x86 = Debug|x86
9+
Release|x86 = Release|x86
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{7B160D6C-98EC-49EF-846C-A0FC5BEF73E1}.Debug|x86.ActiveCfg = Debug|x86
13+
{7B160D6C-98EC-49EF-846C-A0FC5BEF73E1}.Debug|x86.Build.0 = Debug|x86
14+
{7B160D6C-98EC-49EF-846C-A0FC5BEF73E1}.Release|x86.ActiveCfg = Release|x86
15+
{7B160D6C-98EC-49EF-846C-A0FC5BEF73E1}.Release|x86.Build.0 = Release|x86
16+
EndGlobalSection
17+
EndGlobal

KloudlessDemo/Account.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using KloudlessDemo;
3+
using System.Windows.Forms;
4+
using System.Collections.Generic;
5+
using RestSharp;
6+
7+
namespace KloudlessDemo
8+
{
9+
public class Account
10+
{
11+
internal String id { get; set; }
12+
internal String name { get; set; }
13+
internal String service { get; set; }
14+
internal String key { get; set; }
15+
16+
public Account()
17+
{
18+
}
19+
20+
public T Execute<T>(RestRequest request) where T : new()
21+
{
22+
var client = Util.GetClient ();
23+
request.AddHeader ("Authorization", "AccountKey " + key);
24+
request.AddParameter("accountId", id, ParameterType.UrlSegment);
25+
26+
var response = client.Execute<T>(request);
27+
28+
if (response.ErrorException != null)
29+
{
30+
const string message = "Error retrieving response. Check inner details for more info.";
31+
var kloudlessException = new ApplicationException(message, response.ErrorException);
32+
throw kloudlessException;
33+
}
34+
return response.Data;
35+
}
36+
37+
/// <summary>
38+
/// An example API request that retrieves folder contents for an account.
39+
/// </summary>
40+
/// <returns>
41+
/// A list of FileSystem objects representing the folder contents.
42+
/// </returns>
43+
/// <param name="folderId">ID of the folder to retrieve contents of</param>
44+
/// <param name="page">Page number</param>
45+
/// <param name="pageSize">Page size</param>
46+
public FileSystemList RetrieveContents(
47+
string folderId = "root", string page = "1", int pageSize = 1000) {
48+
var request = new RestRequest();
49+
request.Resource = "accounts/{accountId}/folders/{folderId}/contents";
50+
51+
request.AddParameter("folderId", folderId, ParameterType.UrlSegment);
52+
request.AddQueryParameter ("page", page);
53+
request.AddQueryParameter ("page_size", pageSize.ToString());
54+
55+
return Execute<FileSystemList>(request);
56+
}
57+
}
58+
59+
}
60+

KloudlessDemo/Authentication.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using KloudlessDemo;
3+
using System.Windows.Forms;
4+
using System.Collections.Generic;
5+
using System.Text.RegularExpressions;
6+
using System.Threading;
7+
using System.Drawing;
8+
9+
namespace KloudlessDemo
10+
{
11+
public class Authentication
12+
{
13+
public static Dictionary<String, Account> accounts =
14+
new Dictionary<string, Account>();
15+
16+
/// <summary>
17+
/// Opens a web browser for authentication and returns the thread it is in.
18+
/// </summary>
19+
/// <param name="appId">Kloudless App ID.</param>
20+
/// <param name="services">List of services to display for auth.</param>
21+
public static WebBrowser open(String appId, List<String> services = null)
22+
{
23+
String url = Util.GetAuthPath(appId, services: services);
24+
var wb = new WebBrowser();
25+
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(FetchKeys);
26+
wb.Navigate(url);
27+
28+
wb.Dock = DockStyle.Fill;
29+
wb.Size = new System.Drawing.Size(800, 600);
30+
wb.ScriptErrorsSuppressed = true;
31+
wb.MinimumSize = new System.Drawing.Size(100, 100);
32+
33+
var form = new Form();
34+
form.Controls.Add(wb);
35+
form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
36+
form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
37+
form.ClientSize = new System.Drawing.Size(800, 600);
38+
form.Text = "Connect an Account";
39+
form.Name = "Kloudless Authentication";
40+
form.Show();
41+
42+
return wb;
43+
}
44+
45+
private static void FetchKeys(object sender, WebBrowserDocumentCompletedEventArgs e)
46+
{
47+
WebBrowser wb = (WebBrowser)sender;
48+
if (e.Url.Host == new Uri (Util.BASE_URL).Host &&
49+
((new Regex ("/callback/?$")).IsMatch (wb.Url.AbsolutePath))) {
50+
51+
Account account = new Account ();
52+
53+
HtmlElementCollection dataItems = wb.Document.GetElementsByTagName ("data");
54+
foreach (HtmlElement dataItem in dataItems) {
55+
switch (dataItem.Id) {
56+
case "account":
57+
account.id = dataItem.GetAttribute ("title");
58+
break;
59+
case "account_name":
60+
account.name = dataItem.GetAttribute ("title");
61+
break;
62+
case "service":
63+
account.service = dataItem.GetAttribute ("title");
64+
break;
65+
case "account_key":
66+
account.key = dataItem.GetAttribute ("title");
67+
break;
68+
}
69+
}
70+
71+
if (account.id != null)
72+
{
73+
accounts.Add(account.id, account);
74+
Console.WriteLine("Added " + account.service + " account " +
75+
account.name + " (" + account.id + ").");
76+
}
77+
78+
wb.Dispose ();
79+
Application.ExitThread ();
80+
}
81+
}
82+
}
83+
}
84+

KloudlessDemo/FileSystem.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace KloudlessDemo
5+
{
6+
public class FileSystem
7+
{
8+
public string id { get; set; }
9+
public string name { get; set; }
10+
public DateTime created { get; set; }
11+
public DateTime modified { get; set; }
12+
public string type { get; set; }
13+
public int account { get; set; }
14+
public FileSystem parent { get; set; }
15+
public List<FileSystem> ancestors { get; set; }
16+
public string path { get; set; }
17+
public string mimeType { get; set; }
18+
public Boolean downloadable { get; set; }
19+
public string rawId { get; set; }
20+
public Dictionary<string, string> owner { get; set; } // Should be a User object
21+
public Dictionary<string, string> lastModifier { get; set; }
22+
}
23+
}
24+

KloudlessDemo/FileSystemList.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections;
4+
5+
namespace KloudlessDemo
6+
{
7+
public class FileSystemList : IEnumerable
8+
{
9+
public int count { get; set; }
10+
public string page { get; set; }
11+
public string nextPage { get; set; }
12+
public List<FileSystem> objects { get; set; }
13+
14+
15+
#region IEnumerable implementation
16+
public IEnumerator GetEnumerator ()
17+
{
18+
return objects.GetEnumerator ();
19+
}
20+
#endregion
21+
}
22+
}
23+

KloudlessDemo/KloudlessDemo.csproj

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6+
<ProjectGuid>{7B160D6C-98EC-49EF-846C-A0FC5BEF73E1}</ProjectGuid>
7+
<OutputType>Exe</OutputType>
8+
<RootNamespace>KloudlessDemo</RootNamespace>
9+
<AssemblyName>KloudlessDemo</AssemblyName>
10+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11+
<PublishUrl>publish\</PublishUrl>
12+
<Install>true</Install>
13+
<InstallFrom>Disk</InstallFrom>
14+
<UpdateEnabled>false</UpdateEnabled>
15+
<UpdateMode>Foreground</UpdateMode>
16+
<UpdateInterval>7</UpdateInterval>
17+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
18+
<UpdatePeriodically>false</UpdatePeriodically>
19+
<UpdateRequired>false</UpdateRequired>
20+
<MapFileExtensions>true</MapFileExtensions>
21+
<ApplicationRevision>0</ApplicationRevision>
22+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
23+
<IsWebBootstrapper>false</IsWebBootstrapper>
24+
<UseApplicationTrust>false</UseApplicationTrust>
25+
<BootstrapperEnabled>true</BootstrapperEnabled>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
28+
<DebugSymbols>true</DebugSymbols>
29+
<DebugType>full</DebugType>
30+
<Optimize>false</Optimize>
31+
<OutputPath>bin\Debug</OutputPath>
32+
<DefineConstants>DEBUG;</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
<Externalconsole>true</Externalconsole>
36+
<PlatformTarget>x86</PlatformTarget>
37+
</PropertyGroup>
38+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
39+
<DebugType>full</DebugType>
40+
<Optimize>true</Optimize>
41+
<OutputPath>bin\Release</OutputPath>
42+
<ErrorReport>prompt</ErrorReport>
43+
<WarningLevel>4</WarningLevel>
44+
<Externalconsole>true</Externalconsole>
45+
<PlatformTarget>x86</PlatformTarget>
46+
</PropertyGroup>
47+
<ItemGroup>
48+
<Reference Include="System" />
49+
<Reference Include="System.Drawing" />
50+
<Reference Include="System.Windows.Forms" />
51+
<Reference Include="RestSharp">
52+
<HintPath>..\packages\RestSharp.105.1.0\lib\net45\RestSharp.dll</HintPath>
53+
</Reference>
54+
</ItemGroup>
55+
<ItemGroup>
56+
<Compile Include="Program.cs" />
57+
<Compile Include="Properties\AssemblyInfo.cs" />
58+
<Compile Include="Authentication.cs" />
59+
<Compile Include="Util.cs" />
60+
<Compile Include="Account.cs" />
61+
<Compile Include="FileSystemList.cs" />
62+
<Compile Include="FileSystem.cs" />
63+
</ItemGroup>
64+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
65+
<ItemGroup>
66+
<None Include="packages.config" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
70+
<Visible>False</Visible>
71+
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
72+
<Install>true</Install>
73+
</BootstrapperPackage>
74+
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
75+
<Visible>False</Visible>
76+
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
77+
<Install>false</Install>
78+
</BootstrapperPackage>
79+
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
80+
<Visible>False</Visible>
81+
<ProductName>.NET Framework 3.5 SP1</ProductName>
82+
<Install>false</Install>
83+
</BootstrapperPackage>
84+
</ItemGroup>
85+
</Project>

0 commit comments

Comments
 (0)