Exemplo n.º 1
0
        private async void LoadAccessListAsync()
        {
            if (await ApplicationData.Current.LocalFolder.TryGetItemAsync(AccessFileName) is StorageFile jsonFile)
            {
                // 文件存在,读取其内容
                StreamReader sr         = new StreamReader(await jsonFile.OpenStreamForReadAsync());
                var          jsonString = await sr.ReadToEndAsync();

                _rootObject = FJSONHelper.DataContractJSONDeSerizlizer <MRootAccessObject>(jsonString);
                if (_rootObject.groupList is null)
                {
                    _rootObject.groupList = new List <MPathAccessGroup>();
                }
            }
            else
            {
                // 这个文件还不存在,初始化类的相关属性为空
                _rootObject = new MRootAccessObject()
                {
                    groupList    = new List <MPathAccessGroup>(),
                    devicesList  = new List <MDeviceAccessItem>(),
                    LastLocation = null
                };
            }
        }
Exemplo n.º 2
0
        private async void WriteToAccessFileAsync()
        {
            var jsonFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(AccessFileName, CreationCollisionOption.ReplaceExisting);

            FJSONHelper.ToJSONDataAsync(_rootObject, jsonFile);
        }