Example #1
0
 public static Action <Object> TaskCreateWrapper(ClrSyncManager manager)
 {
     return
         (delegate(Object o)
     {
         try
         {
             TaskArg p = (TaskArg)o;
             p.e.Set();
             manager.ThreadBegin(p.s);
             MChessChess.LeaveChess();
             Exception exception = null;
             try
             {
                 var tryExecuteTask = p.taskScheduler.GetType().GetMethod("TryExecuteTask",
                                                                          global::System.Reflection.BindingFlags.NonPublic |
                                                                          global::System.Reflection.BindingFlags.Instance);
                 tryExecuteTask.Invoke(p.taskScheduler, new object[] { p.task });
             }
             catch (Exception e)     // catch recoverable exception in user code
             {
                 exception = e;
             }
             MChessChess.EnterChess();
             manager.SetMethodInfo("Task.End");
             manager.AggregateSyncVarAccess(
                 new object[] { p.task, ((IAsyncResult)p.task).AsyncWaitHandle },
                 MSyncVarOp.RWEVENT);
             manager.CommitSyncVarAccess();
             if (manager.BreakDeadlockMode)
             {
                 MChessChess.WakeNextDeadlockedThread(false, true);
             }
             else if (exception == null)
             {
                 manager.ThreadEnd(Original::Thread.CurrentThread);
             }
             else
             {
                 manager.Shutdown(exception);
             }
         }
         catch (Exception e)     // catch fatal exception in our code
         {
             manager.Shutdown(e);
         }
     });
 }
Example #2
0
        /// <summary>
        /// 绑定节点
        /// </summary>
        /// <param name="dbInfo"></param>
        /// <param name="loadTable"></param>
        private void BindNodes(DBInfo dbInfo, bool loadTable)
        {
            if (!this._dbInfoList.Any(d => d.Key == dbInfo.Key))
            {
                this._dbInfoList.Add(dbInfo);
            }

            var parentNode = this.tvDB.Nodes[dbInfo.Key];

            if (parentNode == null)
            {
                parentNode = this.tvDB.Nodes.Insert(0, dbInfo.Key, dbInfo.Key);
                parentNode.ContextMenuStrip = this.parentTreeNodeMenuItem;
                parentNode.ImageIndex       = 0;
                parentNode.Tag = dbInfo;
            }

            if (loadTable)
            {
                var taskArg1 = new TaskArg();
                taskArg1.BeginAction = () =>
                {
                    var nodes = new List <TreeNode>();

                    dbInfo.TableList = TableBll.GetDBTableNameList(dbInfo.ConnectionString);

                    for (int i = 0; i < dbInfo.TableList.Count; i++)
                    {
                        var item = dbInfo.TableList[i];

                        var childNode = new TreeNode(item);
                        childNode.ContextMenuStrip = this.chideTreeNodeMenuItem;
                        childNode.ImageIndex       = childNode.SelectedImageIndex = 1;

                        nodes.Add(childNode);

                        Thread.Sleep(10);

                        TaskCenter.Instance.ReportProgress(
                            new TaskReportProgressArg
                        {
                            Index = i + 1,
                            Count = dbInfo.TableList.Count,
                            Msg   = item
                        });
                    }

                    return(nodes);
                };
                taskArg1.EndAction = (result) =>
                {
                    this.Invoke(new MethodInvoker(() =>
                    {
                        parentNode.Nodes.Clear();
                        parentNode.Nodes.AddRange((result as List <TreeNode>).ToArray());

                        parentNode.ExpandAll();
                    }));
                };

                TaskCenter.Instance.AddTask(taskArg1);
                TaskCenter.Instance.ExecuteTasks();
            }
        }
