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


C# FilePath.Exists方法代码示例

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


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

示例1: TestLockMissing_RealIndex

		public virtual void TestLockMissing_RealIndex()
		{
			FilePath idx = new FilePath(db.Directory, "index");
			FilePath lck = new FilePath(db.Directory, "index.lock");
			NUnit.Framework.Assert.IsFalse(idx.Exists());
			NUnit.Framework.Assert.IsFalse(lck.Exists());
			DirCache dc = db.LockDirCache();
			NUnit.Framework.Assert.IsNotNull(dc);
			NUnit.Framework.Assert.IsFalse(idx.Exists());
			NUnit.Framework.Assert.IsTrue(lck.Exists());
			NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
			dc.Unlock();
			NUnit.Framework.Assert.IsFalse(idx.Exists());
			NUnit.Framework.Assert.IsFalse(lck.Exists());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:15,代码来源:DirCacheBasicTest.cs

示例2: 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

示例3: TestDeleteFile

		public virtual void TestDeleteFile()
		{
			FilePath f = new FilePath(trash, "test");
			FileUtils.CreateNewFile(f);
			FileUtils.Delete(f);
			NUnit.Framework.Assert.IsFalse(f.Exists());
			try
			{
				FileUtils.Delete(f);
				NUnit.Framework.Assert.Fail("deletion of non-existing file must fail");
			}
			catch (IOException)
			{
			}
			// expected
			try
			{
				FileUtils.Delete(f, FileUtils.SKIP_MISSING);
			}
			catch (IOException)
			{
				NUnit.Framework.Assert.Fail("deletion of non-existing file must not fail with option SKIP_MISSING"
					);
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:25,代码来源:FileUtilTest.cs

示例4: TestReadMissing_RealIndex

		public virtual void TestReadMissing_RealIndex()
		{
			FilePath idx = new FilePath(db.Directory, "index");
			NUnit.Framework.Assert.IsFalse(idx.Exists());
			DirCache dc = db.ReadDirCache();
			NUnit.Framework.Assert.IsNotNull(dc);
			NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:8,代码来源:DirCacheBasicTest.cs

示例5: FileDocument

		/// <summary>Create a FileDocument</summary>
		/// <param name="file"></param>
		public FileDocument(FilePath file)
		{
			if (!file.Exists())
			{
				throw new RuntimeException("File Not Found");
			}
			this.file = file;
		}
开发者ID:Gianluigi,项目名称:dssnet,代码行数:10,代码来源:FileDocument.cs

示例6: TestReadMissing_TempIndex

		public virtual void TestReadMissing_TempIndex()
		{
			FilePath idx = new FilePath(db.Directory, "tmp_index");
			NUnit.Framework.Assert.IsFalse(idx.Exists());
			DirCache dc = DirCache.Read(idx, db.FileSystem);
			NUnit.Framework.Assert.IsNotNull(dc);
			NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:8,代码来源:DirCacheBasicTest.cs

示例7: DeleteRecursive

		public static bool DeleteRecursive(FilePath fileOrDirectory)
		{
			if (fileOrDirectory.IsDirectory())
			{
				foreach (FilePath child in fileOrDirectory.ListFiles())
				{
					DeleteRecursive(child);
				}
			}
			bool result = fileOrDirectory.Delete() || !fileOrDirectory.Exists();
			return result;
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:12,代码来源:FileDirUtils.cs

示例8: 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

示例9: 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

示例10: BlobStore

        public BlobStore(string path, SymmetricKey encryptionKey)
        {
            if (path == null) {
                throw new ArgumentNullException("path");
            }

            _path = path;
            EncryptionKey = encryptionKey;
            FilePath directory = new FilePath(path);
            if (directory.Exists() && directory.IsDirectory()) {
                // Existing blob-store.
                VerifyExistingStore();
            } else {
                // New blob store; create directory:
                directory.Mkdirs();
                if (!directory.IsDirectory()) {
                    throw new InvalidOperationException(string.Format("Unable to create directory for: {0}", directory));
                }

                if (encryptionKey != null) {
                    MarkEncrypted(true);
                }
            }
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:24,代码来源:BlobStore.cs

示例11: LoadGrobalConfig

        /// <summary>
        /// グローバル設定ファイル読み込み
        /// </summary>
        public GrobalConfigEntity LoadGrobalConfig()
        {
            FilePath gitconfig = new FilePath(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".gitconfig");

            if (!gitconfig.Exists())
            {
                return null;
            }
            FileBasedConfig config = new FileBasedConfig(gitconfig, FS.Detect());

            config.Load();
/*
            string text = config.ToText();

            foreach (string section in config.GetSections())
            {
                Console.Out.WriteLine("section = {0}", section);

                if (config.GetSubsections(section).Count > 0)
                {
                    foreach (string subsection in config.GetSubsections(section))
                    {
                        Console.Out.WriteLine(" subsection = {0}", subsection);

                        foreach (string name in config.GetNames(section, subsection))
                        {
                            Console.Out.WriteLine("  name = {0} / value = {1}", name, config.GetString(section, subsection, name));
                        }
                    }
                }
                else
                {
                    foreach (string name in config.GetNames(section))
                    {
                        Console.Out.WriteLine("  name = {0} / value = {1}", name, config.GetString(section, null, name));
                    }
                }
            }
*/
            GrobalConfigEntity result = new GrobalConfigEntity();

            result.EMail = config.GetString("user", null, "email");
            result.Name = config.GetString("user", null, "name");

            if (result.EMail == null || result.Name == null)
            {
                return null;
            }
            return result;
        }
开发者ID:SatoKazuto,项目名称:BluePlumGit,代码行数:53,代码来源:MainWindowModel.cs

示例12: Delete

		/// <summary>Delete file or folder</summary>
		/// <param name="f">
		/// <code>File</code>
		/// to be deleted
		/// </param>
		/// <param name="options">
		/// deletion options,
		/// <code>RECURSIVE</code>
		/// for recursive deletion of
		/// a subtree,
		/// <code>RETRY</code>
		/// to retry when deletion failed.
		/// Retrying may help if the underlying file system doesn't allow
		/// deletion of files being read by another thread.
		/// </param>
		/// <exception cref="System.IO.IOException">
		/// if deletion of
		/// <code>f</code>
		/// fails. This may occur if
		/// <code>f</code>
		/// didn't exist when the method was called. This can therefore
		/// cause IOExceptions during race conditions when multiple
		/// concurrent threads all try to delete the same file.
		/// </exception>
		public static void Delete(FilePath f, int options)
		{
			if ((options & SKIP_MISSING) != 0 && !f.Exists())
			{
				return;
			}
			if ((options & RECURSIVE) != 0 && f.IsDirectory())
			{
				FilePath[] items = f.ListFiles();
				if (items != null)
				{
					foreach (FilePath c in items)
					{
						Delete(c, options);
					}
				}
			}
			if (!f.Delete())
			{
				if ((options & RETRY) != 0 && f.Exists())
				{
					for (int i = 1; i < 10; i++)
					{
						try
						{
							Sharpen.Thread.Sleep(100);
						}
						catch (Exception)
						{
						}
						// ignore
						if (f.Delete())
						{
							return;
						}
					}
				}
				throw new IOException(MessageFormat.Format(JGitText.Get().deleteFileFailed, f.GetAbsolutePath
					()));
			}
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:65,代码来源:FileUtils.cs

示例13: SaveConfig

        /// <summary>
        /// 設定のファイル保存
        /// </summary>
        /// <param name="config">設定</param>
        public void SaveConfig(ConfigEntity config)
        {
            FilePath path = new FilePath(MainWindowModel.ApplicationDataPath);

            if (!path.Exists())
            {
                path.Mkdir();
            }
            string json = JsonConvert.SerializeObject(config, new Newtonsoft.Json.Converters.StringEnumConverter());

            StreamWriter sw = new StreamWriter(MainWindowModel.ConfigFile, false, Encoding.UTF8);

            sw.Write(json);

            sw.Close();
        }
开发者ID:SatoKazuto,项目名称:BluePlumGit,代码行数:20,代码来源:MainWindowModel.cs

示例14: TestMergeRemovingFoldersWithoutFastForward

 public virtual void TestMergeRemovingFoldersWithoutFastForward()
 {
     FilePath folder1 = new FilePath(db.WorkTree, "folder1");
     FilePath folder2 = new FilePath(db.WorkTree, "folder2");
     FileUtils.Mkdir(folder1);
     FileUtils.Mkdir(folder2);
     FilePath file = new FilePath(folder1, "file1.txt");
     Write(file, "folder1--file1.txt");
     file = new FilePath(folder1, "file2.txt");
     Write(file, "folder1--file2.txt");
     file = new FilePath(folder2, "file1.txt");
     Write(file, "folder--file1.txt");
     file = new FilePath(folder2, "file2.txt");
     Write(file, "folder2--file2.txt");
     Git git = new Git(db);
     git.Add().AddFilepattern(folder1.GetName()).AddFilepattern(folder2.GetName()).Call
         ();
     RevCommit @base = git.Commit().SetMessage("adding folders").Call();
     RecursiveDelete(folder1);
     RecursiveDelete(folder2);
     git.Rm().AddFilepattern("folder1/file1.txt").AddFilepattern("folder1/file2.txt").
         AddFilepattern("folder2/file1.txt").AddFilepattern("folder2/file2.txt").Call();
     RevCommit other = git.Commit().SetMessage("removing folders on 'branch'").Call();
     git.Checkout().SetName(@base.Name).Call();
     file = new FilePath(folder2, "file3.txt");
     Write(file, "folder2--file3.txt");
     git.Add().AddFilepattern(folder2.GetName()).Call();
     git.Commit().SetMessage("adding another file").Call();
     MergeCommandResult result = git.Merge().Include(other.Id).SetStrategy(MergeStrategy
         .RESOLVE).Call();
     NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
     NUnit.Framework.Assert.IsFalse(folder1.Exists());
 }
开发者ID:OrangeCloudNetworks,项目名称:ngit,代码行数:33,代码来源:MergeCommandTest.cs

示例15: Delete

        /// <summary>
        /// Deletes the <see cref="Couchbase.Lite.Database" />.
        /// </summary>
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException">
        /// Thrown if an issue occurs while deleting the <see cref="Couchbase.Lite.Database" /></exception>
        public void Delete()
        {
            if (_isOpen && !Close())
            {
                throw new CouchbaseLiteException("The database was open, and could not be closed", StatusCode.InternalServerError);
            }

            Manager.ForgetDatabase(this);
            if (!Exists())
            {
                return;
            }

            var file = new FilePath(Path);
            var fileJournal = new FilePath(AttachmentStorePath + "-journal");

            var deleteStatus = file.Delete();
            if (fileJournal.Exists())
            {
                deleteStatus &= fileJournal.Delete();
            }

            //recursively delete attachments path
            var attachmentsFile = new FilePath(AttachmentStorePath);
            var deleteAttachmentStatus = FileDirUtils.DeleteRecursive(attachmentsFile);

            //recursively delete path where attachments stored( see getAttachmentStorePath())
            var lastDotPosition = Path.LastIndexOf('.');
            if (lastDotPosition > 0)
            {
                var attachmentsFileUpFolder = new FilePath(Path.Substring(0, lastDotPosition));
                FileDirUtils.DeleteRecursive(attachmentsFileUpFolder);
            }

            if (!deleteStatus)
            {
                Log.V(Tag, String.Format("Error deleting the SQLite database file at {0}", file.GetAbsolutePath()));
            }

            if (!deleteStatus)
            {
                throw new CouchbaseLiteException("Was not able to delete the database file", StatusCode.InternalServerError);
            }

            if (!deleteAttachmentStatus)
            {
                throw new CouchbaseLiteException("Was not able to delete the attachments files", StatusCode.InternalServerError);
            }
        }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:54,代码来源:Database.cs


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