瀏覽代碼

Add files via upload

new DB
Marino Faggiana 8 年之前
父節點
當前提交
c304f63088

+ 34 - 0
iOSClient/Database/CCCoreData.h

@@ -0,0 +1,34 @@
+//
+//  CCCoreData.h
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 02/02/16.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreData/CoreData.h>
+
+@class tableMetadata;
+
+@interface CCCoreData : NSObject
+
++ (NSArray *)getAllAccount;
++ (NSMutableArray *)getAllCertificatesLocationOldDB;
+
+@end

+ 64 - 0
iOSClient/Database/CCCoreData.m

@@ -0,0 +1,64 @@
+//
+//  CCCoreData.m
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 02/02/16.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#import "CCCoreData.h"
+
+#import "TableAccount+CoreDataClass.h"
+#import "TableCertificates+CoreDataClass.h"
+#import "TableDirectory+CoreDataClass.h"
+#import "TableLocalFile+CoreDataClass.h"
+
+#import <MagicalRecord/MagicalRecord.h>
+
+@implementation CCCoreData
+
++ (NSArray *)getAllAccount
+{
+    NSMutableArray *accounts = [NSMutableArray new];
+    NSArray *records;
+    
+    records = [TableAccount MR_findAll];
+    
+    for (TableAccount *tableAccount in records)
+        [accounts addObject:tableAccount];
+    
+    return accounts;
+}
+
++ (NSMutableArray *)getAllCertificatesLocationOldDB
+{
+    NSMutableArray *output = [NSMutableArray new];
+    
+    NSArray *records = [TableCertificates MR_findAll];
+    
+    for (TableCertificates *record in records) {
+        
+        if (record.certificateLocation && record.certificateLocation.length > 0)
+            [output addObject:record.certificateLocation];
+        
+    }
+    
+    return output;
+}
+
+@end

+ 217 - 0
iOSClient/Database/NCDatabase.swift

@@ -0,0 +1,217 @@
+//
+//  NCDatabase.swift
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 06/05/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import RealmSwift
+
+class tableAccount: Object {
+
+    dynamic var account = ""
+    dynamic var active : Bool = false
+    dynamic var address = ""
+    dynamic var cameraUpload : Bool = false
+    dynamic var cameraUploadBackground : Bool = false
+    dynamic var cameraUploadCreateSubfolder : Bool = false
+    dynamic var cameraUploadDatePhoto: NSDate? = nil
+    dynamic var cameraUploadDateVideo: NSDate? = nil
+    dynamic var cameraUploadFolderName = ""
+    dynamic var cameraUploadFolderPath = ""
+    dynamic var cameraUploadFull : Bool = false
+    dynamic var cameraUploadPhoto : Bool = false
+    dynamic var cameraUploadVideo : Bool = false
+    dynamic var cameraUploadWWAnPhoto : Bool = false
+    dynamic var cameraUploadWWAnVideo : Bool = false
+    dynamic var displayName = ""
+    dynamic var email = ""
+    dynamic var enabled : Bool = false
+    dynamic var optimization = NSDate()
+    dynamic var password = ""
+    dynamic var phone = ""
+    dynamic var quota : Double = 0
+    dynamic var quotaFree : Double = 0
+    dynamic var quotaRelative : Double = 0
+    dynamic var quotaTotal : Double = 0
+    dynamic var quotaUsed : Double = 0
+    dynamic var twitter = ""
+    dynamic var url = ""
+    dynamic var user = ""
+    dynamic var webpage = ""
+}
+
+class tableActivity: Object {
+    
+    dynamic var account = ""
+    dynamic var action = "Activity"
+    dynamic var date = NSDate()
+    dynamic var file = ""
+    dynamic var fileID = ""
+    dynamic var idActivity : Double = 0
+    dynamic var link = ""
+    dynamic var note = ""
+    dynamic var selector = ""
+    dynamic var type = ""
+    dynamic var verbose : Bool = false
+}
+
+class tableAutomaticUpload: Object {
+    
+    dynamic var account = ""
+    dynamic var assetLocalIdentifier = ""
+    dynamic var date = NSDate()
+    dynamic var fileName = ""
+    dynamic var lock : Bool = false
+    dynamic var priority : Int = 0
+    dynamic var selector = ""
+    dynamic var selectorPost = ""
+    dynamic var serverUrl = ""
+    dynamic var session = ""
+}
+
+class tableCapabilities: Object {
+    
+    dynamic var account = ""
+    dynamic var themingBackground = ""
+    dynamic var themingColor = ""
+    dynamic var themingLogo = ""
+    dynamic var themingName = ""
+    dynamic var themingSlogan = ""
+    dynamic var themingUrl = ""
+    dynamic var versionMajor : Int = 0
+    dynamic var versionMicro : Int = 0
+    dynamic var versionMinor : Int = 0
+    dynamic var versionString = ""
+}
+
+class tableCertificates: Object {
+    
+    dynamic var certificateLocation = ""
+}
+
+class tableDirectory: Object {
+    
+    dynamic var account = ""
+    dynamic var dateReadDirectory: NSDate? = nil
+    dynamic var directoryID = ""
+    dynamic var favorite: Bool = false
+    dynamic var fileID = ""
+    dynamic var lock : Bool = false
+    dynamic var offline : Bool = false
+    dynamic var permissions = ""
+    dynamic var rev = ""
+    dynamic var serverUrl = ""
+    dynamic var synchronized: Bool = false
+    
+    override static func primaryKey() -> String {
+        return "directoryID"
+    }
+}
+
+class tableExternalSites: Object {
+    
+    dynamic var account = ""
+    dynamic var icon = ""
+    dynamic var idExternalSite : Int = 0
+    dynamic var lang = ""
+    dynamic var name = ""
+    dynamic var type = ""
+    dynamic var url = ""
+}
+
+class tableGPS: Object {
+    
+    dynamic var latitude = ""
+    dynamic var location = ""
+    dynamic var longitude = ""
+    dynamic var placemarkAdministrativeArea = ""
+    dynamic var placemarkCountry = ""
+    dynamic var placemarkLocality = ""
+    dynamic var placemarkPostalCode = ""
+    dynamic var placemarkThoroughfare = ""
+}
+
+class tableLocalFile: Object {
+    
+    dynamic var account = ""
+    dynamic var date = NSDate()
+    dynamic var exifDate = NSDate()
+    dynamic var exifLatitude = ""
+    dynamic var exifLongitude = ""
+    dynamic var favorite: Bool = false
+    dynamic var fileID = ""
+    dynamic var fileName = ""
+    dynamic var fileNamePrint = ""
+    dynamic var offline : Bool = false
+    dynamic var rev = ""
+    dynamic var size : Double = 0
+    
+    override static func primaryKey() -> String {
+        return "fileID"
+    }
+}
+
+class tableMetadata: Object {
+    
+    dynamic var account = ""
+    dynamic var assetLocalIdentifier = ""
+    dynamic var cryptated : Bool = false
+    dynamic var date = NSDate()
+    dynamic var directory : Bool = false
+    dynamic var directoryID = ""
+    dynamic var errorPasscode : Bool = false
+    dynamic var favorite : Bool = false
+    dynamic var fileID = ""
+    dynamic var fileName = ""
+    dynamic var fileNameData = ""
+    dynamic var fileNamePrint = ""
+    dynamic var iconName = ""
+    dynamic var model = ""
+    dynamic var nameCurrentDevice = ""
+    dynamic var permissions = ""
+    dynamic var protocolCrypto = ""
+    dynamic var rev = ""
+    dynamic var session = ""
+    dynamic var sessionError = ""
+    dynamic var sessionID = ""
+    dynamic var sessionSelector = ""
+    dynamic var sessionSelectorPost = ""
+    dynamic var sessionTaskIdentifier : Int = -1
+    dynamic var sessionTaskIdentifierPlist : Int = -1
+    dynamic var size : Double = 0
+    dynamic var thumbnailExists : Bool = false
+    dynamic var title = ""
+    dynamic var type = ""
+    dynamic var typeFile = ""
+    dynamic var uuid = ""
+    
+    override static func primaryKey() -> String {
+        return "fileID"
+    }
+}
+
+class tableShare: Object {
+    
+    dynamic var account = ""
+    dynamic var fileName = ""
+    dynamic var serverUrl = ""
+    dynamic var shareLink = ""
+    dynamic var shareUserAndGroup = ""
+}

+ 1943 - 0
iOSClient/Database/NCManageDatabase.swift

