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


C# Sharpen.FilePath类代码示例

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


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

示例1: SetupRepository

		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="NGit.Api.Errors.NoFilepatternException"></exception>
		/// <exception cref="NGit.Api.Errors.NoHeadException"></exception>
		/// <exception cref="NGit.Api.Errors.NoMessageException"></exception>
		/// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException"></exception>
		/// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
		/// <exception cref="NGit.Api.Errors.WrongRepositoryStateException"></exception>
		public virtual void SetupRepository()
		{
			// create initial commit
			git = new Git(db);
			initialCommit = git.Commit().SetMessage("initial commit").Call();
			// create file
			indexFile = new FilePath(db.WorkTree, "a.txt");
			FileUtils.CreateNewFile(indexFile);
			PrintWriter writer = new PrintWriter(indexFile);
			writer.Write("content");
			writer.Flush();
			// add file and commit it
			git.Add().AddFilepattern("a.txt").Call();
			secondCommit = git.Commit().SetMessage("adding a.txt").Call();
			prestage = DirCache.Read(db.GetIndexFile(), db.FileSystem).GetEntry(indexFile.GetName
				());
			// modify file and add to index
			writer.Write("new content");
			writer.Close();
			git.Add().AddFilepattern("a.txt").Call();
			// create a file not added to the index
			untrackedFile = new FilePath(db.WorkTree, "notAddedToIndex.txt");
			FileUtils.CreateNewFile(untrackedFile);
			PrintWriter writer2 = new PrintWriter(untrackedFile);
			writer2.Write("content");
			writer2.Close();
		}
开发者ID:shoff,项目名称:ngit,代码行数:34,代码来源:ResetCommandTest.cs

示例2: CopyFile

		/// <exception cref="System.IO.IOException"></exception>
		protected internal static void CopyFile(FilePath src, FilePath dst)
		{
			FileInputStream fis = new FileInputStream(src);
			try
			{
				FileOutputStream fos = new FileOutputStream(dst);
				try
				{
					byte[] buf = new byte[4096];
					int r;
					while ((r = fis.Read(buf)) > 0)
					{
						fos.Write(buf, 0, r);
					}
				}
				finally
				{
					fos.Close();
				}
			}
			finally
			{
				fis.Close();
			}
		}
开发者ID:shoff,项目名称:ngit,代码行数:26,代码来源:RepositoryTestCase.cs

示例3: RunFileIfExists

		private static void RunFileIfExists(Context cx, Scriptable global, FilePath f)
		{
			if (f.IsFile())
			{
				Main.ProcessFileNoThrow(cx, global, f.GetPath());
			}
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:7,代码来源:ShellTest.cs

示例4: DiscoverGitPrefix

		protected internal override FilePath DiscoverGitPrefix()
		{
			string path = SystemReader.GetInstance().Getenv("PATH");
			FilePath gitExe = SearchPath(path, "git");
			if (gitExe != null)
			{
				return gitExe.GetParentFile().GetParentFile();
			}
			if (SystemReader.GetInstance().IsMacOS())
			{
				// On MacOSX, PATH is shorter when Eclipse is launched from the
				// Finder than from a terminal. Therefore try to launch bash as a
				// login shell and search using that.
				//
				string w = ReadPipe(UserHome(), new string[] { "bash", "--login", "-c", "which git"
					 }, Encoding.Default.Name());
				//
				//
				if (w == null || w.Length == 0)
				{
					return null;
				}
				FilePath parentFile = new FilePath(w).GetParentFile();
				if (parentFile == null)
				{
					return null;
				}
				return parentFile.GetParentFile();
			}
			return null;
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:31,代码来源:FS_POSIX.cs

示例5: TestAddUnstagedChanges

 public virtual void TestAddUnstagedChanges()
 {
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content");
     writer.Close();
     Git git = new Git(db);
     git.Add().AddFilepattern("a.txt").Call();
     RevCommit commit = git.Commit().SetMessage("initial commit").Call();
     TreeWalk tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
     NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", tw.GetObjectId
         (0).GetName());
     writer = new PrintWriter(file);
     writer.Write("content2");
     writer.Close();
     commit = git.Commit().SetMessage("second commit").Call();
     tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
     NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", tw.GetObjectId
         (0).GetName());
     commit = git.Commit().SetAll(true).SetMessage("third commit").SetAll(true).Call();
     tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
     NUnit.Framework.Assert.AreEqual("db00fd65b218578127ea51f3dffac701f12f486a", tw.GetObjectId
         (0).GetName());
 }
开发者ID:dprothero,项目名称:ngit,代码行数:25,代码来源:CommitAndLogCommandTests.cs

