예제 #1
0
        public TagPathGroup DeriveAVersion(int versionNo)
        {
            var tagPathGroup = new TagPathGroup();

            tagPathGroup.Maps = myTagPathService.DeriveAVersion(versionNo);
            return(tagPathGroup);
        }
예제 #2
0
        private void CheckIfGroupLegal(TagPathGroup tagPathGroup)
        {
            var existedTagName = new List <string>();

            foreach (var t in tagPathGroup.Maps)
            {
                Predicate <string> myPredicate = s => s == t.TagName;
                if (existedTagName.Exists(myPredicate) && t.TagName != null && t.TagName != "")
                {
                    throw new Exception("You can't add two Tag with one TagName!");
                }
                existedTagName.Add(t.TagName);
            }
        }
예제 #3
0
        /// <summary>
        /// 通过配置文件夹路径生成一个TagPathGroup以便后续能存入MongoDB
        /// </summary>
        /// <param name="configDirPath">配置文件夹的完整路径,不带结尾分隔符!!!</param>
        /// <returns></returns>
        public TagPathGroup GetNewTagPathGroup(string configDirPath, int versionNo)
        {
            //因为传过来的可能是相对路径,这样可以获取绝对路径
            DirectoryInfo rootDir = new DirectoryInfo(configDirPath);

            var tagPathGroup = new TagPathGroup();

            List <DirectoryInfo> allList = FileDirAssist.GetAllChildDirs(configDirPath);

            allList.Add(rootDir);

            List <DirectoryInfo> realList = new List <DirectoryInfo>();

            //递归搜索将只添加目录下有.csv的文件夹
            foreach (var d in allList)
            {
                if (FileDirAssist.IsThisDirHasCsv(d))
                {
                    realList.Add(d);
                }
            }

            //添加文件夹节点信息到Collection
            foreach (var dir in realList)
            {
                string path = dir.FullName.Remove(0, rootDir.Parent.FullName.Length);
                path.Replace(Path.DirectorySeparatorChar, '/');
                var temp = new TagPath();
                temp.Path      = path;
                temp.VersionNo = versionNo;
                tagPathGroup.Maps.Add(temp);
            }

            var fileAndTagMaps = new List <TagPath>();

            //添加每个文件夹下的.csv文件和文件中的Tag信息到tagPathCollection.Maps
            foreach (var d in tagPathGroup.Maps)
            {
                string realPath = d.Path.Replace('/', Path.DirectorySeparatorChar);
                realPath = realPath.Insert(0, rootDir.Parent.FullName);

                DirectoryInfo dir = new DirectoryInfo(realPath);
                foreach (FileInfo f in dir.GetFiles())
                {
                    if (f.Extension == ".csv")
                    {
                        //转换文件名格式
                        string path = f.FullName.Remove(0, rootDir.Parent.FullName.Length);
                        path.Replace(Path.DirectorySeparatorChar, '/');

                        //添加文件条目
                        var temp = new TagPath();
                        temp.Path      = path;
                        temp.VersionNo = versionNo;
                        fileAndTagMaps.Add(temp);

                        //添加文件中Tag条目
                        var tagList = GetTagsFromCsvFile(f, path, versionNo);
                        fileAndTagMaps.AddRange(tagList);
                    }
                }
            }
            tagPathGroup.Maps.AddRange(fileAndTagMaps);

            CheckIfGroupLegal(tagPathGroup);

            return(tagPathGroup);
        }
예제 #4
0
        /// <summary>
        /// 将一个tagPathGroup导出到一个文件夹,和GetNewTagPathGroup互为逆操作
        /// </summary>
        /// <param name="tagPathGroup"></param>
        /// <param name="configDirPath">导出的位置,注意这里的路径没有root文件夹了</param>
        /// <returns></returns>
        public bool ExportTagPathGroupToDir(TagPathGroup tagPathGroup, string configDirPath)
        {
            if (configDirPath == null)
            {
                configDirPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            }
            var rootDir = new DirectoryInfo(configDirPath);

            if (!rootDir.Exists)
            {
                return(false);
            }

            //依次建立文件夹、文件、Tag条目
            var dirList  = new List <TagPath>();
            var fileList = new List <TagPath>();
            var tagList  = new List <TagPath>();

            foreach (var t in tagPathGroup.Maps)
            {
                if (!t.Path.EndsWith(".csv"))
                {
                    dirList.Add(t);
                    continue;
                }
                if (t.TagName == null || t.TagName == "")
                {
                    fileList.Add(t);
                    continue;
                }
                tagList.Add(t);
            }

            try
            {
                //建立所有文件夹
                foreach (var d in dirList)
                {
                    Directory.CreateDirectory(configDirPath + d.Path);
                }

                //建立所有文件,并写入Tag
                foreach (var f in fileList)
                {
                    var nowTagList = new List <TagPath>();
                    foreach (var t in tagList)
                    {
                        if (t.Path == f.Path)
                        {
                            nowTagList.Add(t);
                        }
                    }
                    WriteACSVFile(configDirPath + f.Path, nowTagList);
                }
            }
            catch
            {
                return(false);
            }


            return(true);
        }
예제 #5
0
 public async void InsertTagPathMany(TagPathGroup many)
 {
     await myTagPathService.InsterManyAsync(many.Maps);
 }