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


C# IAbsoluteFilePath.RemoveReadonlyWhenExists方法代码示例

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


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

示例1: Gzip

            public virtual string Gzip(IAbsoluteFilePath file, IAbsoluteFilePath dest = null,
                bool preserveFileNameAndModificationTime = false) {
                Contract.Requires<ArgumentNullException>(file != null);
                Contract.Requires<ArgumentException>(file.Exists);

                var defDest = (file + ".gz").ToAbsoluteFilePath();
                if (dest == null)
                    dest = defDest;

                var cmd = String.Format("-f --best --rsyncable --keep \"{0}\"", file);
                if (!preserveFileNameAndModificationTime)
                    cmd = "-n " + cmd;

                dest.RemoveReadonlyWhenExists();

                var startInfo =
                    new ProcessStartInfoBuilder(Common.Paths.ToolPath.GetChildFileWithName("gzip.exe"), cmd) {
                        WorkingDirectory = file.ParentDirectoryPath.ToString()
                    }.Build();
                var ret = ProcessManager.LaunchAndGrabTool(startInfo, "Gzip pack");

                if (Path.GetFullPath(dest.ToString()) != Path.GetFullPath(defDest.ToString()))
                    FileUtil.Ops.MoveWithRetry(defDest, dest);

                return ret.StandardOutput + ret.StandardError;
            }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:26,代码来源:GzipTools.cs

