/// <summary>
 /// 读取系统配置文件里面的内容
 /// </summary>
 /// <returns>返回所有系统配置代码</returns>
 public MyXTreeItem LoadCLanguageXSystemFile()
 {
     ///检测文件路劲是否存在
     if (!Directory.Exists(path))
     {
         ///如果不存在
         return(null);
     }
     try
     {
         /// <summary>
         /// 读取XML的类
         /// </summary>
         XmlDocument XmlAppend = new XmlDocument();
         XmlAppend.Load(path + XCSystemFileName);
         ///查询出根节点
         XmlNode root = XmlAppend.SelectSingleNode(RootName);
         ///树状数据的系统代码块的头结点
         MyXTreeItem SystemTreeItem = new MyXTreeItem();
         SystemTreeItem.XName = "C语言版系统代码";
         ///组装数据
         LoadData(SystemTreeItem, root);
         ///保存关闭文件
         XmlAppend.Save(path + XCSystemFileName);
         return(SystemTreeItem);
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
         return(null);
     }
 }
 /// <summary>
 /// 编译代码(C语言)
 /// </summary>
 /// <param name="CodeString">要编译的代码字符串</param>
 /// <param name="OutCode">编译代码时候生成的消息(报错消息和成功消息)</param>
 /// <param name="OutPath">输出路径</param>
 /// <param name="projectName">项目名称</param>
 /// <returns>是否编译成功</returns>
 public static bool AnalyTicalCode(string CodeString, out string OutCode, string OutPath, string projectName)
 {
     try
     {
         ///可执行文件的进程
         Process exeprocess;
         string  filename = projectName + ".cpp";
         ///写入文件
         LoggerHelp.WriteMessageToFile(CodeString, filename, OutPath);
         ///执行编译
         exeprocess = Process.Start(CLanguageEditorPath, OutPath + filename + " /Fe:" + OutPath + projectName + ".exe");
         ///等待进程结束
         exeprocess.WaitForExit();
         ///开启编译好的进程
         Process.Start(OutPath + projectName + ".exe");
         OutCode = "Success";
     }
     catch (Exception ex)
     {
         OutCode = ex.Message;
         ///写入错误日志
         LoggerHelp.WriteLogger(ex.ToString());
     }
     return(true);
 }
Beispiel #3
0
 /// <summary>
 /// 打开项目
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OpenProject_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog();
         openFile.Filter = "配置文件 | *.xpl;";
         if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             ///保存解决方案配置文件路径
             Solution.SolutionConfigPath = openFile.FileName;
             ///加载解决方案
             Solution.LoadSolution(openFile.FileName);
             MyProject = Solution.GetFirstProject();
             ///获取主类
             PicTabPage mainpage = _myProject.GetFirstPicTabPage();
             ///将代码图添加到tab页
             AddLayoutDocument(ContentPanel, mainpage);
             BindingPanels(mainpage);
         }
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
     }
 }
Beispiel #4
0
        /// <summary>
        /// 解析主函数
        /// </summary>
        /// <param name="box">主函数的Box</param>
        protected string AnalyticalMain(CodeBox box)
        {
            string startCode =
                "void main()" + LineBreaks
                + "{" + LineBreaks;
            string codeString = "";

            codeString += startCode;
            try
            {
                ///提取出第一个正常节点
                if (((XAribute)box.RightAribute.Children[0]).SelectType == XAribute.XAttributeType.XExc)
                {
                    CodeBox noramlBox = (CodeBox)((XAribute)box.RightAribute.Children[0]).GetOtherXAribute().ParentControl;
                    codeString += AnalyticalNormal(noramlBox);
                }
            }
            catch (Exception ex)
            {
                LoggerHelp.WriteLogger(ex.ToString());
            }
            codeString += "printf(\"\\n请按任意键退出!\");" + LineBreaks + "getch();" + LineBreaks;
            codeString += "}" + LineBreaks;
            return(codeString);
        }
