//UI提取工程状态进度的函数 还不完整随时增加 //UI和主控之间的文件传输,仍用字符串传输,UI端循环遍历文件夹中的文件 //分割文件、创建工程,任务,文件等数据表插入数据库 public void CreatTables(string path)//path是指工程文件夹的目录 { if (!Directory.Exists(path)) { WcfException ex = new WcfException(); ex.message = "工程文件夹不存在"; LogFileManager.ObjLog.error(ex.message); throw new FaultException <WcfException>(ex, ex.message); //测试异常的传递能否成功 } else { DirectoryInfo di = new DirectoryInfo(path); FileInfo[] txfile = di.GetFiles("*.tx"); FileInfo[] setupdir = di.GetFiles("*.setup"); FileInfo[] rxfile = di.GetFiles("*.rx"); FileInfo[] terfile = di.GetFiles("*.ter"); //如果文件全部存在,则执行分割写表操作,否则抛出异常 if (txfile.Length != 0 && setupdir.Length != 0 && rxfile.Length != 0 && terfile.Length != 0) { string resultdir = path + "\\" + "studyarea"; Directory.CreateDirectory(resultdir); string cnStr = ConfigurationManager.ConnectionStrings["sqlProviderParallelTask"].ConnectionString; TaskModel tm = new TaskModel(cnStr); string splitTxFileDir = null; //分割tx文件,放在该目录下的新文件夹中 try { splitTxFileDir = Split.FileSplit(txfile[0].FullName, setupdir[0].FullName); } catch (nullException ex) { WcfException e = new WcfException(); e.message = ex.Message; LogFileManager.ObjLog.error(ex.Message); throw new FaultException <WcfException>(e, e.message); } //创建工程表 string[] seperate = new string[] { "." }; string[] setupfilename = setupdir[0].Name.Split(seperate, StringSplitOptions.RemoveEmptyEntries); try { tm.CreatePro(setupfilename[0], path, resultdir);//异常还未处理 } catch (SqlException e) { WcfException ex = new WcfException(); ex.message = e.Message; throw new FaultException <WcfException>(ex, ex.message); } //创建FileInfo表 //创建新的文件名数组,不包括被分割的tx总文件 FileInfo[] Allfilenames = new FileInfo[4]; Allfilenames[0] = txfile[0]; Allfilenames[1] = rxfile[0]; Allfilenames[2] = setupdir[0]; Allfilenames[3] = terfile[0]; string[] Allfilenames1 = new string[Allfilenames.Length - 1]; //没有tx总文件的工程文件夹中的文件名 DirectoryInfo ditx = new DirectoryInfo(splitTxFileDir); FileInfo[] splitTxNames = ditx.GetFiles(); //分割后的文件名 string[] filenames = new string[Allfilenames1.Length + splitTxNames.Length]; //新文件名数组 int j = 0; for (int i = 0; i < Allfilenames.Length; i++) { if (Allfilenames[i].Name == txfile[0].Name) { continue; } else { Allfilenames1[j] = Allfilenames[i].Name; j++; } } for (int i = 0; i < Allfilenames1.Length; i++) { filenames[i] = Allfilenames1[i]; } for (int i = Allfilenames1.Length; i < Allfilenames1.Length + splitTxNames.Length; i++) { filenames[i] = splitTxNames[i - Allfilenames1.Length].Name; } //创建新的文件路径,异常还没有处理 string[] filepaths = new string[Allfilenames1.Length + splitTxNames.Length]; for (int a = 0; a < Allfilenames1.Length; a++) { filepaths[a] = path + "\\" + filenames[a]; } for (int a = Allfilenames1.Length; a < Allfilenames1.Length + splitTxNames.Length; a++) { filepaths[a] = splitTxFileDir + "\\" + filenames[a]; } try { tm.CreateFileInfo(filenames, filepaths, setupfilename[0]); } catch (SqlException e) { WcfException ex = new WcfException(); ex.message = e.Message; throw new FaultException <WcfException>(ex, ex.message); } //创建TaskInfo表 int n = splitTxNames.Length; string[] Tfilenames = new string[Allfilenames1.Length + 1]; for (int i = 0; i < Allfilenames1.Length; i++) { Tfilenames[i] = Allfilenames1[i]; } for (int i = 0; i < n; i++) { Tfilenames[Allfilenames1.Length] = splitTxNames[i].Name; try { tm.CreateTask(setupfilename[0], Tfilenames); } catch (SqlException e) { WcfException ex = new WcfException(); ex.message = e.Message; throw new FaultException <WcfException>(ex, ex.message); } } } else { WcfException ex = new WcfException(); ex.message = "工程缺少必要文件"; LogFileManager.ObjLog.error(ex.message); throw new FaultException <WcfException>(ex, ex.message); } } }