コード例 #1
0
ファイル: TransferOptions.cs プロジェクト: xkcu/winscp
 public TransferOptions()
 {
     PreserveTimestamp = true;
     TransferMode      = TransferMode.Binary;
     ResumeSupport     = new TransferResumeSupport();
     OverwriteMode     = OverwriteMode.Overwrite;
 }
コード例 #2
0
    /// <summary>
    /// fluent setter for <see cref="ISupportSwitchOverwriteMode"/>.
    /// </summary>
    /// <typeparam name="T">the builder to support the <see cref="ISupportSwitchOverwriteMode"/>.</typeparam>
    /// <param name="this">The builder-instance.</param>
    /// <param name="mode">The <see cref="OverwriteMode"/> to set.</param>
    /// <returns>The builder-instance for fluent re-use.</returns>
    public static T WithOverwriteMode <T>(this T @this, OverwriteMode mode)
        where T : ISupportSwitchBuilder <ISupportSwitchOverwriteMode>
    {
        @this.Command.OverwriteMode = new SwitchOverwriteMode(mode);

        return(@this);
    }
コード例 #3
0
ファイル: Utils.cs プロジェクト: monkeyman192/MBINCompiler
        public static bool PromptOverwrite(string fileOut, ref OverwriteMode overwrite)
        {
            Console.WriteLine($"File already exists!\n\"{fileOut}\"\n");
            Console.WriteLine("Options:\n" +
                              "  [y]es\n" +
                              "  [n]o\n" +
                              "  [O]verwrite all existing files.\n" +
                              "  [K]eep all existing files.");
            char key;

            while (true)
            {
                Console.Write("\nOverwrite this file? ");
                key = Console.ReadKey().KeyChar;
                key = (key >= 'a') ? (char)(key - 32) : key;
                Console.WriteLine();
                if (key == 'O')
                {
                    overwrite = OverwriteMode.Always;
                }
                if (key == 'K')
                {
                    overwrite = OverwriteMode.Never;
                }
                if ((key == 'Y') || (key == 'O'))
                {
                    return(true);
                }
                if ((key == 'N') || (key == 'K'))
                {
                    return(false);
                }
            }
        }
コード例 #4
0
ファイル: IOHelper.cs プロジェクト: slorion/nlight
		private const int DefaultBufferSize = 16 * 1024; // 16KB

		public static async Task Copy(string sourceFilePath, string destinationFilePath, OverwriteMode overwriteMode = OverwriteMode.AlwaysOverwrite, CopyOptions options = CopyOptions.AllowHardLinkCreation, CancellationToken? cancellationToken = null, Action<long, long> progressCallback = null)
		{
			if (string.IsNullOrEmpty(sourceFilePath)) throw new ArgumentNullException(nameof(sourceFilePath));
			if (string.IsNullOrEmpty(destinationFilePath)) throw new ArgumentNullException(nameof(destinationFilePath));

			var ct = cancellationToken ?? CancellationToken.None;
			Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));

			if (options.HasFlag(CopyOptions.AllowHardLinkCreation))
			{
				if (sourceFilePath.Length > 3 && destinationFilePath.Length > 3
					&& sourceFilePath[1] == Path.VolumeSeparatorChar && sourceFilePath[2] == Path.PathSeparator
					&& sourceFilePath.Take(3).SequenceEqual(destinationFilePath.Take(3)))
				{
					if (NtfsHelper.CreateHardLink(sourceFilePath, destinationFilePath))
					{
						if (progressCallback != null)
						{
							var length = new FileInfo(sourceFilePath).Length;
							progressCallback(length, length);
						}

						return;
					}
				}
			}

			await Win32CopyEx.Copy(sourceFilePath, destinationFilePath, overwriteMode, options, ct, progressCallback).ConfigureAwait(false);

			ct.ThrowIfCancellationRequested();
		}
