예제 #1
0
        private async Task <string> LoadDataAsync_GetFileID(LibraryModel library)
        {
            try
            {
                // LIBRARY FILE ALREADY DEFINED
                var fileID = library.GetKeyValue(SYNC_FILE_ID);
                if (!string.IsNullOrEmpty(fileID))
                {
                    return(fileID);
                }

                // TRY TO SEARCH ON FOLDER
                var folder = new FileData {
                    id = library.Key
                };
                var fileList = await this.Connector.SearchFilesAsync(folder, LibraryModel.SyncFile, 100);

                if (fileList == null || fileList.Count == 0)
                {
                    return(string.Empty);
                }
                var file = fileList.Where(x => x.parentID == library.Key).FirstOrDefault();
                if (file == null)
                {
                    return(string.Empty);
                }

                // RESULT
                return(file.id);
            }
            catch (Exception) { throw; }
        }
예제 #2
0
        public async Task <bool> SaveSyncData(LibraryModel library, byte[] serializedValue)
        {
            try
            {
                using (var serializedStream = new System.IO.MemoryStream(serializedValue))
                {
                    var syncFile = new FileData {
                        FileName = LibraryModel.SyncFile
                    };

                    // SYNC FILE PREVIOUSLY SAVED
                    syncFile.id = library.GetKeyValue(SYNC_FILE_ID);

                    // SET THE MAIN FOLDER WHERE THE FILE MUST BE CREATED
                    if (string.IsNullOrEmpty(syncFile.id))
                    {
                        syncFile.parentID = library.Key;
                    }

                    // UPLOAD CONTENT
                    syncFile = await this.Connector.UploadAsync(syncFile, serializedStream);

                    if (string.IsNullOrEmpty(syncFile.id))
                    {
                        return(false);
                    }

                    // STORE THE LIBRARY FILE ID
                    library.SetKeyValue(SYNC_FILE_ID, syncFile.id);
                    return(true);
                }
            }
            catch (Exception ex) { Helpers.AppCenter.TrackEvent(ex); return(false); }
        }