public static async Task <DeviceScopeIdentitiesCache> Create( IServiceIdentityHierarchy serviceIdentityHierarchy, IServiceProxy serviceProxy, IKeyValueStore <string, string> encryptedStorage, TimeSpan refreshRate, TimeSpan refreshDelay, TimeSpan initializationRefreshDelay) { Preconditions.CheckNotNull(serviceProxy, nameof(serviceProxy)); Preconditions.CheckNotNull(encryptedStorage, nameof(encryptedStorage)); Preconditions.CheckNotNull(serviceIdentityHierarchy, nameof(serviceIdentityHierarchy)); var identityStore = new ServiceIdentityStore(encryptedStorage); IDictionary <string, StoredServiceIdentity> cache = await identityStore.ReadCacheFromStore(encryptedStorage, serviceIdentityHierarchy.GetActorDeviceId()); // Populate the serviceIdentityHierarchy foreach (KeyValuePair <string, StoredServiceIdentity> kvp in cache) { await kvp.Value.ServiceIdentity.ForEachAsync(serviceIdentity => serviceIdentityHierarchy.AddOrUpdate(serviceIdentity)); } var deviceScopeIdentitiesCache = new DeviceScopeIdentitiesCache(serviceIdentityHierarchy, serviceProxy, identityStore, refreshRate, refreshDelay, initializationRefreshDelay, cache.Count > 0); Events.Created(); return(deviceScopeIdentitiesCache); }
DeviceScopeIdentitiesCache( IServiceIdentityHierarchy serviceIdentityHierarchy, IServiceProxy serviceProxy, ServiceIdentityStore identityStore, TimeSpan periodicRefreshRate, TimeSpan refreshDelay, TimeSpan initializationRefreshDelay, bool initializedFromCache) { this.serviceIdentityHierarchy = serviceIdentityHierarchy; this.edgeDeviceId = serviceIdentityHierarchy.GetActorDeviceId(); this.serviceProxy = serviceProxy; this.store = identityStore; this.periodicRefreshRate = periodicRefreshRate; this.refreshDelay = refreshDelay; this.initializationRefreshDelay = initializationRefreshDelay; this.identitiesLastRefreshTime = new Dictionary <string, DateTime>(); this.cacheLastRefreshTime = DateTime.MinValue; this.isInitialized.Set(initializedFromCache); // Kick off the initial refresh after we processed all the stored identities this.refreshCacheTimer = new Timer(this.RefreshCache, null, TimeSpan.Zero, this.periodicRefreshRate); }