示例6: LoadFromPathArray

		/// <exception cref="System.IO.IOException"></exception>
		private ModuleSource LoadFromPathArray(string moduleId, Scriptable paths, object validator)
		{
			long llength = ScriptRuntime.ToUint32(ScriptableObject.GetProperty(paths, "length"));
			// Yeah, I'll ignore entries beyond Integer.MAX_VALUE; so sue me.
			int ilength = llength > int.MaxValue ? int.MaxValue : (int)llength;
			for (int i = 0; i < ilength; ++i)
			{
				string path = EnsureTrailingSlash(ScriptableObject.GetTypedProperty<string>(paths, i));
				try
				{
					Uri uri = new Uri(path);
					if (!uri.IsAbsoluteUri)
					{
						uri = new FilePath(path).ToURI().Resolve(string.Empty);
					}
					ModuleSource moduleSource = LoadFromUri(uri.Resolve(moduleId), uri, validator);
					if (moduleSource != null)
					{
						return moduleSource;
					}
				}
				catch (URISyntaxException e)
				{
					throw new UriFormatException(e.Message);
				}
			}
			return null;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:29,代码来源:ModuleSourceProviderBase.cs

示例7: ReadBytes

		public static sbyte[] ReadBytes(FilePath file)
		{
			int length = (int)file.Length();
			// should only be zero if loading from a network or similar
			System.Diagnostics.Debug.Assert((length != 0));
			sbyte[] bytes = new sbyte[length];
			int totalBytesRead = 0;
			FileInputStream inputStream = null;
			try
			{
				inputStream = new FileInputStream(file);
				while (totalBytesRead != length)
				{
					int bytesRead = inputStream.Read(bytes, totalBytesRead, length - totalBytesRead);
					if (bytesRead == -1)
					{
						break;
					}
					totalBytesRead += bytesRead;
				}
			}
			finally
			{
				if (inputStream != null)
				{
					inputStream.Close();
				}
			}
			return bytes;
		}
开发者ID:renaud91,项目名称:n-metadata-extractor,代码行数:30,代码来源:FileUtil.cs

示例8: TestSameDiff

		public virtual void TestSameDiff()
		{
			Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test");
			FilePath folder = new FilePath(db.Directory.GetParent(), "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "\n\n\n\nfolder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "\n\n\n\nfolder change");
			PatchIdDiffFormatter df = new PatchIdDiffFormatter();
			df.SetRepository(db);
			df.SetPathFilter(PathFilter.Create("folder"));
			DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator newTree = new FileTreeIterator(db);
			df.Format(oldTree, newTree);
			df.Flush();
			NUnit.Framework.Assert.AreEqual("08fca5ac531383eb1da8bf6b6f7cf44411281407", df.GetCalulatedPatchId
				().Name);
			Write(new FilePath(folder, "folder.txt"), "a\n\n\n\nfolder");
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "a\n\n\n\nfolder change");
			df = new PatchIdDiffFormatter();
			df.SetRepository(db);
			df.SetPathFilter(PathFilter.Create("folder"));
			oldTree = new DirCacheIterator(db.ReadDirCache());
			newTree = new FileTreeIterator(db);
			df.Format(oldTree, newTree);
			df.Flush();
			NUnit.Framework.Assert.AreEqual("08fca5ac531383eb1da8bf6b6f7cf44411281407", df.GetCalulatedPatchId
				().Name);
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:33,代码来源:PatchIdDiffFormatterTest.cs

示例9: ReadFully

		/// <summary>Read an entire local file into memory as a byte array.</summary>
		/// <remarks>Read an entire local file into memory as a byte array.</remarks>
		/// <param name="path">location of the file to read.</param>
		/// <param name="max">
		/// maximum number of bytes to read, if the file is larger than
		/// this limit an IOException is thrown.
		/// </param>
		/// <returns>complete contents of the requested local file.</returns>
		/// <exception cref="System.IO.FileNotFoundException">the file does not exist.</exception>
		/// <exception cref="System.IO.IOException">the file exists, but its contents cannot be read.
		/// 	</exception>
		public static byte[] ReadFully(FilePath path, int max)
		{
			FileInputStream @in = new FileInputStream(path);
			try
			{
				long sz = @in.GetChannel().Size();
				if (sz > max)
				{
					throw new IOException(MessageFormat.Format(JGitText.Get().fileIsTooLarge, path));
				}
				byte[] buf = new byte[(int)sz];
				IOUtil.ReadFully(@in, buf, 0, buf.Length);
				return buf;
			}
			finally
			{
				try
				{
					@in.Close();
				}
				catch (IOException)
				{
				}
			}
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:36,代码来源:IOUtil.cs

示例10: ReadSome

		/// <summary>Read at most limit bytes from the local file into memory as a byte array.
		/// 	</summary>
		/// <remarks>Read at most limit bytes from the local file into memory as a byte array.
		/// 	</remarks>
		/// <param name="path">location of the file to read.</param>
		/// <param name="limit">
		/// maximum number of bytes to read, if the file is larger than
		/// only the first limit number of bytes are returned
		/// </param>
		/// <returns>
		/// complete contents of the requested local file. If the contents
		/// exceeds the limit, then only the limit is returned.
		/// </returns>
		/// <exception cref="System.IO.FileNotFoundException">the file does not exist.</exception>
		/// <exception cref="System.IO.IOException">the file exists, but its contents cannot be read.
		/// 	</exception>
		public static byte[] ReadSome(FilePath path, int limit)
		{
			FileInputStream @in = new FileInputStream(path);
			try
			{
				byte[] buf = new byte[limit];
				int cnt = 0;
				for (; ; )
				{
					int n = @in.Read(buf, cnt, buf.Length - cnt);
					if (n <= 0)
					{
						break;
					}
					cnt += n;
				}
				if (cnt == buf.Length)
				{
					return buf;
				}
				byte[] res = new byte[cnt];
				System.Array.Copy(buf, 0, res, 0, cnt);
				return res;
			}
			finally
			{
				try
				{
					@in.Close();
				}
				catch (IOException)
				{
				}
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:51,代码来源:IOUtil.cs

示例11: KeyStoreCertificateSource

 /// <summary>The default constructor for MockTSLCertificateSource.</summary>
 /// <remarks>The default constructor for MockTSLCertificateSource.</remarks>
 public KeyStoreCertificateSource(FilePath keyStoreFile, string keyStoreType, string
      password)
 {
     this.keyStoreFile = keyStoreFile;
     this.keyStoreType = keyStoreType;
     this.password = password;
 }
开发者ID:Gianluigi,项目名称:dssnet,代码行数:9,代码来源:KeyStoreCertificateSource.cs

示例12: Test001_Initalize

		public virtual void Test001_Initalize()
		{
			FilePath gitdir = new FilePath(trash, Constants.DOT_GIT);
			FilePath hooks = new FilePath(gitdir, "hooks");
			FilePath objects = new FilePath(gitdir, "objects");
			FilePath objects_pack = new FilePath(objects, "pack");
			FilePath objects_info = new FilePath(objects, "info");
			FilePath refs = new FilePath(gitdir, "refs");
			FilePath refs_heads = new FilePath(refs, "heads");
			FilePath refs_tags = new FilePath(refs, "tags");
			FilePath HEAD = new FilePath(gitdir, "HEAD");
			NUnit.Framework.Assert.IsTrue(trash.IsDirectory(), "Exists " + trash);
			NUnit.Framework.Assert.IsTrue(hooks.IsDirectory(), "Exists " + hooks);
			NUnit.Framework.Assert.IsTrue(objects.IsDirectory(), "Exists " + objects);
			NUnit.Framework.Assert.IsTrue(objects_pack.IsDirectory(), "Exists " + objects_pack
				);
			NUnit.Framework.Assert.IsTrue(objects_info.IsDirectory(), "Exists " + objects_info
				);
			NUnit.Framework.Assert.AreEqual(2L, objects.ListFiles().Length);
			NUnit.Framework.Assert.IsTrue(refs.IsDirectory(), "Exists " + refs);
			NUnit.Framework.Assert.IsTrue(refs_heads.IsDirectory(), "Exists " + refs_heads);
			NUnit.Framework.Assert.IsTrue(refs_tags.IsDirectory(), "Exists " + refs_tags);
			NUnit.Framework.Assert.IsTrue(HEAD.IsFile(), "Exists " + HEAD);
			NUnit.Framework.Assert.AreEqual(23, HEAD.Length());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:25,代码来源:T0003_BasicTest.cs

示例13: SetUp

 public override void SetUp()
 {
     base.SetUp();
     dbTarget = CreateWorkRepository();
     source = new Git(db);
     target = new Git(dbTarget);
     // put some file in the source repo
     sourceFile = new FilePath(db.WorkTree, "SomeFile.txt");
     WriteToFile(sourceFile, "Hello world");
     // and commit it
     source.Add().AddFilepattern("SomeFile.txt").Call();
     source.Commit().SetMessage("Initial commit for source").Call();
     // configure the target repo to connect to the source via "origin"
     StoredConfig targetConfig = ((FileBasedConfig)dbTarget.GetConfig());
     targetConfig.SetString("branch", "master", "remote", "origin");
     targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
     RemoteConfig config = new RemoteConfig(targetConfig, "origin");
     config.AddURI(new URIish(source.GetRepository().WorkTree.GetPath()));
     config.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
     config.Update(targetConfig);
     targetConfig.Save();
     targetFile = new FilePath(dbTarget.WorkTree, "SomeFile.txt");
     // make sure we have the same content
     target.Pull().Call();
     target.Checkout().SetStartPoint("refs/remotes/origin/master").SetName("master").Call
         ();
     targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
     targetConfig.SetBoolean("branch", "master", "rebase", true);
     targetConfig.Save();
     AssertFileContentsEqual(targetFile, "Hello world");
 }
开发者ID:nnieslan,项目名称:ngit,代码行数:31,代码来源:PullCommandWithRebaseTest.cs

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

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


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