@@ -0,0 +1,1943 @@
+//
+//  NCManageDatabase.swift
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 06/05/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import RealmSwift
+
+class NCManageDatabase: NSObject {
+        
+    static let sharedInstance: NCManageDatabase = {
+        let instance = NCManageDatabase()
+        return instance
+    }()
+    
+    override init() {
+        
+        let dirGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.sharedInstance.capabilitiesGroups)
+        let config = Realm.Configuration(
+        
+            fileURL: dirGroup?.appendingPathComponent("\(appDatabaseNextcloud)/\(k_databaseDefault)"),
+            schemaVersion: 1,
+            
+            migrationBlock: { migration, oldSchemaVersion in
+                // We haven’t migrated anything yet, so oldSchemaVersion == 0
+                if (oldSchemaVersion < 1) {
+                    // Nothing to do!
+                    // Realm will automatically detect new properties and removed properties
+                    // And will update the schema on disk automatically
+                }
+        })
+
+        Realm.Configuration.defaultConfiguration = config
+        _ = try! Realm()
+    }
+    
+    //MARK: -
+    //MARK: Utility Database
+
+    func clearTable(_ table : Object.Type, account: String?) {
+        
+        let results : Results<Object>
+        let realm = try! Realm()
+        
+        realm.beginWrite()
+        
+        if account != nil {
+            
+            results = realm.objects(table).filter("account = %@", account!)
+
+        } else {
+         
+            results = realm.objects(table)
+        }
+    
+        realm.delete(results)
+
+        try! realm.commitWrite()
+    }
+    
+    func removeDB() {
+        
+        let realmURL = Realm.Configuration.defaultConfiguration.fileURL!
+        let realmURLs = [
+            realmURL,
+            realmURL.appendingPathExtension("lock"),
+            realmURL.appendingPathExtension("note"),
+            realmURL.appendingPathExtension("management")
+        ]
+        for URL in realmURLs {
+            do {
+                try FileManager.default.removeItem(at: URL)
+            } catch {
+                // handle error
+            }
+        }
+    }
+    
+    func getThreadConfined(_ table: Object) -> Any {
+     
+        // id tradeReference = [[NCManageDatabase sharedInstance] getThreadConfined:metadata];
+        return ThreadSafeReference(to: table)
+    }
+    
+    func putThreadConfined(_ tableRef: Any) -> Object? {
+        
+        //tableMetadata *metadataThread = (tableMetadata *)[[NCManageDatabase sharedInstance] putThreadConfined:tradeReference];
+        let realm = try! Realm()
+        
+        return realm.resolve(tableRef as! ThreadSafeReference<Object>)
+    }
+    
+    func isTableInvalidated(_ table: Object) -> Bool {
+     
+        return table.isInvalidated
+    }
+    
+    //MARK: -
+    //MARK: Table Account
+    
+    func addAccount(_ account: String, url: String, user: String, password: String) {
+
+        let realm = try! Realm()
+        
+        realm.beginWrite()
+            
+        let addAccount = tableAccount()
+            
+        addAccount.account = account
+            
+        // Brand
+        if NCBrandOptions.sharedInstance.use_default_automatic_upload {
+                
+            addAccount.cameraUpload = true
+            addAccount.cameraUploadPhoto = true
+            addAccount.cameraUploadVideo = true
+
+            addAccount.cameraUploadWWAnVideo = true
+        }
+            
+        addAccount.password = password
+        addAccount.url = url
+        addAccount.user = user
+            
+        realm.add(addAccount)
+        
+        try! realm.commitWrite()
+    }
+    
+    func addTableAccountOldDB(_ table: TableAccount) {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAccount.self).filter("account = %@", table.account!)
+        if (results.count == 0) {
+        
+            try! realm.write {
+                
+                let addAccount = tableAccount()
+                
+                addAccount.account = table.account!
+                if table.active == 1 {
+                    addAccount.active = true
+                }
+                if table.cameraUpload == 1 {
+                    addAccount.cameraUpload = true
+                }
+                if table.cameraUploadBackground == 1 {
+                    addAccount.cameraUploadBackground = true
+                }
+                if table.cameraUploadCreateSubfolder == 1 {
+                    addAccount.cameraUploadCreateSubfolder = true
+                }
+                if table.cameraUploadDatePhoto != nil {
+                    addAccount.cameraUploadDatePhoto = table.cameraUploadDatePhoto! as NSDate
+                }
+                if table.cameraUploadDateVideo != nil {
+                    addAccount.cameraUploadDateVideo = table.cameraUploadDateVideo! as NSDate
+                }
+                if table.cameraUploadFolderName != nil {
+                    addAccount.cameraUploadFolderName = table.cameraUploadFolderName!
+                }
+                if table.cameraUploadFolderPath != nil {
+                    addAccount.cameraUploadFolderPath = table.cameraUploadFolderPath!
+                }
+                if table.cameraUploadFull == 1 {
+                    addAccount.cameraUploadFull = true
+                }
+                if table.cameraUploadPhoto == 1 {
+                    addAccount.cameraUploadPhoto = true
+                }
+                if table.cameraUploadVideo == 1 {
+                    addAccount.cameraUploadVideo = true
+                }
+                if table.cameraUploadWWAnPhoto == 1 {
+                    addAccount.cameraUploadWWAnPhoto = true
+                }
+                if table.cameraUploadWWAnVideo == 1 {
+                    addAccount.cameraUploadWWAnVideo = true
+                }
+                addAccount.password = table.password!
+                addAccount.url = table.url!
+                addAccount.user = table.user!
+                
+                realm.add(addAccount)
+            }
+        }
+    }
+
+    func setAccountPassword(_ account: String, password: String) {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAccount.self).filter("account = %@", account)
+        if (results.count > 0) {
+            
+            try! realm.write {
+                results[0].password = password
+            }
+        }
+    }
+    
+    func deleteAccount(_ account: String) {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAccount.self).filter("account = %@", account)
+        if (results.count > 0) {
+            
+            try! realm.write {
+                realm.delete(results)
+            }
+        }
+    }
+
+    func getAccountActive() -> tableAccount? {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAccount.self).filter("active = true")
+        if (results.count > 0) {
+            return results[0]
+        } else {
+            return nil
+        }
+    }
+
+    func getAccounts() -> [String] {
+        
+        let realm = try! Realm()
+        let results : Results<tableAccount>
+        var accounts = [String]()
+        
+        results = realm.objects(tableAccount.self).sorted(byKeyPath: "account", ascending: true)
+            
+        for result in results {
+            accounts.append(result.account)
+        }
+
+        return Array(accounts)
+    }
+    
+    func getAccountCameraUploadFolderName() -> String {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAccount.self).filter("active = true")
+        if (results.count > 0) {
+            
+            if results[0].cameraUploadFolderName.characters.count > 0 {
+                
+                return results[0].cameraUploadFolderName
+                
+            } else {
+                
+                return NCBrandOptions.sharedInstance.folderDefaultCameraUpload
+            }
+        }
+        
+        return ""
+    }
+    
+    func getAccountCameraUploadFolderPath(activeUrl : String) -> String {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAccount.self).filter("active = true")
+        if (results.count > 0) {
+            
+            if results[0].cameraUploadFolderPath.characters.count > 0 {
+                
+                return results[0].cameraUploadFolderPath
+                
+            } else {
+                
+                return CCUtility.getHomeServerUrlActiveUrl(activeUrl)
+            }
+        }
+        
+        return ""
+    }
+
+    func getAccountCameraUploadFolderPathAndName(activeUrl : String) -> String {
+        
+        let cameraFolderName = self.getAccountCameraUploadFolderName()
+        let cameraFolderPath = self.getAccountCameraUploadFolderPath(activeUrl: activeUrl)
+     
+        let folderPhotos = CCUtility.stringAppendServerUrl(cameraFolderPath, addFileName: cameraFolderName)!
+        
+        return folderPhotos
+    }
+    
+    func setAccountActive(_ account: String) -> tableAccount {
+        
+        let realm = try! Realm()
+        var activeAccount = tableAccount()
+        
+        let results = realm.objects(tableAccount.self)
+        
+        try! realm.write {
+            
+            for result in results {
+                
+                if result.account == account {
+                    
+                    result.active = true
+                    activeAccount = result
+                    
+                } else {
+                    
+                    result.active = false
+                }
+            }
+        }
+        
+        return activeAccount
+    }
+
+    func setAccountCameraStateFiled(_ field: String, state: Bool) {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAccount.self).filter("active = true")
+        if (results.count > 0) {
+            try! realm.write {
+                
+                switch field {
+                case "cameraUpload":
+                    results[0].cameraUpload = state
+                case "cameraUploadBackground":
+                    results[0].cameraUploadBackground = state
+                case "cameraUploadCreateSubfolder":
+                    results[0].cameraUploadCreateSubfolder = state
+                case "cameraUploadFull":
+                    results[0].cameraUploadFull = state
+                case "cameraUploadPhoto":
+                    results[0].cameraUploadPhoto = state
+                case "cameraUploadVideo":
+                    results[0].cameraUploadVideo = state
+                case "cameraUploadWWAnPhoto":
+                    results[0].cameraUploadWWAnPhoto = state
+                case "cameraUploadWWAnVideo":
+                    results[0].cameraUploadWWAnVideo = state
+                default:
+                    print("No founfd field")
+                }
+            }
+        }
+    }
+    
+    func setAccountCameraUploadDateAssetType(_ assetMediaType: PHAssetMediaType, assetDate: NSDate?) {
+
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAccount.self).filter("active = true")
+        
+        try! realm.write {
+            if (assetMediaType == PHAssetMediaType.image && results.count > 0) {
+                results[0].cameraUploadDatePhoto = assetDate
+            }
+            if (assetMediaType == PHAssetMediaType.video && results.count > 0) {
+                results[0].cameraUploadDateVideo = assetDate
+            }
+        }
+    }
+    
+    func setAccountCameraUploadFolderName(_ folderName: String?) {
+        
+        let realm = try! Realm()
+        var folderName : String? = folderName
+        
+        if folderName == nil {
+            folderName = self.getAccountCameraUploadFolderName()
+        }
+        
+        let results = realm.objects(tableAccount.self).filter("active = true")
+        if (results.count > 0) {
+            try! realm.write {
+                
+                results[0].cameraUploadFolderName = folderName!
+            }
+        }
+    }
+
+    func setAccountCameraUploadFolderPath(_ pathName: String?, activeUrl: String) {
+        
+        let realm = try! Realm()
+        var pathName : String? = pathName
+        
+        if pathName == nil {
+            pathName = self.getAccountCameraUploadFolderPath(activeUrl: activeUrl)
+        }
+        
+        let results = realm.objects(tableAccount.self).filter("active = true")
+        if (results.count > 0) {
+            try! realm.write {
+                
+                results[0].cameraUploadFolderPath = pathName!
+            }
+        }
+    }
+    
+    func setAccountsUserProfile(_ userProfile: OCUserProfile) {
+     
+        let tblAccount = self.getAccountActive()
+        if tblAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAccount.self).filter("account = %@", tblAccount!.account)
+        if (results.count > 0) {
+
+            try! realm.write {
+                
+                results[0].enabled = userProfile.enabled
+                results[0].address = userProfile.address
+                results[0].displayName = userProfile.displayName
+                results[0].email = userProfile.email
+                results[0].phone = userProfile.phone
+                results[0].twitter = userProfile.twitter
+                results[0].webpage = results[0].webpage
+                
+                results[0].quota = userProfile.quota
+                results[0].quotaFree = userProfile.quotaFree
+                results[0].quotaRelative = userProfile.quotaRelative
+                results[0].quotaTotal = userProfile.quotaTotal
+                results[0].quotaUsed = userProfile.quotaUsed
+            }
+        }
+    }
+    
+    //MARK: -
+    //MARK: Table Activity
+
+    func getActivity(predicate: NSPredicate) -> [tableActivity] {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableActivity.self).filter(predicate).sorted(byKeyPath: "date", ascending: false)
+        
+        return Array(results)
+    }
+
+    func addActivityServer(_ listOfActivity: [OCActivity]) {
+    
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        try! realm.write {
+            
+            for activity in listOfActivity {
+                
+                let results = realm.objects(tableActivity.self).filter("idActivity = %d", activity.idActivity)
+                if (results.count > 0) {
+                    continue
+                }
+                
+                // Add new Activity
+                let addActivity = tableActivity()
+                
+                addActivity.account = tableAccount!.account
+                
+                if activity.date != nil {
+                    addActivity.date = activity.date! as NSDate
+                }
+                
+                addActivity.idActivity = Double(activity.idActivity)
+                addActivity.link = activity.link
+                addActivity.note = activity.subject
+                addActivity.type = k_activityTypeInfo
+
+                realm.add(addActivity)
+            }
+        }
+    }
+    
+    func addActivityClient(_ file: String, fileID: String, action: String, selector: String, note: String, type: String, verbose: Bool, activeUrl: String?) {
+
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        var noteReplacing : String = ""
+        
+        if (activeUrl != nil) {
+            noteReplacing = note.replacingOccurrences(of: "\(activeUrl!)\(webDAV)", with: "")
+        }
+        noteReplacing = note.replacingOccurrences(of: "\(k_domain_session_queue).", with: "")
+
+        let realm = try! Realm()
+        
+        try! realm.write {
+
+            // Add new Activity
+            let addActivity = tableActivity()
+
+            addActivity.account = tableAccount!.account
+            addActivity.action = action
+            addActivity.file = file
+            addActivity.fileID = fileID
+            addActivity.note = noteReplacing
+            addActivity.selector = selector
+            addActivity.type = type
+            addActivity.verbose = verbose
+
+            realm.add(addActivity)
+        }
+    }
+    
+    //MARK: -
+    //MARK: Table Automatic Upload
+    
+    func addAutomaticUpload(metadataNet: CCMetadataNet) -> Bool {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return false
+        }
+        
+        let realm = try! Realm()
+            
+        let results = realm.objects(tableAutomaticUpload.self).filter("account = %@ AND assetLocalIdentifier = %@", tableAccount!.account, metadataNet.assetLocalIdentifier)
+        if (results.count > 0) {
+            return false
+        }
+        
+        try! realm.write {
+            
+            // Add new AutomaticUpload
+            let addAutomaticUpload = tableAutomaticUpload()
+            
+            addAutomaticUpload.account = tableAccount!.account
+            addAutomaticUpload.assetLocalIdentifier = metadataNet.assetLocalIdentifier
+            addAutomaticUpload.fileName = metadataNet.fileName
+            addAutomaticUpload.selector = metadataNet.selector
+            if (metadataNet.selectorPost != nil) {
+                addAutomaticUpload.selectorPost = metadataNet.selectorPost
+            }
+            addAutomaticUpload.serverUrl = metadataNet.serverUrl
+            addAutomaticUpload.session = metadataNet.session
+            addAutomaticUpload.priority = metadataNet.priority
+            
+            realm.add(addAutomaticUpload)
+        }
+
+        return true
+    }
+    
+    func getAutomaticUpload(selector: String) -> CCMetadataNet? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAutomaticUpload.self).filter("account = %@ AND selector = %@ AND lock == false", tableAccount!.account, selector)
+        if (results.count == 0) {
+            return nil
+        }
+
+        let metadataNet = CCMetadataNet()
+        
+        metadataNet.action = actionUploadAsset
+        metadataNet.assetLocalIdentifier = results[0].assetLocalIdentifier
+        metadataNet.fileName = results[0].fileName
+        metadataNet.priority = results[0].priority
+        metadataNet.selector = results[0].selector
+        metadataNet.selectorPost = results[0].selectorPost
+        metadataNet.serverUrl = results[0].serverUrl
+        metadataNet.session = results[0].session
+        metadataNet.taskStatus = Int(k_taskStatusResume)
+        
+        // Lock
+        try! realm.write {
+            results[0].lock = true
+        }
+        
+        return metadataNet
+    }
+    
+    func getLockAutomaticUpload() -> [tableAutomaticUpload]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAutomaticUpload.self).filter("account = %@ AND lock = true", tableAccount!.account)
+        
+        return Array(results)
+    }
+
+    func unlockAutomaticUpload(assetLocalIdentifier: String) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableAutomaticUpload.self).filter("account = %@ AND assetLocalIdentifier = %@", tableAccount!.account, assetLocalIdentifier)
+        if (results.count > 0) {
+            
+            // UnLock
+            try! realm.write {
+                results[0].lock = false
+            }
+        }
+    }
+    
+    func deleteAutomaticUpload(assetLocalIdentifier: String) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+
+        let realm = try! Realm()
+
+        let results = realm.objects(tableAutomaticUpload.self).filter("account = %@ AND assetLocalIdentifier = %@", tableAccount!.account, assetLocalIdentifier)
+        if (results.count > 0) {
+            
+            try! realm.write {
+                realm.delete(results)
+            }
+        }
+    }
+    
+    func countAutomaticUpload(session: String?) -> Int {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return 0
+        }
+
+        let realm = try! Realm()
+        let results : Results<tableAutomaticUpload>
+        
+        if (session == nil) {
+            
+            results = realm.objects(tableAutomaticUpload.self).filter("account = %@", tableAccount!.account)
+            
+        } else {
+            
+            results = realm.objects(tableAutomaticUpload.self).filter("account = %@ AND session = %@", tableAccount!.account, session!)
+        }
+        
+        return results.count
+    }
+    
+    //MARK: -
+    //MARK: Table Capabilities
+    
+    func addCapabilities(_ capabilities: OCCapabilities) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+
+        let realm = try! Realm()
+
+        let results = realm.objects(tableCapabilities.self).filter("account = %@", tableAccount!.account)
+        
+        try! realm.write {
+            
+            var resultCapabilities = tableCapabilities()
+            
+            if (results.count > 0) {
+                resultCapabilities = results[0]
+            }
+            
+            resultCapabilities.account = tableAccount!.account
+            resultCapabilities.themingBackground = capabilities.themingBackground
+            resultCapabilities.themingColor = capabilities.themingColor
+            resultCapabilities.themingLogo = capabilities.themingLogo
+            resultCapabilities.themingName = capabilities.themingName
+            resultCapabilities.themingSlogan = capabilities.themingSlogan
+            resultCapabilities.themingUrl = capabilities.themingUrl
+            resultCapabilities.versionMajor = capabilities.versionMajor
+            resultCapabilities.versionMinor = capabilities.versionMinor
+            resultCapabilities.versionMicro = capabilities.versionMicro
+            resultCapabilities.versionString = capabilities.versionString
+            
+            if (results.count == 0) {
+                realm.add(resultCapabilities)
+            }
+        }
+    }
+    
+    func getCapabilites() -> tableCapabilities? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+
+        let results = realm.objects(tableCapabilities.self).filter("account = %@", tableAccount!.account)
+        
+        if (results.count > 0) {
+            return results[0]
+        } else {
+            return nil
+        }
+    }
+    
+    func getServerVersion() -> Int {
+
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return 0
+        }
+
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableCapabilities.self).filter("account = %@", tableAccount!.account)
+
+        if (results.count > 0) {
+            return results[0].versionMajor
+        } else {
+            return 0
+        }
+    }
+
+    //MARK: -
+    //MARK: Table Certificates
+    
+    func addCertificates(_ certificateLocation: String) {
+    
+        let realm = try! Realm()
+        
+        try! realm.write {
+            
+            let addCertificates = tableCertificates()
+            
+            addCertificates.certificateLocation = certificateLocation
+            
+            realm.add(addCertificates)
+        }
+    }
+    
+    func getCertificatesLocation(_ localCertificatesFolder: String) -> [String] {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableCertificates.self)
+    
+        var arraycertificatePath = [String]()
+    
+        for result in results {
+            arraycertificatePath.append("\(localCertificatesFolder)\(result.certificateLocation)")
+        }
+        
+        return arraycertificatePath
+    }
+    
+    //MARK: -
+    //MARK: Table Directory
+    
+    func addDirectory(serverUrl: String, permissions: String) -> String {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return ""
+        }
+        
+        let realm = try! Realm()
+        let results = realm.objects(tableDirectory.self).filter("serverUrl = %@", serverUrl)
+        var directoryID: String = ""
+        
+        try! realm.write {
+            
+            if results.count > 0 {
+                
+                results[0].permissions = permissions
+                directoryID = results[0].directoryID
+                realm.add(results, update: true)
+                
+            } else {
+                
+                let addDirectory = tableDirectory()
+                addDirectory.account = tableAccount!.account
+                
+                directoryID =  NSUUID().uuidString
+                addDirectory.directoryID = directoryID
+                
+                addDirectory.permissions = permissions
+                addDirectory.serverUrl = serverUrl
+                realm.add(addDirectory, update: true)
+            }
+        }
+        
+        return directoryID
+    }
+    
+    func deleteDirectoryAndSubDirectory(serverUrl: String) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableDirectory.self).filter("account = %@ AND serverUrl BEGINSWITH %@", tableAccount!.account, serverUrl)
+        
+        try! realm.write {
+            
+            for result in results {
+                
+                // delete metadata
+                self.deleteMetadata(predicate: NSPredicate(format: "directoryID = %@", result.directoryID))
+                
+                // delete local file
+                self.deleteLocalFile(predicate: NSPredicate(format: "fileID = %@", result.fileID))
+                
+                /*
+                 // remove if in session
+                 if ([recordMetadata.session length] >0) {
+                 if (recordMetadata.sessionTaskIdentifier >= 0)
+                 [[CCNetworking sharedNetworking] settingSession:recordMetadata.session sessionTaskIdentifier:[recordMetadata.sessionTaskIdentifier integerValue] taskStatus: k_taskStatusCancel];
+                 
+                 if (recordMetadata.sessionTaskIdentifierPlist >= 0)
+                 [[CCNetworking sharedNetworking] settingSession:recordMetadata.session sessionTaskIdentifier:[recordMetadata.sessionTaskIdentifierPlist integerValue] taskStatus: k_taskStatusCancel];
+                 
+                 }
+                 */
+                
+            }
+            
+            realm.delete(results)
+        }
+    }
+    
+    func setDirectory(serverUrl: String, serverUrlTo: String?, fileID: String?) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        try! realm.write {
+            let results = realm.objects(tableDirectory.self).filter("serverUrl = %@", serverUrl)
+            
+            if results.count > 0 {
+                
+                if serverUrlTo != nil {
+                    results[0].serverUrl = serverUrlTo!
+                }
+                if fileID != nil {
+                    results[0].fileID = fileID!
+                }
+                
+            }
+        }
+    }
+    
+    func clearDateRead(serverUrl: String?, directoryID: String?) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        try! realm.write {
+            
+            var results : Results<tableDirectory>?
+            
+            if serverUrl != nil {
+                results = realm.objects(tableDirectory.self).filter("serverUrl = %@", serverUrl!)
+            }
+            
+            if directoryID != nil {
+                results = realm.objects(tableDirectory.self).filter("directoryID = %@", directoryID!)
+            }
+            
+            if results != nil {
+                
+                if results!.count > 0 {
+                    
+                    results![0].dateReadDirectory = nil
+                    results![0].rev = ""
+                    realm.add(results!, update: true)
+                }
+            }
+        }
+    }
+    
+    func getTableDirectory(predicate: NSPredicate) -> tableDirectory? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableDirectory.self).filter(predicate)
+        
+        if (results.count > 0) {
+            
+            return results[0]
+            
+        } else {
+            
+            return nil
+        }
+    }
+    
+    func getTablesDirectory(predicate: NSPredicate, sorted: String?, ascending: Bool) -> [tableDirectory]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        let results : Results<tableDirectory>
+        
+        if sorted == nil {
+            
+            results = realm.objects(tableDirectory.self).filter(predicate)
+            
+        } else {
+            
+            results = realm.objects(tableDirectory.self).filter(predicate).sorted(byKeyPath: sorted!, ascending: ascending)
+        }
+        
+        if (results.count > 0) {
+            
+            return Array(results)
+            
+        } else {
+            
+            return nil
+        }
+    }
+    
+    func getDirectoryID(_ serverUrl: String) -> String {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return ""
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableDirectory.self).filter("serverUrl = %@", serverUrl)
+        if results.count > 0 {
+            return results[0].directoryID
+        } else {
+            return ""
+        }
+    }
+    
+    func getServerUrl(_ directoryID: String) -> String {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return ""
+        }
+        
+        let realm = try! Realm()
+        let results = realm.objects(tableDirectory.self).filter("directoryID = %@", directoryID)
+        
+        if results.count > 0 {
+            return results[0].serverUrl
+        } else {
+            return ""
+        }
+    }
+    
+    func setDateReadDirectory(directoryID: String) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        let results = realm.objects(tableDirectory.self).filter("account = %@ AND directoryID = %@", tableAccount!.account, directoryID)
+        
+        try! realm.write {
+            
+            if results.count > 0 {
+                return results[0].dateReadDirectory = NSDate()
+            }
+        }
+    }
+    
+    func setClearAllDateReadDirectory() {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        let results = realm.objects(tableDirectory.self)
+        
+        try! realm.write {
+            
+            for result in results {
+                result.dateReadDirectory = nil;
+                result.rev = ""
+            }
+        }
+    }
+    
+    func setDirectoryLock(serverUrl: String, lock: Bool) -> Bool {
+        
+        var update = false
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return update
+        }
+        
+        let realm = try! Realm()
+        
+        try! realm.write {
+            
+            let results = realm.objects(tableDirectory.self).filter("account = %@ AND serverUrl = %@", tableAccount!.account, serverUrl)
+            
+            if results.count > 0 {
+                
+                results[0].lock = lock
+                update = true
+                
+            }
+        }
+        
+        return update
+    }
+    
+    func setAllDirectoryUnLock() {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        let results = realm.objects(tableDirectory.self).filter("account = %@", tableAccount!.account)
+        
+        try! realm.write {
+            
+            for result in results {
+                result.lock = false;
+            }
+        }
+    }
+    
+    func copyTableDirectory(_ table: tableDirectory) -> tableDirectory {
+        
+        let copyTable = tableDirectory.init(value: table)
+        
+        
+        return copyTable
+    }
+
+
+    //MARK: -
+    //MARK: Table External Sites
+    
+    func addExternalSites(_ externalSites: OCExternalSites) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+
+        try! realm.write {
+            
+            let addExternalSite = tableExternalSites()
+            
+            addExternalSite.account = tableAccount!.account
+            addExternalSite.idExternalSite = externalSites.idExternalSite
+            addExternalSite.icon = externalSites.icon
+            addExternalSite.lang = externalSites.lang
+            addExternalSite.name = externalSites.name
+            addExternalSite.url = externalSites.url
+            addExternalSite.type = externalSites.type
+           
+            realm.add(addExternalSite)
+        }
+    }
+
+    func deleteExternalSites() {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+
+        let results = realm.objects(tableExternalSites.self).filter("account = %@", tableAccount!.account)
+        try! realm.write {
+            realm.delete(results)
+        }
+    }
+    
+    func getAllExternalSites(predicate: NSPredicate) -> [tableExternalSites] {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableExternalSites.self).filter(predicate).sorted(byKeyPath: "idExternalSite", ascending: true)
+        
+        return Array(results)
+    }
+
+    //MARK: -
+    //MARK: Table GPS
+    
+    func addGeocoderLocation(_ location: String, placemarkAdministrativeArea: String, placemarkCountry: String, placemarkLocality: String, placemarkPostalCode: String, placemarkThoroughfare: String, latitude: String, longitude: String) {
+
+        let realm = try! Realm()
+
+        // Verify if exists
+        let results = realm.objects(tableGPS.self).filter("latitude = %@ AND longitude = %@", latitude, longitude)
+        if (results.count > 0) {
+            return
+        }
+                
+        try! realm.write {
+            
+            // Add new GPS
+            let addGPS = tableGPS()
+                
+            addGPS.location = location
+            addGPS.placemarkAdministrativeArea = placemarkAdministrativeArea
+            addGPS.placemarkCountry = placemarkCountry
+            addGPS.placemarkLocality = placemarkLocality
+            addGPS.placemarkPostalCode = placemarkPostalCode
+            addGPS.placemarkThoroughfare = placemarkThoroughfare
+            addGPS.latitude = latitude
+            addGPS.longitude = longitude
+                
+            realm.add(addGPS)
+        }
+    }
+    
+    func getLocationFromGeoLatitude(_ latitude: String, longitude: String) -> String? {
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableGPS.self).filter("latitude = %@ AND longitude = %@", latitude, longitude)
+        
+        if (results.count == 0) {
+            return nil
+        } else {
+            return results[0].location
+        }
+    }
+
+    //MARK: -
+    //MARK: Table LocalFile
+    
+    func addLocalFile(metadata: tableMetadata) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        try! realm.write {
+            
+            let addLocaFile = tableLocalFile()
+            
+            addLocaFile.account = tableAccount!.account
+            addLocaFile.date = metadata.date
+            addLocaFile.fileID = metadata.fileID
+            addLocaFile.exifDate = NSDate()
+            addLocaFile.exifLatitude = "-1"
+            addLocaFile.exifLongitude = "-1"
+            addLocaFile.fileName = metadata.fileName
+            addLocaFile.fileNamePrint = metadata.fileNamePrint
+            addLocaFile.rev = metadata.rev
+            addLocaFile.size = metadata.size
+            
+            realm.add(addLocaFile, update: true)
+        }
+    }
+    
+    func deleteLocalFile(predicate: NSPredicate) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableLocalFile.self).filter(predicate)
+        
+        try! realm.write {
+            realm.delete(results)
+        }
+    }
+    
+    func setLocalFile(fileID: String, date: NSDate?, exifDate: NSDate?, exifLatitude: String?, exifLongitude: String?, fileName: String?, fileNamePrint: String?) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableLocalFile.self).filter("fileID = %@", fileID)
+        
+        if results.count > 0 {
+            
+            try! realm.write {
+                
+                if date != nil {
+                    results[0].date = date!
+                }
+                if exifDate != nil {
+                    results[0].exifDate = exifDate!
+                }
+                if exifLatitude != nil {
+                    results[0].exifLatitude = exifLatitude!
+                }
+                if exifLongitude != nil {
+                    results[0].exifLongitude = exifLongitude!
+                }
+                if fileName != nil {
+                    results[0].fileName = fileName!
+                }
+                if fileNamePrint != nil {
+                    results[0].fileNamePrint = fileNamePrint!
+                }
+            }
+        }
+    }
+    
+    func getTableLocalFile(predicate: NSPredicate) -> tableLocalFile? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableLocalFile.self).filter(predicate)
+        
+        if (results.count > 0) {
+            
+            return results[0]
+            
+        } else {
+            
+            return nil
+        }
+    }
+
+    //MARK: -
+    //MARK: Table Metadata
+    
+    func addMetadata(_ metadata: tableMetadata, activeUrl: String) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let cameraFolderName = self.getAccountCameraUploadFolderName()
+        let cameraFolderPath = self.getAccountCameraUploadFolderPath(activeUrl: activeUrl)
+        let directory = NCManageDatabase.sharedInstance.getServerUrl(metadata.directoryID)
+        
+        let realm = try! Realm()
+        
+        try! realm.write {
+            
+            if (metadata.realm == nil) {
+                let metadataWithIcon = CCUtility.insertTypeFileIconName(metadata, directory: directory, cameraFolderName: cameraFolderName, cameraFolderPath: cameraFolderPath)
+                realm.add(metadataWithIcon!, update: true)
+            } else {
+                realm.add(metadata, update: true)
+            }
+        }
+        
+        self.setDateReadDirectory(directoryID: metadata.directoryID)
+    }
+    
+    func deleteMetadata(predicate: NSPredicate) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableMetadata.self).filter(predicate)
+        
+        for result in results {
+            self.setDateReadDirectory(directoryID: result.directoryID)
+        }
+        
+        try! realm.write {
+            realm.delete(results)
+        }
+    }
+    
+    func moveMetadata(fileName: String, directoryID: String, directoryIDTo: String) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableMetadata.self).filter("account = %@ AND fileName = %@ AND directoryID = %@", tableAccount!.account, fileName, directoryID)
+        
+        try! realm.write {
+            
+            for result in results {
+                result.directoryID = directoryIDTo
+            }
+        }
+        
+        self.setDateReadDirectory(directoryID: directoryID)
+        self.setDateReadDirectory(directoryID: directoryIDTo)
+    }
+    
+    func updateMetadata(_ metadata: tableMetadata, activeUrl: String) {
+        
+        let cameraFolderName = self.getAccountCameraUploadFolderName()
+        let cameraFolderPath = self.getAccountCameraUploadFolderPath(activeUrl: activeUrl)
+        let serverUrl = self.getServerUrl(metadata.directoryID)
+        
+        let metadataWithIcon = CCUtility.insertTypeFileIconName(metadata, directory: serverUrl, cameraFolderName: cameraFolderName, cameraFolderPath: cameraFolderPath)
+        
+        let realm = try! Realm()
+        
+        try! realm.write {
+            realm.add(metadataWithIcon!, update: true)
+        }
+        
+        self.setDateReadDirectory(directoryID: metadata.directoryID)
+    }
+    
+    func setMetadataSession(_ session: String?, sessionError: String?, sessionSelector: String?, sessionSelectorPost: String?, sessionTaskIdentifier: Int, sessionTaskIdentifierPlist: Int, predicate: NSPredicate) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableMetadata.self).filter(predicate)
+        
+        try! realm.write {
+            
+            for result in results {
+                
+                if session != nil {
+                    result.session = session!
+                }
+                if sessionError != nil {
+                    result.sessionError = sessionError!
+                }
+                if sessionSelector != nil {
+                    result.sessionSelector = sessionSelector!
+                }
+                if sessionSelectorPost != nil {
+                    result.sessionSelectorPost = sessionSelectorPost!
+                }
+                if sessionTaskIdentifier != Int(k_taskIdentifierNULL) {
+                    result.sessionTaskIdentifier = sessionTaskIdentifier
+                }
+                if sessionTaskIdentifierPlist != Int(k_taskIdentifierNULL) {
+                    result.sessionTaskIdentifierPlist = sessionTaskIdentifierPlist
+                }
+            }
+        }
+        
+        if results.count > 0 {
+            self.setDateReadDirectory(directoryID: results[0].directoryID)
+        }
+    }
+    
+    func setMetadataFavorite(fileID: String, favorite: Bool) {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableMetadata.self).filter("account = %@ AND fileID = %@", tableAccount!.account, fileID)
+        
+        if (results.count > 0) {
+            
+            try! realm.write {
+                results[0].favorite = favorite
+            }
+            
+            self.setDateReadDirectory(directoryID: results[0].directoryID)
+        }
+    }
+    
+    func getMetadata(predicate: NSPredicate) -> tableMetadata? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableMetadata.self).filter(predicate)
+        
+        if (results.count > 0) {
+                        
+            return tableMetadata.init(value: results[0])
+            
+        } else {
+            
+            return nil
+        }
+    }
+    
+    func getMetadatas(predicate: NSPredicate, sorted: String?, ascending: Bool) -> [tableMetadata]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        let results : Results<tableMetadata>
+        
+        if sorted == nil {
+            
+            results = realm.objects(tableMetadata.self).filter(predicate)
+            
+        } else {
+            
+            results = realm.objects(tableMetadata.self).filter(predicate).sorted(byKeyPath: sorted!, ascending: ascending)
+        }
+        
+        if (results.count > 0) {
+            
+            return Array(convertMetadataToUnmanagedMetadata(results)!)
+            
+        } else {
+            
+            return nil
+        }
+    }
+    
+    func getMetadataAtIndex(predicate: NSPredicate, sorted: String?, ascending: Bool, index: Int) -> tableMetadata? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableMetadata.self).filter(predicate).sorted(byKeyPath: sorted!, ascending: ascending)
+        
+        if (results.count > 0  && results.count > index) {
+            
+            return tableMetadata.init(value: results[index])
+            
+        } else {
+            
+            return nil
+        }
+    }
+    
+    func getMetadataFromFileName(_ fileName: String, directoryID: String) -> tableMetadata? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableMetadata.self).filter("account = %@ AND directoryID = %@ AND (fileName = %@ OR fileNameData = %@)", tableAccount!.account, directoryID, fileName, fileName)
+        
+        if (results.count > 0) {
+            
+            return tableMetadata.init(value: results[0])
+            
+        } else {
+            
+            return nil
+        }
+    }
+    
+    func getTableMetadataDownload() -> [tableMetadata]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let predicate = NSPredicate(format: "account = %@ AND (session = %@ OR session = %@) AND (sessionTaskIdentifier != %i OR sessionTaskIdentifierPlist != %i)", tableAccount!.account, k_download_session, k_download_session_foreground, k_taskIdentifierDone, k_taskIdentifierDone)
+        
+        return self.getMetadatas(predicate: predicate, sorted: nil, ascending: false)
+    }
+    
+    func getTableMetadataDownloadWWan() -> [tableMetadata]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let predicate = NSPredicate(format: "account = %@ AND session = %@ AND (sessionTaskIdentifier != %i OR sessionTaskIdentifierPlist != %i)", tableAccount!.account, k_download_session_wwan, k_taskIdentifierDone, k_taskIdentifierDone)
+        
+        return self.getMetadatas(predicate: predicate, sorted: nil, ascending: false)
+    }
+    
+    func getTableMetadataUpload() -> [tableMetadata]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let predicate = NSPredicate(format: "account = %@ AND (session = %@ OR session = %@) AND (sessionTaskIdentifier != %i OR sessionTaskIdentifierPlist != %i)", tableAccount!.account, k_upload_session, k_upload_session_foreground, k_taskIdentifierDone, k_taskIdentifierDone)
+        
+        return self.getMetadatas(predicate: predicate, sorted: nil, ascending: false)
+    }
+    
+    func getTableMetadataUploadWWan() -> [tableMetadata]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let predicate = NSPredicate(format: "account = %@ AND session = %@ AND (sessionTaskIdentifier != %i OR sessionTaskIdentifierPlist != %i)", tableAccount!.account, k_upload_session_wwan, k_taskIdentifierDone, k_taskIdentifierDone)
+        
+        return self.getMetadatas(predicate: predicate, sorted: nil, ascending: false)
+    }
+    
+    func getTableMetadatasPhotosCameraUpload(serverUrl: String) -> [tableMetadata]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        let sorted = CCUtility.getOrderSettings()
+        let ascending = CCUtility.getAscendingSettings()
+        
+        var recordsPhotosCameraUpload = [tableMetadata]()
+        let directories = self.getTablesDirectory(predicate: NSPredicate(format: "account = %@ AND serverUrl BEGINSWITH %@", tableAccount!.account, serverUrl), sorted: "serverUrl", ascending: true)
+        
+        if directories != nil {
+            
+            for directory in directories! {
+            
+                let predicate = NSPredicate(format: "account = %@ AND directoryID = %@ AND session = '' AND type = 'file' AND (typeFile = %@ OR typeFile = %@)", tableAccount!.account, directory.directoryID, k_metadataTypeFile_image, k_metadataTypeFile_video)
+                let metadatas = realm.objects(tableMetadata.self).filter(predicate).sorted(byKeyPath: sorted!, ascending: ascending)
+                
+                if metadatas.count > 0 {
+                    
+                    recordsPhotosCameraUpload.append(contentsOf: metadatas)
+                }
+            }
+        }
+        
+        if recordsPhotosCameraUpload.count > 0 {
+            
+            return Array(recordsPhotosCameraUpload)
+            
+        } else {
+            
+            return nil
+        }
+    }
+    
+    func copyTableMetadata(_ metadata: tableMetadata) -> tableMetadata {
+        
+        let copyMetadata = tableMetadata()
+        
+        copyMetadata.account = metadata.account
+        copyMetadata.assetLocalIdentifier = metadata.assetLocalIdentifier
+        copyMetadata.cryptated = metadata.cryptated
+        copyMetadata.date = metadata.date
+        copyMetadata.directory = metadata.directory
+        copyMetadata.directoryID = metadata.directoryID
+        copyMetadata.errorPasscode = metadata.errorPasscode
+        copyMetadata.fileID = metadata.fileID
+        copyMetadata.favorite = metadata.favorite
+        copyMetadata.fileName = metadata.fileName
+        copyMetadata.fileNameData = metadata.fileNameData
+        copyMetadata.fileNamePrint = metadata.fileNamePrint
+        copyMetadata.iconName = metadata.iconName
+        copyMetadata.model = metadata.model
+        copyMetadata.nameCurrentDevice = metadata.nameCurrentDevice
+        copyMetadata.permissions = metadata.permissions
+        copyMetadata.protocolCrypto = metadata.protocolCrypto
+        copyMetadata.rev = metadata.rev
+        copyMetadata.session = metadata.session
+        copyMetadata.sessionError = metadata.sessionError
+        copyMetadata.sessionID = metadata.sessionID
+        copyMetadata.sessionSelector = metadata.sessionSelector
+        copyMetadata.sessionSelectorPost = metadata.sessionSelectorPost
+        copyMetadata.sessionTaskIdentifier = metadata.sessionTaskIdentifier
+        copyMetadata.sessionTaskIdentifierPlist = metadata.sessionTaskIdentifierPlist
+        copyMetadata.size = metadata.size
+        copyMetadata.thumbnailExists = metadata.thumbnailExists
+        copyMetadata.title = metadata.title
+        copyMetadata.type = metadata.type
+        copyMetadata.typeFile = metadata.typeFile
+        copyMetadata.uuid = metadata.uuid
+        
+        return copyMetadata
+    }
+    
+    func convertMetadataToUnmanagedMetadata(_ metadatas: Results<tableMetadata>?) -> [tableMetadata]? {
+        
+        var unmanageMetadatas = [tableMetadata]()
+        
+        if metadatas == nil {
+            return nil
+        } else {
+            
+            for metadata in metadatas! {
+                unmanageMetadatas.append(tableMetadata.init(value: metadata))
+            }
+        }
+        
+        return unmanageMetadatas
+    }
+
+    //MARK: -
+    //MARK: Table Share
+    
+    func addShareLink(_ share: String, fileName: String, serverUrl: String) -> [String:String]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+
+        // Verify if exists
+        let results = realm.objects(tableShare.self).filter("account = %@ AND fileName = %@ AND serverUrl = %@", tableAccount!.account, fileName, serverUrl)
+        if (results.count > 0) {
+            try! realm.write {
+                results[0].shareLink = share;
+            }
+            
+        } else {
+        
+            // Add new record
+            try! realm.write {
+            
+            let addShare = tableShare()
+            
+                addShare.account = tableAccount!.account
+                addShare.fileName = fileName
+                addShare.serverUrl = serverUrl
+                addShare.shareLink = share
+            
+                realm.add(addShare)
+            }
+        }
+        
+        return ["\(serverUrl)\(fileName)" : share]
+    }
+
+    func addShareUserAndGroup(_ share: String, fileName: String, serverUrl: String) -> [String:String]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        let realm = try! Realm()
+
+        // Verify if exists
+        let results = realm.objects(tableShare.self).filter("account = %@ AND fileName = %@ AND serverUrl = %@", tableAccount!.account, fileName, serverUrl)
+        if (results.count > 0) {
+            try! realm.write {
+                results[0].shareUserAndGroup = share;
+            }
+            
+        } else {
+            
+            // Add new record
+            try! realm.write {
+                
+                let addShare = tableShare()
+                
+                addShare.account = tableAccount!.account
+                addShare.fileName = fileName
+                addShare.serverUrl = serverUrl
+                addShare.shareUserAndGroup = share
+                
+                realm.add(addShare)
+            }
+        }
+        
+        return ["\(serverUrl)\(fileName)" : share]
+    }
+    
+    func unShare(_ share: String, fileName: String, serverUrl: String, sharesLink: [String:String], sharesUserAndGroup: [String:String]) -> [Any]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        var sharesLink = sharesLink
+        var sharesUserAndGroup = sharesUserAndGroup
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableShare.self).filter("account = %@ AND (shareLink CONTAINS %@ OR shareUserAndGroup CONTAINS %@)", tableAccount!.account, share, share)
+        if (results.count > 0) {
+            
+            let result = results[0]
+            
+            realm.beginWrite()
+                
+            if (result.shareLink.contains(share)) {
+                result.shareLink = ""
+            }
+                
+            if (result.shareUserAndGroup.contains(share)) {
+                    
+                var shares : [String] = result.shareUserAndGroup.components(separatedBy: ",")
+                if let index = shares.index(of:share) {
+                    shares.remove(at: index)
+                }
+                result.shareUserAndGroup = shares.joined(separator: ",")
+            }
+            
+            if (result.shareLink.characters.count > 0) {
+                sharesLink.updateValue(result.shareLink, forKey:"\(serverUrl)\(fileName)")
+            } else {
+                sharesLink.removeValue(forKey: "\(serverUrl)\(fileName)")
+            }
+            
+            if (result.shareUserAndGroup.characters.count > 0) {
+                sharesUserAndGroup.updateValue(result.shareUserAndGroup, forKey:"\(serverUrl)\(fileName)")
+            } else {
+                sharesUserAndGroup.removeValue(forKey: "\(serverUrl)\(fileName)")
+            }
+            
+            if (result.shareLink.characters.count == 0 && result.shareUserAndGroup.characters.count == 0) {
+                realm.delete(result)
+            }
+            try! realm.commitWrite()
+        }
+        
+        return [sharesLink, sharesUserAndGroup]
+    }
+    
+    func removeShareActiveAccount() {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        let results = realm.objects(tableShare.self).filter("account = %@", tableAccount!.account)
+        try! realm.write {
+            realm.delete(results)
+        }
+    }
+    
+    func updateShare(_ items: [String:OCSharedDto], activeUrl: String) -> [Any]? {
+        
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        var sharesLink = [String:String]()
+        var sharesUserAndGroup = [String:String]()
+
+        self.removeShareActiveAccount()
+     
+        var itemsLink = [OCSharedDto]()
+        var itemsUsersAndGroups = [OCSharedDto]()
+        
+        for (_, itemOCSharedDto) in items {
+            
+            if (itemOCSharedDto.shareType == Int(shareTypeLink.rawValue)) {
+                itemsLink.append(itemOCSharedDto)
+            }
+            
+            if (itemOCSharedDto.shareWith.characters.count > 0 && (itemOCSharedDto.shareType == Int(shareTypeUser.rawValue) || itemOCSharedDto.shareType == Int(shareTypeGroup.rawValue) || itemOCSharedDto.shareType == Int(shareTypeRemote.rawValue)  )) {
+                itemsUsersAndGroups.append(itemOCSharedDto)
+            }
+        }
+        
+        // Manage sharesLink
+
+        for itemOCSharedDto in itemsLink {
+            
+            let fullPath = CCUtility.getHomeServerUrlActiveUrl(activeUrl) + "\(itemOCSharedDto.path!)"
+            let fileName = NSString(string: fullPath).lastPathComponent
+            var serverUrl = NSString(string: fullPath).substring(to: (fullPath.characters.count - fileName.characters.count - 1))
+            
+            if serverUrl.hasSuffix("/") {
+                serverUrl = NSString(string: serverUrl).substring(to: (serverUrl.characters.count - 1))
+            }
+            
+            if itemOCSharedDto.idRemoteShared > 0 {
+                let sharesLinkReturn = self.addShareLink("\(itemOCSharedDto.idRemoteShared)", fileName: fileName, serverUrl: serverUrl)
+                if sharesLinkReturn != nil {
+                    for (key,value) in sharesLinkReturn! {
+                        sharesLink.updateValue(value, forKey:key)
+                    }
+                }
+            }
+        }
+        
+        // Manage sharesUserAndGroup
+        
+        var paths = [String:[String]]()
+        
+        for itemOCSharedDto in itemsUsersAndGroups {
+            
+            if paths[itemOCSharedDto.path] != nil {
+                
+                var share : [String] = paths[itemOCSharedDto.path]!
+                share.append("\(itemOCSharedDto.idRemoteShared)")
+                paths[itemOCSharedDto.path] = share
+                
+            } else {
+                
+                paths[itemOCSharedDto.path] = ["\(itemOCSharedDto.idRemoteShared)"]
+            }
+        }
+        
+        for (path, idsRemoteSharedArray) in paths {
+            
+            let idsRemoteShared = idsRemoteSharedArray.joined(separator: ",")
+            
+            print("[LOG] share \(String(describing: idsRemoteShared))")
+            
+            let fullPath = CCUtility.getHomeServerUrlActiveUrl(activeUrl) + "\(path)"
+            let fileName = NSString(string: fullPath).lastPathComponent
+            var serverUrl = NSString(string: fullPath).substring(to: (fullPath.characters.count - fileName.characters.count - 1))
+            
+            if serverUrl.hasSuffix("/") {
+                serverUrl = NSString(string: serverUrl).substring(to: (serverUrl.characters.count - 1))
+            }
+            
+            let sharesUserAndGroupReturn = self.addShareUserAndGroup(idsRemoteShared, fileName: fileName, serverUrl: serverUrl)
+            if sharesUserAndGroupReturn != nil {
+                for (key,value) in sharesUserAndGroupReturn! {
+                    sharesUserAndGroup.updateValue(value, forKey:key)
+                }
+            }
+        }
+        
+        return [sharesLink, sharesUserAndGroup]
+    }
+    
+    func getShares() -> [Any]? {
+
+        let tableAccount = self.getAccountActive()
+        if tableAccount == nil {
+            return nil
+        }
+        
+        var sharesLink = [String:String]()
+        var sharesUserAndGroup = [String:String]()
+        
+        let realm = try! Realm()
+
+        let results = realm.objects(tableShare.self).filter("account = %@", tableAccount!.account)
+        
+        for resultShare in results {
+            
+            if (resultShare.shareLink.characters.count > 0) {
+                sharesLink = [resultShare.shareLink: "\(resultShare.serverUrl)\(resultShare.fileName)"]
+            }
+            
+            if (resultShare.shareUserAndGroup.characters.count > 0) {
+                sharesUserAndGroup = [resultShare.shareUserAndGroup: "\(resultShare.serverUrl)\(resultShare.fileName)"]
+            }
+        }
+        
+        return [sharesLink, sharesUserAndGroup]
+    }
+    
+    //MARK: -
+}

