private void LoadProperties(TreeText src) { foreach (TreeText.Node propNode in src.Root.Children) { if (propNode.Children.Count != 1) { propNode.ErrorChecker().Error("プロパティの配下は1つの値でなければなりません。"); } if (propNode.Children[0].Children.Count != 0) { propNode.ErrorChecker().Error("プロパティの値の配下は空でなければなりません。"); } string propName = propNode.Line; string propValue = propNode.Children[0].Line; propNode.ErrorChecker().CheckFairName(propName); // propValue ⇒ 自由な文字列 this.Properties.Add(new Property() { Name = propName, Value = propValue, }); } }
public HtmlDataModel(TreeText src) { this.Source = src; if (src.Root.Children.Count != 1) { src.Root.ErrorChecker().Error("コンポーネントのルートタグは1つでなければなりません。"); } this.Root = this.LoadTag(src.Root.Children[0], null); this.PostLoad(); }
public ComponentFile(string file, string root) { this.FilePath = file; this.CoName = CommonUtils.PathToCoName(file, root); this.CoNamePrefix = CommonUtils.CoNameToCoNamePrefix(this.CoName); this.Text = new TreeText(file); this.CSSText = new TreeText(ComponentFileToCSSFile(file)); Console.WriteLine("FilePath: " + this.FilePath); Console.WriteLine("CoName: " + this.CoName); Console.WriteLine("CoNamePrefix: " + this.CoNamePrefix); Console.WriteLine("Text: " + this.Text); Console.WriteLine("CSSText: " + this.CSSText); this.Html = new HtmlDataModel(this.Text); this.CSS = new CSSDataModel(this.CSSText); Console.WriteLine("Html: " + this.Html); Console.WriteLine("CSS: " + this.CSS); }
public DefineDataModel(TreeText src) { this.Source = src; this.LoadProperties(src); this.PostLoad(); }
private void LoadSelectors(TreeText src) { foreach (TreeText.Node selectorNode in src.Root.Children) { string name = selectorNode.Line; selectorNode.ErrorChecker().CheckFairName(name, ":"); Selector selector = new Selector() { Name = name, }; foreach (TreeText.Node propNode in selectorNode.Children) { if (propNode.Children.Count != 1) { propNode.ErrorChecker().Error("プロパティの配下は1つの値でなければなりません。"); } if (propNode.Children[0].Children.Count != 0) { propNode.ErrorChecker().Error("プロパティの値の配下は空でなければなりません。"); } string propName = propNode.Line; string propValue = propNode.Children[0].Line; if (propName == "@import") { int index = ArrayTools.IndexOf(this.Selectors.ToArray(), s => s.Name == propValue); if (index == -1) { propNode.ErrorChecker().Error("不正なセレクタ参照です。"); } foreach (Property property in this.Selectors[index].Properties) { selector.Properties.Add(new Property() { Name = property.Name, Value = property.Value, }); } } else if (propName[0] == '@') { propNode.ErrorChecker().Error("不正な参照です。"); } else { propNode.ErrorChecker().CheckFairName(propName, "-"); // propValue ⇒ 自由な文字列 selector.Properties.Add(new Property() { Name = propName, Value = propValue, }); } } this.Selectors.Add(selector); } }
public CSSDataModel(TreeText src) { this.Source = src; this.LoadSelectors(src); this.PostLoad(); }
private void OPEN_MenuItem_Click(object sender, EventArgs e) { Stream myStream = null; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "txt files (*.txt)|*.txt"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { if ((myStream = openFileDialog1.OpenFile()) != null) { using (myStream) { string file_content = File.ReadAllText(openFileDialog1.FileName); string[] lines = file_content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); TreeText.Clear(); list.Clear(); if (lines[0] != enditem) { MessageBox.Show("Неверный файл. Попытайтесь еще раз."); return; } for (int i = Application.OpenForms.Count - 1; i >= 0; i--) { if (Application.OpenForms[i].Name != "MainForm") { Application.OpenForms[i].Close(); } } int iter = 0; while (lines[++iter] != enditem) { TreeText.AppendText(lines[iter] + "\r\n"); } while (lines[++iter] != enditem + enditem) { string temp_key = lines[iter]; List <string> temp_list = new List <string>(); while (lines[++iter] != enditem) { temp_list.Add(lines[iter]); } list.Add(temp_key, temp_list); } fill_tree(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 100; j++) { for (int k = 0; k < 100; k++) { w[i, j, k] = Convert.ToDouble(lines[++iter]); } } } TabControl.SelectTab(TreeBuild); } } } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } }
private void LoadFileAndDirectoryConfig() { TreeText src = new TreeText(Ground.FileAndDirectoryConfigFile); { TreeText.Node node = src.Root.Children.First(v => v.Line == "ComponentAndScript"); if (node.Children.Count < 1) { throw null; } Ground.ComponentAndScriptDirs = node.Children.Select( v => { string dir = v.Line; dir = Path.Combine(Ground.RootDir, dir); Console.WriteLine("ComponentAndScriptDir: " + dir); if (Directory.Exists(dir) == false) { throw new Exception("そんなディレクトリ在りません。"); } return(dir); } ).ToArray(); } { TreeText.Node node = src.Root.Children.First(v => v.Line == "Define"); if (node.Children.Count < 1) { throw null; } Ground.DefineFiles = node.Children.Select( v => { string file = v.Line; file = Path.Combine(Ground.RootDir, file); Console.WriteLine("DefineFile: " + file); if (File.Exists(file) == false) { throw new Exception("そんなファイル在りません。"); } return(file); } ).ToArray(); } { TreeText.Node node = src.Root.Children.First(v => v.Line == "HomePage"); if (node.Children.Count != 1) { throw null; } string file = node.Children[0].Line; file = Path.Combine(Ground.RootDir, file); Console.WriteLine("MainHtmlFile: " + file); if (File.Exists(file) == false) { throw new Exception("そんなファイル在りません。"); } Ground.MainHtmlFile = file; } { TreeText.Node node = src.Root.Children.First(v => v.Line == "RiotDirectory"); if (node.Children.Count != 1) { throw null; } string dir = node.Children[0].Line; dir = Path.Combine(Ground.RootDir, dir); Console.WriteLine("RiotRootDir: " + dir); if (Directory.Exists(dir) == false) { throw new Exception("そんなディレクトリ在りません。"); } Ground.RiotRootDir = dir; } }
public DefineFile(string file, string coName = null) { this.Text = new TreeText(file); this.DefineData = new DefineDataModel(this.Text); this.CoName = coName; }