• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IFileInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: DeleteFile

        /// <summary>
        /// Deletes the specified file.
        /// </summary>
        /// <param name="file">The file to delete.</param>
        /// <exception cref="AccessException">The file could not be accessed.</exception>
        public void DeleteFile(IFileInfo file)
        {
            file.ThrowIfNull(() => file);

            if (!(file is LocalFileInfo))
                throw new ArgumentException("The file must be of type LocalFileInfo.", "file");

            try
            {
                File.SetAttributes(file.FullName, FileAttributes.Normal);
                File.Delete(file.FullName);
            }

            catch (IOException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }

            catch (SecurityException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }

            catch (UnauthorizedAccessException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }
        }
开发者ID:SmartFire,项目名称:FlagSync,代码行数:33,代码来源:LocalFileSystem.cs


示例2: IsFileAValidModification

        public bool IsFileAValidModification(IFileInfo file, IProject baseProject, IProject sourceProject, List<string> warnings, List<FileReleaseInfo> releases)
        {
            if (FileIsDeletedItem(file))
                return false;

            if (FileIsSharedResx(file))
            {
                var baseFile = baseProject.Drive.GetFileInfo(file.Url);
                var sourceFile = sourceProject.Drive.GetFileInfo(file.Url);
                ResxDifferences changes = ResxDiffMerge.CompareResxFiles(sourceFile, baseFile);
                if (changes.None)
                    return false;
            }

            if (FileIsRelationship(file))
            {
                Guid sourceId = GetModelItemIdFromFile(file);
                if (sourceId == Guid.Empty)
                    return true;

                OrmRelationship baseRelationship = FindRelationshipInBaseById(sourceId, baseProject);
                if (baseRelationship != null)
                {
                    var sourceRelationship = sourceProject.Get<OrmRelationship>(file.Url);
                    var diffMerge = new ObjectDiffMerge();
                    var changes = diffMerge.CompareObjects(sourceRelationship, baseRelationship);
                    if (!changes.All(change => RelationshipChangeCanBeIgnored(change)))
                        warnings.Add(string.Format("{0} is an existing SalesLogix relationship that was renamed and also modified.  This file will need to be manually merged.", file.Url));

                    return false;
                }
            }

            return true;
        }
开发者ID:Saleslogix,项目名称:ProjectUpgrade,代码行数:35,代码来源:OrmModelUpgradeService.cs


示例3: Save

        public static void Save(IFileInfo File, string Key, string Content)
        {
            ContentItem item;
            if (File.ContentItemID == Null.NullInteger)
            {
                item = CreateFileContentItem();
                File.ContentItemID = item.ContentItemId;
            }
            else
            {
                item = Util.GetContentController().GetContentItem(File.ContentItemID);
            }
            JObject obj;
            if (string.IsNullOrEmpty(item.Content))
                obj = new JObject();
            else
                obj = JObject.Parse(item.Content);

            if (string.IsNullOrEmpty(Content))
                obj[Key] = new JObject();
            else
                obj[Key] = JObject.Parse(Content);

            item.Content = obj.ToString();
            Util.GetContentController().UpdateContentItem(item);

            FileManager.Instance.UpdateFile(File);
        }
开发者ID:HolonCom,项目名称:OpenFiles,代码行数:28,代码来源:ContentItemUtils.cs


示例4: FileTransmissionObject

        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="CmisSync.Lib.Storage.Database.Entities.FileTransmissionObject"/> class.
        /// </summary>
        /// <param name="type">Type of transmission.</param>
        /// <param name="localFile">Local file.</param>
        /// <param name="remoteFile">Remote file.</param>
        public FileTransmissionObject(TransmissionType type, IFileInfo localFile, IDocument remoteFile) {
            if (localFile == null) {
                throw new ArgumentNullException("localFile");
            }

            if (!localFile.Exists) {
                throw new ArgumentException(string.Format("'{0} file does not exist", localFile.FullName), "localFile");
            }

            if (remoteFile == null) {
                throw new ArgumentNullException("remoteFile");
            }

            if (remoteFile.Id == null) {
                throw new ArgumentNullException("remoteFile.Id");
            }

            if (string.IsNullOrEmpty(remoteFile.Id)) {
                throw new ArgumentException("empty string", "remoteFile.Id");
            }

            this.Type = type;
            this.LocalPath = localFile.FullName;
            this.LastContentSize = localFile.Length;
            this.LastLocalWriteTimeUtc = localFile.LastWriteTimeUtc;
            this.RemoteObjectId = remoteFile.Id;
            this.LastChangeToken = remoteFile.ChangeToken;
            this.RemoteObjectPWCId = remoteFile.VersionSeriesCheckedOutId;
            this.LastRemoteWriteTimeUtc = remoteFile.LastModificationDate;
            if (this.LastRemoteWriteTimeUtc != null) {
                this.LastRemoteWriteTimeUtc = this.LastRemoteWriteTimeUtc.GetValueOrDefault().ToUniversalTime();
            }
        }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:40,代码来源:FileTransmissionObject.cs