+ 20 - 0
iOSClient/Database/TableAccount+CoreDataClass.h

@@ -0,0 +1,20 @@
+//
+//  TableAccount+CoreDataClass.h
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreData/CoreData.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface TableAccount : NSManagedObject
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+#import "TableAccount+CoreDataProperties.h"

+ 13 - 0
iOSClient/Database/TableAccount+CoreDataClass.m

@@ -0,0 +1,13 @@
+//
+//  TableAccount+CoreDataClass.m
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableAccount+CoreDataClass.h"
+
+@implementation TableAccount
+
+@end

+ 52 - 0
iOSClient/Database/TableAccount+CoreDataProperties.h

@@ -0,0 +1,52 @@
+//
+//  TableAccount+CoreDataProperties.h
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableAccount+CoreDataClass.h"
+
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface TableAccount (CoreDataProperties)
+
++ (NSFetchRequest<TableAccount *> *)fetchRequest;
+
+@property (nullable, nonatomic, copy) NSString *account;
+@property (nullable, nonatomic, copy) NSNumber *active;
+@property (nullable, nonatomic, copy) NSNumber *cameraUpload;
+@property (nullable, nonatomic, copy) NSNumber *cameraUploadBackground;
+@property (nullable, nonatomic, copy) NSNumber *cameraUploadCreateSubfolder;
+@property (nullable, nonatomic, copy) NSDate *cameraUploadDatePhoto;
+@property (nullable, nonatomic, copy) NSDate *cameraUploadDateVideo;
+@property (nullable, nonatomic, copy) NSString *cameraUploadFolderName;
+@property (nullable, nonatomic, copy) NSString *cameraUploadFolderPath;
+@property (nullable, nonatomic, copy) NSNumber *cameraUploadFull;
+@property (nullable, nonatomic, copy) NSNumber *cameraUploadPhoto;
+@property (nullable, nonatomic, copy) NSNumber *cameraUploadSaveAlbum;
+@property (nullable, nonatomic, copy) NSNumber *cameraUploadVideo;
+@property (nullable, nonatomic, copy) NSNumber *cameraUploadWWAnPhoto;
+@property (nullable, nonatomic, copy) NSNumber *cameraUploadWWAnVideo;
+@property (nullable, nonatomic, copy) NSDate *optimization;
+@property (nullable, nonatomic, copy) NSString *password;
+@property (nullable, nonatomic, copy) NSString *url;
+@property (nullable, nonatomic, copy) NSString *user;
+@property (nullable, nonatomic, copy) NSNumber *enabled;
+@property (nullable, nonatomic, copy) NSString *address;
+@property (nullable, nonatomic, copy) NSString *displayName;
+@property (nullable, nonatomic, copy) NSString *email;
+@property (nullable, nonatomic, copy) NSString *phone;
+@property (nullable, nonatomic, copy) NSString *twitter;
+@property (nullable, nonatomic, copy) NSString *webpage;
+@property (nullable, nonatomic, copy) NSNumber *quota;
+@property (nullable, nonatomic, copy) NSNumber *quotaFree;
+@property (nullable, nonatomic, copy) NSNumber *quotaRelative;
+@property (nullable, nonatomic, copy) NSNumber *quotaTotal;
+@property (nullable, nonatomic, copy) NSNumber *quotaUsed;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 49 - 0
iOSClient/Database/TableAccount+CoreDataProperties.m

