private void btnSave_Click(object sender, EventArgs e) { memdb.AppSettings["RemoteHost"] = tbServerIP.Text; SyncDataViewModel.SaveFile(Utility.jsondbpath, memdb); this.DialogResult = DialogResult.OK; this.Close(); }
private void RFIDBinding_Closing(object sender, CancelEventArgs e) { try { MTRFIDDisable(); memDb = null; } catch (Exception ex) { logger.Error(ex.Message, ex); throw ex; } }
public SyncDataViewModel CloneToUploadSync() { SyncDataViewModel cloneobject = new SyncDataViewModel(); foreach (ETCBinding item in etcbinding.Where(w => w.LastUploadTime == null).ToList()) { item.LastUploadTime = DateTime.Now; cloneobject.ETCBinding.Add(item); } cloneobject.CarPurposeTypes = carpurposetypes; return(cloneobject); }
public RFIDBinding() { try { InitializeComponent(); MemoryStorage = new TempVarInMemory(); //先初始化資料庫 memDb = SyncDataViewModel.LoadFile(Utility.jsondbpath); } catch (Exception ex) { Utility.ShowErrMsg(ex.Message); logger.Error(ex.Message, ex); this.Close(); } }
private void SaveDB() { if (this.InvokeRequired) { this.Invoke(new voidinvoker(SaveDB)); } else { try { SyncDataViewModel.SaveFile(Utility.jsondbpath, memDb); } catch (Exception) { throw; } } }
public static void SaveFile(string path, SyncDataViewModel database) { try { FileStream jsonFile = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read); StreamWriter jsonWriter = new StreamWriter(jsonFile, Encoding.UTF8); //Newtonsoft.Json.JsonTextWriter jwriter = new Newtonsoft.Json.JsonTextWriter(jsonWriter); //jwriter.Flush(); jsonWriter.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(database)); //jwriter.Close(); jsonWriter.Close(); jsonFile.Close(); } catch (Exception ex) { logger.Error(ex.Message, ex); throw ex; } }
private static SyncDataViewModel GetDefaultProperies(SyncDataViewModel model) { model = new SyncDataViewModel(); model.CarPurposeTypes.Add(new CarPurposeTypes() { Id = 1, Name = "自用車", Void = false }); model.CarPurposeTypes.Add(new CarPurposeTypes() { Id = 2, Name = "公務車", Void = false }); #if DEBUG //model.AppSettings.Add("RemoteHost", "http://61.216.6.217:5002"); model.AppSettings.Add("RemoteHost", "http://202.39.229.116"); #else model.AppSettings.Add("RemoteHost", "http://202.39.229.116"); #endif return(model); }
private void bgworker_DoWork(object sender, DoWorkEventArgs e) { try { bgworker.ReportProgress(0, "準備同步..."); WBeParkingPDA.Classes.WebClientHelper client = new WBeParkingPDA.Classes.WebClientHelper(); try { bgworker.ReportProgress(30, "準備同步..."); SyncDataViewModel source = SyncDataViewModel.LoadFile(Utility.jsondbpath); beforecount = source.ETCBinding.Count; bgworker.ReportProgress(50, "連線中..."); SyncDataViewModel clonemem = source.CloneToUploadSync(); bgworker.ReportProgress(75, "上載資料中..."); string remoteurl = source.AppSettings["RemoteHost"] as string; clonemem = client.PostData(clonemem, remoteurl + "/api/SQLiteSync"); aftercount = clonemem.ETCBinding.Count; bgworker.ReportProgress(90, "下載資料並處理..."); clonemem.AppSettings = source.AppSettings; bgworker.ReportProgress(97, "下載資料並處理..."); SyncDataViewModel.SaveFile(Utility.jsondbpath, clonemem); bgworker.ReportProgress(99, "同步即將完成!"); } catch (Exception ex) { bgworker.ReportProgress(75, ex); e.Result = false; return; } bgworker.ReportProgress(99); bgworker.ReportProgress(100); e.Result = true; } catch (Exception ex) { logger.Error(ex.Message, ex); } }
public static SyncDataViewModel LoadFile(string path) { SyncDataViewModel model = null; try { if (System.IO.File.Exists(Utility.jsondbpath)) { FileStream jsonFile = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader jsonReader = new StreamReader(jsonFile, Encoding.UTF8); string filecontent = jsonReader.ReadToEnd(); if (!string.IsNullOrEmpty(filecontent)) { model = Newtonsoft.Json.JsonConvert.DeserializeObject <SyncDataViewModel>(filecontent); } else { model = GetDefaultProperies(model); } jsonReader.Close(); jsonFile.Close(); return(model); } model = GetDefaultProperies(model); return(model); } catch (Exception ex) { if (model == null) { model = GetDefaultProperies(model); } logger.Error(ex.Message, ex); return(model); } }
public OptionForm() { InitializeComponent(); memdb = SyncDataViewModel.LoadFile(Utility.jsondbpath); }