當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。