コード例 #5
0
        /* ----------------------------------------------------------------- */
        ///
        /// Move
        ///
        /// <summary>
        /// Moves from the temporary directory to the specified directory.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void Move(Information item)
        {
            var src = IO.Get(IO.Combine(Tmp, item.FullName));

            if (!src.Exists)
            {
                return;
            }

            var dest = IO.Get(IO.Combine(Destination, item.FullName));

            if (dest.Exists)
            {
                if (item.IsDirectory)
                {
                    return;
                }
                if (!OverwriteMode.HasFlag(OverwriteMode.Always))
                {
                    RaiseOverwriteRequested(src, dest);
                }
                Overwrite(src, dest);
            }
            else
            {
                Move(src, dest);
            }
        }
コード例 #6
0
 public SfcTool(string clipExtentShapeFile, string outputDirectory, string postfix, string backupFolderName,
                OverwriteMode overwriteMode, CancelableProgressorSource cancelHandler)
 {
     this._clipExtentShapeFile = clipExtentShapeFile;
     this._outputDirectory     = outputDirectory;
     this._postfix             = postfix;
     this._backupFolderName    = backupFolderName;
     this._overwriteMode       = overwriteMode;
     this._cancelHandler       = cancelHandler;
 }
コード例 #7
0
        public static bool ConvertToLegacyReplaceFlag(this OverwriteMode @this, ILog logger)
        {
            if (@this == OverwriteMode.IgnoreIfExists)
            {
                logger.Warn("The option to ignore existing versions is only supported by Octopus Server 2019.7.9 or newer. If you want to use this option please upgrade your Octopus Server. In the meantime we are automatically falling back to the default option `replace=false` for this request.");
                return(false);
            }

            return(@this == OverwriteMode.OverwriteExisting);
        }
コード例 #8
0
 protected static void SetDefaultOverwriteMode(int id, OverwriteMode mode)
 {
     lock (defaultOverwriteModeList)
     {
         if (defaultOverwriteModeList.ContainsKey(id))
         {
             defaultOverwriteModeList.Remove(id);
         }
         defaultOverwriteModeList.Add(id, mode);
     }
 }
コード例 #9
0
ファイル: Win32CopyEx.cs プロジェクト: slorion/nlight
		public static Task Copy(string source, string destination, OverwriteMode overwriteMode, CopyOptions options, CancellationToken? cancellationToken = null, Action<long, long> progressCallback = null)
		{
			if (string.IsNullOrEmpty(source)) throw new ArgumentNullException(nameof(source));
			if (string.IsNullOrEmpty(destination)) throw new ArgumentNullException(nameof(destination));

			var copyFileFlags = CopyFileFlags.COPY_FILE_RESTARTABLE;

			if (overwriteMode != OverwriteMode.AlwaysOverwrite)
				copyFileFlags |= CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS;

			if (options.HasFlag(CopyOptions.DisableBuffering))
				copyFileFlags |= CopyFileFlags.COPY_FILE_NO_BUFFERING;

			int isCancelled = 0;
			var ct = cancellationToken ?? CancellationToken.None;

			CopyProgressRoutine progressRoutine =
				(total, transferred, streamSize, streamByteTrans, dwStreamNumber, reason, hSourceFile, hDestinationFile, lpData) =>
				{
					if (progressCallback != null && reason == CopyProgressCallbackReason.CALLBACK_CHUNK_FINISHED)
						progressCallback(transferred, total);

					return ct.IsCancellationRequested ? CopyProgressResult.PROGRESS_CANCEL : CopyProgressResult.PROGRESS_CONTINUE;
				};

			return Task.Run(
				() =>
				{
					if (!CopyFileEx(source, destination, progressRoutine, IntPtr.Zero, ref isCancelled, copyFileFlags))
					{
						int errorCode = Marshal.GetLastWin32Error();

						if (errorCode == (int) Win32ErrorCode.ERROR_FILE_EXISTS || errorCode == (int) Win32ErrorCode.ERROR_ALREADY_EXISTS || errorCode == (int) Win32ErrorCode.ERROR_OBJECT_ALREADY_EXISTS || errorCode == (int) Win32ErrorCode.ERROR_OBJECT_NAME_EXISTS)
						{
							if (overwriteMode == OverwriteMode.OverwriteIfDifferent)
							{
								if (IOHelper.AreSameFile(source, destination))
									return;
								else
								{
									copyFileFlags &= ~CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS;
									if (CopyFileEx(source, destination, progressRoutine, IntPtr.Zero, ref isCancelled, copyFileFlags))
										return;
								}
							}
						}

						throw new Win32Exception(errorCode);
					}
				});
		}