@@ -0,0 +1,49 @@
+//
+//  TableAccount+CoreDataProperties.m
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableAccount+CoreDataProperties.h"
+
+@implementation TableAccount (CoreDataProperties)
+
++ (NSFetchRequest<TableAccount *> *)fetchRequest {
+	return [[NSFetchRequest alloc] initWithEntityName:@"TableAccount"];
+}
+
+@dynamic account;
+@dynamic active;
+@dynamic cameraUpload;
+@dynamic cameraUploadBackground;
+@dynamic cameraUploadCreateSubfolder;
+@dynamic cameraUploadDatePhoto;
+@dynamic cameraUploadDateVideo;
+@dynamic cameraUploadFolderName;
+@dynamic cameraUploadFolderPath;
+@dynamic cameraUploadFull;
+@dynamic cameraUploadPhoto;
+@dynamic cameraUploadSaveAlbum;
+@dynamic cameraUploadVideo;
+@dynamic cameraUploadWWAnPhoto;
+@dynamic cameraUploadWWAnVideo;
+@dynamic optimization;
+@dynamic password;
+@dynamic url;
+@dynamic user;
+@dynamic enabled;
+@dynamic address;
+@dynamic displayName;
+@dynamic email;
+@dynamic phone;
+@dynamic twitter;
+@dynamic webpage;
+@dynamic quota;
+@dynamic quotaFree;
+@dynamic quotaRelative;
+@dynamic quotaTotal;
+@dynamic quotaUsed;
+
+@end

