Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Manager"/> class.
        /// </summary>
        /// <param name="formats">The formats.</param>
        public Manager(IEnumerable <IFormat> formats)
        {
            FormatsByFileType = new ConcurrentDictionary <string, IFormat>();
            FormatsByMimeType = new ConcurrentDictionary <string, IFormat>();
            var ManagerAssembly = typeof(Manager).Assembly;
            var LocalFormats    = formats.Where(x => x.GetType().Assembly == ManagerAssembly);
            var OtherFormats    = formats.Where(x => x.GetType().Assembly != ManagerAssembly);

            AddFormats(OtherFormats);
            AddFormats(LocalFormats);
            DefaultFormat = new TxtFormat();
            Formats       = FormatsByFileType.Values.Distinct();
        }
        public void WriteNotATable()
        {
            var TestObject   = new DelimitedWriter();
            var TestReader   = new TxtFormat();
            var ResultReader = new DelimitedReader();

            using (var ResultFile = File.Open("./Results/WriteNotATable.csv", FileMode.OpenOrCreate))
            {
                using var TestFile = File.OpenRead("../../../TestData/TestTXT.txt");
                Assert.True(TestObject.Write(ResultFile, TestReader.Read(TestFile)));
            }
            using (var ResultFile = File.Open("./Results/WriteNotATable.csv", FileMode.OpenOrCreate))
            {
                var Result = ResultReader.Read(ResultFile);
                Assert.Equal(1, Result.Columns.Count);
                Assert.Equal("This is a test docx", Result.Columns[0]);
            }
        }
Exemple #3
0
        static void UpgradeFiles(string dir, string name)
        {
            string path = Path.Combine(dir, name);

            if (!Directory.Exists(path))
            {
                return;
            }
            string[] files = Directory.GetFiles(path);
            List <Player.UndoPos> buffer = new List <Player.UndoPos>();
            UndoFormatArgs        args   = new UndoFormatArgs(null, DateTime.MinValue, DateTime.MaxValue, null);

            for (int i = 0; i < files.Length; i++)
            {
                path = files[i];
                if (!path.EndsWith(BinFormat.Ext) && !path.EndsWith(TxtFormat.Ext))
                {
                    continue;
                }
                IEnumerable <UndoFormatEntry> data = null;
                Player.UndoPos pos;

                using (FileStream s = File.OpenRead(path)) {
                    data = path.EndsWith(BinFormat.Ext)
                        ? BinFormat.GetEntries(s, args) : TxtFormat.GetEntries(s, args);

                    foreach (UndoFormatEntry P in data)
                    {
                        pos.x       = P.X; pos.y = P.Y; pos.z = P.Z;
                        pos.type    = P.Block; pos.extType = P.ExtBlock;
                        pos.newtype = P.NewBlock; pos.newExtType = P.NewExtBlock;

                        pos.timeDelta = (int)P.Time.Subtract(Server.StartTimeLocal).TotalSeconds;
                        pos.mapName   = P.LevelName;
                        buffer.Add(pos);
                    }

                    buffer.Reverse();
                    string newPath = Path.ChangeExtension(path, NewFormat.Ext);
                    NewFormat.Save(buffer, newPath);
                }
                File.Delete(path);
            }
        }