コード例 #10
0
        void MoveFile(FileInfoEx item, DirectoryInfoEx destDir)
        {
            FileSystemInfoEx lookupItem = destDir[item.Name];

            OverwriteMode overwrite = OverwriteMode.Replace;

            if (lookupItem != null)
            {
                overwrite = AskOverwrite(item, lookupItem);
            }

            switch (overwrite)
            {
            case OverwriteMode.Replace:
                if (lookupItem != null)
                {
                    lookupItem.Delete();
                }
                IOTools.Move(item.FullName, PathEx.Combine(destDir.FullName, item.Name));
                break;
            }
        }
コード例 #11
0
        DirectoryInfoEx PrepateDirectoryForCopy(DirectoryInfoEx srcDir, DirectoryInfoEx baseDir, string dirName)
        {
            bool isDirectory;

            if (!baseDir.Exists)
            {
                baseDir.Create();
            }
            if (baseDir.Contains(dirName, out isDirectory))
            {
                FileSystemInfoEx destSubItem = baseDir[dirName];

                if (!isDirectory)
                {
                    OverwriteMode overwrite = AskOverwrite(srcDir, destSubItem);
                    switch (overwrite)
                    {
                    case OverwriteMode.KeepOriginal:
                        return(null);

                    case OverwriteMode.Replace:
                        destSubItem.Delete();
                        return(baseDir.CreateDirectory(dirName));
                    }
                    throw new NotImplementedException("OverwriteMode");
                }
                else
                {
                    return(destSubItem as DirectoryInfoEx);
                }
            }
            else
            {
                return(baseDir.CreateDirectory(dirName));
            }
        }
コード例 #12
0
        void CopyFile(FileInfoEx item, DirectoryInfoEx destDir)
        {
            FileSystemInfoEx lookupItem = destDir[item.Name];

            if (lookupItem is FileInfoEx)
            {
                if (item.Length == (lookupItem as FileInfoEx).Length)
                {
                    string srcCRC  = Helper.GetFileCRC(item.FullName);
                    string destCRC = Helper.GetFileCRC(lookupItem.FullName);
                    if (srcCRC == destCRC && item.Length == (lookupItem as FileInfoEx).Length)
                    {
                        return; //Same file, no copy needed.
                    }
                }
            }

            OverwriteMode overwrite = OverwriteMode.Replace;

            if (lookupItem != null)
            {
                overwrite = AskOverwrite(item, lookupItem);
            }

            switch (overwrite)
            {
            case OverwriteMode.Replace:
                if (lookupItem != null)
                {
                    lookupItem.Delete();
                }
                FileCancelDelegate cancel = delegate { return(Aborted); };
                IOTools.CopyFile(item.FullName, PathEx.Combine(destDir.FullName, item.Name), cancel);
                break;
            }
        }
コード例 #13
0
 public static Task Move(string sourceFilePath, string destinationFilePath, OverwriteMode overwriteMode = OverwriteMode.AlwaysOverwrite, CancellationToken?cancellationToken = null, Action <long, long> progressCallback = null)
 {
     return(Copy(sourceFilePath, destinationFilePath, overwriteMode, CopyOptions.None, cancellationToken, progressCallback)
            .ContinueWith(t => File.Delete(sourceFilePath), TaskContinuationOptions.OnlyOnRanToCompletion));
 }