+ 20 - 0
iOSClient/Database/TableCertificates+CoreDataClass.h

@@ -0,0 +1,20 @@
+//
+//  TableCertificates+CoreDataClass.h
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreData/CoreData.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface TableCertificates : NSManagedObject
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+#import "TableCertificates+CoreDataProperties.h"

+ 13 - 0
iOSClient/Database/TableCertificates+CoreDataClass.m

@@ -0,0 +1,13 @@
+//
+//  TableCertificates+CoreDataClass.m
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableCertificates+CoreDataClass.h"
+
+@implementation TableCertificates
+
+@end

+ 22 - 0
iOSClient/Database/TableCertificates+CoreDataProperties.h

@@ -0,0 +1,22 @@
+//
+//  TableCertificates+CoreDataProperties.h
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableCertificates+CoreDataClass.h"
+
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface TableCertificates (CoreDataProperties)
+
++ (NSFetchRequest<TableCertificates *> *)fetchRequest;
+
+@property (nullable, nonatomic, copy) NSString *certificateLocation;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 19 - 0
iOSClient/Database/TableCertificates+CoreDataProperties.m

@@ -0,0 +1,19 @@
+//
+//  TableCertificates+CoreDataProperties.m
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableCertificates+CoreDataProperties.h"
+
+@implementation TableCertificates (CoreDataProperties)
+
++ (NSFetchRequest<TableCertificates *> *)fetchRequest {
+	return [[NSFetchRequest alloc] initWithEntityName:@"TableCertificates"];
+}
+
+@dynamic certificateLocation;
+
+@end

