public JsonResult Browse(string path)
        {
            path = Path.Combine(ContentPaths[0], path).Replace('\\', '/') + "/";

            var _client = new DropNetClient(accessKey, secretAccessKey, userTokenKey, userSecretKey);
            var _metaData = _client.GetMetaData(path);

            BrowseResult result = new BrowseResult();
            result.ContentPaths = ContentPaths;
            result.Path = path;

            result.Files = _metaData.Contents.Where(e => e.Extension != "").Select(e =>
                {
                    long size = 0;
                    if (e.Size.Contains(" B"))
                        size = (long)double.Parse(e.Size.Replace(" B", "").Replace('.', ','));
                    else if( e.Size.Contains(" KB"))
                        size = (long)(double.Parse(e.Size.Replace(" KB", "").Replace('.', ',')) * 1024);
                    else if (e.Size.Contains(" MB"))
                        size = (long)(double.Parse(e.Size.Replace(" MB", "").Replace('.', ',')) * 1024 * 1024);
                    else if (e.Size.Contains(" GB"))
                        size = (long)(double.Parse(e.Size.Replace(" GB", "").Replace('.', ',')) * 1024 * 1024 * 1024);
                    return new FileEntry { Name = e.Name, Size = size };
                });
            result.Directories = _metaData.Contents.Where(e => e.Extension == "").Select(e => new DirectoryEntry { Name = e.Name });

            return this.Json(result);
        }
示例#2
0
        public DropboxRepository(string appKey, string appSecret, string userToken, string userSecret, string folderPath)
        {
            if (!string.IsNullOrEmpty(appKey) && !string.IsNullOrEmpty(appSecret) && !string.IsNullOrEmpty(userToken) && !string.IsNullOrEmpty(userSecret) && !string.IsNullOrEmpty(folderPath))
            {
                _client = new DropNetClient(apiKey: appKey, appSecret: appSecret, userToken: userToken, userSecret: userSecret);

                _cacheKey = string.Format(_cacheKey, appKey);
                var cachedMetaData = LoadFromCache<MetaData>(cacheKey: _cacheKey);
                if (cachedMetaData != null)
                {
                    _dropboxImageFolderMetaData = cachedMetaData;
                }
                else
                {
                    _dropboxImageFolderMetaData = _client.GetMetaData(path: folderPath);
                    AddToCache(item: _dropboxImageFolderMetaData, cacheKey: _cacheKey, absoluteExpiration: DateTime.Now.AddHours(1));
                }
            }
        }
        public static void filesync()
        {
            //Testing Connection

            if (!LauncherHelper.TestConnection())
                return;

            if (String.IsNullOrEmpty(Properties.Settings.Default.DropBoxUserToken))
            {

                syncAcc(false);

            }

            DropNetClient dbClient = new DropNetClient(Program.Config.AppKey, Program.Config.AppSecret, Properties.Settings.Default.DropBoxUserToken, Properties.Settings.Default.DropBoxUserSecret);

            #if DEBUG
            dbClient.UseSandbox = true;
            #endif

            DropNet.Models.MetaData meta;

            try
            {
                meta = dbClient.GetMetaData("/");
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.StackTrace + "\n maybe your account is not in the Dropbox Dev group for this App");
                return;
            }

            List<string> filelist = new List<string>();

            if (!Directory.Exists(Program.Config.LauncherDir + "/deck/"))
            {
                Directory.CreateDirectory(Program.Config.LauncherDir + "/deck/");
            }

            if (!Directory.Exists(Program.Config.LauncherDir + "/replay/"))
            {
                Directory.CreateDirectory(Program.Config.LauncherDir + "/replay/");
            }

            foreach (string item in Directory.GetFiles(Program.Config.LauncherDir + "/deck/"))
            {
                filelist.Add(item);
            }

            foreach (string item in Directory.GetFiles(Program.Config.LauncherDir + "/replay/"))
            {
                filelist.Add(item);
            }

            foreach (DropNet.Models.MetaData file in meta.Contents)
            {

                if (Path.GetExtension(file.Name) == ".ydk")
                {

                    if (File.Exists(Program.Config.LauncherDir + "/deck/" + file.Name))
                    {
                        if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) < 0)
                        {
                            FileStream fs = new FileStream(Program.Config.LauncherDir + "/deck/" + file.Name, FileMode.Create);
                            fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                            fs.Close();
                        }
                        else if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) > 0)
                        {
                            FileStream fs = File.OpenRead(Program.Config.LauncherDir + "/deck/" + file.Name);
                            byte[] upfile = new byte[fs.Length];
                            fs.Read(upfile, 0, upfile.Length);
                            fs.Close();
                            dbClient.UploadFile("/", file.Name, upfile);
                        }
                    }
                    else
                    {
                        FileStream fs = new FileStream(Program.Config.LauncherDir + "/deck/" + file.Name, FileMode.Create);
                        fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                        fs.Close();
                    }

                }
                else if (Path.GetExtension(file.Name) == ".yrp")
                {

                    if (File.Exists(Program.Config.LauncherDir + "/replay/" + file.Name))
                    {
                        if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) < 0)
                        {
                            FileStream fs = new FileStream(Program.Config.LauncherDir + "/replay/" + file.Name, FileMode.Create);
                            fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                            fs.Close();
                        }
                        else if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) > 0)
                        {
                            FileStream fs = File.OpenRead(Program.Config.LauncherDir + "/replay/" + file.Name);
                            byte[] upfile = new byte[fs.Length];
                            fs.Read(upfile, 0, upfile.Length);
                            fs.Close();
                            dbClient.UploadFile("/", file.Name, upfile);
                        }
                    }
                    else
                    {
                        FileStream fs = new FileStream(Program.Config.LauncherDir + "/replay/" + file.Name, FileMode.Create);
                        fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                        fs.Close();
                    }

                }

            }

            if (filelist.Count > meta.Contents.Count)
            {
                foreach (string file in filelist)
                {
                    if (Path.GetExtension(file) == ".ydk")
                    {
                        FileStream fs = File.OpenRead(Program.Config.LauncherDir + "/deck/" + Path.GetFileName(file));
                        byte[] upfile = new byte[fs.Length];
                        fs.Read(upfile, 0, upfile.Length);
                        fs.Close();
                        dbClient.UploadFile("/", Path.GetFileName(file), upfile);
                    }
                    else if (Path.GetExtension(file) == ".yrp")
                    {
                        FileStream fs = File.OpenRead(Program.Config.LauncherDir + "/replay/" + Path.GetFileName(file));
                        byte[] upfile = new byte[fs.Length];
                        fs.Read(upfile, 0, upfile.Length);
                        fs.Close();
                        dbClient.UploadFile("/", Path.GetFileName(file), upfile);
                    }

                }

            }

            //MessageBox.Show("yeah!!");
        }