コード例 #14
0
ファイル: WorkBase.cs プロジェクト: Starwer/Lime
 protected void SetDefaultOverwriteMode(OverwriteMode value)
 {
     _overwrite = value;
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SwitchOverwriteMode"/> class.
 /// </summary>
 /// <param name="mode">The mode.</param>
 public SwitchOverwriteMode(OverwriteMode mode)
 {
     this.mode = mode;
 }
コード例 #16
0
 public static void CreateDelimitedFile(string csvPathFilename, Collection <string> csvColumns, string delimiter, OverwriteMode overwriteMode)
 {
     CreateCsvFile(csvPathFilename, csvColumns, new Collection <Feature>(), delimiter, overwriteMode);
 }
コード例 #17
0
 public SfcTool(string clipExtentShapeFile, string outputDirectory, string postfix, string targetReferenceSystem, string backupFolderName,
                OverwriteMode overwriteMode, CancelableProgressorSource cancelHandler) : this(clipExtentShapeFile, outputDirectory, postfix, backupFolderName, overwriteMode, cancelHandler)
 {
     this._targetReferenceSystem = targetReferenceSystem;
 }
コード例 #18
0
        public async Task <OctopusPackageMetadataMappedResource> Push(string packageId, string version, OctopusPackageMetadata octopusMetadata, OverwriteMode overwriteMode)
        {
            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentException("A package Id must be supplied", nameof(packageId));
            }
            if (string.IsNullOrWhiteSpace(version))
            {
                throw new ArgumentException("A version must be supplied", nameof(version));
            }

            var resource = new OctopusPackageMetadataVersionResource
            {
                PackageId = packageId,
                Version   = version,
                OctopusPackageMetadata = octopusMetadata
            };

            var link = await repository.Link("PackageMetadata");

            // if the link contains overwriteMode then we're connected to a new server, if not use the old `replace` parameter
            if (link.Contains(OverwriteModeLink.Link))
            {
                return(await repository.Client.Post <OctopusPackageMetadataVersionResource, OctopusPackageMetadataMappedResource>(link, resource, new { overwriteMode = overwriteMode }));
            }
            else
            {
                return(await repository.Client.Post <OctopusPackageMetadataVersionResource, OctopusPackageMetadataMappedResource>(link, resource, new { replace = overwriteMode == OverwriteMode.OverwriteExisting }));
            }
        }
コード例 #19
0
ファイル: IOHelper.cs プロジェクト: slorion/nlight
		public static Task Move(string sourceFilePath, string destinationFilePath, OverwriteMode overwriteMode = OverwriteMode.AlwaysOverwrite, CancellationToken? cancellationToken = null, Action<long, long> progressCallback = null)
		{
			return Copy(sourceFilePath, destinationFilePath, overwriteMode, CopyOptions.None, cancellationToken, progressCallback)
				.ContinueWith(t => File.Delete(sourceFilePath), TaskContinuationOptions.OnlyOnRanToCompletion);
		}
