Esempio n. 1
0
        public void TestTextFilesAndComplexKeys()
        {
            File.WriteAllText("input_text_1", "Hello World!" + Environment.NewLine);

            using (CombinedFileStream cfs = new CombinedFileStream(File.OpenWrite("text_files"))){
                cfs.WriteFile(new string[] { "key1", "a", "bb", "ccc", "dddd" }, "input_text_1");
                cfs.WriteFile(new string[] { "key2", "a", "bb", "ccc", "dddd" }, "input_text_1");
                cfs.Flush();
            }

            Assert.IsTrue(File.Exists("text_files"));

            using (CombinedFileStream cfs = new CombinedFileStream(File.OpenRead("text_files"))){
                CombinedFileStream.Entry entry = cfs.ReadFile();

                Assert.AreEqual("key2", cfs.SkipFile());
                Assert.IsNull(cfs.ReadFile());
                Assert.IsNull(cfs.SkipFile());

                Assert.AreEqual("key1|a|bb|ccc|dddd", entry.Identifier);
                Assert.AreEqual("key1", entry.KeyName);
                CollectionAssert.AreEqual(new string[] { "a", "bb", "ccc", "dddd" }, entry.KeyValue);

                entry.WriteToFile("text_file_1");
            }

            Assert.IsTrue(File.Exists("text_file_1"));
            Assert.AreEqual("Hello World!" + Environment.NewLine, File.ReadAllText("text_file_1"));
        }
Esempio n. 2
0
        public void TestEmptyFiles()
        {
            TestUtils.WriteText("cfs_input_empty_1", string.Empty);
            TestUtils.WriteText("cfs_input_empty_2", string.Empty);

            using (CombinedFileStream cfs = new CombinedFileStream(TestUtils.WriteFile("cfs_blank_files"))){
                cfs.WriteFile("id1", "cfs_input_empty_1");
                cfs.WriteFile("id2", "cfs_input_empty_2");
                cfs.WriteFile("id2_clone", "cfs_input_empty_2");
                cfs.Flush();
            }

            Assert.IsTrue(File.Exists("cfs_blank_files"));

            using (CombinedFileStream cfs = new CombinedFileStream(TestUtils.ReadFile("cfs_blank_files"))){
                CombinedFileStream.Entry entry1 = cfs.ReadFile();
                string entry2key = cfs.SkipFile();
                CombinedFileStream.Entry entry3 = cfs.ReadFile();

                Assert.IsNull(cfs.ReadFile());
                Assert.IsNull(cfs.SkipFile());

                Assert.AreEqual("id1", entry1.KeyName);
                Assert.AreEqual("id1", entry1.Identifier);
                CollectionAssert.AreEqual(new string[0], entry1.KeyValue);

                Assert.AreEqual("id2", entry2key);

                Assert.AreEqual("id2_clone", entry3.KeyName);
                Assert.AreEqual("id2_clone", entry3.Identifier);
                CollectionAssert.AreEqual(new string[0], entry3.KeyValue);

                entry1.WriteToFile("cfs_blank_file_1");
                entry3.WriteToFile("cfs_blank_file_2");
                TestUtils.DeleteFileOnExit("cfs_blank_file_1");
                TestUtils.DeleteFileOnExit("cfs_blank_file_2");
            }

            Assert.IsTrue(File.Exists("cfs_blank_file_1"));
            Assert.IsTrue(File.Exists("cfs_blank_file_2"));
            Assert.AreEqual(string.Empty, TestUtils.ReadText("cfs_blank_file_1"));
            Assert.AreEqual(string.Empty, TestUtils.ReadText("cfs_blank_file_2"));
        }
Esempio n. 3
0
        public void TestNoFiles()
        {
            using (CombinedFileStream cfs = new CombinedFileStream(File.OpenWrite("empty"))){
                cfs.Flush();
            }

            Assert.IsTrue(File.Exists("empty"));

            using (CombinedFileStream cfs = new CombinedFileStream(File.OpenRead("empty"))){
                Assert.IsNull(cfs.ReadFile());
            }

            using (CombinedFileStream cfs = new CombinedFileStream(File.OpenRead("empty"))){
                Assert.IsNull(cfs.SkipFile());
            }
        }
Esempio n. 4
0
        public Items FindImportItems()
        {
            Items items = Items.None;

            try {
                using CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None));
                string key;

                while ((key = stream.SkipFile()) != null)
                {
                    switch (key)
                    {
                    case "config":
                        items |= Items.UserConfig;
                        break;

                    case "system":
                        items |= Items.SystemConfig;
                        break;

                    case "plugin.config":
                    case "plugin.data":
                        items |= Items.PluginData;
                        break;

                    case "cookies":
                    case "localprefs":
                    case "cookie.auth":
                        items |= Items.Session;
                        break;
                    }
                }
            } catch (Exception) {
                items = Items.None;
            }

            return(items);
        }