public void check_deep_clone() { var ori = new SectionDataCollection(); ori.AddSection("section1"); ori["section1"]["key1"] = "value1"; var copy = (SectionDataCollection)ori.Clone(); copy["section1"]["key1"] = "value2"; Assert.That(ori["section1"]["key1"], Is.EqualTo("value1")); }
public void check_adding_sections_to_collection() { var col = new SectionDataCollection(); var exampleSection = new SectionData("section1"); exampleSection.Keys.AddKey("examplekey"); exampleSection.Keys["examplekey"] = "examplevalue"; col.Add(exampleSection); Assert.That(col["section1"], Is.Not.Null); // Add sections directly to the collection Assert.That(col.AddSection("section2"), Is.True); Assert.That(col.AddSection("section2"), Is.False); Assert.That(col["section2"], Is.Not.Null); }
public void check_section_data_operations() { string strSectionTest = "MySection"; string strComment = "comment"; List <string> commentListTest = new List <string>(new string[] { "testComment 1", "testComment 2" }); //Creation SectionDataCollection sdc = new SectionDataCollection(); Assert.That(sdc, Is.Empty); //Add sectoin sdc.AddSection(strSectionTest); sdc.AddSection(strSectionTest); Assert.That(sdc.Count, Is.EqualTo(1)); //Check access Assert.That(sdc.GetSectionData(strSectionTest), Is.Not.Null); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments, Is.Empty); Assert.That(sdc.GetSectionData(strSectionTest).Keys.Count, Is.EqualTo(0)); //Check add coments sdc.GetSectionData(strSectionTest).LeadingComments.Add(strComment); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments.Count, Is.EqualTo(1)); sdc.GetSectionData(strSectionTest).LeadingComments.Clear(); sdc.GetSectionData(strSectionTest).LeadingComments.AddRange(commentListTest); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments.Count, Is.EqualTo(commentListTest.Count)); //Remove section sdc.RemoveSection("asdf"); Assert.That(sdc.Count, Is.EqualTo(1)); sdc.RemoveSection(strSectionTest); Assert.That(sdc.Count, Is.EqualTo(0)); //Check access Assert.That(sdc[strSectionTest], Is.Null); }
public void check_section_data_operations() { string strSectionTest = "MySection"; string strComment = "comment"; List<string> commentListTest = new List<string>(new string[] { "testComment 1", "testComment 2" }); //Creation SectionDataCollection sdc = new SectionDataCollection(); Assert.That(sdc, Is.Empty); //Add sectoin sdc.AddSection(strSectionTest); sdc.AddSection(strSectionTest); Assert.That(sdc.Count, Is.EqualTo(1)); //Check access Assert.That(sdc.GetSectionData(strSectionTest), Is.Not.Null); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments, Is.Empty); Assert.That(sdc.GetSectionData(strSectionTest).Keys.Count, Is.EqualTo(0)); //Check add coments sdc.GetSectionData(strSectionTest).LeadingComments.Add(strComment); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments.Count, Is.EqualTo(1)); sdc.GetSectionData(strSectionTest).LeadingComments.Clear(); sdc.GetSectionData(strSectionTest).LeadingComments.AddRange(commentListTest); Assert.That(sdc.GetSectionData(strSectionTest).LeadingComments.Count, Is.EqualTo(commentListTest.Count)); //Remove section sdc.RemoveSection("asdf"); Assert.That(sdc.Count, Is.EqualTo(1)); sdc.RemoveSection(strSectionTest); Assert.That(sdc.Count, Is.EqualTo(0)); //Check access Assert.That(sdc[strSectionTest], Is.Null); }
public static void SetLocalScreenMode(string config3DPath) { //初始化INIParser var parser = new FileIniDataParser(); parser.Parser.Configuration.AllowDuplicateKeys = true; parser.Parser.Configuration.OverrideDuplicateKeys = true; parser.Parser.Configuration.AllowDuplicateSections = true; //如果没有ini路径。默认打开3D。 FileInfo ini = new FileInfo(config3DPath); if (!ini.Exists) { if (!Directory.Exists(ini.Directory.FullName)) { Directory.CreateDirectory(ini.Directory.FullName); } var file = File.Create(config3DPath); file.Close(); SectionDataCollection sec = new SectionDataCollection(); IniData iniData = new IniData(sec); sec.AddSection("Screen"); sec.AddSection("ScreenDimensional"); sec.AddSection("ScreenMode"); sec.AddSection("CanUseAR"); iniData["Screen"].AddKey("IsScreen", "True"); iniData["ProjectionMode"].AddKey("Mode", "VR-2D"); //iniData["ScreenDimensional"].AddKey("Dimensional", "2D"); //iniData["ScreenMode"].AddKey("ScreenMode", "VR"); iniData["CanUseAR"].AddKey("AR", "True"); iniData["Display"].AddKey("Name", ""); iniData["VersionNo"].AddKey("CurVersion", "1.0"); parser.WriteFile(config3DPath, iniData); UISetting.isScreen = true; UISetting.isNoneProjection = false; UISetting.lastIsNoneProjection = false; UISetting.screenDimensional = UISetting.ScreenDimensional.TwoDimensional; UISetting.lastScreenDimensional = UISetting.ScreenDimensional.TwoDimensional; UISetting.screenmode = UISetting.ScreenMode.VR; UISetting.lastScreenmode = UISetting.ScreenMode.VR; UISetting.curScreenmode = ScreenManger.DualScreenMode.VR_2D; liu.GlobalConfig.Instance.displayName = ""; liu.GlobalConfig.Instance.versionNO = "1.0"; } else { IniData iniData = parser.ReadFile(ini.FullName); string isOpen = iniData["Screen"]["IsScreen"]; string projectionMode = iniData["ProjectionMode"]["Mode"]; //string cDimensional = iniData["ScreenDimensional"]["Dimensional"]; //string cScreenMode = iniData["ScreenMode"]["ScreenMode"]; string cAR = iniData["CanUseAR"]["AR"]; string displayName = iniData["Display"]["Name"]; string curVersionNo = iniData["VersionNo"]["CurVersion"]; bool isScreen = isOpen == "True" ? true : false; //isScreen = screenNum > 1 ? isScreen : false; //var dimensional = cDimensional == "2D" ? UISetting.ScreenDimensional.TwoDimensional : UISetting.ScreenDimensional.ThreeDimensional; //var screenMode = cScreenMode == "VR" ? UISetting.ScreenMode.VR : UISetting.ScreenMode.AR; var arFunc = cAR == "True" ? true : false; switch (projectionMode) { case "None": UISetting.isNoneProjection = true; UISetting.screenDimensional = UISetting.ScreenDimensional.None; UISetting.screenmode = UISetting.ScreenMode.None; break; case "VR-2D": UISetting.isNoneProjection = false; UISetting.screenDimensional = UISetting.ScreenDimensional.TwoDimensional; UISetting.screenmode = UISetting.ScreenMode.VR; break; case "VR-3D": UISetting.isNoneProjection = false; UISetting.screenDimensional = UISetting.ScreenDimensional.ThreeDimensional; UISetting.screenmode = UISetting.ScreenMode.VR; break; case "AR": UISetting.isNoneProjection = false; UISetting.screenDimensional = UISetting.ScreenDimensional.TwoDimensional; UISetting.screenmode = UISetting.ScreenMode.AR; break; default: break; } UISetting.isScreen = isScreen; //UISetting.screenmode = UISetting.ScreenMode.VR; liu.GlobalConfig.canUseCameraAR = arFunc; liu.GlobalConfig.Instance.displayName = displayName; liu.GlobalConfig.Instance.versionNO = curVersionNo; UISetting.lastIsNoneProjection = UISetting.isNoneProjection; UISetting.lastScreenDimensional = UISetting.screenDimensional; UISetting.lastScreenmode = UISetting.screenmode; } }
/// <summary> /// Load settings from IniData. /// </summary> private void LoadSettings() { foreach (var section in config.VisibleSections) { // Add section title to window AddSectionTitle(section.name); MovePosition(spacing); // Get section from collection SectionDataCollection sectionDataCollection = data.Sections; if (!sectionDataCollection.ContainsSection(section.name)) { sectionDataCollection.AddSection(section.name); } SectionData sectionData = sectionDataCollection.GetSectionData(section.name); foreach (var key in section.keys) { // Get key from collection KeyDataCollection keyDataCollection = sectionData.Keys; if (!keyDataCollection.ContainsKey(key.name)) { keyDataCollection.AddKey(key.name); } KeyData keyData = keyDataCollection.GetKeyData(key.name); // Add key to window with corrispective control TextLabel settingName = AddKeyName(key.name); settingName.ToolTip = defaultToolTip; settingName.ToolTipText = key.description; switch (key.type) { case ModSettingsKey.KeyType.Toggle: bool toggle; AddCheckBox(bool.TryParse(keyData.Value, out toggle) ? toggle : key.toggle.value); break; case ModSettingsKey.KeyType.MultipleChoice: int selected; if (!int.TryParse(keyData.Value, out selected)) { selected = key.multipleChoice.selected; } var multipleChoice = GetSlider(); multipleChoice.SetIndicator(key.multipleChoice.choices, selected); SetSliderIndicator(multipleChoice); break; case ModSettingsKey.KeyType.Slider: var sliderKey = key.slider; int startValue; if (!int.TryParse(keyData.Value, out startValue)) { startValue = key.slider.value; } var slider = GetSlider(); slider.SetIndicator(sliderKey.min, sliderKey.max, startValue); SetSliderIndicator(slider); break; case ModSettingsKey.KeyType.FloatSlider: var floatSliderKey = key.floatSlider; float floatStartValue; if (!float.TryParse(keyData.Value, out floatStartValue)) { floatStartValue = key.floatSlider.value; } var floatSlider = GetSlider(); floatSlider.SetIndicator(floatSliderKey.min, floatSliderKey.max, floatStartValue); SetSliderIndicator(floatSlider); break; case ModSettingsKey.KeyType.Tuple: var tuple = AddTuple(keyData.Value); tuple.First.Numeric = tuple.Second.Numeric = true; break; case ModSettingsKey.KeyType.FloatTuple: AddTuple(keyData.Value); // TextBox.Numeric doesn't allow dot break; case ModSettingsKey.KeyType.Text: TextBox textBox = GetTextbox(95, 40, keyData.Value); modTextBoxes.Add(textBox); break; case ModSettingsKey.KeyType.Color: AddColorPicker(keyData.Value, key); break; } MovePosition(spacing); } } }
public static string GetValFromCfg(SectionDataCollection col, string sect, string key) { return(col.GetSectionData(sect).Keys.GetKeyData(key).Value.Trim(PackRes_Def.trim)); }
/// <summary> /// Initializes an empty IniData instance. /// </summary> public IniData() { _sections = new SectionDataCollection(); }
public StreamIniDataParser() { CommentDelimiter = ';'; KeyValueDelimiter = '='; SectionDelimiters = new char[] { '[', ']' }; mCurrentTmpData = new SectionDataCollection(); }
/// <summary> /// Initializes a new IniData instance using a previous /// <see cref="SectionDataCollection"/>. /// </summary> /// <param name="sdc"> /// <see cref="SectionDataCollection"/> object containing the /// data with the sections of the file /// </param> public IniData(SectionDataCollection sdc) { _sections = (SectionDataCollection)sdc.Clone(); Global = new KeyDataCollection(); SectionKeySeparator = '.'; }
/// <summary> /// 获取该分区中心坐标 /// </summary> /// <param name="SectionDataCollection"></param> /// <returns></returns> public Vector GetCentre(SectionDataCollection SectionDataCollection) { //变量初始化 Vector Result = new Vector(); List <decimal> Tem_Dat_X = new List <decimal>(); List <decimal> Tem_Dat_Y = new List <decimal>(); //获取数据 foreach (var o in SectionDataCollection.SectionDatas) { if (!o.EN) { continue; } if (o.ArcLine.Count > 0) { for (int i = 0; i < o.ArcLine.Count; i++) { if (o.ArcLine[i].Count >= 0)//判断数据大于零 { Tem_Dat_X.Add(o.ArcLine[i].Max(p => p.Start_x)); Tem_Dat_X.Add(o.ArcLine[i].Min(p => p.Start_x)); Tem_Dat_X.Add(o.ArcLine[i].Max(p => p.End_x)); Tem_Dat_X.Add(o.ArcLine[i].Min(p => p.End_x)); Tem_Dat_Y.Add(o.ArcLine[i].Max(p => p.Start_y)); Tem_Dat_Y.Add(o.ArcLine[i].Min(p => p.Start_y)); Tem_Dat_Y.Add(o.ArcLine[i].Max(p => p.End_y)); Tem_Dat_Y.Add(o.ArcLine[i].Min(p => p.End_y)); } } } if (o.Circle.Count > 0) { Tem_Dat_X.Add(o.Circle.Max(p => p.Center_x)); Tem_Dat_X.Add(o.Circle.Min(p => p.Center_x)); Tem_Dat_Y.Add(o.Circle.Max(p => p.Center_y)); Tem_Dat_Y.Add(o.Circle.Min(p => p.Center_y)); } if (o.LWPolyline.Count > 0) { for (int i = 0; i < o.LWPolyline.Count; i++) { if (o.LWPolyline[i].Count >= 0)//判断数据大于零 { Tem_Dat_X.Add(o.LWPolyline[i].Max(p => p.Start_x)); Tem_Dat_X.Add(o.LWPolyline[i].Min(p => p.Start_x)); Tem_Dat_X.Add(o.LWPolyline[i].Max(p => p.End_x)); Tem_Dat_X.Add(o.LWPolyline[i].Min(p => p.End_x)); Tem_Dat_Y.Add(o.LWPolyline[i].Max(p => p.Start_y)); Tem_Dat_Y.Add(o.LWPolyline[i].Min(p => p.Start_y)); Tem_Dat_Y.Add(o.LWPolyline[i].Max(p => p.End_y)); Tem_Dat_Y.Add(o.LWPolyline[i].Min(p => p.End_y)); } } } } //计算返回坐标 if ((Tem_Dat_X.Count <= 0) || (Tem_Dat_Y.Count <= 0)) { Result = new Vector(0, 0); } else { Result = new Vector((Tem_Dat_X.Max() + Tem_Dat_X.Min()) / 2, (Tem_Dat_Y.Max() + Tem_Dat_Y.Min()) / 2); } return(Result); }
/// <summary> /// Initializes a new IniData instance using a previous /// <see cref="SectionDataCollection"/>. /// </summary> /// <param name="sdc"> /// <see cref="SectionDataCollection"/> object containing the /// data with the sections of the file /// </param> public IniDataCaseInsensitive(SectionDataCollection sdc) : base (new SectionDataCollection(sdc, StringComparer.OrdinalIgnoreCase)) {}
/// <summary> /// Initializes a new IniData instance using a previous /// <see cref="SectionDataCollection"/>. /// </summary> /// <param name="sdc"> /// <see cref="SectionDataCollection"/> object containing the /// data with the sections of the file /// </param> public IniData(SectionDataCollection sdc) { _sections = (SectionDataCollection)sdc.Clone(); Global = new KeyDataCollection(); }
/// <summary> /// Initializes a new IniData instance using a previous /// <see cref="SectionDataCollection"/>. /// </summary> /// <param name="sdc"> /// <see cref="SectionDataCollection"/> object containing the /// data with the sections of the file</param> public IniData(SectionDataCollection sdc) { _sections = (SectionDataCollection)sdc.Clone(); }
/// <summary> /// Initializes a new instance of the <see cref="StreamIniDataParser"/> class. /// </summary> /// <remarks> /// By default the various delimiters for the data are setted: /// <para>';' for one-line comments</para> /// <para>'[' ']' for delimiting a section</para> /// <para>'=' for linking key value pairs</para> /// <example> /// An example of well formed data with the default values: /// <para> /// ;section comment<br/> /// [section] ; section comment<br/> /// <br/> /// ; key comment<br/> /// key = value ;key comment<br/> /// <br/> /// ;key2 comment<br/> /// key2 = value<br/> /// </para> /// </example> /// </remarks> public StreamIniDataParser() { //Default delimiter values CommentDelimiter = ';'; KeyValueDelimiter = '='; SectionDelimiters = new char[] { '[', ']' }; _currentTmpData = new SectionDataCollection(); }
public static List <PackRes_Def.BundleData> ParseResCfg(string pckCfgFile, string srcPath, string option, bool compress) { SectionDataCollection sectionList = GetSectsFromCfg(pckCfgFile); if (sectionList == null || sectionList.Count == 0) { return(null); } //get all settings List <PackRes_Def.BundleData> bundlelist = new List <PackRes_Def.BundleData>(); foreach (SectionData sect in sectionList) { PackRes_Def.BundleData bundledata = new PackRes_Def.BundleData(); bundledata.bundleFile = sect.SectionName.Trim(PackRes_Def.trim); bundledata.bundleFile = PackRes_Def.GetPlatformPathString(bundledata.bundleFile); bundledata.option = option; bundledata.compress = compress; string source = GetValFromCfg(sect, "source"); if (source == null || source == "") { throw new PackRes_Def.PckException("can not get source file in section: " + sect); } else { string[] files = source.Split('|'); List <string> srcFiles = new List <string>(); List <string> srcNames = new List <string>(); foreach (string file in files) { string tmp = file.Trim(PackRes_Def.trim); string name = Path.GetFileName(tmp); if (name.StartsWith("*.")) { string path = Path.GetDirectoryName(tmp); string[] names = Directory.GetFiles(Path.Combine(srcPath, path), name, SearchOption.AllDirectories); foreach (string n in names) { string n0 = Path.GetFileName(n); srcFiles.Add(n); //(Path.Combine(srcPath, Path.Combine(path, n0))); srcNames.Add(n0); } } else { srcNames.Add(name); srcFiles.Add(Path.Combine(srcPath, tmp)); } } bundledata.srcFiles = srcFiles.ToArray(); bundledata.names = srcNames.ToArray(); } bundlelist.Add(bundledata); } return(bundlelist); }