示例#4
0
 public static List<StorageTree> BuildDropboxSubtreeTwoLevels(DropNetClient client, string scope)
 {
     var metadata = client.GetMetaData(scope);
     List<StorageTree> subFolders = new List<StorageTree>();
     foreach (var file in metadata.Contents)
     {
         if (file.Is_Dir)
         {
             subFolders.Add(new StorageTree()
             {
                 Id = file.Path,
                 Name = file.Name,
                 Source = StorageService.ServiceTypes.Dropbox,
                 Queried = false,
                 Subtree = BuildDropboxSubtreeOneLevel(client, file.Path)
             });
         }
     }
     return subFolders;
 }
 public void UploadFolderCreate(string folder, string path, DropNetClient client)
 {
     //client = new DropNetClient(apiKey, appSecret, GetUserLoginDB(tokendb), GetUserLoginDB(secretdb));
     try
     {   //Create a Folder
         if (path == null)
         {
             var metaData = client.GetMetaData("/",null,false);
             if (!(metaData.Contents.Any(c => c.Is_Dir && c.Path == "/" + folder)))
             {
                 client.CreateFolder("/" + folder);
             }
         }
         else
         {
             var metaData = client.GetMetaData(path,null,false);
             if (!(metaData.Contents.Any(c => c.Is_Dir && c.Path == folder)))
             {
                 client.CreateFolder(path + "/" + folder);
             }
         }
     }
     catch (DirectoryNotFoundException ex)
     {
         MessageBox.Show(ex.Message.ToString());
     }
 }
        /// <summary>
        /// This method does all the dirty work for you (syncs any folder with db)
        /// </summary>
        /// <param name="folder">the folder you want to sync</param>
        private static void syncFolder(string folder)
        {
            DropNetClient dbClient = new DropNetClient(Program.Config.AppKey, Program.Config.AppSecret, Properties.Settings.Default.DropBoxUserToken, Properties.Settings.Default.DropBoxUserSecret);

            #if DEBUG
            dbClient.UseSandbox = true;
            Program.Config.LauncherDir = "C:/Program Files (x86)/DevPro/";
            #endif

            DropNet.Models.MetaData meta;

            try
            {

                meta = dbClient.GetMetaData("/" + folder);
            }
            catch (Exception exc)
            {
                try
                {
                    dbClient.CreateFolder("/" + folder);
                    meta = dbClient.GetMetaData("/" + folder);
                }
                catch (Exception)
                {
                    MessageBox.Show(exc.StackTrace + "\n maybe your account is not in the Dropbox Dev group for this App");
                    return;
                }

            }

            List<string> filelist = new List<string>();
            List<string> dirlist = new List<string>();
            //Program.Config.LauncherDir + "/" +
            if (!Directory.Exists(Program.Config.LauncherDir + folder))
            {
                Directory.CreateDirectory(Program.Config.LauncherDir + folder);
            }

            foreach (string item in Directory.GetFiles(Program.Config.LauncherDir + folder))
            {
                filelist.Add(item);
            }

            foreach (string item in Directory.GetDirectories(Program.Config.LauncherDir + folder))
            {
                dirlist.Add(item);
            }

            if (filelist.Count == 0 && dirlist.Count != 0)
            {
                foreach (string item in dirlist)
                {
                    syncFolder(folder + Path.GetFileNameWithoutExtension(item) + "/");
                    return;
                }
            }

            foreach (DropNet.Models.MetaData file in meta.Contents)
            {

                if (File.Exists(Program.Config.LauncherDir + folder + file.Name))
                {
                    if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + folder + file.Name)) < 0)
                    {
                        FileStream fs = new FileStream(Program.Config.LauncherDir + folder + file.Name, FileMode.Create);
                        fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                        fs.Close();
                    }
                    else if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + folder + file.Name)) > 0)
                    {
                        FileStream fs = File.OpenRead(Program.Config.LauncherDir + folder + file.Name);
                        byte[] upfile = new byte[fs.Length];
                        fs.Read(upfile, 0, upfile.Length);
                        fs.Close();
                        dbClient.UploadFile("/" + folder, file.Name, upfile);
                    }
                }
                else
                {
                    FileStream fs = new FileStream(Program.Config.LauncherDir + folder + file.Name, FileMode.Create);
                    fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                    fs.Close();
                }

            }

            if (filelist.Count + dirlist.Count > meta.Contents.Count)
            {

                foreach (string file in filelist)
                {

                    FileStream fs = File.OpenRead(Program.Config.LauncherDir + folder + Path.GetFileName(file));
                    byte[] upfile = new byte[fs.Length];
                    fs.Read(upfile, 0, upfile.Length);
                    fs.Close();
                    dbClient.UploadFile("/" + folder, Path.GetFileName(file), upfile);

                }
            }
        }