Esempio n. 1
0
        TextFileInfo ReadTextFile(string filename)
        {
            Console.WriteLine("ReadTextFile " + filename);
            char[] seperatorTab = {'\t'};
            char[] seperatorColon = {':'};
            TextFileInfo fi = new TextFileInfo();
            fi.filename = filename;
            string currentPool = "";
            StreamReader re = File.OpenText(filename);
            string input = null;
            while ((input = re.ReadLine()) != null)
            {
                input.Trim();
                if (input.StartsWith("MemPool:"))
                    currentPool = input.Substring(8);
                else
                {
                    string[] line = input.Split(seperatorTab);
                    int size = int.Parse(line[2]);
                    Allocation a = new Allocation();
                    a.name = line[0];
                    a.ptr = Int32.Parse(line[1], System.Globalization.NumberStyles.AllowHexSpecifier);
                    a.pool = currentPool;
                    a.size = size;
                    fi.allocations.Add(a);

                    // Handle blocks (identically named allocations)
                    Category c;
                    if (fi.blocks.ContainsKey(line[0]))
                        c = fi.blocks[line[0]];
                    else
                        c = new Category();
                    c.name = line[0];
                    c.size += size;
                    ++c.count;

                    fi.blocks[line[0]] = c;

                    // Handle categories
                    string catString = "NO CATEGORY";
                    if (line[0].Contains(":"))
                        catString = line[0].Split(seperatorColon)[0];

                    if (fi.categories.ContainsKey(catString))
                        c = fi.categories[catString];
                    else
                        c = new Category();
                    c.name = catString;
                    c.size += size;
                    ++c.count;

                    fi.categories[catString] = c;
                }
            }
            re.Close();
            return fi;
        }
Esempio n. 2
0
        /// <summary>
        /// 删除文件的索引
        /// </summary>
        /// <param>文件标识符</param>
        /// <param>人员权限</param>
        /// <returns></returns>
        public bool DeleteIndex(string fileId)
        {
            AbstractFileBase fileBase = new TextFileInfo();

            fileBase.FileId = fileId;

            IIndexManager indexManager = new IndexManagerFactory().Create();

            return(indexManager.DeleteIndex(fileBase));
        }
Esempio n. 3
0
        /// <summary>
        /// 根据文件创建索引
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        //private bool CreateIndex(string fileName)
        //{
        //    if (File.Exists(fileName))
        //    {
        //        LibDataAccess dataAccess = new LibDataAccess();

        //        FileInfo info = new FileInfo(fileName);
        //        AbstractFileBase fileBase = new TextFileInfo();
        //        #region 根据文件路径查找
        //        string sql = string.Format("select DOCID from DMDOCUMENT where SAVEPATH = {0}", LibStringBuilder.GetQuotString(fileName));
        //        fileBase.FileId = dataAccess.ExecuteScalar(sql).ToString();
        //        object ret = dataAccess.ExecuteScalar(string.Format("select ISFULLINDEX from DMDOCUMENT where DOCID = {0}", LibStringBuilder.GetQuotString(fileBase.FileId)));
        //        if (LibSysUtils.ToInt32(ret) == 1)
        //        {
        //            return true;
        //        }
        //        #endregion
        //        //fileBase.FileName = info.Name;
        //        //fileBase.FilePath = info.DirectoryName;
        //        //fileBase.UpLoadPersonId = "zhangsan";
        //        //fileBase.CreateTime = DateTime.Now.ToString();
        //        fileBase.Content = ReadContent(fileName, info.Extension.Trim());

        //        IIndexManager indexManager = new IndexManagerFactory().Create();
        //        return indexManager.CreateIndex(fileBase);
        //    }
        //    if (Directory.Exists(fileName))
        //    {
        //        foreach (var item in new DirectoryInfo(fileName).GetFiles())
        //        {
        //            CreateIndex(item.FullName);
        //        }
        //        foreach (var item in new DirectoryInfo(fileName).GetDirectories())
        //        {
        //            CreateIndex(item.FullName);
        //        }
        //    }
        //    return true;
        //}

        /// <summary>
        /// 为文件添加索引
        /// </summary>
        /// <param>文件标识符</param>
        /// <param>人员权限</param>
        /// <returns></returns>
        public bool AddIndex(string fileId)
        {
            AbstractFileBase fileBase = new TextFileInfo();

            fileBase.FileId = fileId;
            #region 根据文件ID查找文件路径
            DirLinkAddress dirlink  = new DirLinkAddress(fileId);
            string         fileName = dirlink.GetDocFullPath(-1);
            #endregion
            //fileBase.FileName = info.Name;
            //fileBase.FilePath = info.DirectoryName;
            //fileBase.UpLoadPersonId = "zhangsan";
            //fileBase.CreateTime = DateTime.Now.ToString();
            fileBase.Content = ReadContent(fileName, dirlink.DocType);

            IIndexManager indexManager = new IndexManagerFactory().Create();
            return(indexManager.CreateIndex(fileBase));
        }
Esempio n. 4
0
 public void KeepLastEmptyLineOnContentEdit()
 {
     RefreshWorkData();
     foreach (var path in new[] { Ja_UTF8_CRLF_TxtPath, Ja_UTF8_CRLF_EndsWithEmptyLine_TxtPath })
     {
         var fileInfo     = new TextFileInfo(path);
         int srcLineCount = fileInfo.ReadAllLines().Count;
         var pathTree     = new PathTree();
         pathTree.TryAdd(path, out string errorMessage);
         var commands = new List <Command>();
         if (Command.TryParse("s/ほげ/ホゲ/g", out var command))
         {
             commands.Add(command);
         }
         var runner = new CommandRunner(commands);
         runner.Run(pathTree, CommandRunnerActionKind.Replace);
         int lineCount = fileInfo.ReadAllLines().Count;
         Assert.Equal(srcLineCount, lineCount);
     }
 }
Esempio n. 5
0
 public void KeepCharactorEncodingOnContentEdit()
 {
     RefreshWorkData();
     foreach (var path in new[] { Ja_UTF8_CRLF_TxtPath, Ja_UTF8WithBom_CRLF_TxtPath, Ja_SJIS_CRLF_TxtPath, Ja_EUCJP_LF_TxtPath })
     {
         var srcInfo  = new TextFileInfo(path);
         var pathTree = new PathTree();
         pathTree.TryAdd(path, out string errorMessage);
         var commands = new List <Command>();
         if (Command.TryParse("s/ほげ/ホゲ/g", out var command))
         {
             commands.Add(command);
         }
         var runner = new CommandRunner(commands);
         runner.Run(pathTree, CommandRunnerActionKind.Replace);
         var editedInfo = new TextFileInfo(path);
         Assert.Equal(srcInfo.Encoding, editedInfo.Encoding);
         Assert.Equal(srcInfo.NewLine, editedInfo.NewLine);
     }
 }
Esempio n. 6
0
        public void WorkWithSedRegex()
        {
            RefreshWorkData();
            string path     = Ja_UTF8_CRLF_TxtPath;
            var    pathTree = new PathTree();

            pathTree.TryAdd(path, out string errorMessage);
            var commands = new List <Command>();

            if (Command.TryParse(@"s/ほ\(げ\)/ホ\1/g", out var command))
            {
                commands.Add(command);
            }
            var runner = new CommandRunner(commands);

            runner.Run(pathTree, CommandRunnerActionKind.Replace);
            var fileInfo = new TextFileInfo(path);
            var lines    = fileInfo.ReadAllLines();

            Assert.Contains(lines, l => l.Contains("ホげ"));
        }