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


C# FilePath.CreateNewFile方法代码示例

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


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

示例1: CopyFile

		/// <exception cref="System.IO.IOException"></exception>
		public static void CopyFile(FilePath sourceFile, FilePath destFile)
		{
			if (!destFile.Exists())
			{
				destFile.CreateNewFile();
			}
			FileChannel source = null;
			FileChannel destination = null;
			try
			{
				source = new FileInputStream(sourceFile).GetChannel();
				destination = new FileOutputStream(destFile).GetChannel();
				destination.TransferFrom(source, 0, source.Size());
			}
			finally
			{
				if (source != null)
				{
					source.Close();
				}
				if (destination != null)
				{
					destination.Close();
				}
			}
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:27,代码来源:FileDirUtils.cs

示例2: TestInitNonEmptyRepository

		public virtual void TestInitNonEmptyRepository()
		{
			FilePath directory = CreateTempDirectory("testInitRepository2");
			FilePath someFile = new FilePath(directory, "someFile");
			someFile.CreateNewFile();
			NUnit.Framework.Assert.IsTrue(someFile.Exists());
			NUnit.Framework.Assert.IsTrue(directory.ListFiles().Length > 0);
			InitCommand command = new InitCommand();
			command.SetDirectory(directory);
			Repository repository = command.Call().GetRepository();
			AddRepoToClose(repository);
			NUnit.Framework.Assert.IsNotNull(repository);
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:13,代码来源:InitCommandTest.cs

示例3: TestUpgradeOldDatabaseFiles

		/// <exception cref="System.Exception"></exception>
		public virtual void TestUpgradeOldDatabaseFiles()
		{
			string directoryName = "test-directory-" + Runtime.CurrentTimeMillis();
			string normalFilesDir = GetRootDirectory().GetAbsolutePath();
			string fakeFilesDir = string.Format("%s/%s", normalFilesDir, directoryName);
			FilePath directory = new FilePath(fakeFilesDir);
			if (!directory.Exists())
			{
				bool result = directory.Mkdir();
				if (!result)
				{
					throw new IOException("Unable to create directory " + directory);
				}
			}
			FilePath oldTouchDbFile = new FilePath(directory, string.Format("old%s", Manager.
				DatabaseSuffixOld));
			oldTouchDbFile.CreateNewFile();
			FilePath newCbLiteFile = new FilePath(directory, string.Format("new%s", Manager.DatabaseSuffix
				));
			newCbLiteFile.CreateNewFile();
			FilePath migratedOldFile = new FilePath(directory, string.Format("old%s", Manager
				.DatabaseSuffix));
			migratedOldFile.CreateNewFile();
			base.StopCBLite();
			manager = new Manager(new FilePath(GetRootDirectory(), directoryName), Manager.DefaultOptions
				);
			NUnit.Framework.Assert.IsTrue(migratedOldFile.Exists());
			//cannot rename old.touchdb in old.cblite, old.cblite already exists
			NUnit.Framework.Assert.IsTrue(oldTouchDbFile.Exists());
			NUnit.Framework.Assert.IsTrue(newCbLiteFile.Exists());
			FilePath dir = new FilePath(GetRootDirectory(), directoryName);
			NUnit.Framework.Assert.AreEqual(3, dir.ListFiles().Length);
			base.StopCBLite();
			migratedOldFile.Delete();
			manager = new Manager(new FilePath(GetRootDirectory(), directoryName), Manager.DefaultOptions
				);
			//rename old.touchdb in old.cblite, previous old.cblite already doesn't exist
			NUnit.Framework.Assert.IsTrue(migratedOldFile.Exists());
			NUnit.Framework.Assert.IsTrue(oldTouchDbFile.Exists() == false);
			NUnit.Framework.Assert.IsTrue(newCbLiteFile.Exists());
			dir = new FilePath(GetRootDirectory(), directoryName);
			NUnit.Framework.Assert.AreEqual(2, dir.ListFiles().Length);
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:44,代码来源:ManagerTest.cs

示例4: TestRefsChangedStackOverflow

		public virtual void TestRefsChangedStackOverflow()
		{
			FileRepository newRepo = CreateBareRepository();
			RefDatabase refDb = newRepo.RefDatabase;
			FilePath packedRefs = new FilePath(newRepo.Directory, "packed-refs");
			NUnit.Framework.Assert.IsTrue(packedRefs.CreateNewFile());
			AtomicReference<StackOverflowError> error = new AtomicReference<StackOverflowError
				>();
			AtomicReference<IOException> exception = new AtomicReference<IOException>();
			AtomicInteger changeCount = new AtomicInteger();
			newRepo.Listeners.AddRefsChangedListener(new _RefsChangedListener_1156(refDb, changeCount
				, error, exception));
			refDb.GetRefs("ref");
			refDb.GetRefs("ref");
			NUnit.Framework.Assert.IsNull(error.Get());
			NUnit.Framework.Assert.IsNull(exception.Get());
			NUnit.Framework.Assert.AreEqual(1, changeCount.Get());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:18,代码来源:RefDirectoryTest.cs

示例5: Checkout

		/// <summary>Execute this checkout</summary>
		/// <returns>
		/// <code>false</code> if this method could not delete all the files
		/// which should be deleted (e.g. because of of the files was
		/// locked). In this case
		/// <see cref="GetToBeDeleted()">GetToBeDeleted()</see>
		/// lists the files
		/// which should be tried to be deleted outside of this method.
		/// Although <code>false</code> is returned the checkout was
		/// successful and the working tree was updated for all other files.
		/// <code>true</code> is returned when no such problem occurred
		/// </returns>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual bool Checkout()
		{
			toBeDeleted.Clear();
			if (headCommitTree != null)
			{
				PreScanTwoTrees();
			}
			else
			{
				PrescanOneTree();
			}
			if (!conflicts.IsEmpty())
			{
				if (failOnConflict)
				{
					dc.Unlock();
					throw new CheckoutConflictException(Sharpen.Collections.ToArray(conflicts, new string
						[conflicts.Count]));
				}
				else
				{
					CleanUpConflicts();
				}
			}
			// update our index
			builder.Finish();
			FilePath file = null;
			string last = string.Empty;
			// when deleting files process them in the opposite order as they have
			// been reported. This ensures the files are deleted before we delete
			// their parent folders
			for (int i = removed.Count - 1; i >= 0; i--)
			{
				string r = removed[i];
				file = new FilePath(repo.WorkTree, r);
				if (!file.Delete() && file.Exists())
				{
					toBeDeleted.AddItem(r);
				}
				else
				{
					if (!IsSamePrefix(r, last))
					{
						RemoveEmptyParents(file);
					}
					last = r;
				}
			}
			if (file != null)
			{
				RemoveEmptyParents(file);
			}
			foreach (string path in updated.Keys)
			{
				// ... create/overwrite this file ...
				file = new FilePath(repo.WorkTree, path);
				file.GetParentFile().Mkdirs();
				file.CreateNewFile();
				DirCacheEntry entry = dc.GetEntry(path);
				CheckoutEntry(repo, file, entry);
			}
			// commit the index builder - a new index is persisted
			if (!builder.Commit())
			{
				dc.Unlock();
				throw new IndexWriteException();
			}
			return toBeDeleted.Count == 0;
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:82,代码来源:DirCacheCheckout.cs

示例6: CreateNewFile

 /// <summary>
 /// Atomically creates a new, empty file named by this abstract pathname if
 /// and only if a file with this name does not yet exist.
 /// </summary>
 /// <remarks>
 /// Atomically creates a new, empty file named by this abstract pathname if
 /// and only if a file with this name does not yet exist. The check for the
 /// existence of the file and the creation of the file if it does not exist
 /// are a single operation that is atomic with respect to all other
 /// filesystem activities that might affect the file.
 /// <p>
 /// Note: this method should not be used for file-locking, as the resulting
 /// protocol cannot be made to work reliably. The
 /// <see cref="Sharpen.FileLock">Sharpen.FileLock</see>
 /// facility
 /// should be used instead.
 /// </remarks>
 /// <param name="f">the file to be created</param>
 /// <exception cref="System.IO.IOException">if the named file already exists or if an I/O error occurred
 /// 	</exception>
 public static void CreateNewFile(FilePath f)
 {
     if (!f.CreateNewFile())
     {
         throw new IOException(MessageFormat.Format(JGitText.Get().createNewFileFailed, f)
             );
     }
 }
开发者ID:kenji-tan,项目名称:ngit,代码行数:28,代码来源:FileUtils.cs


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