コード例 #20
0
        public async Task <OctopusPackageMetadataMappedResource> Push(string packageId, string version, OctopusPackageMetadata octopusMetadata, OverwriteMode overwriteMode)
        {
            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentException("A package Id must be supplied", nameof(packageId));
            }
            if (string.IsNullOrWhiteSpace(version))
            {
                throw new ArgumentException("A version must be supplied", nameof(version));
            }

            var resource = new OctopusPackageMetadataVersionResource
            {
                PackageId = packageId,
                Version   = version,
                OctopusPackageMetadata = octopusMetadata
            };

            if (await repository.HasLink("BuildInformation"))
            {
                Logger.Warn("Connected to an Octopus server that supports the BuildInformation API. It is recommended you move to using the BuildInformationRepository as the PackageMetadataRepository is deprecated.");
            }

            if (!(await repository.HasLink("PackageMetadata")))
            {
                throw new OperationNotSupportedByOctopusServerException(
                          OctopusPackageMetadata.PackageMetadataRequiresOctopusVersionMessage,
                          OctopusPackageMetadata.PackageMetadataRequiresOctopusVersion);
            }

            var link = await repository.Link("PackageMetadata");

            // if the link contains overwriteMode then we're connected to a new server, if not use the old `replace` parameter
            if (link.Contains(OverwriteModeLink.Link))
            {
                return(await repository.Client.Post <OctopusPackageMetadataVersionResource, OctopusPackageMetadataMappedResource>(link, resource, new { overwriteMode = overwriteMode }));
            }
            else
            {
                return(await repository.Client.Post <OctopusPackageMetadataVersionResource, OctopusPackageMetadataMappedResource>(link, resource, new { replace = overwriteMode.ConvertToLegacyReplaceFlag(Logger) }));
            }
        }
コード例 #21
0
        public int LoadEntries(StringSource target, StubbleSource source, Languages lang, OverwriteMode overwrite, IEnumerable<KeyValuePair<UInt64, string>> entries)
        {
            if (source.SourceTable == DBPFReference.MinValue && overwrite != OverwriteMode.All && overwrite != OverwriteMode.None)
                throw new InvalidOperationException();

            Dictionary<UInt64, StubbleEntry> targetlist;
            if (target == StringSource.Modified)
            {
                if (!mModifiedEntries.TryGetValue(lang, out targetlist))
                {
                    targetlist = new Dictionary<ulong, StubbleEntry>();
                    mModifiedEntries[lang] = targetlist;
                }
            }
            else if (target == StringSource.Loaded)
            {
                if (!mLoadedEntries.TryGetValue(lang, out targetlist))
                {
                    targetlist = new Dictionary<ulong, StubbleEntry>();
                    mLoadedEntries[lang] = targetlist;
                }
            }
            else
            {
                throw new InvalidOperationException();
            }

            int added = 0;
            foreach (KeyValuePair<UInt64, string> entry in entries)
            {
                if (overwrite != OverwriteMode.All)
                {
                    StubbleEntry oldentry;
                    if (targetlist.TryGetValue(entry.Key, out oldentry))
                    {
                        if (overwrite == OverwriteMode.None)
                            continue;

                        if (overwrite == OverwriteMode.Priority)
                        {
                            if ((UInt32)source.SourceTable.Instance >= (UInt32)oldentry.Source.SourceTable.Instance)
                                continue;
                        }
                        else
                        {
                            if (source.SourceTable != oldentry.Source.SourceTable
                                && (UInt32)source.SourceTable.Instance >= (UInt32)oldentry.Source.SourceTable.Instance)
                                continue;
                        }
                    }
                }

                StubbleEntry newentry = new StubbleEntry();
                newentry.Value = entry.Value;
                newentry.Source = source;
                targetlist[entry.Key] = newentry;
                added++;
            }
            return added;
        }
コード例 #22
0
 public WorkOverwriteEventArgs(int id, FileSystemInfoEx srcEntry, FileSystemInfoEx destEntry, OverwriteMode defOverwrite, bool defApplyToAll)
 {
     this.ID         = id;
     this.SrcEntry   = srcEntry;
     this.DestEntry  = destEntry;
     this.Overwrite  = defOverwrite;
     this.ApplyToAll = defApplyToAll;
 }
