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

C# TempFile类代码示例

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

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



TempFile类属于命名空间,在下文中一共展示了TempFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: op_Execute_IEnumerable

        public void op_Execute_IEnumerable()
        {
            using (var file = new TempFile())
            {
                file.Info.AppendLine("CANONICAL,SYNONYMS");
                file.Info.AppendLine("1,One");
                file.Info.AppendLine("1,Unit");

                var obj = new LexiconTidy
                {
                    BuildEngine = new Mock<IBuildEngine>().Object,
                    Paths = new ITaskItem[]
                    {
                        new TaskItem(file.Info.FullName)
                    }
                };

                Assert.True(obj.Execute());

                file.Info.Refresh();
                Assert.True(file.Info.Exists);

                Assert.True(File.ReadAllText(file.Info.FullName).Contains("1,One;Unit"));
            }
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:25,代码来源:LexiconTidy.Facts.cs


示例2: ctor

 public void ctor()
 {
     using (var file = new TempFile())
     {
         Assert.NotNull(file);
     }
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:TempFile.Facts.cs


示例3: Process

		public void Process(Crawler crawler, PropertyBag propertyBag)
		{
			if (propertyBag.StatusCode != HttpStatusCode.OK)
			{
				return;
			}

			string extension = MapContentTypeToExtension(propertyBag.ContentType);
			if (extension.IsNullOrEmpty())
			{
				return;
			}

			propertyBag.Title = propertyBag.Step.Uri.PathAndQuery;
			using (TempFile temp = new TempFile())
			{
				temp.FileName += "." + extension;
				using (FileStream fs = new FileStream(temp.FileName, FileMode.Create, FileAccess.Write, FileShare.Read, 0x1000))
				using (Stream input = propertyBag.GetResponse())
				{
					input.CopyToStream(fs);
				}

				using (FilterReader filterReader = new FilterReader(temp.FileName))
				{
					string content = filterReader.ReadToEnd();
					propertyBag.Text = content.Trim();
				}
			}
		}
开发者ID:senzacionale,项目名称:ncrawler,代码行数:30,代码来源:IFilterProcessor.cs


示例4: op_Execute_IEnumerable

        public void op_Execute_IEnumerable()
        {
            using (var file = new TempFile())
            {
                using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Cavity.Build.MSBuildCompliance.xml"))
                {
                    if (null != resource)
                    {
                        using (var reader = new StreamReader(resource))
                        {
                            file.Info.Append(reader.ReadToEnd());
                        }
                    }
                }

                var obj = new MSBuildCompliance
                              {
                                  BuildEngine = new Mock<IBuildEngine>().Object,
                                  Projects = new ITaskItem[]
                                                 {
                                                     new TaskItem(file.Info.FullName)
                                                 },
                                  XPath = "0=count(/b:Project/b:PropertyGroup[@Condition][not(b:WarningLevel[text()='4'])])"
                              };

                Assert.True(obj.Execute());
            }
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:28,代码来源:MSBuildCompliance.Facts.cs


示例5: BothModifiedExampleFormTextWorksWithConflict

        public void BothModifiedExampleFormTextWorksWithConflict()
        {
            const string ancestor = @"<?xml version='1.0' encoding='utf-8'?>
            <lift version='0.10' producer='WeSay 1.0.0.0'>
            <entry id='test'  guid='F169EB3D-16F2-4eb0-91AA-FDB91636F8F6'>
            <sense id='123'>
             <example>
            <form lang='chorus'>
              <text>This is my example sentence.</text>
            </form>
              </example>
            </sense>
            </entry>
            </lift>";
            var ours = ancestor.Replace(@"This is my example", @"This was your example");
            var theirs = ancestor.Replace(@"This is my example", @"It's mine don't touch it.");

            using (var oursTemp = new TempFile(ours))
            using (var theirsTemp = new TempFile(theirs))
            using (var ancestorTemp = new TempFile(ancestor))
            {
                var listener = new ListenerForUnitTests();
                var situation = new NullMergeSituation();
                var mergeOrder = new MergeOrder(oursTemp.Path, ancestorTemp.Path, theirsTemp.Path, situation) { EventListener = listener };
                XmlMergeService.Do3WayMerge(mergeOrder, new LiftEntryMergingStrategy(mergeOrder),
                    false,
                    "header",
                    "entry", "guid");
                var result = File.ReadAllText(mergeOrder.pathToOurs);
                Assert.AreEqual(1, listener.Conflicts.Count);
                var warning = listener.Conflicts[0];
                Assert.AreEqual(typeof(XmlTextBothEditedTextConflict), warning.GetType(), warning.ToString());
                XmlTestHelper.AssertXPathMatchesExactlyOne(result, "//example/form");
            }
        }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:35,代码来源:ExampleSentenceMergingTests.cs


示例6: ctor_FileInfo

 public void ctor_FileInfo()
 {
     using (var temp = new TempFile())
     {
         Assert.NotNull(new TsvDataFile(temp.Info));
     }
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:TsvDataFile.Facts.cs


示例7: InvalidArguments_Mode

        public void InvalidArguments_Mode()
        {
            // FileMode out of range
            Assert.Throws<ArgumentOutOfRangeException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), (FileMode)42));
            Assert.Throws<ArgumentOutOfRangeException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), (FileMode)42, null));
            Assert.Throws<ArgumentOutOfRangeException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), (FileMode)42, null, 4096));
            Assert.Throws<ArgumentOutOfRangeException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), (FileMode)42, null, 4096, MemoryMappedFileAccess.ReadWrite));

            // FileMode.Append never allowed
            Assert.Throws<ArgumentException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Append));
            Assert.Throws<ArgumentException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Append, null));
            Assert.Throws<ArgumentException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Append, null, 4096));
            Assert.Throws<ArgumentException>("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Append, null, 4096, MemoryMappedFileAccess.ReadWrite));

            // FileMode.CreateNew/Create/OpenOrCreate can't be used with default capacity, as the file will be empty
            Assert.Throws<ArgumentException>(() => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.CreateNew));
            Assert.Throws<ArgumentException>(() => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Create));
            Assert.Throws<ArgumentException>(() => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.OpenOrCreate));

            // FileMode.Truncate can't be used with default capacity, as resulting file will be empty
            using (TempFile file = new TempFile(GetTestFilePath()))
            {
                Assert.Throws<ArgumentException>(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Truncate));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:25,代码来源:MemoryMappedFile.CreateFromFile.Tests.cs


示例8: ClickAllControlsOnPage_UsingReflection_Succeeds

        public void ClickAllControlsOnPage_UsingReflection_Succeeds()
        {
            //Arrange
            using (TempFile tempFile = new TempFile(
            @"<html>
            <head>
            <title>test</title>
            </head>
            <body>
            <a href=""#"">test</a>
            <button>test</button>
            <input type=""text"" value=""test""/>
            </body>
            </html>"))
            {
                BrowserWindow.Launch(tempFile.FilePath);
                var window = new BrowserWindowUnderTest("test");

                IControlBase a = window.Get<HtmlHyperlink>("InnerText=test");
                a.Click();

                List<Type> list = new List<Type>();
                list.Add(typeof(HtmlHyperlink));
                list.Add(typeof(HtmlButton));
                list.Add(typeof(HtmlEdit));

                MethodInfo getMethodInfo = typeof(BrowserWindowUnderTest).GetMethod("Get");

                foreach(Type t in list)
                {
                    MethodInfo test = getMethodInfo.MakeGenericMethod(t);

                    IControlBase control;

                    if ((t == typeof(HtmlEdit)) || (t == typeof(HtmlTextArea)))
                    {
                        control = (IControlBase)test.Invoke(window, new object[] { "Value=test" });
                    }
                    else
                    {
                        //window.Get<t>("InnerText=test");
                        control = (IControlBase)test.Invoke(window, new object[] { "InnerText=test" });
                    }

                    //Act
                    control.Click();

                    if (control is HtmlEdit)
                    {
                        (control as HtmlEdit).SetText("text");
                    }
                    else if (control is HtmlTextArea)
                    {
                        (control as HtmlTextArea).SetText("text");
                    }
                }

                window.Close();
            }
        }
开发者ID:umakanthk,项目名称:cuite,代码行数:60,代码来源:HtmlControlTests.cs


示例9: ChorusNotesMergeEventListener

        public ChorusNotesMergeEventListener(string path)
        {
            _path = path;

            try
            {
                if (!File.Exists(path))
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(string.Format("<notes version='{0}'/>", FormatVersionNumber.ToString()));
                    using (var fileWriter = XmlWriter.Create(path, CanonicalXmlSettings.CreateXmlWriterSettings()))
                    {
                        doc.Save(fileWriter);
                    }
                }
            }
            catch (Exception error)
            {
                Debug.Fail("Something went wrong trying to create a blank ChorusNotes file :"+error.Message);
                //todo log that the xml was the wrong format
            }

            _tempFile = new TempFile();
            _readerStream = new FileStream(path, FileMode.Open);
            _reader = XmlReader.Create(_readerStream, CanonicalXmlSettings.CreateXmlReaderSettings());
            _writer = XmlWriter.Create(_tempFile.Path, CanonicalXmlSettings.CreateXmlWriterSettings());
            StreamToInsertionPoint(_reader, _writer);
        }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:28,代码来源:ChorusNotesMergeEventListener.cs


示例10: TestTransactionLogOptions

        public void TestTransactionLogOptions()
        {
            using (TempFile temp = new TempFile())
            {
                temp.Delete();
                var opt = new TransactionLogOptions<int, string>(temp.TempPath,
                                                              PrimitiveSerializer.Int32,
                                                              PrimitiveSerializer.String);
                //FileName
                Assert.AreEqual(temp.TempPath, opt.FileName);
                //Key/Value serializers
                Assert.IsTrue(ReferenceEquals(opt.KeySerializer, PrimitiveSerializer.Int32));
                Assert.IsTrue(ReferenceEquals(opt.ValueSerializer, PrimitiveSerializer.String));
                //FileOptions
                Assert.AreEqual(FileOptions.WriteThrough, opt.FileOptions);
                Assert.AreEqual(FileOptions.WriteThrough | FileOptions.Asynchronous, opt.FileOptions |= FileOptions.Asynchronous);
                //Read Only
                Assert.AreEqual(false, opt.ReadOnly);
                Assert.AreEqual(true, opt.ReadOnly = true);
                //File Buffer
                Assert.AreEqual(8, opt.FileBuffer);
                Assert.AreEqual(0x40000, opt.FileBuffer = 0x40000);
                //Clone
                Assert.IsFalse(ReferenceEquals(opt, opt.Clone()));

                using(TransactionLog<int, string> log = new TransactionLog<int,string>(opt))
                    Assert.AreEqual(0, log.Size);
            }
        }
开发者ID:langimike,项目名称:CSharpTest.Net.Collections,代码行数:29,代码来源:TestTransactionLog.cs


示例11: ctor_FileInfo

 public void ctor_FileInfo()
 {
     using (var file = new TempFile())
     {
         Assert.NotNull(new CsvLexiconStorage(file.Info));
     }
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:CsvLexiconStorage.Facts.cs


示例12: ctor_string

 public void ctor_string()
 {
     using (var temp = new TempFile())
     {
         Assert.NotNull(new TsvDataSheet(temp.Info.FullName));
     }
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:TsvDataSheet.Facts.cs


示例13: SaveLoadTest

        public void SaveLoadTest()
        {
            using (var tempFile = new TempFile(_xml))
            {
                Assert.Throws<ApplicationException>(() =>
                {
                    FishSettingsBase.Load(tempFile.Name, "badName");
                });
                var settings = FishSettingsBase.Load(tempFile.Name, "name0");
                Assert.AreEqual("name0", settings.Name);
                Assert.AreEqual("version0", settings.Version);

                Assert.IsInstanceOf<System.Int32>(settings["a"]);
                Assert.AreEqual(typeof(System.Int32), settings.GetType_TESTONLY("a"));
                Assert.AreEqual(2, settings["a"]);
                Assert.AreEqual(1, settings.GetDefaultValue("a"));

                Assert.IsInstanceOf<int[]>(settings["b"]);
                Assert.AreEqual(typeof(int[]), settings.GetType_TESTONLY("b"));
                CollectionAssert.AreEqual(new [] { 3, 4, 5 }, (int[])settings["b"]);
                CollectionAssert.AreEqual(new [] { 1, 2 }, (int[])settings.GetDefaultValue("b"));

                using (var tempFile2 = new TempFile())
                {
                    settings.Save(tempFile2.Name);
                    Assert.AreEqual(tempFile.Text, tempFile2.Text);
                    FileAssert.AreEqual(tempFile.Name, tempFile2.Name);
                }
            }
        }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:30,代码来源:FishSettingsBase.test.cs


示例14: ctor_FileInfo

 public void ctor_FileInfo()
 {
     using (var temp = new TempFile())
     {
         Assert.NotNull(new ExcelWorksheet(temp.Info));
     }
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:ExcelWorksheet.Facts.cs


示例15: LoadingAndSavingTest

 public void LoadingAndSavingTest()
 {
     var text = @"version = 1.1
     document
     {
     prop1 = a
     obj1
     {
     prop2 = b
     obj2
     {
     prop3 = c
     }
     }
     }
     ";
     using (var tempFile = new TempFile(text))
     {
         var doc = FishDocument.Load(tempFile.Name);
         using (var savedFile = new TempFile())
         {
             doc.Save(savedFile.Name);
     //					TestUtility.CompareWithWinMerge(tempFile.Name, savedFile.Name);
             FileAssert.AreEqual(tempFile.Name, savedFile.Name);
         }
     }
 }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:27,代码来源:FishDocument.test.cs


示例16: DeleteWritingSystemId

		public void DeleteWritingSystemId(string id)
		{
			var fileToBeWrittenTo = new TempFile();
			var reader = XmlReader.Create(_liftFilePath, CanonicalXmlSettings.CreateXmlReaderSettings());
			var writer = XmlWriter.Create(fileToBeWrittenTo.Path, 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:jwickberg,项目名称:libpalaso,代码行数:60,代码来源:WritingSystemsInLiftFileHelper.cs


示例17: LoadingTest

        public void LoadingTest()
        {
            var text = @"
            element1
            {
            element2
            {
            text2
            }

            element3 = ""text3""
            }
            ";

            using (var tempFile = new TempFile(text))
            {
                var doc = FishDocument.Load(tempFile.Name);
                var element = doc.Items.First();

                Assert.AreEqual("element1", element.Name);
                Assert.AreEqual(2, element.Items.Count());
                int i = 0;
                {
                    var item = element.Items[i++];
                    Assert.AreEqual("element2", item.Name);
                    Assert.AreEqual("text2", item.Value);
                }
                {
                    var item = element.Items[i++];
                    Assert.AreEqual("element3", item.Name);
                    Assert.AreEqual(@"""text3""", item.Value);
                }
            }
        }
开发者ID:kaijin-games,项目名称:larning-english-game,代码行数:34,代码来源:FishDocument.test.cs


示例18: Process

        public void Process(Crawler crawler, PropertyBag propertyBag)
        {
            if (propertyBag.StatusCode != HttpStatusCode.OK)
            {
                return;
            }

            string extension = MapContentTypeToExtension(propertyBag.ContentType);
            if (extension.IsNullOrEmpty())
            {
                return;
            }

            propertyBag.Title = propertyBag.Step.Uri.PathAndQuery;
            using (TempFile temp = new TempFile())
            {
                temp.FileName += "." + extension;
                File.WriteAllBytes(temp.FileName, propertyBag.Response);
                using (FilterReader filterReader = new FilterReader(temp.FileName))
                {
                    string content = filterReader.ReadToEnd();
                    propertyBag.Text = content.Trim();
                }
            }
        }
开发者ID:bormaxi,项目名称:NCrawler,代码行数:25,代码来源:IFilterProcessor.cs


示例19: SymLinkLength

        public void SymLinkLength()
        {
            string path = GetTestFilePath();
            string linkPath = GetTestFilePath();

            const int FileSize = 2000;
            using (var tempFile = new TempFile(path, FileSize))
            {
                Assert.True(MountHelper.CreateSymbolicLink(linkPath, path, isDirectory: false));

                var info = new FileInfo(path);
                Assert.Equal(FileSize, info.Length);

                var linkInfo = new FileInfo(linkPath);
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // On Windows, symlinks have length 0.
                    Assert.Equal(0, linkInfo.Length);
                }
                else
                {
                    // On Unix, a symlink contains the path to the target, and thus has that length.
                    // But the length could actually be longer if it's not just ASCII characters.
                    // We just verify it's at least that big, but also verify that we're not accidentally
                    // getting the target file size.
                    Assert.InRange(linkInfo.Length, path.Length, FileSize - 1);
                }

                // On both, FileStream should however open the target such that its length is the target length
                using (FileStream linkFs = File.OpenRead(linkPath))
                {
                    Assert.Equal(FileSize, linkFs.Length);
                }
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:35,代码来源:Length.cs


示例20: Construct_FileDoesExistButEmpty_OK

		public void Construct_FileDoesExistButEmpty_OK()
		{
			using (var f = new TempFile())
			{
				var x = AudioFactory.CreateAudioSession(f.Path);
			}
		}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:7,代码来源:AudioRecorderTests.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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