public void AddSectionIntoIniStringsFile() { var iniFile = new IniStrings(); var section = new IniSection("Test"); section.Comment = "a\r\nb\r\nc\r\n"; section.Add(new IniSectionItem("Connection", " a, b, c, d", "definition of connection string")); section.Add(new IniSectionItem("Type", "selector")); iniFile.Add(section); Assert.AreEqual(1, iniFile.Count); Assert.IsTrue(iniFile.Contains("test")); Assert.IsTrue(iniFile["test"].Contains("connection")); Assert.IsNotNull(iniFile.ToString()); }
public void AddSectionIntoIniStringsFile() { var iniFile = new IniStrings(); var section = new IniSection("Test"); section.Comment = "a\r\nb\r\nc\r\n"; section.Add(new IniSectionItem("Connection", " a, b, c, d", "definition of connection string")); section.Add(new IniSectionItem("Type", "selector")); iniFile.Add(section); Assert.AreEqual(1, iniFile.Count); Assert.IsTrue(iniFile.Contains("test")); Assert.IsTrue(iniFile["test"].Contains("connection")); Assert.IsNotNull(iniFile.ToString()); }
private void StoreKeyValue() { string key = TokenParser.ReadKey(this); string value = TokenParser.ReadValue(this); _currentSection.Add(new KeyValueItem <string, string>(key, value)); _lastLineType = IniLineType.KeyValue; }
/// <summary> /// Processes parsed key/value pair /// </summary> private static void ProcessKeyValuePair(IniSection CurrentSection, string Key, string SingleValue, ParseAction Action) { switch (Action) { case ParseAction.New: { // New/replace IniValues Value; if (CurrentSection.TryGetValue(Key, out Value) == false) { Value = new IniValues(); CurrentSection.Add(Key, Value); } Value.Clear(); Value.Add(SingleValue); } break; case ParseAction.Add: { IniValues Value; if (CurrentSection.TryGetValue(Key, out Value) == false) { Value = new IniValues(); CurrentSection.Add(Key, Value); } Value.Add(SingleValue); } break; case ParseAction.Remove: { IniValues Value; if (CurrentSection.TryGetValue(Key, out Value)) { var ExistingIndex = Value.FindIndex(X => (String.Compare(Key, X, true) == 0)); if (ExistingIndex >= 0) { Value.RemoveAt(ExistingIndex); } } } break; } }
// Method // private static bool CreateTrim() { IniSection section = new IniSection(); section.Add("Prm", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"); _Data.Add("Trim", section); Log.WriteLineSucces(string.Format("Creating: {0}", Filename)); return(Save()); }
private void saveHUDLocation(DirectX_HUDs hud) { if (hud != null) { IniFile file = new IniFile(MainWindow.settings_path); if (file.Exists()) { file.Load(); } IniSection section = new IniSection(); string str = hud.ContentHUDType.ToString() + " HUD"; if (file.HasSection(str)) { section = file[str]; file.Remove(str); } if (section.ContainsKey("X")) { section["X"] = base.Location.X.ToString(); } else { section.Add("X", base.Location.X.ToString()); } if (section.ContainsKey("Y")) { section["Y"] = base.Location.Y.ToString(); } else { section.Add("Y", base.Location.Y.ToString()); } file.Add(str, section); file.Save(); } }
public KHR_1HV_MotionFile() { khr_1hv_motion = new IniFile(""); IniSection section = new IniSection(); section.Add("Type", "0"); section.Add("Width", "854"); section.Add("Height", "480"); section.Add("Items", "0"); section.Add("Links", "0"); section.Add("Start", "-1"); section.Add("Name", ""); section.Add("Ctrl", "65535"); khr_1hv_motion.Add("GraphicalEdit", section); }
public IniFile ReadIni() { IniFile ini = new Ini.IniFile("sys.ini"); if (ini.Exists()) { ini.Load(); } else { IniSection section = new IniSection(); section.Add("startdate", "1-05-2011"); section.Add("enddate", "15-05-2011"); ini.Add("DATES", section); section = new IniSection(); section.Add("email_user", "*****@*****.**"); section.Add("email_password", "Paz.planner01"); section.Add("email_from", "*****@*****.**"); section.Add("email_host", "smtp.gmail.com"); section.Add("email_port", "587"); section.Add("email_onderwerp", "Afstudeerzitting(en)"); ini.Add("EMAILSETTINGS", section); section = new IniSection(); section.Add("this.DB_host", "student.aii.avans.nl"); section.Add("this.DB_username", "MI4Ie"); section.Add("this.DB_password", "4DRcUrzV"); section.Add("this.DB_database", "MI4Ie_this.DB"); ini.Add("DATABASESETTINGS", section); ini.Save(); } return(ini); }
public unsafe override void Convert(ResourceLocation source, ResourceLocation dest) { Stream stm = source.GetStream; Bitmap bmp = new Bitmap(stm); BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); uint *src = (uint *)data.Scan0; ulong totalR = 0; ulong totalG = 0; ulong totalB = 0; for (int i = 0; i < bmp.Height; i++) { for (int j = 0; j < bmp.Width; j++) { uint clr = src[i * bmp.Width + j]; totalR += ((clr & 0x00ff0000) >> 16); totalG += ((clr & 0x0000ff00) >> 8); totalB += clr & 0xff; } } totalR /= (ulong)(bmp.Width * bmp.Height); totalG /= (ulong)(bmp.Width * bmp.Height); totalB /= (ulong)(bmp.Width * bmp.Height); StringBuilder sb = new StringBuilder(50); sb.Append(totalR.ToString()); sb.Append(", "); sb.Append(totalG.ToString()); sb.Append(", "); sb.Append(totalB.ToString()); iniSect.Add(source.Name, sb.ToString()); stm.Close(); bmp.Dispose(); }
// Method // private static bool CreateTable() { for (int i = 0; i < StaticUtilities.numberOfMotions; i++) { IniSection section = new IniSection(); section.Add("Motion", string.Format("M{0}", (i + 1))); section.Add("Filename", string.Empty); section.Add("Name", string.Empty); section.Add("Count", string.Format("{0}", 0)); section.Add("Date", "--/--/---- --:--"); section.Add("Control", string.Format("{0}", 65535)); MotionTable.Add("Motion" + (i + 1).ToString(), section); } Log.WriteLineSucces(string.Format("Creating: {0}", Filename)); return(Save()); }
// Method // private static bool CreateTable() { for (int i = 0; i < StaticUtilities.numberOfMotions; i++) { IniSection section = new IniSection(); section.Add("Motion", string.Format("M{0}", (i + 1))); section.Add("Filename", string.Empty); section.Add("Name", string.Empty); section.Add("Count", string.Format("{0}", 0)); section.Add("Date", "--/--/---- --:--"); section.Add("Control", string.Format("{0}", 65535)); MotionTable.Add("Motion" + (i + 1).ToString(), section); } Log.WriteLineSucces(string.Format("Creating: {0}", Filename)); return Save(); }
private void saveConfigFile() { string currentPath = Directory.GetCurrentDirectory(); IniFile ini = new IniFile(currentPath + "\\config.ini"); foreach (ListViewItem lsti in HostListView.Items) { IniSection section = new IniSection(); section.Add("HostName", lsti.SubItems[0].Text); section.Add("Port", lsti.SubItems[1].Text); section.Add("Community", lsti.SubItems[2].Text); section.Add("Version", lsti.SubItems[3].Text); section.Add("User", lsti.SubItems[4].Text); section.Add("Password", lsti.SubItems[5].Text); ini.Add(lsti.SubItems[0].Text, section); } ini.Save(); }
// // public static void mainServer_messageHandler(object sender, NewMessageEventsArgs e) { networkBusy = true; Log.WriteLineMessage(e.NewMessage); string sendMsg = string.Empty; string[] message; string[] Msg; message = e.NewMessage.Split(','); // first index contains the command // Make a command parser. // switch (message[0]) { // // Main Menu case "Information": sendMsg = string.Empty; sendMsg = string.Format("{0},{1},{2},{3},{4},{5}", RCServo.CPU(), RCServo.Version(), Convert.ToString(RCServo.Connected), Convert.ToString(I2C.Connected), Convert.ToString(AD7918.Connected), Convert.ToString(SPI.Connected)); break; case "Options": switch (message[1]) { case "Read": string tmp = string.Empty; sendMsg = Server.MainIni.MotionReplay.ToString() + "," + Server.MainIni.EnableRemoteControl.ToString() + "," + Server.MainIni.PowerUpMotion + "," + Server.MainIni.LowPowerMotion + "," + Server.MainIni.LowPowerVoltage.ToString() + "," + Server.MainIni.TimeBase.ToString(); for (int i = 0; i < StaticUtilities.numberOfServos; i++) { tmp += string.Format(",{0}", Server.MainIni.ChannelFunction[i]); } sendMsg = sendMsg + tmp; break; case "Write": Server.MainIni.MotionReplay = Convert.ToBoolean(message[2]); Server.MainIni.EnableRemoteControl = Convert.ToBoolean(message[3]); Server.MainIni.PowerUpMotion = Convert.ToInt32(message[4]); Server.MainIni.LowPowerMotion = Convert.ToInt32(message[5]); Server.MainIni.LowPowerVoltage = Convert.ToInt32(message[6]); Server.MainIni.TimeBase = Convert.ToInt32(message[7]); int[] temp = new int[StaticUtilities.numberOfServos]; for (int i = 0; i < StaticUtilities.numberOfServos; i++) { temp[i] = Convert.ToInt32(message[8 + i]); } Server.MainIni.ChannelFunction = temp; Server.MainIni.Save(); Server.RCServo.Close(); Server.RCServo.Init(); if (MainIni.EnableRemoteControl) { if (!Server.XBox360.Open) { Server.XBox360.Init(); } } sendMsg = "Ok"; break; default: break; } break; case "ReadMotionFile": switch (message[1]) { case "Open": // Get the selected motion index and check // in the motiontable if the motion exists // return true if the file exist. selectedMotionIndex = Convert.ToInt32(message[2]) + 1; string file = Server.Table.MotionTable["Motion" + selectedMotionIndex.ToString()]["Filename"]; if (file != string.Empty) { khr_1hv_motion = new IniFile(file); khr_1hv_motion.Load(); sendMsg = "Ok"; } else { sendMsg = "No motion to read"; } break; case "GraphicalEdit": Msg = new string[8]; Msg[0] = khr_1hv_motion["GraphicalEdit"]["Type"]; Msg[1] = khr_1hv_motion["GraphicalEdit"]["Width"]; Msg[2] = khr_1hv_motion["GraphicalEdit"]["Height"]; Msg[3] = khr_1hv_motion["GraphicalEdit"]["Items"]; Msg[4] = khr_1hv_motion["GraphicalEdit"]["Links"]; Msg[5] = khr_1hv_motion["GraphicalEdit"]["Start"]; Msg[6] = khr_1hv_motion["GraphicalEdit"]["Name"]; Msg[7] = khr_1hv_motion["GraphicalEdit"]["Ctrl"]; Items = 0; Links = 0; sendMsg = string.Join(",", Msg); break; case "Item": Msg = new string[8]; string strItems = string.Format("Item{0}", Items++); Msg[0] = khr_1hv_motion[strItems]["Name"]; Msg[1] = khr_1hv_motion[strItems]["Width"]; Msg[2] = khr_1hv_motion[strItems]["Height"]; Msg[3] = khr_1hv_motion[strItems]["Left"]; Msg[4] = khr_1hv_motion[strItems]["Top"]; Msg[5] = khr_1hv_motion[strItems]["Color"]; Msg[6] = khr_1hv_motion[strItems]["Type"]; Msg[7] = khr_1hv_motion[strItems]["Prm"]; sendMsg = string.Join(",", Msg); break; case "Link": Msg = new string[4]; string strLinks = string.Format("Link{0}", Links++); Msg[0] = khr_1hv_motion[strLinks]["Main"]; Msg[1] = khr_1hv_motion[strLinks]["Origin"]; Msg[2] = khr_1hv_motion[strLinks]["Final"]; Msg[3] = khr_1hv_motion[strLinks]["Point"]; sendMsg = string.Join(",", Msg); break; default: break; } break; case "WriteMotionFile": switch (message[1]) { case "Open": // create random filename. fileName = Path.ChangeExtension(Path.GetRandomFileName(), "RMF"); fileName = string.Format("{0}\\{1}", motionsFolder, fileName); // get the index for the datatable where the // motion is going to be writen. selectedMotionIndex = Convert.ToInt32(message[2]) + 1; khr_1hv_motion = new IniFile(fileName); sendMsg = "Ok"; break; case "GraphicalEdit": IniSection section1 = new IniSection(); section1.Add("Type", message[2]); section1.Add("Width", message[3]); section1.Add("Height", message[4]); section1.Add("Items", message[5]); section1.Add("Links", message[6]); section1.Add("Start", message[7]); section1.Add("Name", message[8]); section1.Add("Ctrl", message[9]); khr_1hv_motion.Add("GraphicalEdit", section1); Items = 0; Links = 0; sendMsg = "Ok"; break; case "Item": IniSection section2 = new IniSection(); section2.Add("Name", message[2]); section2.Add("Width", message[3]); section2.Add("Height", message[4]); section2.Add("Left", message[5]); section2.Add("Top", message[6]); section2.Add("Color", message[7]); section2.Add("Type", message[8]); string strChannel = string.Format("{0}", message[9]); for (int i = 10; i < message.Length; i++) { strChannel = string.Format("{0},{1}", strChannel, message[i]); } section2.Add("Prm", strChannel); string strItems = string.Format("Item{0}", Items++); khr_1hv_motion.Add(strItems, section2); sendMsg = "Ok"; break; case "Link": IniSection section3 = new IniSection(); section3.Add("Main", message[2]); section3.Add("Origin", message[3]); section3.Add("Final", message[4]); string strPoint = string.Format("{0}", message[5]); for (int i = 6; i < message.Length; i++) { strPoint = string.Format("{0},{1}", strPoint, message[i]); } section3.Add("Point", strPoint); string strLinks = string.Format("Link{0}", Links++); khr_1hv_motion.Add(strLinks, section3); sendMsg = "Ok"; break; case "Save": // get the filename of the motion to be deleted string file = Server.Table.MotionTable["Motion" + selectedMotionIndex.ToString()]["Filename"]; if (file != string.Empty) { if (File.Exists(file)) { File.Delete(file); Log.WriteLineSucces(string.Format("Deleting: {0}", Server.Table.MotionTable["Motion" + selectedMotionIndex.ToString()]["Name"])); } else { Log.WriteLineFail(string.Format("Deleting: {0}", Server.Table.MotionTable["Motion" + selectedMotionIndex.ToString()]["Name"])); } } Name = khr_1hv_motion["GraphicalEdit"]["Name"]; Ctrl = khr_1hv_motion["GraphicalEdit"]["Ctrl"]; if (!khr_1hv_motion.Save()) { Log.WriteLineError(string.Format("Saving: {0}", Name)); sendMsg = "NOk"; } else { Log.WriteLineSucces(string.Format("Saving: {0}", Name)); Server.Table.addNewMotion(selectedMotionIndex, fileName, Name, Ctrl); Server.Table.Save(); sendMsg = "Ok"; } break; } break; case "PlayMotionFile": int strMotion = (int.Parse(message[1])); Log.WriteLineMessage(string.Format("Playing motion: {0}, {1}", Table.MotionTable["Motion" + (strMotion + 1).ToString()]["Name"], Table.MotionTable["Motion" + (strMotion + 1).ToString()]["Control"])); Server.MotionInterpreter.Filename = Server.Table.MotionTable["Motion" + (strMotion + 1).ToString()]["Filename"]; Server.MotionInterpreter.Play(); //sendMsg = "Ok"; // No need for this. break; case "StopMotionFile": Server.MotionInterpreter.Stop(); break; case "PauseMotionFile": Server.MotionInterpreter.Pause(); break; case "DataTable": switch (message[1]) { case "Open": sendMsg = string.Format("Open,{0},{1}", StaticUtilities.numberOfMotions, StaticUtilities.numberOfDataTableItems); break; case "Get": string[] strTable = new string[StaticUtilities.numberOfDataTableItems]; string tmp = string.Format("{0}{1}", StaticUtilities.DataTableMotion, message[2]); strTable[0] = Server.Table.MotionTable[tmp][StaticUtilities.DataTableMotion]; strTable[1] = Server.Table.MotionTable[tmp][StaticUtilities.DataTableName]; strTable[2] = Server.Table.MotionTable[tmp][StaticUtilities.DataTableCount]; strTable[3] = Server.Table.MotionTable[tmp][StaticUtilities.DataTableDate]; strTable[4] = Server.Table.MotionTable[tmp][StaticUtilities.DataTableCtrl]; sendMsg = string.Format("Get,{0}", string.Join(",", strTable)); break; default: break; } break; case "DeleteMotionFile": int strMotion1 = int.Parse(message[1]) + 1; string file1 = Server.Table.MotionTable["Motion" + strMotion1.ToString()]["Filename"]; Server.Table.deleteMotion(strMotion1); Server.Table.Save(); if (file1 != string.Empty) { if (File.Exists(file1)) { File.Delete(file1); Log.WriteLineSucces(string.Format("Deleting: {0}", file1)); } else { Log.WriteLineFail(string.Format("Deleting: {0}", file1)); } } else { Log.WriteLineFail("Deleting: No such file"); } // send something back as conformation. sendMsg = "Ok"; break; case "Servos": switch (message[1]) { case "Set": int[] width = new int[StaticUtilities.numberOfServos]; Array.Copy(message, 2, strChannelData, 0, 24); for (int q = 0; q < StaticUtilities.numberOfServos; q++) { width[q] = Convert.ToInt32(strChannelData[q]); } Server.MotionInterpreter.Servos(width, 100); break; default: break; } break; case "Trim": switch (message[1]) { case "Get": sendMsg = Server.Trim.Data; // Set the servo's position to the trim values MotionInterpreter.Trim(); break; case "Set": Array.Copy(message, 2, strChannelData, 0, 24); Server.Trim.Data = string.Join(",", strChannelData); sendMsg = "Ok"; // misschien als check de trim.data weer terugsturen. MotionInterpreter.Trim(); break; case "Stop": Server.Trim.Save(); sendMsg = "Ok"; break; default: break; } break; case "Close": case "close": infinteLoop = false; sendMsg = "No Connection"; break; case "Open": sendMsg = "Connected"; break; case "XBox360Controller": switch (message[1]) { case "Open": if (Server.XBox360.Open) { Server.XBox360.ControllerState(); } sendMsg = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13}", Server.XBox360.Open, Server.XBox360.Buttons, Server.XBox360.ThumbsticksX1, Server.XBox360.ThumbsticksY1, Server.XBox360.ThumbsticksX2, Server.XBox360.ThumbsticksY2, Server.XBox360.TriggerLeft, Server.XBox360.TriggerRight, MainIni.PA1Reference, MainIni.PA2Reference, MainIni.PA3Reference, MainIni.PA4Reference, MainIni.PA5Reference, MainIni.PA6Reference); break; case "Read": Server.XBox360.ControllerState(); sendMsg = string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", Server.XBox360.Open, Server.XBox360.Buttons, Server.XBox360.ThumbsticksX1, Server.XBox360.ThumbsticksY1, Server.XBox360.ThumbsticksX2, Server.XBox360.ThumbsticksY2, Server.XBox360.TriggerLeft, Server.XBox360.TriggerRight); break; case "Stop": MainIni.PA1Reference = Convert.ToInt32(message[2]); MainIni.PA2Reference = Convert.ToInt32(message[3]); MainIni.PA3Reference = Convert.ToInt32(message[4]); MainIni.PA4Reference = Convert.ToInt32(message[5]); MainIni.PA5Reference = Convert.ToInt32(message[6]); MainIni.PA6Reference = Convert.ToInt32(message[7]); MainIni.Save(); //sendMsg = "Ok"; break; default: break; } break; case "MagnetoData": short[] compass = Compass.CompassData(); sendMsg = "MagnetoData," + compass[0].ToString() + "," + compass[1].ToString() + "," + compass[2].ToString(); break; case "AcceleroData": short[] accelero = Accelero.AcceleroData(); sendMsg = "AcceleroData," + accelero[0].ToString() + "," + accelero[1].ToString() + "," + accelero[2].ToString(); break; case "GyroscopeData": short[] gyro = Gyro.GyroData(); sendMsg = "GyroscopeData," + gyro[0].ToString() + "," + gyro[1].ToString() + "," + gyro[2].ToString() + "," + gyro[3].ToString() + "," + gyro[4].ToString() + "," + gyro[5].ToString() + "," + gyro[6].ToString() + "," + gyro[7].ToString(); break; default: break; } if (sendMsg != string.Empty) { Network.SendMessage(sendMsg); } networkBusy = false; }
void cmdMnuControl_TrimFileDialogPressed(object sender, TrimCommandMenu.TrimFileDialogEventsArgs e) { if (e.Filedialog == "Open") { string _fileName = string.Empty; this.openFD.Title = "Open a Robot Trim File"; this.openFD.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal); this.openFD.FileName = string.Empty; this.openFD.Filter = "Robot Trim files|*.rcb|All files|*.*"; if (this.openFD.ShowDialog() != DialogResult.Cancel) { trimFile = new IniFile(this.openFD.FileName); if (trimFile.Exists()) { if (trimFile.Load()) { try { // Load the selected trim file saServo = trimFile["Trim"]["Prm"].Split(','); // Position the sliders on the UI trimservosSlider(saServo); // Send the servo trim values to the server trimservos.changeAllChannels(saServo); } catch { MessageBox.Show("No Trim file..."); } } } } } else if (e.Filedialog == "Save") { string str = string.Empty; string[] strArray = new string[StaticUtilities.numberOfServos]; for (int i = 0; i < StaticUtilities.numberOfServos; i++) { strArray[i] = horizontalSliderArray[i].sliderValue.ToString(); } str = string.Join(",", strArray); this.saveFD.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal); this.saveFD.Title = "Save the Robot Trim File"; this.saveFD.Filter = "Robot Trim Files|*.rcb|All files|*.*"; this.saveFD.AddExtension = true; if (this.saveFD.ShowDialog() != DialogResult.Cancel) { trimFile = new IniFile(this.saveFD.FileName); IniSection section = new IniSection(); section.Add("Prm", str); trimFile.Add("Trim", section); trimFile.Save(); } } }
public static bool Init() { string applicationFolder = Path.GetDirectoryName(Application.ExecutablePath); Filename = "KHR-1HV.ini"; main_ini = new IniFile(string.Format("{0}\\{1}", applicationFolder, Filename)); Log.Module = Module; if (main_ini.Exists()) { Log.WriteLineSucces(string.Format("Opening: {0}", Filename)); if (main_ini.Load()) { Log.WriteLineSucces(string.Format("Loading: {0}", Filename)); Read(); return true; } Log.WriteLineFail(string.Format("Loading: {0}", Filename)); return false; } else { Log.WriteLineFail(string.Format("Opening: {0}", Filename)); IniSection section = new IniSection(); section.Add("Roboard", "RB100"); section.Add("MotionReplay", "false"); section.Add("EnableRemoteControl", "false"); section.Add("PowerUpMotion", "-1"); section.Add("LowPowerMotion", "-1"); section.Add("LowPowerVoltage", "120"); section.Add("Timebase", "100"); section.Add("FPS", "1"); section.Add("PA1REF", "0"); section.Add("PA2REF", "0"); section.Add("PA3REF", "0"); section.Add("PA4REF", "0"); section.Add("PA5REF", "0"); section.Add("PA6REF", "0"); for (int i = 0; i < StaticUtilities.numberOfServos; i++) { string tmp = string.Format("CH{0}", (i + 1)); section.Add(tmp, "1"); } main_ini.Add("Main", section); Log.WriteLineSucces(string.Format("Creating: {0}", Filename)); if (Save()) { Read(); return true; } return false; } }
public static void Test() { Player player = new Player(""); SimulationRegion region = new SimulationRegion(); City city = new City(region); City city2 = new City(region); IniSection sect = new IniSection(""); sect.Add("Name", "HUST"); sect.Add("Longitude", "0"); sect.Add("Latitude", "0"); sect.Add("Population", "150"); sect.Add("Size", UrbanSize.Large.ToString()); city.Parse(sect); sect = new IniSection(""); sect.Add("Name", "Home"); sect.Add("Longitude", "1"); sect.Add("Latitude", "0"); sect.Add("Population", "1"); sect.Add("Size", UrbanSize.Small.ToString()); city2.Parse(sect); region.Add(city); //region.Add(city2); //city.AddNearbyCity(city2); //city2.AddNearbyCity(city); OilField oilFld = new OilField(region); sect = new IniSection(""); sect.Add("Amount", "100000"); sect.Add("Latitude", "1"); sect.Add("Longitude", "0"); oilFld.Parse(sect); region.Add(oilFld); CityPluginType plgType = new CityPluginType(); sect = new IniSection(""); sect.Add("Cost", "100"); sect.Add("HRCSpeed", "100"); sect.Add("Behaviour", CityPluginBehaviourType.CollectorFactory.ToString()); plgType.Parse(sect); CityPlugin plg = new CityPlugin(plgType, CityPluginTypeId.OilRefinary); city.Add(plg); plgType = new CityPluginType(); sect = new IniSection(""); sect.Add("Cost", "100"); sect.Add("FoodConvRate", "0.50"); sect.Add("FoodCostSpeed", "100"); sect.Add("Behaviour", CityPluginBehaviourType.CollectorFactory.ToString()); plgType.Parse(sect); plg = new CityPlugin(plgType, CityPluginTypeId.BiofuelFactory); city.Add(plg); //OilField oil = new OilField(region); //Forest forest = new Forest(region); float c = 0; while (true) { Console.Clear(); Console.WriteLine("Energy Status:"); Console.Write(" Current Food Storage "); Console.WriteLine(region.EnergyStatus.CurrentFood); Console.Write(" Current HR Storage "); Console.WriteLine(region.EnergyStatus.CurrentHR); Console.Write(" Current LR Storage "); Console.WriteLine(region.EnergyStatus.CurrentLR); Console.Write(" Current Natural HR "); Console.WriteLine(region.EnergyStatus.RemainingHR); Console.Write(" Current Natural LR "); Console.WriteLine(region.EnergyStatus.RemainingLR); Console.WriteLine("City :" + city.Name); Console.WriteLine("City Status:"); Console.Write(" Development "); Console.WriteLine(city.Development); Console.Write(" Population "); Console.WriteLine(city.Population); Console.Write(" Disease "); Console.WriteLine(city.Disease); Console.Write(" Size "); Console.WriteLine(city.Size); Console.WriteLine(" Local H[{0}] L[{1}] F[{2}]", city.LocalHR.Current, city.LocalLR.Current, city.LocalFood.Current); Console.WriteLine(" Drain H[{0}] L[{1}] F[{2}]", city.GetSelfHRCSpeed(), city.GetSelfLRCSpeed(), city.GetSelfFoodCostSpeed()); Console.WriteLine(" Ratio H[{0:P}] L[{1:P}] F[{2:P}]", city.SelfHRCRatio, city.SelfLRCRatio, city.SelfFoodCostRatio); c += city.GetCarbonChange(); //city.LocalFood.Commit(250); //city.LocalHR.Commit(250); city.LocalLR.Commit(100); //Console.WriteLine("City :" + city2.Name); //Console.WriteLine("City Status:"); //Console.Write(" Development "); //Console.WriteLine(city2.Development); //Console.Write(" Population "); //Console.WriteLine(city2.Population); //Console.Write(" Disease "); //Console.WriteLine(city2.Disease); //Console.Write(" Size "); //Console.WriteLine(city2.Size); //Console.WriteLine(" Local H[{0}] L[{1}] F[{2}]", city2.LocalHR.Current, city2.LocalLR.Current, city2.LocalFood.Current); //Console.WriteLine(" Drain H[{0}] L[{1}] F[{2}]", city2.GetSelfHRCSpeed(), city2.GetSelfLRCSpeed(), city2.GetSelfFoodCostSpeed()); //Console.WriteLine(" Ratio H[{0:P}] L[{1:P}] F[{2:P}]", city2.SelfHRCRatio, city2.SelfLRCRatio, city2.SelfFoodCostRatio); //c += city2.GetCarbonChange(); Console.WriteLine("World Carbon {0}", c); GameTime gt = new GameTime(0, 0, TimeSpan.FromHours(1), TimeSpan.FromHours(1)); region.Update(gt); Thread.Sleep(5); } }
// // public static void mainServer_messageHandler(object sender, NewMessageEventsArgs e) { networkBusy = true; Log.WriteLineMessage(e.NewMessage); string sendMsg = string.Empty; string[] message; string[] Msg; message = e.NewMessage.Split(','); // first index contains the command // Make a command parser. // switch(message[0]) { // // Main Menu case "Information": sendMsg = string.Empty; sendMsg = string.Format("{0},{1},{2},{3},{4},{5}", RCServo.CPU(), RCServo.Version(), Convert.ToString(RCServo.Connected), Convert.ToString(I2C.Connected), Convert.ToString(AD7918.Connected), Convert.ToString(SPI.Connected)); break; case "Options": switch (message[1]) { case "Read": string tmp = string.Empty; sendMsg = Server.MainIni.MotionReplay.ToString() + "," + Server.MainIni.EnableRemoteControl.ToString() + "," + Server.MainIni.PowerUpMotion + "," + Server.MainIni.LowPowerMotion + "," + Server.MainIni.LowPowerVoltage.ToString() + "," + Server.MainIni.TimeBase.ToString(); for (int i = 0; i < StaticUtilities.numberOfServos; i++) { tmp += string.Format(",{0}", Server.MainIni.ChannelFunction[i]); } sendMsg = sendMsg + tmp; break; case "Write": Server.MainIni.MotionReplay = Convert.ToBoolean(message[2]); Server.MainIni.EnableRemoteControl = Convert.ToBoolean(message[3]); Server.MainIni.PowerUpMotion = Convert.ToInt32(message[4]); Server.MainIni.LowPowerMotion = Convert.ToInt32(message[5]); Server.MainIni.LowPowerVoltage = Convert.ToInt32(message[6]); Server.MainIni.TimeBase = Convert.ToInt32(message[7]); int[] temp = new int[StaticUtilities.numberOfServos]; for (int i = 0; i < StaticUtilities.numberOfServos; i++) { temp[i] = Convert.ToInt32(message[8 + i]); } Server.MainIni.ChannelFunction = temp; Server.MainIni.Save(); Server.RCServo.Close(); Server.RCServo.Init(); if (MainIni.EnableRemoteControl) if (!Server.XBox360.Open) Server.XBox360.Init(); sendMsg = "Ok"; break; default: break; } break; case "ReadMotionFile": switch(message[1]) { case "Open": // Get the selected motion index and check // in the motiontable if the motion exists // return true if the file exist. selectedMotionIndex = Convert.ToInt32(message[2]) + 1; string file = Server.Table.MotionTable["Motion" + selectedMotionIndex.ToString()]["Filename"]; if (file != string.Empty) { khr_1hv_motion = new IniFile(file); khr_1hv_motion.Load(); sendMsg = "Ok"; } else { sendMsg = "No motion to read"; } break; case "GraphicalEdit": Msg = new string[8]; Msg[0] = khr_1hv_motion["GraphicalEdit"]["Type"]; Msg[1] = khr_1hv_motion["GraphicalEdit"]["Width"]; Msg[2] = khr_1hv_motion["GraphicalEdit"]["Height"]; Msg[3] = khr_1hv_motion["GraphicalEdit"]["Items"]; Msg[4] = khr_1hv_motion["GraphicalEdit"]["Links"]; Msg[5] = khr_1hv_motion["GraphicalEdit"]["Start"]; Msg[6] = khr_1hv_motion["GraphicalEdit"]["Name"]; Msg[7] = khr_1hv_motion["GraphicalEdit"]["Ctrl"]; Items = 0; Links = 0; sendMsg = string.Join(",", Msg); break; case "Item": Msg = new string[8]; string strItems = string.Format("Item{0}", Items++); Msg[0] = khr_1hv_motion[strItems]["Name"]; Msg[1] = khr_1hv_motion[strItems]["Width"]; Msg[2] = khr_1hv_motion[strItems]["Height"]; Msg[3] = khr_1hv_motion[strItems]["Left"]; Msg[4] = khr_1hv_motion[strItems]["Top"]; Msg[5] = khr_1hv_motion[strItems]["Color"]; Msg[6] = khr_1hv_motion[strItems]["Type"]; Msg[7] = khr_1hv_motion[strItems]["Prm"]; sendMsg = string.Join(",", Msg); break; case "Link": Msg = new string[4]; string strLinks = string.Format("Link{0}", Links++); Msg[0] = khr_1hv_motion[strLinks]["Main"]; Msg[1] = khr_1hv_motion[strLinks]["Origin"]; Msg[2] = khr_1hv_motion[strLinks]["Final"]; Msg[3] = khr_1hv_motion[strLinks]["Point"]; sendMsg = string.Join(",", Msg); break; default: break; } break; case "WriteMotionFile": switch (message[1]) { case "Open": // create random filename. fileName = Path.ChangeExtension(Path.GetRandomFileName(), "RMF"); fileName = string.Format("{0}\\{1}", motionsFolder, fileName); // get the index for the datatable where the // motion is going to be writen. selectedMotionIndex = Convert.ToInt32(message[2]) + 1; khr_1hv_motion = new IniFile(fileName); sendMsg = "Ok"; break; case "GraphicalEdit": IniSection section1 = new IniSection(); section1.Add("Type", message[2]); section1.Add("Width", message[3]); section1.Add("Height", message[4]); section1.Add("Items", message[5]); section1.Add("Links", message[6]); section1.Add("Start", message[7]); section1.Add("Name", message[8]); section1.Add("Ctrl", message[9]); khr_1hv_motion.Add("GraphicalEdit", section1); Items = 0; Links = 0; sendMsg = "Ok"; break; case "Item": IniSection section2 = new IniSection(); section2.Add("Name", message[2]); section2.Add("Width", message[3]); section2.Add("Height", message[4]); section2.Add("Left", message[5]); section2.Add("Top", message[6]); section2.Add("Color", message[7]); section2.Add("Type", message[8]); string strChannel = string.Format("{0}", message[9]); for (int i = 10; i < message.Length; i++) { strChannel = string.Format("{0},{1}", strChannel, message[i]); } section2.Add("Prm", strChannel); string strItems = string.Format("Item{0}", Items++); khr_1hv_motion.Add(strItems, section2); sendMsg = "Ok"; break; case "Link": IniSection section3 = new IniSection(); section3.Add("Main", message[2]); section3.Add("Origin", message[3]); section3.Add("Final", message[4]); string strPoint = string.Format("{0}", message[5]); for (int i = 6; i < message.Length; i++) { strPoint = string.Format("{0},{1}", strPoint, message[i]); } section3.Add("Point", strPoint); string strLinks = string.Format("Link{0}", Links++); khr_1hv_motion.Add(strLinks, section3); sendMsg = "Ok"; break; case "Save": // get the filename of the motion to be deleted string file = Server.Table.MotionTable["Motion" + selectedMotionIndex.ToString()]["Filename"]; if (file != string.Empty) { if (File.Exists(file)) { File.Delete(file); Log.WriteLineSucces(string.Format("Deleting: {0}", Server.Table.MotionTable["Motion" + selectedMotionIndex.ToString()]["Name"])); } else { Log.WriteLineFail(string.Format("Deleting: {0}", Server.Table.MotionTable["Motion" + selectedMotionIndex.ToString()]["Name"])); } } Name = khr_1hv_motion["GraphicalEdit"]["Name"]; Ctrl = khr_1hv_motion["GraphicalEdit"]["Ctrl"]; if (!khr_1hv_motion.Save()) { Log.WriteLineError(string.Format("Saving: {0}", Name)); sendMsg = "NOk"; } else { Log.WriteLineSucces(string.Format("Saving: {0}", Name)); Server.Table.addNewMotion(selectedMotionIndex, fileName, Name, Ctrl); Server.Table.Save(); sendMsg = "Ok"; } break; } break; case "PlayMotionFile": int strMotion = (int.Parse(message[1])); Log.WriteLineMessage(string.Format("Playing motion: {0}, {1}", Table.MotionTable["Motion" + (strMotion + 1).ToString()]["Name"], Table.MotionTable["Motion" + (strMotion + 1).ToString()]["Control"])); Server.MotionInterpreter.Filename = Server.Table.MotionTable["Motion" + (strMotion + 1).ToString()]["Filename"]; Server.MotionInterpreter.Play(); //sendMsg = "Ok"; // No need for this. break; case "StopMotionFile": Server.MotionInterpreter.Stop(); break; case "PauseMotionFile": Server.MotionInterpreter.Pause(); break; case "DataTable": switch (message[1]) { case "Open": sendMsg = string.Format("Open,{0},{1}", StaticUtilities.numberOfMotions, StaticUtilities.numberOfDataTableItems); break; case "Get": string[] strTable = new string[StaticUtilities.numberOfDataTableItems]; string tmp = string.Format("{0}{1}", StaticUtilities.DataTableMotion, message[2]); strTable[0] = Server.Table.MotionTable[tmp][StaticUtilities.DataTableMotion]; strTable[1] = Server.Table.MotionTable[tmp][StaticUtilities.DataTableName]; strTable[2] = Server.Table.MotionTable[tmp][StaticUtilities.DataTableCount]; strTable[3] = Server.Table.MotionTable[tmp][StaticUtilities.DataTableDate]; strTable[4] = Server.Table.MotionTable[tmp][StaticUtilities.DataTableCtrl]; sendMsg = string.Format("Get,{0}", string.Join(",", strTable)); break; default: break; } break; case "DeleteMotionFile": int strMotion1 = int.Parse(message[1]) + 1; string file1 = Server.Table.MotionTable["Motion" + strMotion1.ToString()]["Filename"]; Server.Table.deleteMotion(strMotion1); Server.Table.Save(); if (file1 != string.Empty) { if (File.Exists(file1)) { File.Delete(file1); Log.WriteLineSucces(string.Format("Deleting: {0}", file1)); } else { Log.WriteLineFail(string.Format("Deleting: {0}", file1)); } } else { Log.WriteLineFail("Deleting: No such file"); } // send something back as conformation. sendMsg = "Ok"; break; case "Servos": switch (message[1]) { case "Set": int[] width = new int[StaticUtilities.numberOfServos]; Array.Copy(message, 2, strChannelData, 0, 24); for (int q = 0; q < StaticUtilities.numberOfServos; q++) { width[q] = Convert.ToInt32(strChannelData[q]); } Server.MotionInterpreter.Servos(width, 100); break; default: break; } break; case "Trim": switch (message[1]) { case "Get": sendMsg = Server.Trim.Data; // Set the servo's position to the trim values MotionInterpreter.Trim(); break; case "Set": Array.Copy(message, 2, strChannelData, 0, 24); Server.Trim.Data = string.Join(",", strChannelData); sendMsg = "Ok"; // misschien als check de trim.data weer terugsturen. MotionInterpreter.Trim(); break; case "Stop": Server.Trim.Save(); sendMsg = "Ok"; break; default: break; } break; case "Close": case "close": infinteLoop = false; sendMsg = "No Connection"; break; case "Open": sendMsg = "Connected"; break; case "XBox360Controller": switch (message[1]) { case "Open": if (Server.XBox360.Open) Server.XBox360.ControllerState(); sendMsg = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13}", Server.XBox360.Open, Server.XBox360.Buttons, Server.XBox360.ThumbsticksX1, Server.XBox360.ThumbsticksY1, Server.XBox360.ThumbsticksX2, Server.XBox360.ThumbsticksY2, Server.XBox360.TriggerLeft, Server.XBox360.TriggerRight, MainIni.PA1Reference, MainIni.PA2Reference, MainIni.PA3Reference, MainIni.PA4Reference, MainIni.PA5Reference, MainIni.PA6Reference); break; case "Read": Server.XBox360.ControllerState(); sendMsg = string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", Server.XBox360.Open, Server.XBox360.Buttons, Server.XBox360.ThumbsticksX1, Server.XBox360.ThumbsticksY1, Server.XBox360.ThumbsticksX2, Server.XBox360.ThumbsticksY2, Server.XBox360.TriggerLeft, Server.XBox360.TriggerRight); break; case "Stop": MainIni.PA1Reference = Convert.ToInt32(message[2]); MainIni.PA2Reference = Convert.ToInt32(message[3]); MainIni.PA3Reference = Convert.ToInt32(message[4]); MainIni.PA4Reference = Convert.ToInt32(message[5]); MainIni.PA5Reference = Convert.ToInt32(message[6]); MainIni.PA6Reference = Convert.ToInt32(message[7]); MainIni.Save(); //sendMsg = "Ok"; break; default: break; } break; case "MagnetoData": short[] compass = Compass.CompassData(); sendMsg = "MagnetoData," + compass[0].ToString() + "," + compass[1].ToString() + "," + compass[2].ToString(); break; case "AcceleroData": short[] accelero = Accelero.AcceleroData(); sendMsg = "AcceleroData," + accelero[0].ToString() + "," + accelero[1].ToString() + "," + accelero[2].ToString(); break; case "GyroscopeData": short[] gyro = Gyro.GyroData(); sendMsg = "GyroscopeData," + gyro[0].ToString() + "," + gyro[1].ToString() + "," + gyro[2].ToString() + "," + gyro[3].ToString() + "," + gyro[4].ToString() + "," + gyro[5].ToString() + "," + gyro[6].ToString() + "," + gyro[7].ToString(); break; default: break; } if (sendMsg != string.Empty) Network.SendMessage(sendMsg); networkBusy = false; }
//======================= // DEFAULT CONSTRUCTOR //======================= public KHR_1HV_IniFile() { khr_1hv_ini = new IniFile("./KHR-1HV.ini"); if (khr_1hv_ini.Exists()) khr_1hv_ini.Load(); else { IniSection section = new IniSection(); section.Add("IPAddress", "0.0.0.0"); section.Add("Grid", "1"); section.Add("GridWidth", "5"); section.Add("GridHeight", "5"); section.Add("Form", "804,900,-2147483633"); section.Add("Bmp", ""); section.Add("Background", "0"); section.Add("CH1", "1,0,0,-2147483633,0,1,CH1"); section.Add("CH2", "1,0,31,-2147483633,0,1,CH2"); section.Add("CH3", "1,0,62,-2147483633,0,1,CH3"); section.Add("CH4", "1,0,93,-2147483633,0,1,CH4"); section.Add("CH5", "1,0,124,-2147483633,0,1,CH5"); section.Add("CH6", "1,0,155,-2147483633,0,1,CH6"); section.Add("CH7", "1,0,186,-2147483633,0,1,CH7"); section.Add("CH8", "1,0,217,-2147483633,0,1,CH8"); section.Add("CH9", "1,0,248,-2147483633,0,1,CH9"); section.Add("CH10", "1,0,279,-2147483633,0,1,CH10"); section.Add("CH11", "1,0,310,-2147483633,0,1,CH11"); section.Add("CH12", "1,0,341,-2147483633,0,1,CH12"); section.Add("CH13", "1,329,0,-2147483633,0,1,CH13"); section.Add("CH14", "1,329,31,-2147483633,0,1,CH14"); section.Add("CH15", "1,329,62,-2147483633,0,1,CH15"); section.Add("CH16", "1,329,93,-2147483633,0,1,CH16"); section.Add("CH17", "1,329,124,-2147483633,0,1,CH17"); section.Add("CH18", "1,329,155,-2147483633,0,1,CH18"); section.Add("CH19", "1,329,186,-2147483633,0,1,CH19"); section.Add("CH20", "1,329,217,-2147483633,0,1,CH20"); section.Add("CH21", "1,329,248,-2147483633,0,1,CH21"); section.Add("CH22", "1,329,279,-2147483633,0,1,CH22"); section.Add("CH23", "1,329,310,-2147483633,0,1,CH23"); section.Add("CH24", "1,329,341,-2147483633,0,1,CH24"); section.Add("SPEED", "1,0,372,-2147483633"); section.Add("CMD", "1,0,403,-2147483633"); section.Add("LINK", "1,329,372,-2147483633"); khr_1hv_ini.Add("KHR-1HV", section); khr_1hv_ini.Save(); } }
public static bool Init() { string applicationFolder = Path.GetDirectoryName(Application.ExecutablePath); Filename = "KHR-1HV.ini"; main_ini = new IniFile(string.Format("{0}\\{1}", applicationFolder, Filename)); Log.Module = Module; if (main_ini.Exists()) { Log.WriteLineSucces(string.Format("Opening: {0}", Filename)); if (main_ini.Load()) { Log.WriteLineSucces(string.Format("Loading: {0}", Filename)); Read(); return(true); } Log.WriteLineFail(string.Format("Loading: {0}", Filename)); return(false); } else { Log.WriteLineFail(string.Format("Opening: {0}", Filename)); IniSection section = new IniSection(); section.Add("Roboard", "RB100"); section.Add("MotionReplay", "false"); section.Add("EnableRemoteControl", "false"); section.Add("PowerUpMotion", "-1"); section.Add("LowPowerMotion", "-1"); section.Add("LowPowerVoltage", "120"); section.Add("Timebase", "100"); section.Add("FPS", "1"); section.Add("PA1REF", "0"); section.Add("PA2REF", "0"); section.Add("PA3REF", "0"); section.Add("PA4REF", "0"); section.Add("PA5REF", "0"); section.Add("PA6REF", "0"); for (int i = 0; i < StaticUtilities.numberOfServos; i++) { string tmp = string.Format("CH{0}", (i + 1)); section.Add(tmp, "1"); } main_ini.Add("Main", section); Log.WriteLineSucces(string.Format("Creating: {0}", Filename)); if (Save()) { Read(); return(true); } return(false); } }
private void saveSnmpConfigFile() { IniFile ini = new IniFile("SNMP Config.ini"); foreach (ListViewItem lsti in SnmpHostListView.Items) { IniSection section = new IniSection(); section.Add("HostName", lsti.SubItems[0].Text); section.Add("Port", lsti.SubItems[1].Text); section.Add("Community", lsti.SubItems[2].Text); section.Add("Version", lsti.SubItems[3].Text); section.Add("User", lsti.SubItems[4].Text); section.Add("Password", lsti.SubItems[5].Text); ini.Add(lsti.SubItems[0].Text, section); } ini.Save(); }
public static void Test() { Player player = new Player(""); SimulationRegion region = new SimulationRegion(); City city = new City(region); City city2 = new City(region); IniSection sect = new IniSection(""); sect.Add("Name", "HUST"); sect.Add("Longitude", "0"); sect.Add("Latitude", "0"); sect.Add("Population", "150"); sect.Add("Size", UrbanSize.Large.ToString()); city.Parse(sect); sect = new IniSection(""); sect.Add("Name", "Home"); sect.Add("Longitude", "1"); sect.Add("Latitude", "0"); sect.Add("Population", "1"); sect.Add("Size", UrbanSize.Small.ToString()); city2.Parse(sect); region.Add(city); //region.Add(city2); //city.AddNearbyCity(city2); //city2.AddNearbyCity(city); OilField oilFld = new OilField(region); sect = new IniSection(""); sect.Add("Amount", "100000"); sect.Add("Latitude", "1"); sect.Add("Longitude", "0"); oilFld.Parse(sect); region.Add(oilFld); CityPluginType plgType = new CityPluginType(); sect = new IniSection(""); sect.Add("Cost", "100"); sect.Add("HRCSpeed", "100"); sect.Add("Behaviour", CityPluginBehaviourType.CollectorFactory.ToString()); plgType.Parse(sect); CityPlugin plg = new CityPlugin(plgType, CityPluginTypeId.OilRefinary); city.Add(plg); plgType = new CityPluginType(); sect = new IniSection(""); sect.Add("Cost", "100"); sect.Add("FoodConvRate", "0.50"); sect.Add("FoodCostSpeed", "100"); sect.Add("Behaviour", CityPluginBehaviourType.CollectorFactory.ToString()); plgType.Parse(sect); plg = new CityPlugin(plgType, CityPluginTypeId.BiofuelFactory); city.Add(plg); //OilField oil = new OilField(region); //Forest forest = new Forest(region); float c = 0; while (true) { Console.Clear(); Console.WriteLine("Energy Status:"); Console.Write(" Current Food Storage "); Console.WriteLine(region.EnergyStatus.CurrentFood); Console.Write(" Current HR Storage "); Console.WriteLine(region.EnergyStatus.CurrentHR); Console.Write(" Current LR Storage "); Console.WriteLine(region.EnergyStatus.CurrentLR); Console.Write(" Current Natural HR "); Console.WriteLine(region.EnergyStatus.RemainingHR); Console.Write(" Current Natural LR "); Console.WriteLine(region.EnergyStatus.RemainingLR); Console.WriteLine("City :" + city.Name); Console.WriteLine("City Status:"); Console.Write(" Development "); Console.WriteLine(city.Development); Console.Write(" Population "); Console.WriteLine(city.Population); Console.Write(" Disease "); Console.WriteLine(city.Disease); Console.Write(" Size "); Console.WriteLine(city.Size); Console.WriteLine(" Local H[{0}] L[{1}] F[{2}]", city.LocalHR.Current, city.LocalLR.Current, city.LocalFood.Current); Console.WriteLine(" Drain H[{0}] L[{1}] F[{2}]", city.GetSelfHRCSpeed(), city.GetSelfLRCSpeed(), city.GetSelfFoodCostSpeed()); Console.WriteLine(" Ratio H[{0:P}] L[{1:P}] F[{2:P}]", city.SelfHRCRatio, city.SelfLRCRatio, city.SelfFoodCostRatio); c += city.GetCarbonChange(); //city.LocalFood.Commit(250); //city.LocalHR.Commit(250); city.LocalLR.Commit(100); //Console.WriteLine("City :" + city2.Name); //Console.WriteLine("City Status:"); //Console.Write(" Development "); //Console.WriteLine(city2.Development); //Console.Write(" Population "); //Console.WriteLine(city2.Population); //Console.Write(" Disease "); //Console.WriteLine(city2.Disease); //Console.Write(" Size "); //Console.WriteLine(city2.Size); //Console.WriteLine(" Local H[{0}] L[{1}] F[{2}]", city2.LocalHR.Current, city2.LocalLR.Current, city2.LocalFood.Current); //Console.WriteLine(" Drain H[{0}] L[{1}] F[{2}]", city2.GetSelfHRCSpeed(), city2.GetSelfLRCSpeed(), city2.GetSelfFoodCostSpeed()); //Console.WriteLine(" Ratio H[{0:P}] L[{1:P}] F[{2:P}]", city2.SelfHRCRatio, city2.SelfLRCRatio, city2.SelfFoodCostRatio); //c += city2.GetCarbonChange(); Console.WriteLine("World Carbon {0}", c); GameTime gt = new GameTime(0, 0, TimeSpan.FromHours(1), TimeSpan.FromHours(1)); region.Update(gt); Thread.Sleep(5); } }
public IniFile ReadIni() { IniFile ini = new Ini.IniFile("sys.ini"); if (ini.Exists()) { ini.Load(); } else { IniSection section = new IniSection(); section.Add("startdate", "1-05-2011"); section.Add("enddate", "15-05-2011"); ini.Add("DATES", section); section = new IniSection(); section.Add("email_user", "*****@*****.**"); section.Add("email_password", "Paz.planner01"); section.Add("email_from", "*****@*****.**"); section.Add("email_host", "smtp.gmail.com"); section.Add("email_port", "587"); section.Add("email_onderwerp", "Afstudeerzitting(en)"); ini.Add("EMAILSETTINGS", section); section = new IniSection(); section.Add("this.DB_host", "student.aii.avans.nl"); section.Add("this.DB_username", "MI4Ie"); section.Add("this.DB_password", "4DRcUrzV"); section.Add("this.DB_database", "MI4Ie_this.DB"); ini.Add("DATABASESETTINGS", section); ini.Save(); } return ini; }
// Methods // public static bool Read() { // Read a motion from the server Roboard.NetworkClient.messageHandler += new NetworkClient.NewMessageEventHandler(WriteNetworkClient_messageHandler); string strCommand = string.Format("ReadMotionFile"); // 1 - send the selectedmotion index to the server // sendString = string.Format("{0},Open,{1}", strCommand, _selectedMotionIndex); if (!handleNetworkMessage(sendString)) return false; // 2 - if exists than create a new motionData. // tempMotionData = new IniFile(string.Empty); //======================================== // 3 - Read the GraphicalEdit part section //======================================== // send to the server sendString = string.Format("{0},{1}", strCommand, StaticUtilities.SectionGraphicalEdit); if (!handleNetworkMessage(sendString)) return false; IniSection graphicalEditSection = new IniSection(); for (int i = 0; i < StaticUtilities.GraphicalEdit.Length; i++) graphicalEditSection.Add(StaticUtilities.GraphicalEdit[i], strMessage[i]); tempMotionData.Add(StaticUtilities.SectionGraphicalEdit, graphicalEditSection); //=========================== // 4 - Read the items section //=========================== int Items = Convert.ToInt32(tempMotionData[StaticUtilities.SectionGraphicalEdit][StaticUtilities.GraphicalEditItems]); for (int i = 0; i < Items; i++) { // send to the server sendString = string.Format("{0},{1}", strCommand, StaticUtilities.SectionItem); if (!handleNetworkMessage(sendString)) return false; IniSection itemSection = new IniSection(); for (int j = 0; j < StaticUtilities.Item.Length - 1; j++) // minus one because Prm itemSection.Add(StaticUtilities.Item[j], strMessage[j]); string strChannel = string.Format("{0}", strMessage[StaticUtilities.Item.Length - 1]); for (int k = StaticUtilities.Item.Length; k < strMessage.Length; k++) strChannel = string.Format("{0},{1}", strChannel, strMessage[k]); itemSection.Add(StaticUtilities.ItemPrm, strChannel); tempMotionData.Add(string.Format("{0}{1}", StaticUtilities.SectionItem, i), itemSection); } //=========================== // 5 - Read the links section //=========================== int Links = Convert.ToInt32(tempMotionData[StaticUtilities.SectionGraphicalEdit][StaticUtilities.GraphicalEditLinks]); for (int i = 0; i < Links; i++) { // send to the server sendString = string.Format("{0},{1}", strCommand, StaticUtilities.SectionLink); if (!handleNetworkMessage(sendString)) return false; IniSection linkSection = new IniSection(); for (int j = 0; j < StaticUtilities.Link.Length - 1; j++) // minus one because Point linkSection.Add(StaticUtilities.Link[j], strMessage[j]); string strPoint = string.Format("{0}", strMessage[StaticUtilities.Link.Length - 1]); for (int k = StaticUtilities.Link.Length; k < strMessage.Length; k++) strPoint = string.Format("{0},{1}", strPoint, strMessage[k]); linkSection.Add(StaticUtilities.LinkPoint, strPoint); tempMotionData.Add(string.Format("{0}{1}", StaticUtilities.SectionLink, i), linkSection); } // 6 - close and other things to be done. motionData = tempMotionData; Close(); return true; }
// Method // private static bool CreateTrim() { IniSection section = new IniSection(); section.Add("Prm", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"); _Data.Add("Trim", section); Log.WriteLineSucces(string.Format("Creating: {0}", Filename)); return Save(); }
//bool firstPos = true; private void DataSheet_MouseDown(object sender, MouseEventArgs e) { //Control currentCtrl; //currentCtrl = (Control)sender; if (e.Button == MouseButtons.Right) { DataSheet.ContextMenuStrip.Show(DataSheet, new Point(e.X, e.Y)); } else if (e.Button == MouseButtons.Left) { // Create and configure the shape with some defaults. Shape newShape = new Shape(); newShape.Size = new Size(iWidth, iHeight); bool objectMenuSelected = false; if (tsPos.Checked == true) { //newShape.Name = "Position";// misschien moet hier de itemnummer komen te staan, zodat het uniek blijft. newShape.Type = 0;// Shape.ShapeType.PosRectangle; newShape.ForeColor = Color.Black; newShape.Item = string.Format("Item{0}", Item);// Tag = string.Format("Item{0}", Item); objectMenuSelected = true; //if (firstPos) { IniSection section = new IniSection(); section.Add("Name", string.Format("POS{0}",Pos)); section.Add("Width", iWidth.ToString()); section.Add("Height", iHeight.ToString()); section.Add("Left", e.X.ToString()); section.Add("Top", e.Y.ToString()); section.Add("Color", ColorTranslator.ToOle(Color.Black).ToString()); section.Add("Type", "0"); section.Add("Prm", "100,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384,16384"); currentMotion.Add(string.Format("Item{0}", Item), section); Item++; Pos++; //firstPos = false; } //else { // copy van de vorige? } //currentMotion[string.Format("Item{0}", Item)]["Name"] = "POS1"; //currentMotion[string.Format("Item{0}", Item)]["Width"] = iWidth.ToString(); //currentMotion[string.Format("Item{0}", Item)]["Height"] = iHeight.ToString(); //currentMotion[string.Format("Item{0}", Item)]["Left"] = e.X.ToString(); //currentMotion[string.Format("Item{0}", Item)]["Top"] = e.Y.ToString(); //currentMotion[string.Format("Item{0}", Item)]["Color"] = ColorTranslator.ToOle(Color.Black).ToString(); //currentMotion[string.Format("Item{0}", Item)]["Type"] = "0"; //currentMotion[string.Format("Item{0}", Item)]["Prm"] = "100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"; } else if (tsSet.Checked == true) { //newShape.Name = "Set"; newShape.Type = 1;// Shape.ShapeType.Ellipse; newShape.ForeColor = Color.Blue; objectMenuSelected = true; } else if (tsMix.Checked == true) { //newShape.Name = "Mix"; newShape.Type = 2;// Shape.ShapeType.Ellipse; newShape.ForeColor = Color.Red; objectMenuSelected = true; } else if (tsCompare.Checked == true) { //newShape.Name = "Compare"; newShape.Type = 3;// Shape.ShapeType.Ellipse; newShape.ForeColor = Color.SlateGray; objectMenuSelected = true; } if (objectMenuSelected == true) { // To determine where to place the shape, you need to convert the // current screen-based mouse coordinates into relative form coordinates. newShape.Location = DataSheet.PointToClient(Control.MousePosition); // Attach a context menu to the shape. newShape.ContextMenuStrip = contextMenu1; // Connect the shape to all its event handlers. newShape.MouseDown += new MouseEventHandler(newShape_MouseDown); newShape.MouseMove += new MouseEventHandler(newShape_MouseMove); newShape.MouseUp += new MouseEventHandler(newShape_MouseUp); newShape.MouseDoubleClick += new MouseEventHandler(newShape_MouseDoubleClick); // Add the shape to the form. DataSheet.Controls.Add(newShape); //currentMotion } } }
public void SaveSettings() { IniFile file = new IniFile(MainWindow.settings_path); if (file.Exists()) { file.Load(); } else { if (!Directory.Exists(MainWindow.settings_folder)) { Directory.CreateDirectory(MainWindow.settings_folder); } File.Create(MainWindow.settings_path).Close(); } IniSection section = new IniSection(); if (file.HasSection("OptionsUpdates")) { file.Remove("OptionsUpdates"); } section.Add("chkAutoUpdate", this.chkAutoUpdate.Checked.ToString()); file.Add("OptionsUpdates", section); section = new IniSection(); if (file.HasSection("OptionsDrawing")) { file.Remove("OptionsDrawing"); } section.Add("chkTeamColors", this.checkBoxTeamColors.Checked.ToString()); section.Add("chkAutoHideHUDs", this.checkBoxHideHUDs.Checked.ToString()); section.Add("cbObserverPanelDrawDirection", this.cbObserverPanelDrawDirection.SelectedItem.ToString()); section.Add("chkCameraEnemies", this.chkCameraEnemies.Checked.ToString()); section.Add("chkCameraAllies", this.chkCameraAllies.Checked.ToString()); section.Add("chkCameraSelf", this.chkCameraSelf.Checked.ToString()); section.Add("chkSpectator", this.chkSpectator.Checked.ToString()); section.Add("chkUnitsEnemies", this.chkUnitsEnemies.Checked.ToString()); section.Add("chkUnitsAllies", this.chkUnitsAllies.Checked.ToString()); section.Add("chkUnitsSelf", this.chkUnitsSelf.Checked.ToString()); section.Add("chk0Radius", this.chk0Radius.Checked.ToString()); section.Add("chkUnitDestinationEnemies", this.chkUnitDestinationEnemies.Checked.ToString()); section.Add("chkUnitDestinationAllies", this.chkUnitDestinationAllies.Checked.ToString()); section.Add("chkUnitDestinationSelf", this.chkUnitDestinationSelf.Checked.ToString()); section.Add("chkUnitEnemiesScreen", this.chkUnitEnemiesScreen.Checked.ToString()); section.Add("chkUnitDestinationEnemiesScreen", this.chkUnitDestinationEnemiesScreen.Checked.ToString()); file.Add("OptionsDrawing", section); section = new IniSection(); if (file.HasSection("OptionsHotkeys")) { file.Remove("OptionsHotkeys"); } section.Add("cbRepositionHotkey", this.cbRepositionHotkey.Text); section.Add("cbNextPanelHotkey", this.cbNextPanelHotkey.Text); section.Add("cbPreviousPanelHotkey", this.cbPreviousPanelHotkey.Text); file.Add("OptionsHotkeys", section); section = new IniSection(); string str3 = "OptionsTimers"; if (file.HasSection(str3)) { file.Remove(str3); } section.Add("udGUI", this.udGUI.Value.ToString()); section.Add("udDrawing", this.udDrawing.Value.ToString()); section.Add("udData", this.udData.Value.ToString()); file.Add(str3, section); file.Save(); }
private void saveInfoMartConfigFile() { IniFile ini = new IniFile("InfoMart Config.ini"); if (InfoMartJobConfig != null) { IniSection section = new IniSection(); section.Add("HostName", InfoMartJobConfig.hostname); section.Add("Port", InfoMartJobConfig.port ); section.Add("Service", InfoMartJobConfig.service ); section.Add("Table", InfoMartJobConfig.table ); section.Add("Username", InfoMartJobConfig.username ); section.Add("Password", InfoMartJobConfig.password ); ini.Add("InfoMart DB", section); } ini.Save(); }