Beispiel #5
0
 /// <summary>
 /// 新建项目
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void NewProject_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         NewProject nProject = new NewProject();
         ///设置项目类
         nProject.SetProjectClass(_myProject, _solution);
         nProject.ShowDialog();
         if (_myProject.RootPath != "")
         {
             ///设置项目根目录
             Solution.RootPath = _myProject.RootPath;
             ///创建主类和主函数信息
             PicTabPage mainpage = new PicTabPage((new Random()).Next(1, 2000000), this.ChileEventCallBack, "Program.cx");
             CodeBox    mainbox  = mainpage.CreateXCodeBox("Main", PicTabPage.CenterPoint, CodeBox.XAType.XMain);
             mainbox.AddAttribute(MyXAribute.XAribute.XAttributeType.XExc, MyXAribute.XAribute.XAttributeSpec.XNone,
                                  MyXAribute.XAribute.XPositonStyle.right, "出口", MyXAribute.XAribute.CanLinkType.One, "主函数出口", "");
             ///添加主信息
             _myProject.AddPicTabPage(mainpage);
             ///将代码图添加到tab页
             AddLayoutDocument(ContentPanel, mainpage);
             ///绑定各个面板数据
             BindingPanels(mainpage);
         }
         ///保存配置文件路径
         Solution.SolutionConfigPath = XCreateConfigurationInformation.SolutionConfigPath;
         ///添加到解决方案
         Solution.AddProjectClass(MyProject);
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
     }
 }
Beispiel #6
0
 /// <summary>
 /// 保存项目
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SaveProject_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Solution.SaveSolution();
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
     }
 }
Beispiel #7
0
 /// <summary>
 /// 运行项目
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Run_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string ErrorString = Solution.Editor();
         ///显示编译信息
         ((RichTextBox)_outWindows.Content).AppendText(ErrorString);
     }catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #8
0
 /// <summary>
 /// 删除一个子控件
 /// </summary>
 /// <param name="addchild"></param>
 public void DelXAbutrite(XAribute addchild)
 {
     try
     {
         MyPanel.Children.Remove(addchild);
         ///修改尺寸
         AutoSize();
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
     }
 }
Beispiel #9
0
 /// <summary>
 /// 删除一个函数
 /// </summary>
 /// <param name="Title">函数的名字</param>
 public bool DelPicFunctionPage(PicFunctionTabPage function)
 {
     try
     {
         ///从函数列表删除一个函数
         ListFunction.Remove(function);
         return(true);
     }catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
         MessageBox.Show("删除函数出错");
         return(false);
     }
 }
Beispiel #10
0
 /// <summary>
 /// 根据id删除一个内置的语句块
 /// </summary>
 /// <param name="id"></param>
 private void DelControl(int id)
 {
     try
     {
         CodeBox xb = ListCodeBoxChild[id] as CodeBox;
         ///不能删除主函数入口
         if (xb.CodeBoxType != CodeBox.XAType.XMain && xb.CodeBoxType != CodeBox.XAType.XFunctionEnter)
         {
             ///删除代码块
             xb.DelCodeBox();
             ListCodeBoxChild.Remove(id);
             Children.Remove(xb);
         }
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
     }
 }
Beispiel #11
0
 /// <summary>
 /// LayoutDocument控件改变时候
 /// </summary>
 /// <param name="sender">消息发送者</param>
 /// <param name="e">事件</param>
 public void LayoutDocumentChanged(object sender, PropertyChangedEventArgs e)
 {
     try
     {
         if (sender.GetType().Name == "LayoutDocument")
         {
             LayoutDocument ldt = (LayoutDocument)sender;
             if (ldt.Content != null)
             {
                 PicTabPage page = (PicTabPage)ldt.Content;
                 page.Width  = ldt.FloatingWidth;
                 page.Height = ldt.FloatingHeight;
             }
         }
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
     }
 }
