예제 #1
0
        private void Save(Stream stream)
        {
            using BinaryWriter bw = new BinaryWriter(stream, Encoding.UTF8, true);
            bw.Write(FullPath ?? "");
            bw.Write((long)fileSize);
            //保存xml文件
            bw.Write(0);
            long start = stream.Position;

            xml.Save(stream);
            long end    = stream.Position;
            int  length = Convert.ToInt32(end - start);

            if (length > 0)
            {
                stream.Position = start - 4;
                bw.Write(length);
                stream.Position = end;
            }
            bool isnull = lines == null;

            bw.Write(isnull);
            if (!isnull)
            {
                //保存未翻译完的行
                bw.Write(lines.Count);
                IReadWriter <XmlFileOfVSLine> readWriter = XmlFileOfVSLine.GetLineReadWriter(null);
                foreach (ITranslatingLine line in lines)
                {
                    if (line is XmlFileOfVSLine vsLine)
                    {
                        readWriter.Write(stream, vsLine);
                    }
                }
            }
            bw.Flush();
        }
예제 #2
0
 public int Write(byte[] buffer, int offset, int count) => _rw.Write(buffer, offset, count);
예제 #3
0
 public void Write(string fileName)
 {
     readWriter.Write(this, fileName);
 }
예제 #4
0
        public static void RunCommand()
        {
            var r       = new Regex("(?<command>list |import file |export file )(?<args>.*)", RegexOptions.IgnoreCase);
            var rSearch = new Regex("(?<name>[a-z]+( [a-z])?)(?<date> .*)?", RegexOptions.IgnoreCase);

            Console.WriteLine("\"List All\" or \"List (Account)\" or \"Import File (FileName)\" " +
                              "or \"Export File (FileName)\"");
            var input = Console.ReadLine();
            var m     = r.Match(input);

            if (!m.Success)
            {
                Console.WriteLine("Command not recognised");
                return;
            }

            switch (m.Groups["command"].ToString().ToLower())
            {
            case "list ": {
                var m2 = rSearch.Match(m.Groups["args"].ToString());
                if (!m2.Success)
                {
                    Console.WriteLine("Name/date not recognised");
                    return;
                }
                var date = DateTime.Now;
                if (!m2.Groups["date"].ToString().Equals(""))
                {
                    try {
                        date = DateTime.Parse(m2.Groups["date"].ToString());
                    }
                    catch {
                        Console.WriteLine("Date not recognised");
                    }
                }
                var name = m2.Groups["name"].ToString();
                if (name.ToLower().Equals("all"))
                {
                    ListAll(date);
                }
                else
                {
                    ListAccount(name, date);
                }
                break;
            }

            case "import file ": {
                var filename = m.Groups["args"].ToString();
                try {
                    if (filename.EndsWith(".json"))
                    {
                        transactions.UnionWith(jsonReadWriter.Read(filename));
                    }
                    else if (filename.EndsWith(".xml"))
                    {
                        transactions.UnionWith(xmlReadWriter.Read(filename));
                    }
                    else
                    {
                        transactions.UnionWith(csvReadWriter.Read(filename));
                    }
                } catch {
                    Console.WriteLine($"Could not read file: {filename}");
                }
                break;
            }

            case "export file ": {
                var filename = m.Groups["args"].ToString();
                try {
                    if (filename.EndsWith(".json"))
                    {
                        jsonReadWriter.Write(filename, transactions);
                    }
                    else if (filename.EndsWith(".xml"))
                    {
                        xmlReadWriter.Write(filename, transactions);
                    }
                    else
                    {
                        csvReadWriter.Write(filename, transactions);
                    }
                } catch {
                    Console.WriteLine($"Could not write file: {filename}");
                }
                break;
            }
            }
        }