コード例 #23
0
        public async Task <PackageFromBuiltInFeedResource> PushPackage(string fileName, Stream contents, OverwriteMode overwriteMode, bool useDeltaCompression)
        {
            if (useDeltaCompression)
            {
                try
                {
                    var deltaResult = await AttemptDeltaPush(fileName, contents, overwriteMode).ConfigureAwait(false);

                    if (deltaResult != null)
                    {
                        return(deltaResult);
                    }
                }
                catch (TimeoutException ex)
                {
                    Logger.Info("Delta push timed out: " + ex.Message);

                    var verificationResult = await VerifyTransfer(fileName, contents).ConfigureAwait(false);

                    if (verificationResult != null)
                    {
                        return(verificationResult);
                    }
                }
                catch (Exception ex) when(!(ex is OctopusValidationException))
                {
                    Logger.Info("Something went wrong while performing a delta transfer: " + ex.Message);
                }

                Logger.Info("Falling back to pushing the complete package to the server");
            }
            else
            {
                Logger.Info("Pushing the complete package to the server, as delta compression was explicitly disabled");
            }

            var link = await repository.Link("PackageUpload").ConfigureAwait(false);

            object pathParameters;

            // if the link contains overwriteMode then we're connected to a new server, if not use the old `replace` parameter
            if (link.Contains(OverwriteModeLink.Link))
            {
                pathParameters = new { overwriteMode = overwriteMode };
            }
            else
            {
                pathParameters = new { replace = overwriteMode.ConvertToLegacyReplaceFlag(Logger) };
            }

            contents.Seek(0, SeekOrigin.Begin);

            try
            {
                return(await repository.Client.Post <FileUpload, PackageFromBuiltInFeedResource>(
                           link,
                           new FileUpload()
                {
                    Contents = contents, FileName = fileName
                },
                           pathParameters).ConfigureAwait(false));
            }
            catch (TimeoutException)
            {
                var verificationResult = await VerifyTransfer(fileName, contents);

                if (verificationResult != null)
                {
                    return(verificationResult);
                }

                throw;
            }
        }
コード例 #24
0
 public static void CreateCsvFile(string csvPathFileName, IEnumerable <string> databaseColumns, IEnumerable <Feature> features, string delimiter, OverwriteMode overWriteMode, Encoding encoding)
 {
     CreateFile(csvPathFileName, databaseColumns, features, delimiter, overWriteMode, encoding);
 }
コード例 #25
0
 protected static void SetDefaultOverwriteMode(int id, OverwriteMode mode)
 {
     lock (defaultOverwriteModeList)
     {
         if (defaultOverwriteModeList.ContainsKey(id))
             defaultOverwriteModeList.Remove(id);
         defaultOverwriteModeList.Add(id, mode);
     }
 }
コード例 #26
0
        private static void CreateFile(string pathFilename, IEnumerable <string> columns, IEnumerable <Feature> features, string delimiter, OverwriteMode overwriteMode,
                                       Encoding encoding)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var column in columns)
            {
                sb.Append(column);
                sb.Append(delimiter);
            }
            sb.Remove(sb.Length - 1, 1);
            sb.AppendLine();

            //foreach (var feature in features)
            //{
            //    foreach (var value in feature.ColumnValues)
            //    {
            //        sb.Append("\"");
            //        sb.Append(value.Value);
            //        sb.Append("\"");
            //        sb.Append(delimiter);
            //    }
            //    sb.Remove(sb.Length - 1, 1);
            //    sb.AppendLine();
            //}

            File.WriteAllText(pathFilename, sb.ToString());
        }
コード例 #27
0
 public void OverwriteMode_work(OverwriteMode mode, string expected)
 {
     mode.ToString().ShouldBe(expected);
 }
