コード例 #1
0
        public void ConvertToResources(Tools.StringGroup value)
        {
            if (value.sourceString == "")
            {
                return;
            }

            //处理文件数据
            string[] result = value.ToStringGroup();
            lineName = result[0];
            for (int a = 0; a < 5; a++)
            {
                lineMessage[a] = result[a + 1];
            }
            if (result[6] == "0")
            {
                lineType = enumLineType.Bus;
            }
            else
            {
                lineType = enumLineType.Subway;
            }
            lineWait = (enumLineWait)(int.Parse(result[7]));
            for (int a = 0; a < 4; a++)
            {
                lineRuntime[a] = System.Convert.ToInt32(result[a + 8]);
            }
            lineUpStop   = new Tools.StringGroup(result[12], ",");
            lineDownStop = new Tools.StringGroup(result[13], ",");
        }
コード例 #2
0
        /// <summary>
        /// 开始随机读取
        /// </summary>
        /// <param name="searchHead">要搜寻的头</param>
        public List <T> SeekRead(List <seekIndexStruct> seekHead)
        {
            if (seekHead.Count != 0)
            {
                throw new NullReferenceException("head is empty!");
            }

            //确认结果
            var result = new List <T>(seekHead.Count);

            //=======================================================从内存暂存区读
            //读取循环
            int cache = -1;

            foreach (seekIndexStruct item in seekHead)
            {
                cache += 1;
                var cacheGet = memorizeManagement.TryGetItem(item.Head);

                //有了
                if (cacheGet.sourceString != "")
                {
                    //写入
                    var cacheRes = new T();
                    cacheRes.ConvertToResources(cacheGet);
                    result[cache] = cacheRes;
                    //取消这部分的文件读取
                    //设头为空,取消读取
                    seekHead[cache].Head = "";
                }
            }


            //=======================================================读取序号
            StreamReader indexReader = new StreamReader(Kernel.Tools.SystemInformation.WorkingPath + seekFilePath, Assistance.utf8WithoutBOM);
            string       word        = "";

            //读取循环
            while (true)
            {
                word = indexReader.ReadLine();

                if (word == "")
                {
                    throw new IOException("Out of file!");
                }

                int searchIndex = CheckHeadInSeekHead(seekHead, word);
                if (searchIndex != -1)
                {
                    //对的
                    Kernel.Tools.StringGroup index = new Kernel.Tools.StringGroup(indexReader.ReadLine(), ",");
                    string[] indexString           = index.ToStringGroup();

                    //0表示seek坐标,1表示seek读取长度
                    seekHead[searchIndex].Index  = System.Convert.ToInt64(indexString[0]);
                    seekHead[searchIndex].Length = System.Convert.ToInt32(indexString[1]);

                    //检测写满
                    if (CheckSeekHeadIsFull(seekHead) == true)
                    {
                        break;
                    }
                }
                else
                {
                    //不是的
                    indexReader.ReadLine();
                }
            }

            indexReader.Dispose();

            //====================================================================================读取
            var seekReader = new FileStream(Kernel.Tools.SystemInformation.WorkingPath + mainFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);

            //读取循环
            cache = -1;
            foreach (seekIndexStruct item in seekHead)
            {
                cache += 1;
                //检测空头,空头放过去
                if (item.Head == "")
                {
                    continue;
                }

                //seek
                seekReader.Seek(item.Index, SeekOrigin.Begin);

                //get
                byte[] getByte = new byte[item.Length];
                seekReader.Read(getByte, 0, item.Length);

                //translate
                Kernel.Tools.StringGroup outContant = new Kernel.Tools.StringGroup(System.Text.Encoding.UTF8.GetString(getByte), Environment.NewLine);

                //削去最后一行的空行
                ArrayList cacheOutContant = outContant.ToArrayList();
                cacheOutContant.RemoveAt(cacheOutContant.Count - 1);
                outContant = new Tools.StringGroup(cacheOutContant, Environment.NewLine);

                var cacheRes = new T();
                cacheRes.ConvertToResources(outContant);
                result[cache] = cacheRes;
            }

            return(result);
        }