Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #23

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
12 changes: 10 additions & 2 deletions OneDriveApiExplorer/App.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="NewApiBrowser.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
Expand All @@ -15,4 +15,12 @@
</setting>
</NewApiBrowser.Properties.Settings>
</userSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
16 changes: 13 additions & 3 deletions OneDriveApiExplorer/FormBrowser.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 31 additions & 4 deletions OneDriveApiExplorer/FormBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,28 @@ private async Task LoadFolderFromId(string id)
{
if (null == Connection) return;

ODItemReference item = new ODItemReference { Id = id };
await LoadFolderFromReference(item);
}

private async Task LoadFolderFromReference(ODItemReference item)
{
// Update the UI for loading something new
ShowWork(true);
LoadChildren(null); // Clear the current folder view

try
{
ODItemReference item = new ODItemReference { Id = id };

var selectedItem = await Connection.GetItemAsync(item, ItemRetrievalOptions.DefaultWithChildrenThumbnails);
ProcessFolder(selectedItem);
}
catch (ODException exception)
{
PresentOneDriveException(exception);
}

FixBreadCrumbForCurrentFolder(this.CurrentFolder);

ShowWork(false);
}
Expand Down Expand Up @@ -195,7 +203,7 @@ private void FixBreadCrumbForCurrentFolder(ODItem folder)
}
}

private void linkLabelBreadcrumb_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
private async void linkLabelBreadcrumb_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
LinkLabel link = (LinkLabel)sender;

Expand All @@ -205,11 +213,11 @@ private void linkLabelBreadcrumb_LinkClicked(object sender, LinkLabelLinkClicked
if (null == item)
{

Task t = LoadFolderFromId("root");
await LoadFolderFromId("root");
}
else
{
Task t = LoadFolderFromId(item.Id);
await LoadFolderFromId(item.Id);
}
}

Expand Down Expand Up @@ -677,6 +685,25 @@ private async void getDriveToolStripMenuItem_Click(object sender, EventArgs e)
display.Show();

}

private async void openItemByPathToolStripMenuItem_Click(object sender, EventArgs e)
{
if (null == Connection) return;

var currentFolder = this.CurrentFolder;
var selectedItem = this.SelectedItem;
if (null == selectedItem || null == currentFolder) return;

string pathToItem = selectedItem.Path(false);
if (null == pathToItem)
{
pathToItem = currentFolder.Path(false) + "/" + selectedItem.Name;
}

var itemRef = ODConnection.ItemReferenceForDrivePath(pathToItem);

await LoadFolderFromReference(itemRef);
}
}

}
25 changes: 17 additions & 8 deletions OneDriveApiExplorer/OneDriveApiExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@
<SignManifests>false</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="MicrosoftAccount.WindowsForms, Version=1.0.3.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\MicrosoftAccount.WindowsForms.1.0.3.0\lib\net45\MicrosoftAccount.WindowsForms.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -87,6 +89,12 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="MicrosoftAccount.WindowsForms">
<HintPath>..\packages\MicrosoftAccount.WindowsForms.1.0.4.0\lib\net45\MicrosoftAccount.WindowsForms.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Auth\OAuthAuthenticator.cs" />
Expand Down Expand Up @@ -222,6 +230,7 @@
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
Expand Down
2 changes: 1 addition & 1 deletion OneDriveApiExplorer/Picker/FormOneDrivePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void webBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
private void CloseWindow()
{
const int interval = 100;
var t = new System.Threading.Timer(new System.Threading.TimerCallback((state) =>
new System.Threading.Timer(new System.Threading.TimerCallback((state) =>
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.BeginInvoke(new MethodInvoker(() => this.Close()));
Expand Down
9 changes: 5 additions & 4 deletions OneDriveApiExplorer/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.8" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="MicrosoftAccount.WindowsForms" version="1.0.3.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net45" />
<package id="MicrosoftAccount.WindowsForms" version="1.0.4.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
</packages>
9 changes: 9 additions & 0 deletions OneDriveSDK/CommandOptions/ViewChangesOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public int? PageSize
set { SetValueForQueryString(ApiConstants.PageSizeQueryParameterKey, value.ToString()); }
}

/// <summary>
/// Select properties on the expanded objects
/// </summary>
public string Select
{
get { return ValueForQueryString(ApiConstants.SelectQueryParameterKey); }
set { SetValueForQueryString(ApiConstants.SelectQueryParameterKey, value); }
}

public static ViewChangesOptions Default
{
get { return new ViewChangesOptions(); }
Expand Down
24 changes: 24 additions & 0 deletions OneDriveSDK/DataType/ODExtendedItemReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OneDrive
{
public class ODExtendedItemReference : ODItemReference
{
public ODExtendedItemReference(ODItemReference itemRef)
{
this.DriveId = itemRef.DriveId;
this.Id = itemRef.Id;
this.Path = itemRef.Path;
}

/// <summary>
/// AdditionalPath enables you to address an item by ID + AdditionalPath. When this reference is converted into
/// a URL, the value of AdditionalPath is appended to the resolved item.
/// </summary>
public string AdditionalPath { get; set; }
}
}
13 changes: 13 additions & 0 deletions OneDriveSDK/Extensions/GenericExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,18 @@ public static bool IsSuccess(this HttpStatusCode code)
else
return false;
}

/// <summary>
/// Ensures that a path component has a leading path seperator "foo/bar" => "/foo/bar"
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string EnsureLeadingPathSeperator(this string path)
{
if (path.StartsWith("/"))
return path;
else
return "/" + path;
}
}
}
34 changes: 23 additions & 11 deletions OneDriveSDK/Extensions/ItemExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,35 @@ public static string JsonString(this ODDataModel item)
}

/// <summary>
/// Returns the Path for an item.
/// Returns the Path for an item. Returns null if a path is not available for the item.
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static string Path(this ODItem item, bool includeApiRoot = false)
{
if (null != item.ParentReference)

if (null != item.ParentReference && null != item.ParentReference.Path)
{
var decodedPath = Uri.UnescapeDataString(item.ParentReference.Path);

if (!includeApiRoot)
{
string userPath = item.ParentReference.Path.Split(new char[] { ':' })[1];
if (null != userPath && !userPath.EndsWith("/"))
string userPath = decodedPath.Split(new char[] { ':' })[1];
if (null != userPath && userPath.Length > 0 && !userPath.EndsWith("/"))
{
userPath = string.Concat(userPath, "/");
return "/" + userPath + item.Name;
}

return (!userPath.StartsWith("/") ? "/" : "") + userPath + item.Name;
}

var parentPath = item.ParentReference.Path;
if (null != parentPath && !parentPath.EndsWith("/"))
else
{
parentPath = string.Concat(parentPath, "/");
if (!decodedPath.EndsWith("/"))
{
decodedPath = string.Concat(decodedPath, "/");
}
return decodedPath + item.Name;
}

return parentPath + item.Name;
}

return null;
Expand All @@ -127,5 +133,11 @@ public static string Path(this ODItem item, bool includeApiRoot = false)
{
return await connection.DownloadStreamForItemAsync(item.ItemReference(), downloadOptions);
}


public static ODItemReference AddPathComponent(this ODItemReference itemRef, string pathComponent)
{
return new ODExtendedItemReference(itemRef) { AdditionalPath = pathComponent };
}
}
}
2 changes: 1 addition & 1 deletion OneDriveSDK/Facets/FolderFacet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OneDrive.Facets
{
public class FolderFacet
{
[JsonProperty("childCount")]
[JsonProperty("childCount", DefaultValueHandling=DefaultValueHandling.Ignore)]
public long ChildCount { get; set; }
}
}
Loading