+ 20 - 0
iOSClient/Database/TableDirectory+CoreDataClass.h

@@ -0,0 +1,20 @@
+//
+//  TableDirectory+CoreDataClass.h
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreData/CoreData.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface TableDirectory : NSManagedObject
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+#import "TableDirectory+CoreDataProperties.h"

+ 13 - 0
iOSClient/Database/TableDirectory+CoreDataClass.m

@@ -0,0 +1,13 @@
+//
+//  TableDirectory+CoreDataClass.m
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableDirectory+CoreDataClass.h"
+
+@implementation TableDirectory
+
+@end

+ 32 - 0
iOSClient/Database/TableDirectory+CoreDataProperties.h

@@ -0,0 +1,32 @@
+//
+//  TableDirectory+CoreDataProperties.h
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableDirectory+CoreDataClass.h"
+
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface TableDirectory (CoreDataProperties)
+
++ (NSFetchRequest<TableDirectory *> *)fetchRequest;
+
+@property (nullable, nonatomic, copy) NSString *account;
+@property (nullable, nonatomic, copy) NSDate *dateReadDirectory;
+@property (nullable, nonatomic, copy) NSString *directoryID;
+@property (nullable, nonatomic, copy) NSNumber *favorite;
+@property (nullable, nonatomic, copy) NSString *fileID;
+@property (nullable, nonatomic, copy) NSNumber *lock;
+@property (nullable, nonatomic, copy) NSNumber *offline;
+@property (nullable, nonatomic, copy) NSString *permissions;
+@property (nullable, nonatomic, copy) NSString *rev;
+@property (nullable, nonatomic, copy) NSString *serverUrl;
+@property (nullable, nonatomic, copy) NSNumber *synchronized;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 29 - 0
iOSClient/Database/TableDirectory+CoreDataProperties.m