示例5: Compile

        public async Task<CompilationResult> Compile(IFileInfo fileInfo)
        {
            Directory.CreateDirectory(_tempDir);
            string outFile = Path.Combine(_tempDir, Path.GetRandomFileName() + ".dll");
            StringBuilder args = new StringBuilder("/target:library ");
            args.AppendFormat("/out:\"{0}\" ", outFile);
            foreach (var file in  Directory.EnumerateFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "*.dll"))
            {
                args.AppendFormat("/R:\"{0}\" ", file);
            }
            args.AppendFormat("\"{0}\"", fileInfo.PhysicalPath);
            var outputStream = new MemoryStream();

            // common execute
            var process = CreateProcess(args.ToString());
            int exitCode = await Start(process, outputStream);

            string output = GetString(outputStream);
            if (exitCode != 0)
            {
                IEnumerable<CompilationMessage> messages = output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                                                                 .Skip(3)
                                                                 .Select(e => new CompilationMessage(e));
                return CompilationResult.Failed(String.Empty, messages);
            }

            var type = Assembly.LoadFrom(outFile)
                               .GetExportedTypes()
                               .First();
            return CompilationResult.Successful(String.Empty, type);
        }
开发者ID:464884492,项目名称:Mvc,代码行数:31,代码来源:CscBasedCompilationService.cs


示例6: FileProjectItem

 public FileProjectItem(string kind, IFileInfo fileInfo, IFileSystem fileSystem, PathInfo subPath) 
     : base(subPath.ToString(), kind)
 {
     _subPath = subPath;
     _fileSystem = fileSystem;
     FileInfo = fileInfo;
 }
开发者ID:TerrificNet,项目名称:TerrificNet,代码行数:7,代码来源:FileProjectItem.cs


示例7: IsFileAValidAddition

        public bool IsFileAValidAddition(IFileInfo file, IProject baseProject, IProject sourceProject, List<string> warnings)
        {
            if (FileIsOrderCollection(file))
                return OrderedCollectionIsAValidAddition(file, baseProject, sourceProject, warnings);

            return true;
        }
开发者ID:Saleslogix,项目名称:ProjectUpgrade,代码行数:7,代码来源:PortalModelUpgradeService.cs


示例8: CompileCore

        private async Task<CompilationResult> CompileCore(IFileInfo file)
        {
            var host = new MvcRazorHost();
            var engine = new RazorTemplateEngine(host);
            GeneratorResults results;
            using (TextReader rdr = new StreamReader(file.CreateReadStream()))
            {
                results = engine.GenerateCode(rdr, '_' + Path.GetFileNameWithoutExtension(file.Name), "Asp", file.PhysicalPath ?? file.Name);
            }

            string generatedCode;

            using (var writer = new StringWriter())
            using (var codeProvider = new CSharpCodeProvider())
            {
                codeProvider.GenerateCodeFromCompileUnit(results.GeneratedCode, writer, new CodeGeneratorOptions());
                generatedCode = writer.ToString();
            }

            if (!results.Success) 
            {
                return CompilationResult.Failed(generatedCode, results.ParserErrors.Select(e => new CompilationMessage(e.Message)));
            }

            Directory.CreateDirectory(_tempPath);
            string tempFile = Path.Combine(_tempPath, Path.GetRandomFileName() + ".cs");

            File.WriteAllText(tempFile, generatedCode);

            _tempFileSystem.TryGetFileInfo(tempFile, out file);
            return await _baseCompilationService.Compile(file);
        }
开发者ID:464884492,项目名称:Mvc,代码行数:32,代码来源:RazorCompilationService.cs


