• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IO.TempFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.IO.TempFile的典型用法代码示例。如果您正苦于以下问题:C# TempFile类的具体用法?C# TempFile怎么用?C# TempFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TempFile类属于System.IO命名空间,在下文中一共展示了TempFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
			}
		}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:7,代码来源:ParserTests.cs


示例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");
            }
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:29,代码来源:FileSystemWatcher.Renamed.cs


示例3: Should_create_temporary_file

 public void Should_create_temporary_file()
 {
     using( var file = new TempFile() )
     {
         Assert.IsTrue(file.FileInfo.Exists);
     }
 }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:7,代码来源:TempFileFixture.cs


示例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);
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:28,代码来源:ThumbnailGeneratorTests.cs


示例5: IsMigrationNeeded_ReturnsTrue

		public void IsMigrationNeeded_ReturnsTrue()
		{
			using (TempFile f = new TempFile("<lift version='0.10'></lift>"))
			{
				Assert.IsTrue(Migrator.IsMigrationNeeded(f.Path));
			}
		}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:7,代码来源:V10To11MigratorTests.cs


示例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));
			}
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:7,代码来源:GeneralMigratorTests.cs


示例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));
                }
            }
        }
开发者ID:borgahmed,项目名称:corefx,代码行数:26,代码来源:MemoryMappedFilesTests.cs


示例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;
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:HttpRawUploadedContent.cs


示例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);
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:60,代码来源:WritingSystemsInLiftFileHelper.cs


示例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);
				}
			}
		}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:27,代码来源:MigrateToV13Tests.cs


示例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);
			}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:7,代码来源:WritingSystemsInOptionsListFileHelperTests.cs


示例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);
			}
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:7,代码来源:GeneralMigratorTests.cs


示例13: MigrateToLatestVersion_VersionWithoutMigrationXsl_Throws

		public void MigrateToLatestVersion_VersionWithoutMigrationXsl_Throws()
		{
			using (TempFile f = new TempFile("<lift version='0.5'></lift>"))
			{
				Migrator.MigrateToLatestVersion(f.Path);
			}
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:7,代码来源:GeneralMigratorTests.cs


示例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);
			}
		}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:7,代码来源:ParserTests.cs


示例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);
			}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:8,代码来源:WritingSystemsInLiftFileHelperTests.cs


示例16: Can_read_and_write_text

 public void Can_read_and_write_text()
 {
     using( var file = new TempFile() )
     {
         var text = TestStrings.Internationalisation;
         file.WriteAllText(text);
         Assert.AreEqual(text, file.ReadAllText());
     }
 }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:9,代码来源:TempFileFixture.cs


示例17: Allows_constructor_argument_to_choose_filename

 public void Allows_constructor_argument_to_choose_filename()
 {
     using( var file = new TempFile("{0}.gif"))
     {
         file.FileInfo.Refresh();
         Assert.IsTrue(file.FileInfo.Name.EndsWith(".gif", StringComparison.OrdinalIgnoreCase));
         Assert.IsTrue(file.FileInfo.Exists);
     }
 }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:9,代码来源:TempFileFixture.cs


示例18: GetMappingCollection_returns_mapping

        public void GetMappingCollection_returns_mapping()
        {
            var edmxContents = @"<?xml version='1.0'?>
<Edmx Version='3.0' xmlns='http://schemas.microsoft.com/ado/2009/11/edmx'>
  <Runtime>
    <ConceptualModels>
      <Schema Namespace='Model' Alias='Self' annotation:UseStrongSpatialTypes='false' xmlns:annotation='http://schemas.microsoft.com/ado/2009/02/edm/annotation' xmlns='http://schemas.microsoft.com/ado/2009/11/edm'>
        <EntityContainer Name='DatabaseEntities' annotation:LazyLoadingEnabled='true'>
          <EntitySet Name='Entities' EntityType='Model.Entity' />
        </EntityContainer>
        <EntityType Name='Entity'>
          <Key>
            <PropertyRef Name='Id' />
          </Key>
          <Property Name='Id' Type='Int32' Nullable='false' annotation:StoreGeneratedPattern='Identity' />
        </EntityType>
      </Schema>
    </ConceptualModels>
    <Mappings>
      <Mapping Space='C-S' xmlns='http://schemas.microsoft.com/ado/2009/11/mapping/cs'>
        <EntityContainerMapping StorageEntityContainer='ModelStoreContainer' CdmEntityContainer='DatabaseEntities'>
          <EntitySetMapping Name='Entities'>
            <EntityTypeMapping TypeName='Model.Entity'>
              <MappingFragment StoreEntitySet='Entities'>
                <ScalarProperty Name='Id' ColumnName='Id' />
              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>
        </EntityContainerMapping>
      </Mapping>
    </Mappings>
    <StorageModels>
      <Schema Namespace='Model.Store' Alias='Self' Provider='System.Data.SqlClient' ProviderManifestToken='2008' xmlns:store='http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator' xmlns='http://schemas.microsoft.com/ado/2009/11/edm/ssdl'>
        <EntityContainer Name='ModelStoreContainer'>
          <EntitySet Name='Entities' EntityType='Model.Store.Entities' store:Type='Tables' Schema='dbo' />
        </EntityContainer>
        <EntityType Name='Entities'>
          <Key>
            <PropertyRef Name='Id' />
          </Key>
          <Property Name='Id' Type='int' Nullable='false' StoreGeneratedPattern='Identity' />
        </EntityType>
      </Schema>
    </StorageModels>
  </Runtime>
</Edmx>";
            StorageMappingItemCollection mappingCollection;

            using (var edmx = new TempFile(edmxContents))
            {
                mappingCollection = new EdmxUtility(edmx.FileName)
                    .GetMappingCollection();
            }

            Assert.True(mappingCollection.Contains("DatabaseEntities"));
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:56,代码来源:EdmxUtilityTests.cs


示例19: AddNewPath_PathExists_PathAtTopOfList

 public void AddNewPath_PathExists_PathAtTopOfList()
 {
     using (TempFile existingFile = new TempFile())
     {
         _MostRecentPathsList.AddNewPath(existingFile.FileName);
         string[] mruPaths = _MostRecentPathsList.Paths;
         Assert.AreEqual(1, mruPaths.Length);
         Assert.AreEqual(existingFile.FileName, mruPaths[0]);
     }
 }
开发者ID:JohnThomson,项目名称:testBloom,代码行数:10,代码来源:MostRecentPathsTests.cs


示例20: WrapScriptBlockWithScriptTag

 public void WrapScriptBlockWithScriptTag()
 {
     using (var tempFile = new TempFile())
     {
         Assert.Equal(
           String.Format(ScriptResources.ScriptIncludeFormat, tempFile.FileName),
           new ScriptInclude(tempFile.FileName).ToScriptFragment()
         );
     }
 }
开发者ID:cbaxter,项目名称:JSTest.NET,代码行数:10,代码来源:ScriptIncludeTests.cs



注:本文中的System.IO.TempFile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.TextReader类代码示例发布时间:2022-05-26
下一篇:
C# IO.TempDirectory类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap