Exemplo n.º 1
0
        public override void Persist(object syncRoot = null)
        {
            if (syncRoot == null)
            {
                throw new ArgumentNullException(nameof(syncRoot));
            }

            if (Document != null)
            {
                lock (syncRoot)
                {
                    base.Persist(syncRoot);
                }
                Document = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                return;
            }

            // Always write the end element and flush the writer
            // before validating.
            _xmlTextWriter.WriteFullEndElement();
            _xmlTextWriter.Flush();

            // Validation.
            _shadowFileStream.Seek(0, SeekOrigin.Begin);
            using (var xmlReader = XmlReader.Create(_shadowFileStream, CreateXmlReaderSettings(Schema, ValidationType.Schema)))
            {
                while (xmlReader.Read())
                {
                }
            }

            // Close the writer and the shadow file stream.
            _xmlTextWriter.Close();
            _shadowFileStream.Close();

            // Rename the shadow file to the archive table file.
            try
            {
                lock (syncRoot)
                {
                    DeleteFile(FilePath);

                    _shadowFile.CopyTo(FilePath.FullName);
                    DeleteFile(_shadowFile);

                    FilePath.Refresh();
                    FileIndex.AddFile(FilePath);
                }
            }
            catch (Exception ex)
            {
                throw new DeliveryEngineRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.FileWriteError, FilePath.FullName), ex);
            }
        }
Exemplo n.º 2
0
        public void Perist()
        {
            try
            {
                using (var filestream = new FileStream(_path.FullName, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    using (var xmlwriter = new XmlTextWriter(filestream, Encoding.Unicode))
                    {
                        xmlwriter.Formatting = Formatting.Indented;
                        Schema.Write(xmlwriter);
                    }
                }
                _path.Refresh();
            }
            catch (Exception ex)
            {
                throw new DeliveryEngineRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.FileWriteError, _path.FullName), ex);
            }

            _fileIndex.AddFile(_path);
        }
Exemplo n.º 3
0
        public void TestBasicFileIndex()
        {
            FileIndex fileIndex = new FileIndex();

            string[] fileList = {
                    @"c:\bah\humbug\foo\bar\123.txt",
                    @"c:\bah\humbug\foo\bar\humbug.txt",
                    @"c:\bah\humbug\foo\bar\cat.txt",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt",
                    @"c:\bah\dog\manyanimals.jpg",
                    @"c:\bah\cat\manyanimals.jpg",
                    @"c:\project\Thing1\obj\output.obj",
                    @"c:\project\Thing2\obj\output.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\bubu.obj",
            };

            foreach (string file in fileList)
            {
                fileIndex.AddFile(file);
            }

            TestFileIndexCase(fileIndex, "123", new string[] { @"c:\bah\humbug\foo\bar\123.txt" });

            TestFileIndexCase(fileIndex, "humbugster", new string[] { });

            TestFileIndexCase(fileIndex, ".t", new string[] {
                    @"c:\bah\humbug\foo\bar\123.txt",
                    @"c:\bah\humbug\foo\bar\cat.txt",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\foo\bar\humbug.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt" });

            TestFileIndexCase(fileIndex, "anIM", new string[] {
                    @"c:\bah\humbug\cat\dog\animals.txt",
                    @"c:\bah\cat\manyanimals.jpg",
                    @"c:\bah\dog\manyanimals.jpg" });

            TestFileIndexCase(fileIndex, "bu", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\bah\humbug\foo\bar\humbug.txt",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt",
                    @"c:\bah\humbug\foo\bar\123.txt",
                    @"c:\bah\humbug\foo\bar\cat.txt" });

            TestFileIndexCase(fileIndex, "obj", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj" ,
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing1\obj\output.obj",
                    @"c:\project\Thing2\obj\output.obj" });

            TestFileIndexCase(fileIndex, "ing", new string[] {
                    @"c:\project\Thing1\obj\output.obj",
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj" });

            TestFileIndexCase(fileIndex, "cat\\", new string[] {
                    @"c:\bah\cat\manyanimals.jpg",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt" });

            TestFileIndexCase(fileIndex, "humbug\\cat\\", new string[] {
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt" });

            TestFileIndexCase(fileIndex, "at\\", new string[] {
                    @"c:\bah\cat\manyanimals.jpg",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt" });

            TestFileIndexCase(fileIndex, "cat\\d", new string[] {
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt" });

            TestFileIndexCase(fileIndex, "cat\\a", new string[] {} );

            TestFileIndexCase(fileIndex, "dfgdfgsdgsdgsdfgsdgqrsdfasfadsfgdsg\\humbu", new string[] { });

            TestFileIndexCase(fileIndex, @"Thing1\o", new string[] {
                    @"c:\project\Thing1\obj\output.obj" } );

            TestFileIndexCase(fileIndex, @"thing2", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"Thing2\", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"Thing2", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"Thing2\ob", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"thing2\obj", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"Thing2\obJ\", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj"  });

            TestFileIndexCase(fileIndex, @"Thing2\OBJ\B", new string[] {
                    @"c:\project\Thing2\obj\bubu.obj" });

            TestFileIndexCase(fileIndex, "", new string[] {
                    @"c:\bah\cat\manyanimals.jpg",
                    @"c:\bah\dog\manyanimals.jpg",
                    @"c:\bah\humbug\cat\dog.txt",
                    @"c:\bah\humbug\cat\dog\animals.txt",
                    @"c:\bah\humbug\foo\bar\123.txt",
                    @"c:\bah\humbug\foo\bar\cat.txt",
                    @"c:\bah\humbug\foo\bar\humbug.txt",
                    @"c:\project\Thing1\obj\output.obj",
                    @"c:\project\Thing2\obj\bubu.obj",
                    @"c:\project\Thing2\obj\cacaca.obj",
                    @"c:\project\Thing2\obj\output.obj" });

            fileIndex.RemoveAll();

            TestFileIndexCase(fileIndex, "obj", new string[] { });
        }