当前位置: 首页>>代码示例>>C#>>正文


C# TempFile.Dispose方法代码示例

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


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

示例1: TestFinalizer

		public void TestFinalizer()
		{
			string filename;
			try
			{
				TempFile file = new TempFile();
				filename = file.TempPath;
				Assert.IsTrue(File.Exists(file.TempPath));

				IDisposable flock = file.Open();
				file.Dispose();

				Assert.IsTrue(File.Exists(file.TempPath));//dua, it's still open

				flock.Dispose();
				file = null;
			}
			finally { }

			//wait for GC to collect tempfile
			GC.Collect(0, GCCollectionMode.Forced);
			GC.WaitForPendingFinalizers();

			Assert.IsFalse(File.Exists(filename));
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:25,代码来源:TestTempFiles.cs

示例2: TestDispose

		public void TestDispose()
		{
			TempFile file = new TempFile();
			Assert.IsTrue(File.Exists(file.TempPath));
			Assert.IsTrue(file.Exists);

			file.Dispose();
			Assert.IsFalse(file.Exists);
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:9,代码来源:TestTempFiles.cs

示例3: RemoveTempFiles

		internal static void RemoveTempFiles(ref TempFile ourFile, ref TempFile commonFile, ref TempFile theirFile)
		{
			ourFile.Dispose();
			ourFile = null;

			commonFile.Dispose();
			commonFile = null;

			theirFile.Dispose();
			theirFile = null;
		}
开发者ID:gmartin7,项目名称:flexbridge,代码行数:11,代码来源:FieldWorksTestServices.cs

示例4: RemoveTempFilesAndParentDir

		internal static void RemoveTempFilesAndParentDir(ref TempFile ourFile, ref TempFile commonFile, ref TempFile theirFile)
		{
			var parentDir = Path.GetDirectoryName(ourFile.Path);
			ourFile.Dispose();
			ourFile = null;
			Directory.Delete(parentDir, true);

			parentDir = Path.GetDirectoryName(commonFile.Path);
			commonFile.Dispose();
			commonFile = null;
			Directory.Delete(parentDir, true);

			parentDir = Path.GetDirectoryName(theirFile.Path);
			theirFile.Dispose();
			theirFile = null;
			Directory.Delete(parentDir, true);
		}
开发者ID:gmartin7,项目名称:flexbridge,代码行数:17,代码来源:FieldWorksTestServices.cs

示例5: op_Dispose

        public void op_Dispose()
        {
            TempFile file = null;
            FileInfo info;
            try
            {
                file = new TempFile();
                info = file.Info;
            }
            finally
            {
                if (null != file)
                {
                    file.Dispose();
                }
            }

            Assert.Null(file.Info);

            info.Refresh();
            Assert.False(info.Exists);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:22,代码来源:TempFile.Facts.cs

示例6: GetXmlDomFromHtml


//.........这里部分代码省略.........
            var temp = new TempFile();
            {
                RobustFile.WriteAllText(temp.Path, content, Encoding.UTF8);
                using (var tidy = RobustIO.DocumentFromFile(temp.Path))
                {
                    tidy.ShowWarnings = false;
                    tidy.Quiet = true;
                    tidy.WrapAt = 0; // prevents textarea wrapping.
                    tidy.AddTidyMetaElement = false;
                    tidy.OutputXml = true;
                    tidy.CharacterEncoding = EncodingType.Utf8;
                    tidy.InputCharacterEncoding = EncodingType.Utf8;
                    tidy.OutputCharacterEncoding = EncodingType.Utf8;
                    tidy.DocType = DocTypeMode.Omit; //when it supports html5, then we will let it out it
                    //maybe try this? tidy.Markup = true;

                    tidy.AddXmlDeclaration = includeXmlDeclaration;

                    //NB: this does not prevent tidy from deleting <span data-libray='somethingImportant'></span>
                    tidy.MergeSpans = AutoBool.No;
                    tidy.DropEmptyParagraphs = false;
                    tidy.MergeDivs = AutoBool.No;

                    var errors = tidy.CleanAndRepair();
                    if (!string.IsNullOrEmpty(errors))
                    {
                        throw new ApplicationException(errors);
                    }
                    var newContents = tidy.Save();
                    try
                    {
                        newContents = RemoveFillerInEmptyElements(newContents);

                        newContents = newContents.Replace("&nbsp;", "&#160;");
                        //REVIEW: 1) are there others? &amp; and such are fine.  2) shoul we to convert back to &nbsp; on save?

                        // The regex here is mainly for the \s as a convenient way to remove whatever whitespace TIDY
                        // has inserted. It's a fringe benefit that we can use the[bi] to deal with both elements in one replace.
                        newContents = Regex.Replace(newContents, @"REMOVEWHITESPACE\s*<([biu]|em|strong)>", "<$1>");

                        //In BL2250, we still had REMOVEWHITESPACE sticking around sometimes. The way we reproduced it was
                        //with <u> </u>. That is, we started with
                        //"REMOVEWHITESPACE <u> </u>", then libtidy (properly) removed the <u></u>, leaving us with only
                        //"REMOVEWHITESPACE".
                        newContents = Regex.Replace(newContents, @"REMOVEWHITESPACE", "");

                        // remove blank lines at the end of style blocks
                        newContents = Regex.Replace(newContents, @"\s+<\/style>", "</style>");

                        // remove <br> elements immediately preceding </p> close tag (BL-2557)
                        // These are apparently inserted by ckeditor as far as we can tell.  They don't show up on
                        // fields that have never had a ckeditor activated, and always show up on fields that have
                        // received focus and activated an inline ckeditor.  The ideal ckeditor use case appears
                        // to be for data entry as part of a web page that get stored separately, with the data
                        // obtained something like the following in javascript:
                        //        ckedit.on('blur', function(evt) {
                        //            var editor = evt['editor'];
                        //            var data = editor.getData();
                        //            <at this point, the data looks okay, with any <br> element before the </p> tag.>
                        //            <store the data somewhere: the following lines have no effect, and may be silly.>
                        //            var div = mapCkeditDiv[editor.id];
                        //            div.innerHTML = data;
                        //        });
                        // Examining the initial value of div.innerHTML shows the unwanted <br> element, but it is
                        // not in the data returned by editor.getData().  Since assigning to div.innerHTML doesn't
                        // affect what gets written to the file, this hack was implemented instead.
                        newContents = Regex.Replace(newContents, @"(<br></br>|<br ?/>)[\r\n]*</p>", "</p>");

                        // Don't let spaces between <strong>, <em>, or <u> elements be removed. (BL-2484)
                        dom.PreserveWhitespace = true;
                        dom.LoadXml(newContents);
                    }
                    catch (Exception e)
                    {
                        var exceptionWithHtmlContents = new Exception(string.Format("{0}{2}{2}{1}",
                            e.Message, newContents, Environment.NewLine));
                        throw exceptionWithHtmlContents;
                    }
                }
            }
            try
            {
                //It's a mystery but http://jira.palaso.org/issues/browse/BL-46 was reported by several people on Win XP, even though a look at html tidy dispose indicates that it does dispose (and thus close) the stream.
                // Therefore, I'm moving the dispose to an explict call so that I can catch the error and ignore it, leaving an extra file in Temp.

                temp.Dispose();
                    //enhance... could make a version of this which collects up any failed deletes and re-attempts them with each call to this
            }
            catch (Exception error)
            {
                //swallow
                Debug.Fail("Repro of http://jira.palaso.org/issues/browse/BL-46 ");
            }

            //this is a hack... each time we write the content, we add a new <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            //so for now, we remove it when we read it in. It'll get added again when we write it out
            RemoveAllContentTypesMetas(dom);

            return dom;
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:101,代码来源:XmlHtmlConverter.cs

示例7: GetXmlDomFromHtml

        /// <summary>
        ///
        /// </summary>
        /// <param name="content"></param>
        /// <param name="includeXmlDeclaration"></param>
        /// <exception cref="">Throws if there are parsing errors</exception>
        /// <returns></returns>
        public static XmlDocument GetXmlDomFromHtml(string content, bool includeXmlDeclaration)
        {
            var dom = new XmlDocument();
            //hack. tidy deletes <span data-libray='somethingImportant'></span>
            content = content.Replace("></span>", ">REMOVEME</span>");

            //using (var temp = new TempFile())
            var temp = new TempFile();
            {
                File.WriteAllText(temp.Path, content, Encoding.UTF8);
                using (var tidy = TidyManaged.Document.FromFile(temp.Path))
                {
                    tidy.ShowWarnings = false;
                    tidy.Quiet = true;
                    tidy.WrapAt = 0; // prevents textarea wrapping.
                    tidy.AddTidyMetaElement = false;
                    tidy.OutputXml = true;
                    tidy.CharacterEncoding = EncodingType.Utf8;
                    tidy.InputCharacterEncoding = EncodingType.Utf8;
                    tidy.OutputCharacterEncoding = EncodingType.Utf8;
                    tidy.DocType = DocTypeMode.Omit; //when it supports html5, then we will let it out it
                    //maybe try this? tidy.Markup = true;

                    tidy.AddXmlDeclaration = includeXmlDeclaration;

                    //NB: this does not prevent tidy from deleting <span data-libray='somethingImportant'></span>
                    tidy.MergeSpans = AutoBool.No;
                    tidy.DropEmptyParagraphs = false;
                    tidy.MergeDivs = AutoBool.No;

                    var errors = tidy.CleanAndRepair();
                    if (!string.IsNullOrEmpty(errors))
                    {
                        throw new ApplicationException(errors + "\r\n\r\n" + content);
                    }
                    var newContents = tidy.Save();
                    try
                    {
                        newContents = newContents.Replace("&nbsp;", "&#160;");
                            //REVIEW: 1) are there others? &amp; and such are fine.  2) shoul we to convert back to &nbsp; on save?
                        newContents = newContents.Replace("REMOVEME", "");
                        dom.LoadXml(newContents);
                    }
                    catch (Exception e)
                    {
                        var exceptionWithHtmlContents = new Exception(e.Message + "\r\n\r\n" + newContents);
                        throw exceptionWithHtmlContents;
                    }
                }
            }
            try
            {
                //It's a mystery but http://jira.palaso.org/issues/browse/BL-46 was reported by several people on Win XP, even though a look at html tidy dispose indicates that it does dispose (and thus close) the stream.
                // Therefore, I'm moving the dispose to an explict call so that I can catch the error and ignore it, leaving an extra file in Temp.

                temp.Dispose();
                    //enhance... could make a version of this which collects up any failed deletes and re-attempts them with each call to this
            }
            catch (Exception error)
            {
                //swallow
                Debug.Fail("Repro of http://jira.palaso.org/issues/browse/BL-46 ");
            }

            //this is a hack... each time we write the content, we add a new <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            //so for now, we remove it when we read it in. It'll get added again when we write it out
            RemoveAllContentTypesMetas(dom);

            return dom;
        }
开发者ID:JohnThomson,项目名称:testBloom,代码行数:77,代码来源:XmlHtmlConverter.cs

示例8: TestFinalizerReschedule

		public void TestFinalizerReschedule()
		{
			IDisposable flock;
			string filename;
			try
			{
				TempFile file = new TempFile();
				filename = file.TempPath;
				Assert.IsTrue(File.Exists(file.TempPath));

				flock = file.Open();
				file.Dispose();

				Assert.IsTrue(File.Exists(file.TempPath));//dua, it's still open
				file = null;
			}
			finally { }

			//wait for GC to collect tempfile
			GC.Collect(0, GCCollectionMode.Forced);
			GC.WaitForPendingFinalizers();

			Assert.IsTrue(File.Exists(filename));

			//now the finalizer should have fire, as proven by TestFinalizer(), see if the
			//rescheduled object will finalize...

			flock.Dispose();
			GC.Collect(0, GCCollectionMode.Forced);
			GC.WaitForPendingFinalizers();

			Assert.IsFalse(File.Exists(filename));
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:33,代码来源:TestTempFiles.cs

示例9: TestPathOnDisposed

		public void TestPathOnDisposed()
		{
			TempFile f = new TempFile();
			f.Dispose();
			Assert.Fail(f.TempPath);
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:6,代码来源:TestTempFiles.cs

示例10: TestInfo

		public void TestInfo()
		{
			TempFile f = new TempFile();
			f.Length = 5;
			Assert.AreEqual(f.Length, f.Info.Length);
			f.Dispose();

			Assert.AreEqual(0, f.Length);
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:9,代码来源:TestTempFiles.cs

示例11: TestInfoOnDisposed

		public void TestInfoOnDisposed()
		{
			TempFile f = new TempFile();
			f.Dispose();
			f.Info.OpenText();
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:6,代码来源:TestTempFiles.cs

示例12: TestCopyTo

		public void TestCopyTo()
		{
			TempFile filea = new TempFile();

			File.WriteAllText(filea.TempPath, "Test");
			Assert.AreEqual("Test", File.ReadAllText(filea.TempPath));

			TempFile fileb = new TempFile();
			Assert.AreNotEqual(filea.TempPath, fileb.TempPath);

			filea.CopyTo(fileb.TempPath, true);
			Assert.AreEqual("Test", File.ReadAllText(fileb.TempPath));

			File.Delete(filea.TempPath);
			Assert.IsFalse(File.Exists(filea.TempPath));

			fileb.CopyTo(filea.TempPath);
			Assert.AreEqual("Test", File.ReadAllText(filea.TempPath));

			filea.Dispose();
			fileb.Dispose();
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:22,代码来源:TestTempFiles.cs

示例13: TestDetach

		public void TestDetach()
		{
			TempFile filea = new TempFile();
			string path = filea.TempPath;
			Assert.IsTrue(File.Exists(path));

			Assert.AreEqual(path, filea.Detatch());
			Assert.IsTrue(File.Exists(path));
			filea.Dispose();
			Assert.IsTrue(File.Exists(path));

			File.Delete(path);
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:13,代码来源:TestTempFiles.cs

示例14: TestFileDelete

		public void TestFileDelete()
		{
			TempFile file = new TempFile();

			Assert.IsTrue(File.Exists(file.TempPath));
			TempFile.Delete(file.TempPath);

			Assert.IsFalse(File.Exists(file.TempPath));
			file.Dispose();

			//ignres bad paths:
			TempFile.Delete("@~+_(%!&($_~!(&*+%_~&^%^|||&&&\\\\ THIS IS AN INVALID FILE NAME.*");
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:13,代码来源:TestTempFiles.cs

示例15: TestFileReadAccess

		public void TestFileReadAccess()
		{
			TempFile file = new TempFile();

			Stream r = file.Read();
			Assert.IsFalse(r.CanWrite);
			Assert.IsTrue(r.CanRead);

			Stream o = file.Open();
			Assert.IsTrue(o.CanWrite);
			Assert.IsTrue(o.CanRead);

			o.Dispose();
			r.Dispose();
			file.Dispose();
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:16,代码来源:TestTempFiles.cs


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