コード例 #28
0
        public int LoadEntries(StringSource target, StubbleSource source, Languages lang, OverwriteMode overwrite, IEnumerable <KeyValuePair <UInt64, string> > entries)
        {
            if (source.SourceTable == DBPFReference.MinValue && overwrite != OverwriteMode.All && overwrite != OverwriteMode.None)
            {
                throw new InvalidOperationException();
            }

            Dictionary <UInt64, StubbleEntry> targetlist;

            if (target == StringSource.Modified)
            {
                if (!mModifiedEntries.TryGetValue(lang, out targetlist))
                {
                    targetlist             = new Dictionary <ulong, StubbleEntry>();
                    mModifiedEntries[lang] = targetlist;
                }
            }
            else if (target == StringSource.Loaded)
            {
                if (!mLoadedEntries.TryGetValue(lang, out targetlist))
                {
                    targetlist           = new Dictionary <ulong, StubbleEntry>();
                    mLoadedEntries[lang] = targetlist;
                }
            }
            else
            {
                throw new InvalidOperationException();
            }

            int added = 0;

            foreach (KeyValuePair <UInt64, string> entry in entries)
            {
                if (overwrite != OverwriteMode.All)
                {
                    StubbleEntry oldentry;
                    if (targetlist.TryGetValue(entry.Key, out oldentry))
                    {
                        if (overwrite == OverwriteMode.None)
                        {
                            continue;
                        }

                        if (overwrite == OverwriteMode.Priority)
                        {
                            if ((UInt32)source.SourceTable.Instance >= (UInt32)oldentry.Source.SourceTable.Instance)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (source.SourceTable != oldentry.Source.SourceTable &&
                                (UInt32)source.SourceTable.Instance >= (UInt32)oldentry.Source.SourceTable.Instance)
                            {
                                continue;
                            }
                        }
                    }
                }

                StubbleEntry newentry = new StubbleEntry();
                newentry.Value        = entry.Value;
                newentry.Source       = source;
                targetlist[entry.Key] = newentry;
                added++;
            }
            return(added);
        }
コード例 #29
0
 private void Button3_Click(object sender, EventArgs e)
 {
     DlgResult = OverwriteMode.Cancel;
     Close();
 }
コード例 #30
0
ファイル: WorkBase.cs プロジェクト: Choi-Insu/arrengers
 protected void SetDefaultOverwriteMode(OverwriteMode value)
 {
     _overwrite = value;
 }
コード例 #31
0
ファイル: IExWork.cs プロジェクト: notsonormal/AstoundingDock
 public WorkOverwriteEventArgs(int id, FileSystemInfoEx srcEntry, FileSystemInfoEx destEntry, OverwriteMode defOverwrite, bool defApplyToAll)
 {
     this.ID = id;
     this.SrcEntry = srcEntry;
     this.DestEntry = destEntry;
     this.Overwrite = defOverwrite;
     this.ApplyToAll = defApplyToAll;
 }
コード例 #32
0
 private void Button2_Click(object sender, EventArgs e)
 {
     DlgResult = OverwriteMode.Reload;
     Close();
 }
コード例 #33
0
        private PackageFromBuiltInFeedResource AttemptDeltaPush(string fileName, Stream contents, OverwriteMode overwriteMode)
        {
            if (!repository.HasLink("PackageDeltaSignature"))
            {
                Logger.Info("Server does not support delta compression for package push");
                return(null);
            }

            if (!PackageIdentityParser.TryParsePackageIdAndVersion(Path.GetFileNameWithoutExtension(fileName), out var packageId, out var version))
            {
                Logger.Info("Could not determine the package ID and/or version based on the supplied filename");
                return(null);
            }

            PackageSignatureResource signatureResult;

            try
            {
                Logger.Info($"Requesting signature for delta compression from the server for upload of a package with id '{packageId}' and version '{version}'");
                signatureResult = repository.Client.Get <PackageSignatureResource>(repository.Link("PackageDeltaSignature"), new { packageId, version });
            }
            catch (OctopusResourceNotFoundException)
            {
                Logger.Info("No package with the same ID exists on the server");
                return(null);
            }

            using (var deltaTempFile = new TemporaryFile())
            {
                var shouldUpload = DeltaCompression.CreateDelta(contents, signatureResult, deltaTempFile.FileName);
                if (!shouldUpload)
                {
                    return(null);
                }

                using (var delta = File.OpenRead(deltaTempFile.FileName))
                {
                    var    link = repository.Link("PackageDeltaUpload");
                    object pathParameters;

                    // if the link contains overwriteMode then we're connected to a new server, if not use the old `replace` parameter
                    if (link.Contains(OverwriteModeLink.Link))
                    {
                        pathParameters = new { overwriteMode = overwriteMode, packageId, signatureResult.BaseVersion };
                    }
                    else
                    {
                        pathParameters = new { replace = overwriteMode == OverwriteMode.OverwriteExisting, packageId, signatureResult.BaseVersion };
                    }

                    var result = repository.Client.Post <FileUpload, PackageFromBuiltInFeedResource>(
                        link,
                        new FileUpload()
                    {
                        Contents = delta, FileName = Path.GetFileName(fileName)
                    },
                        pathParameters);

                    Logger.Info($"Delta transfer completed");
                    return(result);
                }
            }
        }
