public bool SendParameter(int shipId, string str) { string[] strs = str.Split('|'); foreach (var item in strs) { waterdataEntities entity = new waterdataEntities(); task lasttask = entity.task.Where(s => s.ship_id == shipId && s.route_id != null).OrderByDescending(s => s.create_time).First(); ship ship = entity.ship.SingleOrDefault(s => s.ship_id == shipId); WaterData waterdata = DataParse.dealSensorData(item); parameter parameter = entity.parameter.SingleOrDefault(s => s.parameter_name == waterdata.ParameterName && s.company_id == ship.company_id); waterdata.ParameterId = parameter.parameter_id.ToString(); waterdata.TaskId = lasttask.task_id.ToString(); water_data newdata = new water_data() { task_id = Convert.ToInt32(waterdata.TaskId), parameter_id = Convert.ToInt32(waterdata.ParameterId), parameter_value = Convert.ToDouble(waterdata.ParameterValue), longitude = Convert.ToDouble(waterdata.Longitude), latitude = Convert.ToDouble(waterdata.Latitude), create_time = DateTime.Now }; entity.water_data.Add(newdata); entity.SaveChanges(); } return(true); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); this.DispatcherUnhandledException += App_DispatcherUnhandledException; var proc = System.Diagnostics.Process.GetProcessesByName("WordAndImgOperationApp"); //两个进程的话就杀掉一个 if (proc.Length > 1) { Application.Current.Dispatcher.Invoke((Action)(() => Application.Current.Shutdown())); return; } try { WordAndImgAppInfo info = new WordAndImgAppInfo(); info.Path = AppDomain.CurrentDomain.BaseDirectory + "WordAndImgOperationApp.exe"; string infos = string.Format(@"{0}\WordAndImgAppInfo.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\LoginInOutInfo\\"); DataParse.WriteToXmlPath(JsonConvert.SerializeObject(info), infos); } catch (Exception ex) { } try { UtilSystemVar.UrlStr = ConfigurationManager.AppSettings["UrlStr"].ToString() + ConfigurationManager.AppSettings["APIVersion"].ToString() + "/"; } catch { } BootStrapper(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); this.DispatcherUnhandledException += App_DispatcherUnhandledException; var proc = System.Diagnostics.Process.GetProcessesByName("WordAndImgOperationApp"); //两个进程的话就杀掉一个 if (proc.Length > 1) { Application.Current.Dispatcher.Invoke((Action)(() => Application.Current.Shutdown())); return; } StartService(); try { WordAndImgAppInfo info = new WordAndImgAppInfo(); info.Path = AppDomain.CurrentDomain.BaseDirectory + "WordAndImgOperationApp.exe"; string infos = string.Format(@"{0}\WordAndImgAppInfo.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\LoginInOutInfo\\"); DataParse.WriteToXmlPath(JsonConvert.SerializeObject(info), infos); } catch (Exception ex) { } MainWindow window = new MainWindow(); window.Show(); }
public void InitData() { string chekedWordSettingsInfo = string.Format(@"{0}ChekedWordSettings\ChekedWordSettings.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\"); var ui = DataParse.ReadFromXmlPath <string>(chekedWordSettingsInfo); if (ui != null && ui.ToString() != "") { try { var list = JsonConvert.DeserializeObject <List <ChekedWordSettingsInfo> >(ui.ToString()); ChekedWordSettingsInfos = new ObservableCollection <ChekedWordSettingsInfo>(list); foreach (var item in ChekedWordSettingsInfos) { item.IsChecked = true; } SetIsCircleCheckBtnEnable(); } catch { } } else { IsCircleCheckBtnEnabled = false; } }
public override void BuildFromXml(XmlReader reader) { bool listEnded = false; while (reader.Read()) { var dbVal = GetNextXmlValue(reader); if (dbVal == null) { return; } else if (dbVal.hash == "spirit_list") { spirit_list = new List <string>(); while (reader.Read() && !listEnded) { var result = GetNextXmlListItems(reader); listEnded = result == null; if (!listEnded) { spirit_list.Add(result); } } } else { this.SetValueFromName(DataParse.ImportNameFixer(dbVal.hash), dbVal.value); } } return; }
private void SetCheckBtnEnableAndSavePathsToXml() { try { viewModel.SetIsCircleCheckBtnEnable(); //保存路径设置信息到本地 string chekedWordSettingsInfo = string.Format(@"{0}ChekedWordSettings\ChekedWordSettings.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\"); DataParse.WriteToXmlPath(Newtonsoft.Json.JsonConvert.SerializeObject(viewModel.ChekedWordSettingsInfos.ToList()), chekedWordSettingsInfo); } catch (Exception ex) { } }
private static void InitData() { BlockCost = new Dictionary <int, int>(); var data = DataParse.FromFile(ShipCostFilePath); foreach (IDataStruct entry in data) { var value = entry.GetValue("ident").ToString(); int blockId = int.Parse(value); IDataStruct costToken = entry.Get("deadliness"); int cost = costToken.IsNull ? 0 : int.Parse(costToken.ToString()); BlockCost.Add(blockId, cost); } }
public bool BatchWrite(string imei, string distance, string temperature) { lock (_lockerSocket) { bool ret = false; byte[] bsSend = {}; int recvRigLen = 0; byte[] recvBytes = {}; recvBytes = new byte[recvRigLen]; int reSendCount = 0; while (true) { reSendCount++; if (reSendCount > 3) { break; } try { bsSend = DataParse.SendBytesToServer(imei, distance, temperature); _clientSocket.Send(bsSend, bsSend.Length); ret = true; break; } catch (Exception ex) { LogManager.WriteLog(LogFile.Error, ex.ToString()); } } if (ret == false) { NetStatus = NetStatus.Cutoff; string error = ""; Connect(out error); } else { if (reSendCount == 1) { NetStatus = NetStatus.Good; } else { NetStatus = NetStatus.Block; } } return(ret); } }
private void SaveLoginInfo(string userName, string pwd, bool isAutoLogin) { try { UserLoginInfo userLoginInfo = new UserLoginInfo(); userLoginInfo.UserName = userName; userLoginInfo.PassWord = pwd; userLoginInfo.IsAutoLogin = isAutoLogin; //保存用户登录信息到本地 string userLoginInfos = string.Format(@"{0}\UserLoginInfo.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\LoginInOutInfo\\"); DataParse.WriteToXmlPath(JsonConvert.SerializeObject(userLoginInfo), userLoginInfos); } catch (Exception ex) { } }
private void HidePopWindowBtn_Click(object sender, RoutedEventArgs e) { this.AllowDrop = true; viewModel.HidePopWindowVisibility = Visibility.Collapsed; viewModel.IsPopWindowOpen = false; try { SearchPopSettingInfo searchPopSettingInfo = new SearchPopSettingInfo(); searchPopSettingInfo.IsSearchPopStateOpen = false; //保存用户登录信息到本地 string searchPopSettingInfos = string.Format(@"{0}\SearchPopWindowTipsSettingInfo.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\LoginInOutInfo\\"); DataParse.WriteToXmlPath(JsonConvert.SerializeObject(searchPopSettingInfo), searchPopSettingInfos); } catch (Exception ex) { } }
void GetActions() { text_directory = Directory.GetCurrentDirectory(); root_directory = text_directory; if (DataParse.windows) { root_directory += "\\Data"; text_directory += "\\Text"; } else { root_directory += "//Data"; text_directory += "//Text"; } string[] files = Directory.GetFiles(text_directory); string[] lines = File.ReadAllLines(files[0]); //line is ID|Folder|Description|Weight foreach (string line in lines) { string[] splitLine = line.Split('|'); float w = float.Parse(splitLine[3]); int cost = int.Parse(splitLine[5]); bool locked = false; if (splitLine[4] == "y") { locked = true; GameObject button = ButtonSpawn.instance.Spawn(); button.GetComponentInChildren <Text>().text = splitLine[1]; button.GetComponent <ButtonScript>().cost = cost; button.GetComponent <ButtonScript>().ID = splitLine[0]; } Action a = new Action(splitLine[0], splitLine[1], splitLine[2], w, locked, cost); if (DataParse.windows) { current_directory = root_directory + "\\" + splitLine[1]; } else { current_directory = root_directory + "//" + splitLine[1]; } string[] csvFiles = Directory.GetFiles(current_directory); //print(file); //only parse the first file in each dir a._stockData.Add(DataParse.Parse(csvFiles[0])); action_list.Add(a); } }
public static List <Blueprint> FromFile(string path) { using (IDataStruct data = DataParse.FromFile(path)) { List <Blueprint> results = new List <Blueprint>(); IDataStruct blueprints = data.Get("blueprints"); for (int i = 0; i < blueprints.Count; i++) { IDataStruct blueprintTable = blueprints.Get(i); if (blueprintTable.Count > 1) { results.Add(FromTable(blueprintTable)); } } return(results); } }
public void SaveDataTest() { // SETUP DateTime dateOfProgram = DateTime.Now; int limitDrinks = 4; double hoursBeforeReset = 12; int ageReq = 21; var peopleTable = new DataTable("People"); peopleTable.Columns.Add("DoDID32", typeof(string)); peopleTable.Columns.Add("Count", typeof(int)); peopleTable.PrimaryKey = new[] { peopleTable.Columns["DoDID32"] }; DataRow newPerson = peopleTable.NewRow(); newPerson["DoDID32"] = 123; newPerson["Count"] = 1; peopleTable.Rows.Add(newPerson); // SAVE THE DATA DataParse.SaveData(dateOfProgram, limitDrinks, hoursBeforeReset, ageReq, peopleTable); DateTime dateOfProgramActual = DateTime.Now; int limitDrinksActual = 0; double hoursBeforeResetActual = 5; int ageReqActual = 85; DataParse.LoadFile(ref limitDrinksActual, ref hoursBeforeResetActual, ref ageReqActual, ref dateOfProgramActual, ref peopleTable); Assert.AreEqual(limitDrinksActual, limitDrinks); Assert.AreEqual(hoursBeforeResetActual, hoursBeforeReset); Assert.AreEqual(ageReqActual, ageReq); }
/// <summary> /// 登陆 /// </summary> private void LoginIn() { viewModel.MessageInfo = ""; viewModel.UserName = UserNameTextBox.Text; viewModel.YZMStr = YZMTextBox.Text; if (!FindPswCheckPhoneAndCodePass(viewModel.UserName, viewModel.YZMStr, viewModel.PassWord, viewModel.NewPassWord)) { return; } EventAggregatorRepository.EventAggregator.GetEvent <SettingWindowBusyIndicatorEvent>().Publish(new AppBusyIndicator() { IsBusy = true }); System.Threading.ThreadStart startLogin = delegate() { APIService service = new APIService(); string messageInfo = ""; string token = service.FindPsw(viewModel.UserName, viewModel.PassWord, viewModel.YZMStr, out messageInfo); if (!string.IsNullOrEmpty(token)) { UtilSystemVar.UserToken = token; UtilSystemVar.UserName = viewModel.UserName; EventAggregatorRepository.EventAggregator.GetEvent <LoginInOrOutEvent>().Publish("LoginIn"); viewModel.FindPswGridVisibility = Visibility.Collapsed; viewModel.FindPswResultGridVisibility = Visibility.Visible; Task task = new Task(() => { try { string loginInOutInfos = string.Format(@"{0}\UserLoginInfo.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\LoginInOutInfo\\"); var ui = CheckWordUtil.DataParse.ReadFromXmlPath <string>(loginInOutInfos); if (ui != null && ui.ToString() != "") { try { var userLoginInfo = JsonConvert.DeserializeObject <UserLoginInfo>(ui.ToString()); if (userLoginInfo != null) { if (userLoginInfo.IsAutoLogin) { userLoginInfo.PassWord = viewModel.PassWord; //保存用户登录信息到本地 string userLoginInfos = string.Format(@"{0}\UserLoginInfo.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WordAndImgOCR\\LoginInOutInfo\\"); DataParse.WriteToXmlPath(JsonConvert.SerializeObject(userLoginInfo), userLoginInfos); } } } catch { } } } catch (Exception ex) { } System.Threading.Thread.Sleep(2000); EventAggregatorRepository.EventAggregator.GetEvent <LoadSettingWindowGridViewEvent>().Publish("UserInfoControl"); }); task.Start(); } else { viewModel.MessageInfo = messageInfo; } EventAggregatorRepository.EventAggregator.GetEvent <SettingWindowBusyIndicatorEvent>().Publish(new AppBusyIndicator() { IsBusy = false }); }; System.Threading.Thread t = new System.Threading.Thread(startLogin); t.IsBackground = true; t.Start(); }
public static List <string[]> ParseDynData(List <string> filePaths) { // DEFINE GLOBALS DataParse csvParser = new DataParse(); List <string[]> trainingData = new List <string[]>(); foreach (var fileName in filePaths) //Loop over all the files in teh directory { string dynTitle = System.IO.Path.GetFileName(fileName); dynTitle = dynTitle.Remove(dynTitle.Length - 4); Console.WriteLine(dynTitle); using (StreamReader reader = File.OpenText(fileName)) { try { // Read JSON file, and get a JToken from it for iterating JObject jObject = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); //Define the Nodes into a JToken JToken nodeObject = jObject["Nodes"]; JToken connectorObject = jObject["Connectors"]; //Define Dictionaries for the node and the In / Out Dictionary <string, string> NodeDictionary = new Dictionary <string, string>(); Dictionary <string, string> IODictionary = new Dictionary <string, string>(); //Console.Write(nodeObject); //Create dictionary for ID and node name foreach (var node in nodeObject) { string stringnodeID = node["Id"].ToString(); string stringnodename = string.Empty; try { stringnodename = node["FunctionSignature"].ToString(); Console.WriteLine(stringnodename); } catch { Console.WriteLine("MISSING FUNCTION SIGNATURE"); stringnodename = node["ConcreteType"].ToString().Split(',')[0]; } if (!string.IsNullOrEmpty(stringnodename)) { NodeDictionary.Add(stringnodeID, stringnodename); JToken outputObject = node["Outputs"]; foreach (var output in outputObject) { string outputID = output["Id"].ToString(); IODictionary.Add(outputID, stringnodeID); } JToken inputObject = node["Inputs"]; foreach (var inputs in inputObject) { string inputID = inputs["Id"].ToString(); IODictionary.Add(inputID, stringnodeID); } //Console.WriteLine(IODictionary); } } foreach (var connector in connectorObject) { string inputID = connector["Start"].ToString(); string outputID = connector["End"].ToString(); try { string NodeAID = IODictionary[inputID]; string NodeBID = IODictionary[outputID]; string NodeASig = NodeDictionary[NodeAID]; string NodeBSig = NodeDictionary[NodeBID]; string[] dataObservation = new string[] { NodeASig, NodeBSig }; trainingData.Add(dataObservation); Console.WriteLine(NodeAID); Console.WriteLine(NodeBID); Console.WriteLine(NodeASig); Console.WriteLine(NodeBSig); csvParser.AppendToCsv(NodeASig, NodeBSig, NodeAID, NodeBID); } catch (Exception) { } } } catch { } } } csvParser.ExportCSV(); Console.Read(); return(trainingData); }
public ActionResult Create(FormCollection form) { bool isok = true; string[] allkeys = form.AllKeys; int inclpostSum = 0; int carrySum = 0; foreach (var key in allkeys) { if (key.StartsWith("InclPostageProvisos")) { inclpostSum++; } if (key.StartsWith("CarryModes")) { carrySum++; } } inclpostSum = inclpostSum / 5; //条件包邮记录数量 carrySum = carrySum / 7; //运送方式数量 //添加运费模板 FareTemplateModel faretemplate = new FareTemplateModel(); faretemplate.DispatchTime = form["DispatchTime"]; bool ispost = form["IsInclPostage"] == "1";//是否包邮 faretemplate.IsInclPostage = ispost; bool ispostif = form["IsInclPostageByif"] == "1";//是否指定条件包邮 faretemplate.IsInclPostageByif = ispostif; faretemplate.Name = form["Name"]; faretemplate.ShopAddr = form["ShopAddr"]; int mode = DataParse.ToInt(form["ValuationModel"], 1);//计价方式 faretemplate.ValuationModel = mode; //var fareId = faretemplate.Id; #region 添加包邮条件 if (ispostif) { for (int i = 0; i < inclpostSum; i++) { InclPostageProvisoModel inclpostage = new InclPostageProvisoModel(); inclpostage.CarryWay = DataParse.ToInt(form["InclPostageProvisos[" + i + "][CarryWay]"], 0); //inclpostage.FareId = fareId; inclpostage.Region = form["InclPostageProvisos[" + i + "][Region]"]; int seleif = DataParse.ToInt(form["InclPostageProvisos[" + i + "][SelectIf]"], 0); if (seleif == 0 || seleif == 2) { switch (mode) { case 1: inclpostage.PieceNo = DataParse.ToInt(form["InclPostageProvisos[" + i + "][First]"], 0); break; case 2: inclpostage.WeightNo = DataParse.ToDecimal(form["InclPostageProvisos[" + i + "][First]"], 0); break; case 3: inclpostage.BulkNo = DataParse.ToDecimal(form["InclPostageProvisos[" + i + "][First]"], 0); break; } } if (seleif == 1) { inclpostage.Amount = DataParse.ToDecimal(form["InclPostageProvisos[" + i + "][First]"], 0); } if (seleif == 2) { inclpostage.Amount = DataParse.ToDecimal(form["InclPostageProvisos[" + i + "][Secand]"], 0); inclpostage.IsAll = true; } faretemplate.InclPostageProvisos.Add(inclpostage); } } #endregion #region 添加运送方式 if (!ispost) { for (int i = 0; i < carrySum; i++) { CarryModeModel carry = new CarryModeModel(); carry.CarryWay = DataParse.ToInt(form["CarryModes[" + i + "][CarryWay]"], 0); //carry.FareId = fareId; carry.FirstAmount = DataParse.ToDecimal(form["CarryModes[" + i + "][FirstAmount]"], 0); carry.IsDefault = form["CarryModes[" + i + "][IsDefault]"] == "1"; carry.Region = form["CarryModes[" + i + "][Region]"]; carry.SecondAmount = DataParse.ToDecimal(form["CarryModes[" + i + "][SecondAmount]"], 0); switch (mode) { case 1: carry.FirstPiece = DataParse.ToInt(form["CarryModes[" + i + "][FirstSum]"], 0); carry.SecondPiece = DataParse.ToInt(form["CarryModes[" + i + "][SecondSum]"], 0); break; case 2: carry.FirstWeight = DataParse.ToDecimal(form["CarryModes[" + i + "][FirstSum]"], 0); carry.SecondWeight = DataParse.ToDecimal(form["CarryModes[" + i + "][SecondSum]"], 0); break; case 3: carry.FirstBulk = DataParse.ToDecimal(form["CarryModes[" + i + "][FirstSum]"], 0); carry.SecondBulk = DataParse.ToDecimal(form["CarryModes[" + i + "][SecondSum]"], 0); break; } faretemplate.CarryModes.Add(carry); } } try { _faretemplateservice.InsertFareTemplate(faretemplate.ToEntity()); } catch (Exception) { isok = false; } #endregion string msg = "添加失败!"; if (isok) { msg = "添加成功!"; } return(Json(new { msg = msg, isok = isok })); }