コード例 #1
0
 public static int GetStorageIndex(string key)
 {
     return(StorageHelper.GetStorageList().IndexOf(StorageHelper.GetStorageManager(key)));
 }
コード例 #2
0
 public static int GetCurrentIndex()
 {
     return(StorageHelper.GetStorageList().IndexOf(CurrentManager));
 }
コード例 #3
0
 public static void SetStorageTo(string key)
 {
     CurrentManager = StorageHelper.GetStorageManager(key);
 }
コード例 #4
0
        public static IStorageManager GetMainStorage()
        {
            IStorageManager retStorage = StorageHelper.GetStorageManager((string)App.ApplicationSettings[MAIN_PLATFORM_TYPE_KEY]);

            return(retStorage);
        }
コード例 #5
0
        public async static Task <bool> Synchronize(string key)
        {
            IStorageManager Storage = StorageHelper.GetStorageManager(key);
            bool            result  = await TaskHelper.WaitSignInTask(Storage.GetStorageName());

            if (result == false)
            {
                return(false);
            }
            // Fetching from SQL
            if (false && App.ApplicationSettings.Contains(SYNC_KEYS + key))
            {
                System.Diagnostics.Debug.WriteLine("Fetching From SQL");
                try
                {
                    //var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, key + "data.db3");
                    //using (var db = new SQLite.SQLiteConnection(dbpath))
                    //{
                    //    // Create the tables if they don't exist
                    //    db.DropTable<FileObjectSQL>();
                    //    db.CreateTable<FileObjectSQL>();
                    //    db.Commit();

                    //    var rootDB = from fos in db.Table<FileObjectSQL>() where fos.ParentId.Equals(ROOT_ID) select fos;

                    //    List<FileObjectSQL> getsqlList = rootDB.ToList<FileObjectSQL>();

                    //    if (getsqlList.Count != 1) System.Diagnostics.Debugger.Break();

                    //    FileObjectSQL rootFos = getsqlList.First<FileObjectSQL>();

                    //    FileObject rootFolder = FileObject.ConvertToFileObject(db, rootFos);

                    //    if (DictionaryRoot.ContainsKey(key))
                    //    {
                    //        DictionaryRoot.Remove(key);
                    //    }
                    //    DictionaryRoot.Add(key, rootFolder);

                    //    Stack<FileObject> stack = new Stack<FileObject>();
                    //    stack.Push(rootFolder);
                    //    if (DictionaryTree.ContainsKey(key))
                    //    {
                    //        DictionaryTree.Remove(key);
                    //    }
                    //    DictionaryTree.Add(key, stack);

                    //    //db.Dispose();
                    //    //db.Close();
                    //}



                    //using (FileObjectDataContext db = new FileObjectDataContext("isostore:/" + key + "_db.sdf"))
                    //{
                    //    if (!db.DatabaseExists())
                    //    {
                    //        App.ApplicationSettings.Remove(SYNC_KEYS + key);
                    //        return await Synchronize(key);
                    //    }
                    //    var rootDB = from FileObjectSQL fos in db.FileItems where fos.ParentId.Equals(ROOT_ID) select fos;

                    //    List<FileObjectSQL> getsqlList = rootDB.ToList<FileObjectSQL>();

                    //    if (getsqlList.Count != 1) System.Diagnostics.Debugger.Break();

                    //    FileObjectSQL rootFos = getsqlList.First<FileObjectSQL>();

                    //    FileObject rootFolder = FileObject.ConvertToFileObject(db, rootFos);

                    //    if (DictionaryRoot.ContainsKey(key))
                    //    {
                    //        DictionaryRoot.Remove(key);
                    //    }
                    //    DictionaryRoot.Add(key, rootFolder);

                    //    Stack<FileObject> stack = new Stack<FileObject>();
                    //    stack.Push(rootFolder);
                    //    if (DictionaryTree.ContainsKey(key))
                    //    {
                    //        DictionaryTree.Remove(key);
                    //    }
                    //    DictionaryTree.Add(key, stack);
                    //}
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.ToString());
                    System.Diagnostics.Debugger.Break();
                    return(false);
                }
            }
            // Fetching from Server
            else
            {
                System.Diagnostics.Debug.WriteLine("Fetching From Server");
                if (Storage.IsSignIn())
                {
                    FileObject rootFolder = await Storage.Synchronize();

                    if (DictionaryRoot.ContainsKey(key))
                    {
                        DictionaryRoot.Remove(key);
                    }
                    DictionaryRoot.Add(key, rootFolder);

                    Stack <FileObject> stack = new Stack <FileObject>();
                    stack.Push(rootFolder);
                    if (DictionaryTree.ContainsKey(key))
                    {
                        DictionaryTree.Remove(key);
                    }
                    DictionaryTree.Add(key, stack);
                    ////////////////////////////////////////////
                    // Saving to SQL job
                    ////////////////////////////////////////////
                    //try
                    //{
                    //    var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, key + "data.db3");
                    //    System.Diagnostics.Debug.WriteLine(dbpath);
                    //    using (var db = new SQLite.SQLiteConnection("Data Source=database.db"))
                    //    {
                    //        // Create the tables if they don't exist
                    //        db.DropTable<FileObjectSQL>();
                    //        db.CreateTable<FileObjectSQL>();
                    //        db.Commit();


                    //        List<FileObjectSQL> sqlList = new List<FileObjectSQL>();

                    //        FileObject.ConvertToFileObjectSQL(sqlList, rootFolder, ROOT_ID);

                    //        for (var i = 0; i < sqlList.Count; i++)
                    //        {
                    //            db.Insert(sqlList[i]);
                    //        }
                    //        db.Commit();

                    //    }
                    //    using (FileObjectDataContext db = new FileObjectDataContext("isostore:/" + key + "_db.sdf"))
                    //    {
                    //        if (db.DatabaseExists())
                    //        {
                    //            db.DeleteDatabase();
                    //        }
                    //        db.CreateDatabase();


                    //        List<FileObjectSQL> sqlList = new List<FileObjectSQL>();

                    //        FileObject.ConvertToFileObjectSQL(sqlList, rootFolder, ROOT_ID);

                    //        for (var i = 0; i < sqlList.Count; i++)
                    //        {
                    //            db.FileItems.InsertOnSubmit(sqlList[i]);
                    //        }

                    //        db.SubmitChanges();
                    //    }
                    //}
                    //catch (Exception e)
                    //{
                    //    System.Diagnostics.Debug.WriteLine(e.ToString());
                    //    System.Diagnostics.Debugger.Break();
                    //}

                    App.ApplicationSettings[SYNC_KEYS + key] = true;
                    App.ApplicationSettings.Save();
                    return(true);
                }
                return(false);
            }
        }