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


C# IFileSystem.OpenFile方法代码示例

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


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

示例1: Move

        public void Move(IFileSystem source, FileSystemPath sourcePath, IFileSystem destination, FileSystemPath destinationPath)
        {
            bool isFile;
            if ((isFile = sourcePath.IsFile) != destinationPath.IsFile)
                throw new ArgumentException("The specified destination-path is of a different type than the source-path.");

            if (isFile)
            {
                using (var sourceStream = source.OpenFile(sourcePath, FileAccess.Read))
                {
                    using (var destinationStream = destination.CreateFile(destinationPath))
                    {
                        byte[] buffer = new byte[BufferSize];
                        int readBytes;
                        while ((readBytes = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
                            destinationStream.Write(buffer, 0, readBytes);
                    }
                }
                source.Delete(sourcePath);
            }
            else
            {
                destination.CreateDirectory(destinationPath);
                foreach (var ep in source.GetEntities(sourcePath).ToArray())
                {
                    var destinationEntityPath = ep.IsFile
                                                    ? destinationPath.AppendFile(ep.EntityName)
                                                    : destinationPath.AppendDirectory(ep.EntityName);
                    Move(source, ep, destination, destinationEntityPath);
                }
                if (!sourcePath.IsRoot)
                    source.Delete(sourcePath);
            }
        }
开发者ID:readelivery,项目名称:sharpfilesystem,代码行数:34,代码来源:StandardEntityMover.cs

示例2: UploadPartialFile

		// Upload partial file
		private IEnumerable<FilesStatus> UploadPartialFile(string fileName, HttpContext context, IFileSystem fs, SelectionUtility selection)
		{
			if (context.Request.Files.Count != 1) throw new HttpRequestValidationException("Attempt to upload chunked file containing more than one fragment per request");

			var fileUpload = context.Request.Files[0];
			var inputStream = fileUpload.InputStream;
			var virtualPath = Url.Combine(selection.SelectedItem.Url, fileName);

			if (!IsFilenameTrusted(fileName))
			{
				yield return new FilesStatus(virtualPath, 0) { error = "Unsafe filename" };
			}
			else
			{

				using (var s = fs.OpenFile(virtualPath))
				{
					var buffer = new byte[1024];

					var l = inputStream.Read(buffer, 0, 1024);
					while (l > 0)
					{
						s.Write(buffer, 0, l);
						l = inputStream.Read(buffer, 0, 1024);
					}
					s.Flush();
					s.Close();
				}
				yield return new FilesStatus(virtualPath, fileUpload.ContentLength);
			}
		}
开发者ID:Biswo,项目名称:n2cms,代码行数:32,代码来源:UploadFile.ashx.cs

示例3: GetDocument

 private static XDocument GetDocument(IFileSystem fileSystem, string path)
 {
     using (Stream configStream = fileSystem.OpenFile(path))
     {
         return XDocument.Load(configStream);
     }
 }
开发者ID:nickfloyd,项目名称:NuGet,代码行数:7,代码来源:XmlUtility.cs

示例4: GetDocument

 private static XDocument GetDocument(IFileSystem fileSystem, string path)
 {
     using (Stream configStream = fileSystem.OpenFile(path))
     {
         return XDocument.Load(configStream, LoadOptions.PreserveWhitespace);
     }
 }
开发者ID:OsirisTerje,项目名称:sonarlint-vs,代码行数:7,代码来源:XmlUtility.cs

示例5: GetDocument

 internal static XDocument GetDocument(IFileSystem fileSystem, string path)
 {
     using (Stream configStream = fileSystem.OpenFile(path))
     {
         return XmlUtility.LoadSafe(configStream, LoadOptions.PreserveWhitespace);
     }
 }
开发者ID:Newtopian,项目名称:nuget,代码行数:7,代码来源:XmlUtility.cs

示例6: StreamFile

        public StreamFile(IFileSystem fileSystem, string path, bool readOnly)
        {
            file = fileSystem.FileExists(path) ? fileSystem.OpenFile(path, readOnly) : fileSystem.CreateFile(path);

            endPointer = file.Length;
            fileStream = new StreamFileStream(this);

            ownsFile = true;
        }
开发者ID:deveel,项目名称:deveeldb,代码行数:9,代码来源:StreamFile.cs

示例7: ReadDocument

 private static string ReadDocument(IFileSystem fileSystem, string path)
 {
     string document;
     using (Stream stream = fileSystem.OpenFile(path))
     using (StreamReader sr = new StreamReader(stream))
     {
         document = sr.ReadToEnd();
     }
     return document;
 }
开发者ID:zhiliangxu,项目名称:TestEasy,代码行数:10,代码来源:NuGetWebProjectSystem.cs

示例8: GetInputStream

        private Stream GetInputStream(IFileSystem fs, string url)
        {
            byte[] image;
            using (var s = fs.OpenFile(url))
            {
                image = new byte[s.Length];
                s.Read(image, 0, image.Length);
            }

            return new MemoryStream(image);
        }
开发者ID:brianmatic,项目名称:n2cms,代码行数:11,代码来源:Crop.aspx.cs

示例9: GetOrCreateDocument

 internal static XDocument GetOrCreateDocument(XName rootName, IFileSystem fileSystem, string path)
 {
     if (fileSystem.FileExists(path)) {
         try {
             using (Stream configSream = fileSystem.OpenFile(path)) {
                 return XDocument.Load(configSream);
             }
         }
         catch (FileNotFoundException) {
             return CreateDocument(rootName, fileSystem, path);
         }
     }
     return CreateDocument(rootName, fileSystem, path);
 }
开发者ID:grendello,项目名称:nuget,代码行数:14,代码来源:XmlUtility.cs

示例10: SafeResolveRefreshPath

 private static string SafeResolveRefreshPath(IFileSystem fileSystem, string file)
 {
     string relativePath;
     try
     {
         using (var stream = fileSystem.OpenFile(file))
         {
             relativePath = stream.ReadToEnd();
         }
         return fileSystem.GetFullPath(relativePath);
     }
     catch 
     {
         // Ignore the .refresh file if it cannot be read.
     }
     return null;
 }
开发者ID:Newtopian,项目名称:nuget,代码行数:17,代码来源:ProjectSystemExtensions.cs

示例11: Intro

        public override void Intro( params object [] args )
        {
            variableTable = new VariableTable ();

            fileSystem = FileSystemManager.GetFileSystem ( "LocalFileSystem" );
            if ( fileSystem.IsFileExist ( "vartab.dat" ) )
                variableTable.Load ( fileSystem.OpenFile ( "vartab.dat" ) );
            else
            {
                variableTable.AddPackageVariableTable ( myGuid, 3 );
                variableTable.SetVariable ( myGuid, 0, 0 );
                variableTable.SetVariable ( myGuid, 1, 0.0 );
                variableTable.SetVariable ( myGuid, 2, false );
            }

            base.Intro ( args );
        }
开发者ID:Daramkun,项目名称:Misty,代码行数:17,代码来源:Container.cs

示例12: Solution

 public Solution(IFileSystem fileSystem, string solutionFileName)
 {
     var solutionParser = _solutionParserType.GetConstructor(
         BindingFlags.Instance | BindingFlags.NonPublic, 
         binder: null, types: Type.EmptyTypes, modifiers: null).Invoke(null);
     using (var streamReader = new StreamReader(fileSystem.OpenFile(solutionFileName)))
     {
         _solutionReaderProperty.SetValue(solutionParser, streamReader, index: null);
         _parseSolutionMethod.Invoke(solutionParser, parameters: null);
     }
     var projects = new List<ProjectInSolution>();
     foreach (var proj in (object[])_projectsProperty.GetValue(solutionParser, index: null))
     {
         projects.Add(new ProjectInSolution(proj));
     }
     this.Projects = projects;
 }
开发者ID:Newtopian,项目名称:nuget,代码行数:17,代码来源:Solution.cs

示例13: Logger

        public Logger(IFileSystem fileSystem)
        {
            //Create the StreamWriter which the logger will use for outputting to file
            _fileSystem = fileSystem;

            if (!fileSystem.FileExists(_LOG_FILE_PATH))
            {
                _logFileStream = fileSystem.CreateFile(_LOG_FILE_PATH);
            }
            else
            {
                _logFileStream = fileSystem.OpenFile(_LOG_FILE_PATH, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
            }

            _logFileStreamWriter = new StreamWriter(_logFileStream);
            //Since we are logging, set autoflush to true for immediate writes
            _logFileStreamWriter.AutoFlush = true;
            _logFileStreamWriter.WriteLine("------------ New Buttercup Session (" + DateTime.Now + ") ------------" + Environment.NewLine);
        }
开发者ID:knifhen,项目名称:buttercup-swedish,代码行数:19,代码来源:Logger.cs

示例14: Write

        public void Write(IFileSystem fs, ContentItem item, XmlTextWriter writer)
        {
            string url = item[Name] as string;
            if(!string.IsNullOrEmpty(url))
            {
                string path = url;
                if(fs.FileExists(path))
                {
                    using(ElementWriter ew = new ElementWriter("file", writer))
                    {
                        ew.WriteAttribute("url", url);

                        byte[] fileContents = ReadFully(fs.OpenFile(path));
                        string base64representation = Convert.ToBase64String(fileContents);
                        ew.Write(base64representation);
                    }
                }
            }
        }
开发者ID:arp51,项目名称:n2cms,代码行数:19,代码来源:FileAttachmentAttribute.cs

示例15: EnsureFileExists

 private static void EnsureFileExists(IFileSystem fileSystem, string configFilePath)
 {
     using (fileSystem.OpenFile(configFilePath))
     {
         // Do nothing
     }
 }
开发者ID:riteshparekh,项目名称:NuGet,代码行数:7,代码来源:InstallCommand.cs


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