Exemplo n.º 1
0
 private async Task EnsureInitializedAsync()
 {
     if (!await AsyncFileSystem.ExistsAsync(Path))
     {
         await AsyncFileSystem.CreateDirectoryAsync(Path);
     }
 }
Exemplo n.º 2
0
        public async Task EnsureInitializedAsync()
        {
            if (_initialized)
            {
                return;
            }

            using (_lock.WriteLock())
            {
                if (!await AsyncFileSystem.ExistsAsync(Path))
                {
                    _initialized = true;
                    return;
                }

                using (var stream = await AsyncFileSystem.OpenFileAsync(Path, DesiredFileAccess.Read))
                    using (var instream = new StreamReader(stream))
                    {
                        var json     = "[" + instream.ReadToEnd().Replace(Environment.NewLine, ",") + "]";
                        var entities = JsonConvert.DeserializeObject(
                            json,
                            typeof(List <>).MakeGenericType(typeof(MetadataEntity))
                            ) as IEnumerable <MetadataEntity>;

                        _entities = entities.ToDictionary(
                            key => key.Identity,
                            value => new Tuple <object, MetadataEntity>(value.EntityOfType(EntityType), value)
                            );
                        _initialized = true;
                    }
            }
        }