Beispiel #12
0
 /// <summary>
 /// 输出窗口
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OUTWindow_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (Root.Hidden.Count != 0)
         {
             for (int i = 0; i < Root.Hidden.Count; i++)
             {
                 if (Root.Hidden[i].Title == _outWindows.Title)
                 {
                     Root.Hidden[i].Show();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
     }
 }
Beispiel #13
0
 /// <summary>
 /// 生成相应代码
 /// </summary>
 /// <param name="sender">事件发送者</param>
 /// <param name="e">事件信息</param>
 private void Code_Click(object sender, RoutedEventArgs e)
 {
     if (_solution != null)
     {
         try
         {
             //保存代码
             _solution.SaveCode();
         }
         catch (Exception ex)
         {
             LoggerHelp.WriteLogger(ex.ToString());
             ((RichTextBox)_outWindows.Content).AppendText(ex.Message);
         }
     }
     else
     {
         ((RichTextBox)_outWindows.Content).AppendText("还没有项目,请先创建或者打开项目然后再使用生成代码功能!");
     }
 }
Beispiel #14
0
 /// <summary>
 /// 检测这个是否已经打开
 /// </summary>
 /// <param name="page">要检查的页面</param>
 /// <returns>返回结果</returns>
 public bool CheckIsOpen(PicTabPage page)
 {
     try
     {
         if (ContentPanel.Children.Count == 0)
         {
             return(false);
         }
         foreach (LayoutDocument doc in ContentPanel.Children)
         {
             if ((doc.Content as PicTabPage).Equals(page))
             {
                 return(true);
             }
         }
     }catch (Exception ex)
     {
         LoggerHelp.WriteLogger(ex.ToString());
         return(false);
     }
     return(false);
 }
Beispiel #15
0
        /// <summary>
        /// 确认按钮按下
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Click_1(object sender, RoutedEventArgs e)
        {
            XCodeDataOption         xdo       = new XCodeDataOption();
            List <XAributeDataItem> writeData = new List <XAributeDataItem>();

            ///数据转换
            for (int i = 0; i < XAributeData.Count; i++)
            {
                writeData.Add(XAributeData[i]);
            }
            bool issure = true;

            ///写入数据
            if (FileType.SelectedIndex == 0 || FileType.SelectedIndex == 2)
            {
                try
                {
                    XCodeDataOptionDataStructClass dataclass = new XCodeDataOptionDataStructClass();
                    dataclass.nodeList       = writeData;
                    dataclass.CodeboxName    = CodeBoxName.Text;
                    dataclass.CodeBoxHitText = HitText.Text;
                    dataclass.CodeBoxType    = (((KeyValuePair <CodeBox.XAType, string>)CodeBoxType.SelectedItem).Key).ToString();
                    ///获取SystemCodeString的内容
                    TextRange textRange = new TextRange(SystemCodeString.Document.ContentStart, SystemCodeString.Document.ContentEnd);
                    dataclass.CodeBoxSystemCodeString = DelLinebreakString(textRange.Text);
                    ///获取ReturnValue的内容
                    TextRange ReturnValuetextRange = new TextRange(ReturnValue.Document.ContentStart, ReturnValue.Document.ContentEnd);
                    dataclass.ReturnValue = DelLinebreakString(ReturnValuetextRange.Text);
                    ///将代码块信息写入文件
                    if (FileType.SelectedIndex == 0)
                    {
                        issure = xdo.WriteXSystemFile(dataclass);
                    }
                    else
                    {
                        issure = xdo.WriteXCLanguageSystemFile(dataclass);
                    }
                }catch (Exception ex)
                {
                    LoggerHelp.WriteLogger(ex.ToString());
                    MessageBox.Show("数据错误请检查填写错误!");
                }
            }
            else if (FileType.SelectedIndex == 1)
            {
                issure = xdo.WriteUserFile(writeData, CodeBoxName.Text, HitText.Text);
            }
            else if (FileType.SelectedIndex == 2)
            {
            }
            if (!issure)
            {
                MessageBox.Show("该代码块和已存在的代码块重名请修改名称或者先删除原先的代码块");
            }
            else
            {
                MessageBox.Show("添加成功");
            }
            ///关闭当前窗口
            //this.Close();
        }
Beispiel #16
0
        /// <summary>
        /// 显示具体内容
        /// </summary>
        protected void Play()
        {
            try
            {
                ///数据
                Dictionary <string, string> data;
                ///获取属性的值转换为字符串
                string value = Property.GetValue(TargetObject).ToString();
                #region 如果要展示的是属性的类型的话
                ///如果要展示的是属性的类型的话
                if (Property.Name == "ExName" && TargetObject != null)
                {
                    ///获取解析类
                    Type         targetType = TargetObject.GetType();
                    PropertyInfo info       = targetType.GetProperty("ProjectUseClassType");
                    ///转换为需要的数据
                    data = info.GetValue(TargetObject) as Dictionary <string, string>;
                    if (data != null)
                    {
                        ///绑定数据
                        DataComBox.ItemsSource       = data;
                        DataComBox.SelectedValuePath = "Key";
                        DataComBox.DisplayMemberPath = "Value";
                    }
                }
                #endregion
                #region 如果是普通枚举值
                else
                {
                    ///获取属性的类型
                    Type PropertyType = Property.PropertyType;

                    ///反射枚举为数据
                    data = AnyEnumGetData(PropertyType);
                    if (data != null)
                    {
                        ///绑定数据
                        DataComBox.ItemsSource       = data;
                        DataComBox.SelectedValuePath = "Key";
                        DataComBox.DisplayMemberPath = "Value";
                    }
                }
                #endregion
                ///设置属性名称
                PropertyName.Text = Property.Name;
                ///设置默认值
                foreach (string key in data.Keys)
                {
                    if (value == key)
                    {
                        //DataComBox.SelectedItem = (KeyValuePair<string,string>
                        ///设置默认值
                        DataComBox.SelectedValue = key;
                        break;
                    }
                }
            }catch (Exception ex)
            {
                ///写入错误信息
                LoggerHelp.WriteLogger(ex.ToString());
            }
        }