BJUTDUHelper.DAL.LocalSetting.GetLocalInfo C# (CSharp) Method

GetLocalInfo() public method

public GetLocalInfo ( string fileName ) : Task
fileName string
return Task
        public async Task<T> GetLocalInfo<T>(string fileName) where T : class
        {
            T entity = null;
            try
            {
                var item = await _localFolder.TryGetItemAsync(fileName);
                if (item == null)
                {
                    return entity;
                }
                var file = item as StorageFile;
                using (var ras = await file.OpenAsync(FileAccessMode.Read))
                {
                    using (var stream = ras.AsStream())
                    {
                        DataContractSerializer serializer = new DataContractSerializer(typeof(T));
                        var o = serializer.ReadObject(stream);
                        if (o != null)
                        {
                            entity = o as T;
                        }
                    }
                }
            }
            catch (NullReferenceException nullref)
            {
                return null;
            }
            catch(SerializationException ser)
            {
                return null;
            }
            catch (XmlException e)
            {
                return null;
            }
            return entity;
        }
        public async Task SetLocalInfo<T>(string fileName,T entity)

Usage Example

Example #1
0
        public async void LoadBasicSetting()
        {
            DAL.LocalSetting _localSetting = new DAL.LocalSetting();
            var model = await _localSetting.GetLocalInfo <Model.ThemeColorModel>(typeof(Model.ThemeColorModel).Name);

            if (model != null)
            {
                Service.SettingService.SetThemeColor(model.ThemeColor);
            }
            else
            {
                var brush = Application.Current.Resources["BJUTDUHelperBaseBackgroundThemeColor"] as SolidColorBrush;
                Service.SettingService.SetThemeColor(brush.Color);
            }
        }