示例2: TryDownloadAsync

        async Task TryDownloadAsync(TransferSpec spec, IWebClient webClient, IAbsoluteFilePath tmpFile) {
            try {
                tmpFile.RemoveReadonlyWhenExists();
                if (!string.IsNullOrWhiteSpace(spec.Uri.UserInfo))
                    webClient.SetAuthInfo(spec.Uri);
                using (webClient.HandleCancellationToken(spec))
                    await webClient.DownloadFileTaskAsync(spec.Uri, tmpFile.ToString()).ConfigureAwait(false);
                VerifyIfNeeded(spec, tmpFile);
                _fileOps.Move(tmpFile, spec.LocalFile);
            } catch (OperationCanceledException e) {
                _fileOps.DeleteIfExists(tmpFile.ToString());
                throw CreateTimeoutException(spec, e);
            } catch (WebException ex) {
                _fileOps.DeleteIfExists(tmpFile.ToString());
                var cancelledEx = ex.InnerException as OperationCanceledException;
                if (cancelledEx != null)
                    throw CreateTimeoutException(spec, cancelledEx);
                if (ex.Status == WebExceptionStatus.RequestCanceled)
                    throw CreateTimeoutException(spec, ex);

                var response = ex.Response as HttpWebResponse;
                if (response == null)
                    throw GenerateDownloadException(spec, ex);

                switch (response.StatusCode) {
                case HttpStatusCode.NotFound:
                    throw new RequestFailedException("Received a 404: NotFound response", ex);
                case HttpStatusCode.Forbidden:
                    throw new RequestFailedException("Received a 403: Forbidden response", ex);
                case HttpStatusCode.Unauthorized:
                    throw new RequestFailedException("Received a 401: Unauthorized response", ex);
                }
                throw GenerateDownloadException(spec, ex);
            }
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:35,代码来源:HttpDownloadProtocol.cs

示例3: Gzip

            public virtual string Gzip(IAbsoluteFilePath file, IAbsoluteFilePath dest = null,
                bool preserveFileNameAndModificationTime = true, ITProgress status = null) {
                Contract.Requires<ArgumentNullException>(file != null);
                Contract.Requires<ArgumentException>(file.Exists);

                var defDest = (file + ".gz").ToAbsoluteFilePath();
                if (dest == null)
                    dest = defDest;

                var cmd = $"-f --best --rsyncable --keep \"{file}\"";
                if (!preserveFileNameAndModificationTime)
                    cmd = "-n " + cmd;

                dest.RemoveReadonlyWhenExists();

                var startInfo =
                    new ProcessStartInfoBuilder(Common.Paths.ToolPath.GetChildFileWithName("gzip.exe"), cmd) {
                        WorkingDirectory = file.ParentDirectoryPath
                    }.Build();

                var srcSize = file.FileInfo.Length;
                ProcessExitResultWithOutput ret;
                var predictedSize = srcSize*DefaultPredictedCompressionRatio;
                using (StatusProcessor.Conditional(defDest, status, (long) predictedSize))
                    ret = ProcessManager.LaunchAndGrabTool(startInfo, "Gzip pack");
                if (Path.GetFullPath(dest.ToString()) != Path.GetFullPath(defDest.ToString()))
                    FileUtil.Ops.MoveWithRetry(defDest, dest);

                return ret.StandardOutput + ret.StandardError;
            }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:30,代码来源:ToolsGzipTools.cs

示例4: UnpackFile

        public virtual void UnpackFile(IAbsoluteFilePath srcFile, IAbsoluteFilePath dstFile, IStatus status = null) {
            var dstPath = dstFile.ParentDirectoryPath;
            dstPath.MakeSurePathExists();
            dstFile.RemoveReadonlyWhenExists();

            Tools.Compression.Unpack(srcFile, dstPath, true, progress: status);
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:7,代码来源:RepositoryTools.cs

示例5: Pack

        public virtual void Pack(IAbsoluteFilePath file, IAbsoluteFilePath dest = null,
            string archiveFormat = Repository.DefaultArchiveFormat) {
            if (dest == null)
                dest = (file + archiveFormat).ToAbsoluteFilePath();
            dest.ParentDirectoryPath.MakeSurePathExists();
            dest.RemoveReadonlyWhenExists();

            if (archiveFormat == Repository.DefaultArchiveFormat)
                Tools.Compression.Gzip.GzipAuto(file, dest);
            else
                Tools.Compression.PackSevenZipNative(file, dest);
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:12,代码来源:RepositoryTools.cs

示例6: GzipStdOut

            public virtual string GzipStdOut(IAbsoluteFilePath inputFile, IAbsoluteFilePath outputFile = null,
                bool preserveFileNameAndModificationTime = false) {
                Contract.Requires<ArgumentException>(inputFile != null);
                Contract.Requires<ArgumentException>(inputFile.Exists);

                if (outputFile == null)
                    outputFile = (inputFile + ".gz").ToAbsoluteFilePath();

                var cmd = String.Format("-f --best --rsyncable --keep --stdout \"{0}\" > \"{1}\"",
                    inputFile, outputFile);
                if (!preserveFileNameAndModificationTime)
                    cmd = "-n " + cmd;

                outputFile.RemoveReadonlyWhenExists();
                var startInfo =
                    new ProcessStartInfoBuilder(Common.Paths.ToolPath.GetChildFileWithName("gzip.exe"), cmd) {
                        WorkingDirectory = Common.Paths.LocalDataPath.ToString()
                    }.Build();
                var ret = ProcessManager.LaunchAndGrabToolCmd(startInfo, "Gzip pack");
                return ret.StandardOutput + ret.StandardError;
            }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:21,代码来源:GzipTools.cs

示例7: TryDownloadAsync

        async Task TryDownloadAsync(TransferSpec spec, IWebClient webClient, IAbsoluteFilePath tmpFile) {
            try {
                tmpFile.RemoveReadonlyWhenExists();
                if (!string.IsNullOrWhiteSpace(spec.Uri.UserInfo))
                    webClient.SetAuthInfo(spec.Uri);
                using (webClient.HandleCancellationToken(spec))
                    await webClient.DownloadFileTaskAsync(spec.Uri, tmpFile.ToString()).ConfigureAwait(false);
                VerifyIfNeeded(spec, tmpFile);
                _fileOps.Move(tmpFile, spec.LocalFile);
            } catch (OperationCanceledException e) {
                _fileOps.DeleteIfExists(tmpFile.ToString());
                throw CreateTimeoutException(spec, e);
            } catch (WebException e) {
                _fileOps.DeleteIfExists(tmpFile.ToString());
                var cancelledEx = e.InnerException as OperationCanceledException;
                if (cancelledEx != null)
                    throw CreateTimeoutException(spec, cancelledEx);
                if (e.Status == WebExceptionStatus.RequestCanceled)
                    throw CreateTimeoutException(spec, e);

                GenerateDownloadException(spec, e);
            }
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:23,代码来源:HttpDownloadProtocol.cs

示例8: GzipStdOut

            public virtual string GzipStdOut(IAbsoluteFilePath inputFile, IAbsoluteFilePath outputFile = null,
                bool preserveFileNameAndModificationTime = true, ITProgress status = null) {
                Contract.Requires<ArgumentException>(inputFile != null);
                Contract.Requires<ArgumentException>(inputFile.Exists);

                if (outputFile == null)
                    outputFile = (inputFile + ".gz").ToAbsoluteFilePath();

                var cmd = $"-f --best --rsyncable --keep --stdout \"{inputFile}\" > \"{outputFile}\"";
                if (!preserveFileNameAndModificationTime)
                    cmd = "-n " + cmd;

                outputFile.RemoveReadonlyWhenExists();
                var startInfo =
                    new ProcessStartInfoBuilder(Common.Paths.ToolPath.GetChildFileWithName("gzip.exe"), cmd) {
                        WorkingDirectory = Common.Paths.LocalDataPath
                    }.Build();
                var srcSize = inputFile.FileInfo.Length;
                ProcessExitResultWithOutput ret;
                var predictedSize = srcSize*DefaultPredictedCompressionRatio;
                using (StatusProcessor.Conditional(outputFile, status, (long) predictedSize))
                    ret = ProcessManager.LaunchAndGrabToolCmd(startInfo, "Gzip pack");
                return ret.StandardOutput + ret.StandardError;
            }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:24,代码来源:ToolsGzipTools.cs

示例9: UnpackSingleGzip

            public void UnpackSingleGzip(IAbsoluteFilePath sourceFile, IAbsoluteFilePath destFile,
                ITProgress progress = null) {
                using (var archive = GZipArchive.Open(sourceFile.ToString())) {
                    if (progress != null) {
                        archive.CompressedBytesRead += (sender, args) => {
                            double prog = (args.CompressedBytesRead/(float) archive.TotalSize);
                            if (prog > 1)
                                prog = 1;
                            progress.Progress = prog*100;
                        };
                    }
                    destFile.RemoveReadonlyWhenExists();
                    var entry = archive.Entries.First();

                    entry.WriteToFile(destFile.ToString());
                }
            }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:17,代码来源:GzipTools.cs

示例10: TryUnpackArchive

 private static void TryUnpackArchive(IAbsoluteFilePath destFile, ITProgress progress, GZipArchive archive) {
     destFile.RemoveReadonlyWhenExists();
     var entry = archive.Entries.First();
     if (progress != null) {
         var startTime = DateTime.UtcNow;
         archive.CompressedBytesRead += (sender, args) => {
             double prog = args.CompressedBytesRead/(float) archive.TotalSize;
             if (prog > 1)
                 prog = 1;
             var totalMilliseconds = (DateTime.UtcNow - startTime).TotalMilliseconds;
             progress.Update(
                 totalMilliseconds > 0 ? (long?) (args.CompressedBytesRead/(totalMilliseconds/1000.0)) : null,
                 prog*100);
         };
     }
     entry.WriteToFile(destFile.ToString());
     progress?.Update(null, 100);
 }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:18,代码来源:CompressionUtil.cs


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