Example #3
0
        private void Core()
        {
            var index        = 1;
            var tables       = this.lbTargetTable.Items;
            var tempList     = this._selectedTemps;
            var codeBaseDict = new Dictionary <string, CodeBaseInfo>();

            //step1 获取表结构信息
            var taskArg1 = new TaskArg();

            taskArg1.BeginAction = () =>
            {
                foreach (string table in tables)
                {
                    var dt = TableBll.GetDBTableInfo(this._dbInfo.ConnectionString, table);

                    var codeBaseInfo = TableBll.GetCodeBaseInfoByDBTable(dt);
                    codeBaseInfo.NameSpace = this.txtNameSpace.Text;
                    codeBaseInfo.ClassName = TableBll.GetClassName(dt.TableName);

                    codeBaseDict.Add(table, codeBaseInfo);

                    Thread.Sleep(1);

                    TaskCenter.Instance.ReportProgress(
                        new TaskReportProgressArg
                    {
                        Index = index++,
                        Count = tables.Count,
                        Msg   = string.Format("step1/3 获取 {0} 结构信息......", table)
                    });
                }

                return(null);
            };
            taskArg1.EndAction = (result) =>
            {
                index = 1;
            };

            //step2 创建模板文件夹
            var taskArg2 = new TaskArg();

            taskArg2.BeginAction = () =>
            {
                foreach (var temp in tempList)
                {
                    //一个模板一个子文件夹
                    var savePath = Path.Combine(this.txtOutputDirectory.Text, temp.DirName);

                    if (!Directory.Exists(savePath))
                    {
                        Directory.CreateDirectory(savePath);
                    }

                    Thread.Sleep(100);

                    TaskCenter.Instance.ReportProgress(
                        new TaskReportProgressArg
                    {
                        Index = index++,
                        Count = tempList.Count,
                        Msg   = string.Format("step2/3 创建模板文件夹{0}......", temp.DirName)
                    });
                }

                return(null);
            };
            taskArg2.EndAction = (result) =>
            {
                index = 1;
            };

            //step3 生成代码
            var taskArg3 = new TaskArg();

            taskArg3.BeginAction = () =>
            {
                var list = tempList.Where(d => !d.IsRanOnlyOnceByBath);

                foreach (var temp in list)
                {
                    foreach (string table in tables)
                    {
                        var codeBaseInfo = codeBaseDict[table];
                        codeBaseInfo.ClassNameExtend = temp.ClassNameExtend;

                        var output = TableBll.CodeGenerator(codeBaseInfo, temp.Path);
                        var msg    = string.Format(@"{0}\{1}", temp.Name, table);

                        if (output.StartsWith("error:"))
                        {
                            this._failureTableList.Add(msg);
                        }
                        else
                        {
                            var fileName = string.IsNullOrEmpty(temp.FileName) ? codeBaseInfo.ClassName : temp.FileName;
                            fileName = string.Format("{0}{1}{2}", fileName, temp.ClassNameExtend, temp.FileNameExtend);

                            //一个模板一个子文件夹
                            var savePath = Path.Combine(this.txtOutputDirectory.Text, temp.DirName);

                            if (temp.IsCreateChildDirByTableName)
                            {
                                savePath = Path.Combine(savePath, codeBaseInfo.ClassName);

                                if (!Directory.Exists(savePath))
                                {
                                    Directory.CreateDirectory(savePath);
                                }
                            }

                            savePath = Path.Combine(savePath, fileName);

                            File.WriteAllText(savePath, output, Encoding.UTF8);

                            this._successTableList.Add(msg);
                        }

                        Thread.Sleep(1);

                        TaskCenter.Instance.ReportProgress(
                            new TaskReportProgressArg
                        {
                            Index = index++,
                            Count = list.Count() * tables.Count,
                            Msg   = string.Format("step3/3 生成代码{0}/{1}......", temp.Name, table)
                        });
                    }
                }

                index = 1;

                //RanOnlyOnce
                list = tempList.Where(d => d.IsRanOnlyOnceByBath);

                foreach (var temp in list)
                {
                    var output = TableBll.CodeGenerator("dts", codeBaseDict.Values.Select(d => d.ClassName).ToList(), temp.Path, null);
                    var msg    = temp.Name;

                    if (output.StartsWith("error:"))
                    {
                        this._failureTableList.Add(msg);
                    }
                    else
                    {
                        var fileName = string.Format("{0}{1}{2}", temp.FileName, temp.ClassNameExtend, temp.FileNameExtend);
                        var savePath = Path.Combine(this.txtOutputDirectory.Text, temp.DirName);

                        savePath = Path.Combine(savePath, fileName);

                        File.WriteAllText(savePath, output, Encoding.UTF8);

                        this._successTableList.Add(msg);

                        Thread.Sleep(1);

                        TaskCenter.Instance.ReportProgress(
                            new TaskReportProgressArg
                        {
                            Index = index++,
                            Count = list.Count(),
                            Msg   = string.Format("step3/3 生成代码{0}......", temp.Name)
                        });
                    }
                }

                return(null);
            };
            taskArg3.EndAction = (result) =>
            {
                this.Invoke(new MethodInvoker(() =>
                {
                    var msg = "导出完成";

                    //if (e.Error != null)
                    //{
                    //    msg = e.Error.Message;

                    //    this._successTableList.Clear();
                    //    this._failureTableList.Clear();
                    //}
                    //else if (e.Cancelled)
                    //    msg = "导出被取消!";
                    //else
                    //    msg = "导出完成!";

                    this.SetContorlsEnabled(true);

                    var form = new BathCodeGeneratorResultForm(msg, this.txtOutputDirectory.Text, this._successTableList, this._failureTableList);
                    form.ShowDialog();
                }));
            };

            TaskCenter.Instance.AddTask(taskArg1);
            TaskCenter.Instance.AddTask(taskArg2);
            TaskCenter.Instance.AddTask(taskArg3);
            TaskCenter.Instance.ExecuteTasks();
        }