Skip to content

Commit

Permalink
Update samples by adding namespace and replacing INodeInfo with INode
Browse files Browse the repository at this point in the history
  • Loading branch information
gpailler committed Jan 29, 2022
1 parent 700d44b commit d07175c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/articles/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async void Main()
client.LoginAnonymous();

Uri fileLink = new Uri("https://mega.nz/#!bkwkHC7D!AWJuto8_fhleAI2WG0RvACtKkL_s9tAtvBXXDUp2bQk");
INodeInfo node = client.GetNodeFromLink(fileLink);
INode node = client.GetNodeFromLink(fileLink);

IProgress<double> progressHandler = new Progress<double>(x => Console.WriteLine("{0}%", x));
await client.DownloadFileAsync(fileLink, node.Name, progressHandler);
Expand Down
41 changes: 32 additions & 9 deletions docs/articles/samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ uid: samples

### List all files / folders on your Mega account
```csharp
using CG.Web.MegaApiClient;

void Main()
{
var client = new MegaApiClient();
MegaApiClient client = new MegaApiClient();
client.Login("[email protected]", "passw0rd");

// GetNodes retrieves all files/folders metadata from Mega
Expand Down Expand Up @@ -37,13 +39,15 @@ void DisplayNodesRecursive(IEnumerable<INode> nodes, INode parent, int level = 0

### Download file from a Mega link
```csharp
using CG.Web.MegaApiClient;

void Main()
{
var client = new MegaApiClient();
MegaApiClient client = new MegaApiClient();
client.LoginAnonymous();

Uri fileLink = new Uri("https://mega.nz/#!bkwkHC7D!AWJuto8_fhleAI2WG0RvACtKkL_s9tAtvBXXDUp2bQk");
INodeInfo node = client.GetNodeFromLink(fileLink);
Uri fileLink = new Uri("https://mega.nz/file/W0UAgJaK#XOYyTETrIy8daz3_dw3fdh6Hh8EFEdrnbyoop1r9R6g");
INode node = client.GetNodeFromLink(fileLink);

Console.WriteLine($"Downloading {node.Name}");
client.DownloadFile(fileLink, node.Name);
Expand All @@ -55,29 +59,48 @@ void Main()

### Download folder content from a Mega link
```csharp
using CG.Web.MegaApiClient;

void Main()
{
var client = new MegaApiClient();
MegaApiClient client = new MegaApiClient();
client.LoginAnonymous();

Uri folderLink = new Uri("https://mega.nz/#F!e1ogxQ7T!ee4Q_ocD1bSLmNeg9B6kBw");
Uri folderLink = new Uri("https://mega.nz/folder/e4diDZ7T#iJnegBO_m6OXBQp27lHCrg");
IEnumerable<INode> nodes = client.GetNodesFromLink(folderLink);
foreach (INode node in nodes.Where(x => x.Type == NodeType.File))
{
Console.WriteLine($"Downloading {node.Name}");
client.DownloadFile(node, node.Name);
string parents = GetParents(node, nodes);
Directory.CreateDirectory(parents);
Console.WriteLine($"Downloading {parents}\\{node.Name}");
client.DownloadFile(node, Path.Combine(parents, node.Name));
}

client.Logout();
}

string GetParents(INode node, IEnumerable<INode> nodes)
{
List<string> parents = new List<string>();
while (node.ParentId != null)
{
INode parentNode = nodes.Single(x => x.Id == node.ParentId);
parents.Insert(0, parentNode.Name);
node = parentNode;
}

return string.Join('\\', parents);
}
```


### Upload a file to your Mega account and retrieve public download link
```csharp
using CG.Web.MegaApiClient;

void Main()
{
var client = new MegaApiClient();
MegaApiClient client = new MegaApiClient();
client.Login("[email protected]", "passw0rd");

IEnumerable<INode> nodes = client.GetNodes();
Expand Down

0 comments on commit d07175c

Please sign in to comment.