Пример #1
0
        private bool CopyMethodFiles(MethodInfo method, string parentDirectory)
        {
            try
            {
                eftir_cls_ident_method cls_method = eftir_cls_ident_method.Deserialize(method.methodFile);
                if (cls_method == null)
                {
                    return(false);
                }

                //拷贝引用的光谱文件
                //会将模型中的数状结构变成平面结构,因此要保证模型中所引用的文件名不相同
                foreach (eftir_cls_ident_method.analyte item in cls_method.analytes)
                {
                    string filename = Path.Combine(parentDirectory, Path.GetFileName(item.filename));
                    File.Copy(item.filename, filename, true);
                    item.filename = filename;   //修改引用文件路径到当前路径
                }
                foreach (eftir_cls_ident_method.interferent item in cls_method.interferents)
                {
                    string filename = Path.Combine(parentDirectory, Path.GetFileName(item.filename));
                    File.Copy(item.filename, filename, true);
                    item.filename = filename;
                }

                //序列化模型文件到当前文件夹
                string clsfile = Path.Combine(parentDirectory, Path.GetFileName(method.methodFile));
                if (!cls_method.Serialize(clsfile))
                {
                    return(false);
                }

                //序列化MethodInfo到当前文件夹
                clsfile = Path.Combine(parentDirectory, "MethodInfo_Temp.methodinfo");      //MethodInfo的内容
                return(method.Serialize(clsfile));
            }
            catch (Exception ex)
            {
                CommonMethod.ErrorMsgBox(ex.Message);
                return(false);
            }
        }
Пример #2
0
        private MethodTreeNode CreateMethodNodeFromDirectory(string currentPath)
        {
            try
            {
                //先查找当前node的名称, 从文件methodnode.name中读取
                string namefile = Path.Combine(currentPath, "methodnode.name");
                if (!File.Exists(namefile))
                {
                    throw new Exception("文件格式不正确或者被损坏");
                }
                MethodTreeNode curnode = new MethodTreeNode();
                StreamReader   reader  = new StreamReader(namefile, Encoding.GetEncoding(SettingData.UTF8));
                curnode.Name = reader.ReadLine();
                reader.Close();
                File.Delete(namefile);      //删除临时的methodnode.name

                string tempmethodfile = Path.Combine(currentPath, "MethodInfo_Temp.methodinfo");
                if (File.Exists(tempmethodfile))      //查看是否包含MethodInfo信息
                {
                    //加载MethodInfo信息
                    curnode.Method = MethodInfo.Deserialize(tempmethodfile);
                    File.Delete(tempmethodfile);    //删除临时的MethodInfo_Temp.methodinfo

                    //更改引用拉曼方法的路径为当前路径
                    curnode.Method.methodFile = Path.Combine(currentPath, Path.GetFileName(curnode.Method.methodFile));

                    //处理拉曼方法
                    var files = Directory.EnumerateFiles(currentPath, Path.GetFileName(curnode.Method.methodFile));
                    foreach (string file in files)
                    {
                        eftir_cls_ident_method method = eftir_cls_ident_method.Deserialize(Path.Combine(currentPath, file));
                        if (method == null)
                        {
                            throw new Exception("文件格式不正确或者被损坏");
                        }

                        //更改引用光谱的路径为当前路径
                        foreach (eftir_cls_ident_method.analyte item in method.analytes)
                        {
                            item.filename = Path.Combine(currentPath, Path.GetFileName(item.filename));
                        }
                        foreach (eftir_cls_ident_method.interferent item in method.interferents)
                        {
                            item.filename = Path.Combine(currentPath, Path.GetFileName(item.filename));
                        }

                        //保存修改路径后的方法
                        method.Serialize(Path.Combine(currentPath, file));
                    }
                }

                //处理子目录, 也就是子节点
                var subdirs = Directory.GetDirectories(currentPath);
                foreach (string dir in subdirs)
                {
                    MethodTreeNode subnode = CreateMethodNodeFromDirectory(dir);
                    if (subnode == null)
                    {
                        return(null);
                    }
                    curnode.Children.Add(subnode);
                }

                return(curnode);
            }
            catch (Exception ex)
            {
                CommonMethod.ErrorMsgBox(ex.Message);
                return(null);
            }
        }