コード例 #34
0
 /* ----------------------------------------------------------------- */
 ///
 /// Execute
 ///
 /// <summary>
 /// 上書き内容を設定します。
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private void Execute(OverwriteMode mode)
 {
     OverwriteMode = mode;
     Close();
 }
コード例 #35
0
 public PackageFromBuiltInFeedResource PushPackage(string fileName, Stream contents, OverwriteMode overwriteMode)
 {
     return(PushPackage(fileName, contents, overwriteMode, useDeltaCompression: true));
 }
コード例 #36
0
        public OctopusPackageVersionBuildInformationMappedResource Push(string packageId, string version, OctopusBuildInformation octopusMetadata, OverwriteMode overwriteMode)
        {
            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentException("A package Id must be supplied", nameof(packageId));
            }
            if (string.IsNullOrWhiteSpace(version))
            {
                throw new ArgumentException("A version must be supplied", nameof(version));
            }

            if (!repository.HasLink("BuildInformation"))
            {
                throw new OperationNotSupportedByOctopusServerException(
                          OctopusBuildInformation.BuildInformationRequiresOctopusVersionMessage,
                          OctopusBuildInformation.BuildInformationRequiresOctopusVersion);
            }
            var link = repository.Link("BuildInformation");

            var resource = new OctopusPackageVersionBuildInformationResource
            {
                PackageId = packageId,
                Version   = version,
                OctopusBuildInformation = octopusMetadata,
            };

            return(repository.Client.Post <OctopusPackageVersionBuildInformationResource, OctopusPackageVersionBuildInformationMappedResource>(link, resource, new { overwriteMode = overwriteMode }));
        }
コード例 #37
0
        public PackageFromBuiltInFeedResource PushPackage(string fileName, Stream contents, OverwriteMode overwriteMode, bool useDeltaCompression)
        {
            if (useDeltaCompression)
            {
                try
                {
                    var deltaResult = AttemptDeltaPush(fileName, contents, overwriteMode);
                    if (deltaResult != null)
                    {
                        return(deltaResult);
                    }
                }
                catch (Exception ex) when(!(ex is OctopusValidationException))
                {
                    Logger.Info("Something went wrong while performing a delta transfer: " + ex.Message);
                }
                Logger.Info("Falling back to pushing the complete package to the server");
            }
            else
            {
                Logger.Info("Pushing the complete package to the server, as delta compression was explicitly disabled");
            }

            contents.Seek(0, SeekOrigin.Begin);

            var    link = repository.Link("PackageUpload");
            object pathParameters;

            // if the link contains overwriteMode then we're connected to a new server, if not use the old `replace` parameter
            if (link.Contains(OverwriteModeLink.Link))
            {
                pathParameters = new { overwriteMode = overwriteMode };
            }
            else
            {
                pathParameters = new { replace = overwriteMode == OverwriteMode.OverwriteExisting };
            }


            var result = repository.Client.Post <FileUpload, PackageFromBuiltInFeedResource>(
                link,
                new FileUpload()
            {
                Contents = contents, FileName = fileName
            },
                pathParameters);

            Logger.Info("Package transfer completed");

            return(result);
        }