示例9: FileProviderGlobbingDirectory

        public FileProviderGlobbingDirectory(
            [NotNull] IFileProvider fileProvider,
            IFileInfo fileInfo,
            FileProviderGlobbingDirectory parent)
        {
            _fileProvider = fileProvider;
            _fileInfo = fileInfo;
            _parent = parent;

            if (_fileInfo == null)
            {
                // We're the root of the directory tree
                RelativePath = string.Empty;
                _isRoot = true;
            }
            else if (!string.IsNullOrEmpty(parent?.RelativePath))
            {
                // We have a parent and they have a relative path so concat that with my name
                RelativePath = _parent.RelativePath + DirectorySeparatorChar + _fileInfo.Name;
            }
            else
            {
                // We have a parent which is the root, so just use my name
                RelativePath = _fileInfo.Name;
            }
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:26,代码来源:FileProviderGlobbingDirectory.cs


示例10: UrlForm

        public UrlForm(IFileInfo fileInfo)
        {
            InitializeComponent();

            this.fileInfo = fileInfo;
            this.Url = fileInfo.Url;
        }
开发者ID:godly-devotion,项目名称:Baka-MPlayer-old,代码行数:7,代码来源:UrlForm.cs


示例11: DownloadImageAndConvertToDataUri

        /// <summary>
        /// Downloads an image at the provided URL and converts it to a valid Data Uri scheme (https://en.wikipedia.org/wiki/Data_URI_scheme)
        /// </summary>
        /// <param name="url">The url where the image is located.</param>
        /// <param name="logger">A logger.</param>
        /// <param name="fallbackFileInfo">A FileInfo to retrieve the local fallback image.</param>
        /// <param name="fallbackMediaType">The media type of the fallback image.</param>
        /// <param name="messageHandler">An optional message handler.</param>
        /// <returns>A string that contains the data uri of the downloaded image, or a default image on any error.</returns>
        public static async Task<string> DownloadImageAndConvertToDataUri(this string url, ILogger logger, IFileInfo fallbackFileInfo, string fallbackMediaType = "image/png", HttpMessageHandler messageHandler = null)
        {
            // exclude completely invalid URLs
            if (!string.IsNullOrWhiteSpace(url))
            {
                try
                {
                    // set a timeout to 10 seconds to avoid waiting on that forever
                    using (var client = new HttpClient(messageHandler) { Timeout = TimeSpan.FromSeconds(10) })
                    {
                        var response = await client.GetAsync(url);
                        response.EnsureSuccessStatusCode();

                        // set the media type and default to JPG if it wasn't provided
                        string mediaType = response.Content.Headers.ContentType?.MediaType;
                        mediaType = string.IsNullOrWhiteSpace(mediaType) ? "image/jpeg" : mediaType;

                        // return the data URI according to the standard
                        return (await response.Content.ReadAsByteArrayAsync()).ToDataUri(mediaType);
                    }
                }
                catch (Exception ex)
                {
                    logger.LogInformation(0, ex, "Error while downloading resource");
                }
            }

            // any error or invalid URLs just return the default data uri
            return await fallbackFileInfo.ToDataUri(fallbackMediaType);
        }
开发者ID:Cimpress-MCP,项目名称:dotnet-core-httputils,代码行数:39,代码来源:DataUriConversion.cs


示例12: FileCopyErrorEventArgs

        /// <summary>
        /// Initializes a new instance of the <see cref="FileCopyErrorEventArgs"/> class.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="targetDirectory">The target directory.</param>
        public FileCopyErrorEventArgs(IFileInfo file, IDirectoryInfo targetDirectory)
        {
            file.ThrowIfNull(() => file);
            targetDirectory.ThrowIfNull(() => targetDirectory);

            this.File = file;
            this.TargetDirectory = targetDirectory;
        }
开发者ID:dineshkummarc,项目名称:FlagSync,代码行数:13,代码来源:FileCopyErrorEventArgs.cs


示例13: GetFile

        /// <summary>
        /// Get one file.
        /// </summary>
        /// <param name="path"> File path. </param>
        /// <param name="file"> File. </param>
        /// <returns> Whether the file was found or not. </returns>
        public override bool GetFile(string path, List<string> currentPath, Queue<string> remainingPathParts, out IFileInfo file)
        {
            string currentPathStr = this.GetPathString(currentPath);
            path = path.Substring(currentPathStr.Length);

            var found = this.FileSystem.TryGetFileInfo(path, out file);
            return found;
        }
开发者ID:btcioner,项目名称:novaburst.ModularTypeScript,代码行数:14,代码来源:FileSystemLeafNode.cs


示例14: SetFileInfo

 /// <summary>
 /// Returns file info extracted from the request.
 /// Good point to add extra fields or override some of them
 /// </summary>
 /// <param name="fileInfo"></param>
 /// <param name="contentHeaders"></param>
 /// <returns></returns>
 protected virtual IFileInfo SetFileInfo(IFileInfo fileInfo, HttpContentHeaders contentHeaders)
 {
     return new IncomeFileInfo
     {
         MimeType = contentHeaders.ContentType.ToString(),
         OriginalName = GetOriginalFileName(contentHeaders),
     };
 }
开发者ID:CactusSoft,项目名称:Cactus.Fileserver,代码行数:15,代码来源:AddFileHandler.cs


示例15: SpaContext

 public SpaContext(HttpContext context, SpaOptions options, IFileInfo fileInfo, ILogger logger)
 {
     Debug.Assert(fileInfo.Exists, $"The file {fileInfo.Name} does not exist");
     _context = context; 
     _options = options;
     _logger = logger;
     _fileInfo = fileInfo;
 }
开发者ID:cloudmark,项目名称:Spa.Extensions,代码行数:8,代码来源:SpaContext.cs


示例16: SnapshotForm

        public SnapshotForm(Bitmap image, IFileInfo fileInfo)
        {
            InitializeComponent();

            this.SnapshotImage = image;
            this.fileInfo = fileInfo;
            snapshotPicbox_SizeChanged(null, null);
        }
开发者ID:godly-devotion,项目名称:Baka-MPlayer-old,代码行数:8,代码来源:SnapshotForm.cs


示例17: AddLocalFile

 public static Mock<IMappedObject> AddLocalFile(this Mock<IMetaDataStorage> db, IFileInfo path, string id) {
     var file = new Mock<IMappedObject>();
     file.SetupAllProperties();
     file.Setup(o => o.Type).Returns(MappedObjectType.File);
     file.Object.RemoteObjectId = id;
     file.Object.Name = path.Name;
     db.AddMappedFile(file.Object, path.FullName);
     return file;
 }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:9,代码来源:MockMetaDataStorageUtil.cs


示例18: TryGetFileInfo

 public bool TryGetFileInfo(string subpath, out IFileInfo fileInfo)
 {
     if (subpath == EnvironmentScriptSubpath)
     {
         fileInfo = _environmentScript;
         return true;
     }
     var tryGetFileInfo = _fileSystem.TryGetFileInfo(subpath, out fileInfo);
     return tryGetFileInfo;
 }
开发者ID:no1dead,项目名称:HaloMasterMaster,代码行数:10,代码来源:AppFileSystem.cs


示例19: GetImageFileUrl

 /// <summary>
 /// GetImageFileUrl - this method returns the valid URL for any file, regardless to folder or folder provider in use
 /// </summary>
 /// <param name="Image">Fully loaded IFileInfo object</param>
 /// <returns></returns>
 /// <remarks>
 /// WARNING!!! This method can return exceptions. They should be caught and processed in the UI though.
 /// </remarks>
 public string GetImageFileUrl(IFileInfo Image)
 {
     /*******************************************************'
     ' WARNING!!!
     ' This method can return exceptions. They should be
     ' caught and processed in the UI though.
     '*******************************************************/
     var mapFolder = FolderMappingController.Instance.GetFolderMapping(Image.FolderMappingID);
     return FolderProvider.Instance(mapFolder.FolderProviderType).GetFileUrl(Image);
 }
开发者ID:nvisionative,项目名称:dnnextensions,代码行数:18,代码来源:FeatureController.cs


示例20: FileMovedEvent

 /// <summary>
 /// Initializes a new instance of the <see cref="CmisSync.Lib.Events.FileMovedEvent"/> class.
 /// </summary>
 /// <param name="oldLocalFile">Old local file.</param>
 /// <param name="newLocalFile">New local file.</param>
 /// <param name="oldRemoteFilePath">Old remote file path.</param>
 /// <param name="newRemoteFile">New remote file.</param>
 public FileMovedEvent(
     IFileInfo oldLocalFile = null,
     IFileInfo newLocalFile = null,
     string oldRemoteFilePath = null,
     IDocument newRemoteFile = null)
     : base(newLocalFile, newRemoteFile) {
     this.Local = MetaDataChangeType.MOVED;
     this.OldLocalFile = oldLocalFile;
     this.OldRemoteFilePath = oldRemoteFilePath;
 }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:17,代码来源:FileMovedEvent.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IFileProvider类代码示例发布时间:2022-05-24
下一篇:
C# IFileDialogCustomize类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap