本文整理汇总了C#中System.IO.TempFile类的典型用法代码示例。如果您正苦于以下问题:C# TempFile类的具体用法?C# TempFile怎么用?C# TempFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TempFile类属于System.IO命名空间,在下文中一共展示了TempFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadLiftFile_CurrentVersion_Happy
public void ReadLiftFile_CurrentVersion_Happy()
{
using (TempFile f = new TempFile(string.Format("<lift version='{0}'></lift>", Validator.LiftVersion)))
{
_parser.ReadLiftFile(f.Path);
}
}
示例2: FileSystemWatcher_Renamed_Negative
public void FileSystemWatcher_Renamed_Negative()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var dir = new TempDirectory(Path.Combine(testDirectory.Path, GetTestFileName())))
using (var watcher = new FileSystemWatcher(testDirectory.Path))
{
// put everything in our own directory to avoid collisions
watcher.Path = Path.GetFullPath(dir.Path);
watcher.Filter = "*.*";
AutoResetEvent eventOccurred = WatchForEvents(watcher, WatcherChangeTypes.Renamed);
watcher.EnableRaisingEvents = true;
// run all scenarios together to avoid unnecessary waits,
// assert information is verbose enough to trace to failure cause
// create a file
using (var testFile = new TempFile(Path.Combine(dir.Path, "file")))
using (var testDir = new TempDirectory(Path.Combine(dir.Path, "dir")))
{
// change a file
File.WriteAllText(testFile.Path, "changed");
// deleting a file & directory by leaving the using block
}
ExpectNoEvent(eventOccurred, "created");
}
}
示例3: Should_create_temporary_file
public void Should_create_temporary_file()
{
using( var file = new TempFile() )
{
Assert.IsTrue(file.FileInfo.Exists);
}
}
示例4: Creating_thumbnail_creates_new_entry_in_cache
public void Creating_thumbnail_creates_new_entry_in_cache()
{
var cache = generator.Cache as ThumbnailCache;
Assert.IsNotNull(cache);
Assert.AreEqual(0, cache.CacheDirectory.GetFiles().Length);
using( var thumb = new TempFile()) // This will be the location of the thumbnail
using (var image = new TempFile("{0}.jpg")) // This is the test image we will make a thumb out of
using (var destStream = image.FileInfo.OpenWrite()) // Writes the test image data to the test image file
using (var imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Foundation.Tests.Resources.TestImage.jpg"))
{
var buffer = new byte[9012];
var bytesRead = imageStream.Read(buffer, 0, buffer.Length);
while (bytesRead > 0)
{
destStream.Write(buffer, 0, bytesRead);
bytesRead = imageStream.Read(buffer, 0, buffer.Length);
}
destStream.Close();
imageStream.Close();
// Create thumbnail
generator.Generate(image.FileInfo.FullName, thumb.FileInfo.FullName);
}
Assert.AreEqual(1, ((ThumbnailCache) generator.Cache).CacheDirectory.GetFiles().Length);
}
示例5: IsMigrationNeeded_ReturnsTrue
public void IsMigrationNeeded_ReturnsTrue()
{
using (TempFile f = new TempFile("<lift version='0.10'></lift>"))
{
Assert.IsTrue(Migrator.IsMigrationNeeded(f.Path));
}
}
示例6: IsMigrationNeeded_Latest_ReturnsFalse
public void IsMigrationNeeded_Latest_ReturnsFalse()
{
using (TempFile f = new TempFile(string.Format("<lift version='{0}'></lift>", Validator.LiftVersion)))
{
Assert.IsFalse(Migrator.IsMigrationNeeded(f.Path));
}
}
示例7: DataShared
public void DataShared()
{
// Create a new file and load it into an MMF
using (TempFile file = new TempFile(GetTestFilePath(), 4096))
using (FileStream fs = new FileStream(file.Path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fs, null, fs.Length, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, true))
using (MemoryMappedViewAccessor acc = mmf.CreateViewAccessor())
{
// Write some known data to the map
long capacity = acc.Capacity;
for (int i = 0; i < capacity; i++)
{
acc.Write(i, (byte)i);
}
acc.Flush();
// Spawn and then wait for the other process, which will verify the data and write its own known pattern
RemoteInvoke("DataShared_OtherProcess", file.Path).Dispose();
// Now verify we're seeing the data from the other process
for (int i = 0; i < capacity; i++)
{
Assert.Equal((byte)(capacity - i - 1), acc.ReadByte(i));
}
}
}
示例8: AddBytes
internal void AddBytes(byte[] data, int offset, int length)
{
if (this._completed)
{
throw new InvalidOperationException();
}
if (length > 0)
{
if (this._file == null)
{
if ((this._length + length) <= this._data.Length)
{
Array.Copy(data, offset, this._data, this._length, length);
this._length += length;
return;
}
if ((this._length + length) <= this._fileThreshold)
{
byte[] destinationArray = new byte[this._fileThreshold];
if (this._length > 0)
{
Array.Copy(this._data, 0, destinationArray, 0, this._length);
}
Array.Copy(data, offset, destinationArray, this._length, length);
this._data = destinationArray;
this._length += length;
return;
}
this._file = new TempFile();
this._file.AddBytes(this._data, 0, this._length);
}
this._file.AddBytes(data, offset, length);
this._length += length;
}
}
示例9: DeleteWritingSystemId
public void DeleteWritingSystemId(string id)
{
var fileToBeWrittenTo = new IO.TempFile();
var reader = XmlReader.Create(_liftFilePath, Xml.CanonicalXmlSettings.CreateXmlReaderSettings());
var writer = XmlWriter.Create(fileToBeWrittenTo.Path, Xml.CanonicalXmlSettings.CreateXmlWriterSettings());
//System.Diagnostics.Process.Start(fileToBeWrittenTo.Path);
try
{
bool readerMovedByXmlDocument = false;
while (readerMovedByXmlDocument || reader.Read())
{
readerMovedByXmlDocument = false;
var xmldoc = new XmlDocument();
if (reader.NodeType == XmlNodeType.Element && reader.Name == "entry")
{
var entryFragment = xmldoc.ReadNode(reader);
readerMovedByXmlDocument = true;
var nodesWithLangId = entryFragment.SelectNodes(String.Format("//*[@lang='{0}']", id));
if (nodesWithLangId != null)
{
foreach (XmlNode node in nodesWithLangId)
{
var parent = node.SelectSingleNode("parent::*");
if (node.Name == "gloss")
{
parent.RemoveChild(node);
}
else
{
var siblingNodes =
node.SelectNodes("following-sibling::form | preceding-sibling::form");
if (siblingNodes.Count == 0)
{
var grandParent = parent.SelectSingleNode("parent::*");
grandParent.RemoveChild(parent);
}
else
{
parent.RemoveChild(node);
}
}
}
}
entryFragment.WriteTo(writer);
}
else
{
writer.WriteNodeShallow(reader);
}
//writer.Flush();
}
}
finally
{
reader.Close();
writer.Close();
}
File.Delete(_liftFilePath);
fileToBeWrittenTo.MoveTo(_liftFilePath);
}
示例10: SenseLiteralDefinition_WasOnSense_MovedToEntry
public void SenseLiteralDefinition_WasOnSense_MovedToEntry()
{
using (TempFile f = new TempFile("<lift version='0.12' producer='tester'>" +
"<entry>" +
"<sense>" +
"<field type='LiteralMeaning' dateCreated='2009-03-31T08:28:37Z'><form lang='en'><text>trial</text></form></field>" +
"<trait name='SemanticDomainDdp4' value='6.1.2.9 Opportunity'/>" +
"</sense>" +
"</entry>" +
"</lift>"))
{
var path = Migrator.MigrateToLatestVersion(f.Path);
try
{
Assert.AreEqual(Validator.LiftVersion, Validator.GetLiftVersion(path));
AssertXPathAtLeastOne("//lift[@producer='tester']", path);
AssertXPathAtLeastOne("//entry/field[@type='literal-meaning']", path);
AssertXPathNotFound("//entry/sense/field", path);
AssertXPathAtLeastOne("//entry/sense/trait[@name='semantic-domain-ddp4']", path);
AssertXPathNotFound("//entry/sense/trait[@name='SemanticDomainDdp4']", path);
}
finally
{
File.Delete(path);
}
}
}
示例11: TestEnvironment
public TestEnvironment(string rfctag, string rfctag2)
{
_folder = new TemporaryFolder("WritingSystemsInoptionListFileHelper");
var pathtoOptionsListFile1 = Path.Combine(_folder.Path, "test1.xml");
_optionListFile = new IO.TempFile(String.Format(_optionListFileContent, rfctag, rfctag2));
_optionListFile.MoveTo(pathtoOptionsListFile1);
}
示例12: MigrateToLatestVersion_HasCurrentVersion_Throws
public void MigrateToLatestVersion_HasCurrentVersion_Throws()
{
using (TempFile f = new TempFile(string.Format("<lift version='{0}'></lift>", Validator.LiftVersion)))
{
Migrator.MigrateToLatestVersion(f.Path);
}
}
示例13: MigrateToLatestVersion_VersionWithoutMigrationXsl_Throws
public void MigrateToLatestVersion_VersionWithoutMigrationXsl_Throws()
{
using (TempFile f = new TempFile("<lift version='0.5'></lift>"))
{
Migrator.MigrateToLatestVersion(f.Path);
}
}
示例14: ReadLiftFile_OldVersion_Throws
public void ReadLiftFile_OldVersion_Throws()
{
using (TempFile f = new TempFile(string.Format("<lift version='{0}'></lift>", /*Validator.LiftVersion*/ "0.0")))
{
_parser.ReadLiftFile(f.Path);
}
}
示例15: TestEnvironment
public TestEnvironment(string liftFileContent)
{
_folder = new TemporaryFolder("WritingSystemsInLiftFileHelper");
var pathtoLiftFile1 = Path.Combine(_folder.Path, "test1.lift");
_liftFile1 = new IO.TempFile(liftFileContent);
_liftFile1.MoveTo(pathtoLiftFile1);
Helper = new WritingSystemsInLiftFileHelper(WritingSystems, _liftFile1.Path);
}