@@ -0,0 +1,29 @@
+//
+//  TableDirectory+CoreDataProperties.m
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableDirectory+CoreDataProperties.h"
+
+@implementation TableDirectory (CoreDataProperties)
+
++ (NSFetchRequest<TableDirectory *> *)fetchRequest {
+	return [[NSFetchRequest alloc] initWithEntityName:@"TableDirectory"];
+}
+
+@dynamic account;
+@dynamic dateReadDirectory;
+@dynamic directoryID;
+@dynamic favorite;
+@dynamic fileID;
+@dynamic lock;
+@dynamic offline;
+@dynamic permissions;
+@dynamic rev;
+@dynamic serverUrl;
+@dynamic synchronized;
+
+@end

+ 20 - 0
iOSClient/Database/TableLocalFile+CoreDataClass.h

@@ -0,0 +1,20 @@
+//
+//  TableLocalFile+CoreDataClass.h
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CoreData/CoreData.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface TableLocalFile : NSManagedObject
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+#import "TableLocalFile+CoreDataProperties.h"

+ 33 - 0
iOSClient/Database/TableLocalFile+CoreDataProperties.h

@@ -0,0 +1,33 @@
+//
+//  TableLocalFile+CoreDataProperties.h
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableLocalFile+CoreDataClass.h"
+
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface TableLocalFile (CoreDataProperties)
+
++ (NSFetchRequest<TableLocalFile *> *)fetchRequest;
+
+@property (nullable, nonatomic, copy) NSString *account;
+@property (nullable, nonatomic, copy) NSDate *date;
+@property (nullable, nonatomic, copy) NSDate *exifDate;
+@property (nullable, nonatomic, copy) NSString *exifLatitude;
+@property (nullable, nonatomic, copy) NSString *exifLongitude;
+@property (nullable, nonatomic, copy) NSNumber *favorite;
+@property (nullable, nonatomic, copy) NSString *fileID;
+@property (nullable, nonatomic, copy) NSString *fileName;
+@property (nullable, nonatomic, copy) NSString *fileNamePrint;
+@property (nullable, nonatomic, copy) NSNumber *offline;
+@property (nullable, nonatomic, copy) NSString *rev;
+@property (nullable, nonatomic, copy) NSNumber *size;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 30 - 0
iOSClient/Database/TableLocalFile+CoreDataProperties.m

@@ -0,0 +1,30 @@
+//
+//  TableLocalFile+CoreDataProperties.m
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/02/17.
+//  Copyright © 2017 TWS. All rights reserved.
+//
+
+#import "TableLocalFile+CoreDataProperties.h"
+
+@implementation TableLocalFile (CoreDataProperties)
+
++ (NSFetchRequest<TableLocalFile *> *)fetchRequest {
+	return [[NSFetchRequest alloc] initWithEntityName:@"TableLocalFile"];
+}
+
+@dynamic account;
+@dynamic date;
+@dynamic exifDate;
+@dynamic exifLatitude;
+@dynamic exifLongitude;
+@dynamic favorite;
+@dynamic fileID;
+@dynamic fileName;
+@dynamic fileNamePrint;
+@dynamic offline;
+@dynamic rev;
+@dynamic size;
+
+@end