using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;
using DropNet;
using System.IO;
using RestSharp;
namespace DropBoxAPI
{
internal static class UnmanagedExports
{
[DllExport("CanLogin", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static bool CanLogin(string apikey, string secretkey, string username, string password)
{
DropNetClient _client;
_client = new DropNetClient(apikey, secretkey);
var user = _client.Login(username, password);
if (user == null)
{
return true;
}
else
{
return false;
}
}
[DllExport("Upload", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static void Upload(string apikey, string secretkey, string username, string password, string file, string path)
{
DropNetClient _client;
_client = new DropNetClient(apikey, secretkey);
_client.Login(username, password);
FileInfo ffile = new FileInfo(file);
byte[] content = _client.GetFileContentFromFS(ffile);
_client.UploadFile(path, ffile.Name, content);
}
[DllExport("UploadAsync", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static void UploadAsync(string apikey, string secretkey, string username, string password, string file, string path)
{
DropNetClient _client;
_client = new DropNetClient(apikey, secretkey);
_client.Login(username, password);
FileInfo ffile = new FileInfo(file);
byte[] content = _client.GetFileContentFromFS(ffile);
_client.UploadFile(path, ffile.Name, content);
_client.UploadFileAsync(path, ffile.Name, content, Can_Upload_File_Async_Callback);
}
static void Can_Upload_File_Async_Callback(RestSharp.RestResponse response)
{
}
[DllExport("Delete", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static void delete(string apikey, string secretkey, string username, string password, string file)
{
DropNetClient _client;
_client = new DropNetClient(apikey, secretkey);
_client.Login(username, password);
_client.Delete(file);
}
[DllExport("CreateFolder", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static void createfolder(string apikey, string secretkey, string username, string password, string path)
{
DropNetClient _client;
_client = new DropNetClient(apikey, secretkey);
_client.Login(username, password);
_client.CreateFolder(path);
}
[DllExport("GetMetaData", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static string getmetadata(string apikey, string secretkey, string username, string password, string path)
{
DropNetClient _client;
_client = new DropNetClient(apikey, secretkey);
_client.Login(username, password);
var md = _client.GetMetaData(path);
string retorno="";
for (int i = 0; i < md.Contents.Count; i++)
{
if (i == 0)
{
retorno += md.Contents.Name;
}
else
{
retorno += "|" + md.Contents.Name;
}
}
return retorno;
}
[DllExport("GetFile", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static string getfile(string apikey, string secretkey, string username, string password, string path)
{
DropNetClient _client;
_client = new DropNetClient(apikey, secretkey);
_client.Login(username, password);
var fs = _client.GetFile(path);
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
string str = enc.GetString(fs);
return str;
}
[DllExport("GetFileSave", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static void getfilesave(string apikey, string secretkey, string username, string password, string path, string save)
{
DropNetClient _client;
_client = new DropNetClient(apikey, secretkey);
_client.Login(username, password);
var fs = _client.GetFile(path);
var writeStream = new FileStream(save, FileMode.Create, FileAccess.Write);
writeStream.Write(fs, 0, fs.Length);
writeStream.Close();
}
}
}