Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  WebClientSessionStore.swift   Sprache: JAVA

 

import Foundation
import ThreemaFramework

final class WebClientSessionStore {
    
    static let shared = WebClientSessionStore()
    
    private let entityManager: EntityManager

    init() {
        self.entityManager = BusinessInjector.ui.entityManager
    }
    
    func webClientSessionForHash(_ hash: String) -> WebClientSessionEntity? {
        entityManager.entityFetcher.webClientSessionEntity(for: hash)
    }
        
    func activeWebClientSession() -> WebClientSessionEntity? {
        entityManager.entityFetcher.activeWebClientSessionEntity()
    }
    
    func allWebClientSessions() -> [WebClientSessionEntity]? {
        entityManager.entityFetcher.webClientSessionEntities()
    }
    
    func addWebClientSession(dictionary: [String: Any]) -> WebClientSessionEntity {
        var session: WebClientSessionEntity?
        
        if let hash = dictionary["initiatorPermanentPublicKeyHash"] as? String {
            session = entityManager.entityFetcher.webClientSessionEntity(for: hash)
        }
        
        if let session {
            return session
        }
        
        entityManager.performAndWaitSave {
            session = self.entityManager.entityCreator.webClientSessionEntity(
                initiatorPermanentPublicKey: dictionary["initiatorPermanentPublicKey"] as! Data,
                permanent: dictionary["permanent"] as! Bool,
                saltyRTCHost: dictionary["saltyRTCHost"] as! String,
                saltyRTCPort: Int64(dictionary["saltyRTCPort"] as! Int),
                selfHosted: dictionary["selfHosted"] as! Bool,
                serverPermanentPublicKey: dictionary["serverPermanentPublicKey"] as! Data
            )
   
            session!.version = dictionary["webClientVersion"] as? NSNumber
            
            if let lastConnection = dictionary["lastConnection"] as? Date {
                session!.lastConnection = lastConnection
            }
            
            if let initiatorPermanentPublicKeyHash = dictionary["initiatorPermanentPublicKeyHash"] as? String {
                session!.initiatorPermanentPublicKeyHash = initiatorPermanentPublicKeyHash
            }
            
            if let privateKey = dictionary["privateKey"] as? Data {
                session!.privateKey = privateKey
            }
            
            if let browserName = dictionary["browserName"] as? String {
                session!.browserName = browserName
            }
            
            if let browserVersion = dictionary["browserVersion"] as? NSNumber {
                session!.browserVersion = browserVersion
            }
            
            if let active = dictionary["active"] as? Bool {
                session!.active = NSNumber(value: active) as NSNumber
            }
        }
        return session!
    }
    
    func updateWebClientSession(session: WebClientSessionEntity, active: Bool) {
        entityManager.performAndWaitSave {
            session.active = NSNumber(value: active) as NSNumber
        }
    }
    
    func updateWebClientSession(session: WebClientSessionEntity, privateKey: Data?) {
        entityManager.performAndWaitSave {
            session.privateKey = privateKey
        }
    }
    
    func updateWebClientSession(session: WebClientSessionEntity, hash: String) {
        entityManager.performAndWaitSave {
            session.initiatorPermanentPublicKeyHash = hash
        }
    }
    
    func updateWebClientSession(session: WebClientSessionEntity, lastConnection: Date) {
        entityManager.performAndWaitSave {
            session.lastConnection = lastConnection
        }
    }
    
    func updateWebClientSession(session: WebClientSessionEntity, browserName: String, browserVersion: NSNumber) {
        entityManager.performAndWaitSave {
            session.browserName = browserName
            session.browserVersion = browserVersion
        }
    }
    
    func updateWebClientSession(session: WebClientSessionEntity, sessionName: String?) {
        entityManager.performAndWaitSave {
            session.name = sessionName
        }
    }
    
    func deleteAllWebClientSessions() {
        entityManager.performAndWaitSave {
            if let sessions = self.entityManager.entityFetcher.webClientSessionEntities() {
                for session in sessions {
                    self.entityManager.entityDestroyer.delete(webClientSessionEntity: session)
                }
            }
        }
    }
    
    func deleteWebClientSession(_ session: WebClientSessionEntity) {
        entityManager.performAndWaitSave {
            self.entityManager.entityDestroyer.delete(webClientSessionEntity: session)
        }
    }
    
    func setAllWebClientSessionsInactive() {
        entityManager.performAndWaitSave {
            if let sessions = self.entityManager.entityFetcher.activeWebClientSessionEntities() {
                for session in sessions {
                    session.active = NSNumber(value: false) as NSNumber
                }
            }
        }
    }
        
    func removeAllNotPermanentSessions() {
        entityManager.performAndWaitSave {
            if let sessions = self.entityManager.entityFetcher
                .notPermanentWebClientSessionEntities() {
                for session in sessions {
                    self.entityManager.entityDestroyer.delete(webClientSessionEntity: session)
                }
            }
        }
    }
}

Messung
CHZG
829710093

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1104848
#Domains=416967