1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // NCManageDatabase.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 06/05/17.
- // Copyright © 2017 TWS. All rights reserved.
- //
- import RealmSwift
- class NCManageDatabase: NSObject {
-
- static let sharedInstance: NCManageDatabase = {
- let instance = NCManageDatabase()
- return instance
- }()
-
- override init() {
-
- let dirGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: k_capabilitiesGroups)
- var config = Realm.Configuration()
-
- config.fileURL = dirGroup?.appendingPathComponent("\(appDatabaseNextcloud)/\(k_databaseDefault)")
-
- Realm.Configuration.defaultConfiguration = config
- }
-
-
- func addActivityServer(_ listOfActivity: [OCActivity], account: String) {
-
- let realm = try! Realm()
-
- try! realm.write {
-
- for activity in listOfActivity {
-
- // Verify
- let records = realm.objects(DBActivity.self).filter("idActivity = \(activity.idActivity)")
- if (records.count > 0) {
- continue
- }
-
- // Add new Activity
- let dbActivity = DBActivity()
-
- dbActivity.account = account
- dbActivity.date = activity.date
- dbActivity.idActivity = Double(activity.idActivity)
- dbActivity.link = activity.link
- dbActivity.note = activity.subject
- dbActivity.type = k_activityTypeInfo
- realm.add(dbActivity)
- }
- }
- }
-
- func addActivityClient(_ file: String, fileID: String, action: String, selector: String, note: String, type: String, verbose: Bool, account: String?, activeUrl: String?) {
- 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 dbActivity = DBActivity()
- if (account != nil) {
- dbActivity.account = account!
- }
-
- dbActivity.action = action
- dbActivity.file = file
- dbActivity.fileID = fileID
- dbActivity.note = noteReplacing
- dbActivity.selector = selector
- dbActivity.type = type
- dbActivity.verbose = verbose
- realm.add(dbActivity)
- }
- }
-
- func getAllTableActivityWithPredicate(_ predicate : NSPredicate) -> Results<DBActivity> {
-
- let realm = try! Realm()
- let records = realm.objects(DBActivity.self).filter(predicate).sorted(byKeyPath: "date")
-
- return records;
- }
- }
|