Ejemplo n.º 1
0
    public static void ImportAll(string directoryName)
    {
        var namespaces = HelpLogic.AllTypes().Select(a => a.Namespace !).Distinct().ToDictionary(a => a);

        var types = HelpLogic.AllTypes().ToDictionary(a => a.FullName !);

        foreach (var path in Directory.GetFiles(directoryName, "*.help", SearchOption.AllDirectories))
        {
            try
            {
                XDocument doc = XDocument.Load(path);

                ImportAction action =
                    doc.Root !.Name == AppendixXml._Appendix ? AppendixXml.Load(doc):
                    doc.Root !.Name == NamespaceXml._Namespace ? NamespaceXml.Load(doc, namespaces):
                    doc.Root !.Name == EntityXml._Entity ? EntityXml.Load(doc, types):
                    doc.Root !.Name == QueryXml._Query ? QueryXml.Load(doc) :
                    throw new InvalidOperationException("Unknown Xml root: " + doc.Root.Name);

                ConsoleColor color =
                    action == ImportAction.Inserted ? ConsoleColor.Green :
                    action == ImportAction.Updated ? ConsoleColor.DarkGreen :
                    action == ImportAction.Skipped ? ConsoleColor.Yellow :
                    action == ImportAction.NoChanges ? ConsoleColor.DarkGray :
                    throw new InvalidOperationException("Unexpected action");

                SafeConsole.WriteLineColor(color, " {0} {1}".FormatWith(action, path));
            }
            catch (Exception e)
            {
                SafeConsole.WriteLineColor(ConsoleColor.Red, " Error {0}:\r\n\t".FormatWith(path) + e.Message);
            }
        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// 按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AutoBuildEntityEvent(object sender, EventArgs e)
        {
            var uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));

            //获取选中项目信息
            var autoBuildEntityContent = new AutoBuildEntityContent {
                SelectedProject = GetSelectedProject()
            };

            if (autoBuildEntityContent.SelectedProject == null)
            {
                uiShell.ShowMessageBox("获取项目信息失败");
                return;
            }

            //读取选中项目下的配置信息
            var entityXmlModel = new EntityXml(autoBuildEntityContent.SelectedProject.EntityXmlPath);

            entityXmlModel.Load();
            autoBuildEntityContent.EntityXml = entityXmlModel;

            try
            {
                //读取表集合
                autoBuildEntityContent.TablesName = GetTables(entityXmlModel.ConnString);
            }
            catch (Exception ex)
            {
                uiShell.ShowMessageBox(string.Format("数据库访问异常:{0}", ex.Message));
                return;
            }

            new MainForm(autoBuildEntityContent).ShowDialog();
        }