public void Load(string fileName = null) { if (fileName == null) { if (String.IsNullOrEmpty(Properties.Settings.Default.DataFileName)) { fileName = REPOSITORY_FILE_NAME; } else { fileName = Properties.Settings.Default.DataFileName; } } App.ToLogInfo(String.Format("Чтение репозитория из файла <{0}>", fileName)); fileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ResourceAssembly.Location), REPOSITORY_FILE_NAME); IList <IRepositoryItem> list = BaseDeserializer <List <IRepositoryItem> > .GzJsonDeSerialize( fileName, (e) => { App.ToLogException(e); App.ShowError( String.Format("Не удалось загрузить список запросов.\n\t{0}", e.Message), "ОШИБКА"); return; }); InitRepositoryItemsList(ref list); RepositoryItems = new ObservableCollection <IRepositoryItem>(list); }
public async Task HotGet(ServiceArgument args, Action <CollectHot> callback) { var pair = new Dictionary <string, object>(); pair.Add("id", args.id); pair.Add("type", 1); pair.Add("feature", args.feature); pair.Add("page", args.page); pair.Add("language", DeviceUtil.Language); pair.Add("client_id", DeviceUtil.DEVICE_CLIENTID); pair.Add("device_id", DeviceUtil.UniqueId); pair.Add("version", DeviceUtil.Version); pair.Add("channel", DeviceUtil.Channel); pair.Add("model", "N918St"); args.Dic = pair; args.Uri = Const_def.API_Category; await Get(args, response => { switch (response.Statused) { case HttpErrorStatus.Success: { //缓存分开 //异步写入数据库 不使用文件保存 下次加载缓存数据从数据库加载 var taskCache = FileCache.SaveFile(Const_def.db_CacheDir, response.Data); //序列化 BaseDeserializer serializer = DeserializerManager.Instance.BuildHotDeserializer(); CollectHot list = serializer.ReadList(response.Data) as CollectHot; callback?.Invoke(list); break; } case HttpErrorStatus.JsonError: break; case HttpErrorStatus.NetworkError: break; case HttpErrorStatus.UnknownError: break; case HttpErrorStatus.UserCancelOperation: break; } }); }
public void Save(string fileName = null) { if (fileName == null) { fileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ResourceAssembly.Location), REPOSITORY_FILE_NAME); } App.ToLogInfo(String.Format("Запись репозитория в файл <{0}>", fileName)); BaseDeserializer <List <IRepositoryItem> > .GzJsonSerialize( _repositoryItems.ToList(), fileName, (e) => { App.ToLogException(e); App.ShowError( String.Format("Не удалось сохранить список запросов.\n\t{0}", e.Message), "ОШИБКА"); }); }
private HierarchicalEmcosPointCollection LoadConfigPoints() { if (File.Exists(CONFIGURATION_FILENAME)) { try { //var result = BaseRepository<EmcosPoint>.XmlDeSerialize(LIST_Balance_POINTS_FILENAME, _callBackAction); var result = BaseDeserializer <EmcosPoint> .GzJsonDeSerialize(CONFIGURATION_FILENAME, _callBackAction); return(result?.Children); } catch (Exception ex) { _callBackAction(ex); return(null); } } else { return(null); } }